SchedulerLifecycle implements EventSubscriber { public LeadershipListener prepare() { stateMachine.transition(State.PREPARING_STORAGE); return leadershipListener; } @Inject  SchedulerLifecycle(
      NonVolatileStorage storage,
      Lifecycle lifecycle,
      Driver driver,
      LeadingOptions leadingOptions,
      ScheduledExecutorService executorService,
      ShutdownRegistry shutdownRegistry,
      StatsProvider statsProvider,
      @SchedulerActive ServiceManagerIface schedulerActiveServiceManager); @VisibleForTesting  SchedulerLifecycle(
      final NonVolatileStorage storage,
      final Lifecycle lifecycle,
      final Driver driver,
      final DelayedActions delayedActions,
      final ShutdownRegistry shutdownRegistry,
      StatsProvider statsProvider,
      final ServiceManagerIface schedulerActiveServiceManager); LeadershipListener prepare(); @Subscribe void registered(DriverRegistered event);  }
@Test public void testRegistrationTimeout() throws Exception { storageUtil.storage.prepare(); expectLoadStorage(); delayedActions.onAutoFailover(EasyMock.anyObject()); Capture<Runnable> registrationTimeout = createCapture(); delayedActions.onRegistrationTimeout(capture(registrationTimeout)); expect(driver.startAsync()).andReturn(driver); driver.awaitRunning(); expectShutdown(); replayAndCreateLifecycle(); LeadershipListener leaderListener = schedulerLifecycle.prepare(); leaderListener.onLeading(leaderControl); registrationTimeout.getValue().run(); }
@Test public void testDefeatedBeforeRegistered() throws Exception { storageUtil.storage.prepare(); expectLoadStorage(); delayedActions.onAutoFailover(EasyMock.anyObject()); delayedActions.onRegistrationTimeout(EasyMock.anyObject()); expect(driver.startAsync()).andReturn(driver); driver.awaitRunning(); expectShutdown(); replayAndCreateLifecycle(); LeadershipListener leaderListener = schedulerLifecycle.prepare(); leaderListener.onLeading(leaderControl); leaderListener.onDefeated(); }
@Test public void testStorageStartFails() throws Exception { storageUtil.storage.prepare(); storageUtil.expectOperations(); storageUtil.storage.start(EasyMock.anyObject()); expectLastCall().andThrow(new StorageException("Recovery failed.")); expectShutdown(); replayAndCreateLifecycle(); LeadershipListener leaderListener = schedulerLifecycle.prepare(); try { leaderListener.onLeading(leaderControl); fail(); } catch (StorageException e) { } }