示例#1
0
  @Test
  public void shouldResumePullingUpdatesWhenThisInstanceSwitchesFromSlaveToMaster()
      throws Throwable {
    final UpdatePullerClient puller =
        new UpdatePullerClient(1, scheduler, logging, updatePuller, availabilityGuard);

    puller.init();
    puller.start();
    updatePuller.unpause();
    scheduler.runJob();

    verify(lastUpdateTime, times(1)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(1)).isAvailable(anyLong());
    verify(master, times(1)).pullUpdates(Matchers.<RequestContext>any());

    scheduler.runJob();

    verify(lastUpdateTime, times(2)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(2)).isAvailable(anyLong());
    verify(master, times(2)).pullUpdates(Matchers.<RequestContext>any());

    stateMachine.masterIsElected(); // pauses the update puller

    verifyNoMoreInteractions(lastUpdateTime, availabilityGuard);
  }
示例#2
0
  @Test
  public void shouldResumePullingUpdatesWhenThisInstanceSwitchesFromMasterToSlave()
      throws Throwable {
    // GIVEN
    final UpdatePullerClient puller =
        new UpdatePullerClient(1, scheduler, logging, updatePuller, availabilityGuard);

    // WHEN
    puller.init();
    puller.start();
    updatePuller.unpause();
    scheduler.runJob();

    // THEN
    verify(lastUpdateTime, times(1)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(1)).isAvailable(anyLong());
    verify(master, times(1)).pullUpdates(Matchers.<RequestContext>any());

    stateMachine.masterIsElected(); // pauses the update puller

    // This job should be ignored, since I'm now master
    scheduler.runJob();

    updatePuller.unpause();

    scheduler.runJob();

    verify(lastUpdateTime, times(2)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(2)).isAvailable(anyLong());
    verify(master, times(2)).pullUpdates(Matchers.<RequestContext>any());
  }
示例#3
0
  @Test
  public void shouldStartAndStopPullingUpdatesWhenStartAndStopIsCalled() throws Throwable {
    // GIVEN
    final UpdatePullerClient puller =
        new UpdatePullerClient(1, scheduler, logging, updatePuller, availabilityGuard);

    // WHEN
    puller.init();

    // THEN
    // Asserts the puller set the job
    assertNotNull(scheduler.getJob());

    puller.start();
    updatePuller.unpause();
    scheduler.runJob();

    verify(lastUpdateTime, times(1)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(1)).isAvailable(anyLong());
    verify(master, times(1)).pullUpdates(Matchers.<RequestContext>any());

    updatePuller.stop();
    scheduler.runJob();

    verifyNoMoreInteractions(lastUpdateTime, availabilityGuard);
  }
示例#4
0
  @Test
  public void shouldNotStartPullingUpdatesUntilStartIsCalled() throws Throwable {
    // GIVEN
    final UpdatePullerClient puller =
        new UpdatePullerClient(1, scheduler, logging, updatePuller, availabilityGuard);

    // WHEN
    puller.init();

    // THEN
    // Asserts the puller set the job
    assertNotNull(scheduler.getJob());
    scheduler.runJob();
    verifyZeroInteractions(lastUpdateTime, availabilityGuard);
  }
示例#5
0
  @Test
  public void shouldKeepPullingUpdatesWhenThisInstanceBecomesASlave() throws Throwable {
    // GIVEN
    final UpdatePullerClient puller =
        new UpdatePullerClient(1, scheduler, logging, updatePuller, availabilityGuard);

    // WHEN
    puller.init();
    puller.start();
    updatePuller.unpause();
    scheduler.runJob();

    // THEN
    verify(lastUpdateTime, times(1)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(1)).isAvailable(anyLong());
    verify(master, times(1)).pullUpdates(Matchers.<RequestContext>any());

    scheduler.runJob();

    verify(lastUpdateTime, times(2)).setLastUpdateTime(anyLong());
    verify(availabilityGuard, times(2)).isAvailable(anyLong());
    verify(master, times(2)).pullUpdates(Matchers.<RequestContext>any());
  }