Exemplo n.º 1
0
  @Test
  public void shouldReturnFalseIfPullerInitiallyInactiveNonStrict() throws Exception {
    // GIVEN
    Condition condition = mock(Condition.class);
    updatePuller.pause();

    // WHEN
    boolean result = updatePuller.await(condition, false);

    // THEN
    assertFalse(result);
    verifyNoMoreInteractions(condition);
  }
Exemplo n.º 2
0
  @Test
  public void shouldThrowIfPullerInitiallyInactiveStrict() throws Exception {
    // GIVEN
    Condition condition = mock(Condition.class);
    updatePuller.pause();

    // WHEN
    try {
      updatePuller.await(condition, true);
      fail("Should have thrown");
    } catch (IllegalStateException e) { // THEN Good
      verifyNoMoreInteractions(condition);
    }
  }
  /**
   * Triggers pulling of updates up until at least {@code toTxId} if no pulling is currently
   * happening and returns immediately.
   *
   * @return {@link Future} which will block on {@link Future#get()} until {@code toTxId} has been
   *     applied.
   */
  @Override
  public void fulfill(final long toTxId) throws InterruptedException {
    if (!updatePuller.isActive()) {
      throw new IllegalStateException("Update puller not active " + updatePuller);
    }

    updatePuller.await(
        new Condition() {
          @Override
          public boolean evaluate(int currentTicket, int targetTicket) {
            /**
             * We need to await last *closed* transaction id, not last *committed* transaction id
             * since right after leaving this method we might read records off of disk, and they had
             * better be up to date, otherwise we read stale data.
             */
            return transactionIdStore.getLastClosedTransactionId() >= toTxId;
          }
        });
  }
Exemplo n.º 4
0
  @Test
  public void shouldReturnFalseIfPullerBecomesInactiveWhileWaitingNonStrict() throws Exception {
    // GIVEN
    Condition condition = mock(Condition.class);
    updatePuller.unpause();
    when(condition.evaluate(anyInt(), anyInt()))
        .thenAnswer(
            new Answer<Boolean>() {
              @Override
              public Boolean answer(InvocationOnMock invocation) throws Throwable {
                updatePuller.pause();
                return false;
              }
            });

    // WHEN
    boolean result = updatePuller.await(condition, false);

    // THEN
    assertFalse(result);
    verify(condition, times(1)).evaluate(anyInt(), anyInt());
  }
Exemplo n.º 5
0
  @Test
  public void shouldThrowIfPullerBecomesInactiveWhileWaitingStrict() throws Exception {
    // GIVEN
    Condition condition = mock(Condition.class);
    updatePuller.unpause();
    when(condition.evaluate(anyInt(), anyInt()))
        .thenAnswer(
            new Answer<Boolean>() {
              @Override
              public Boolean answer(InvocationOnMock invocation) throws Throwable {
                updatePuller.pause();
                return false;
              }
            });

    // WHEN
    try {
      updatePuller.await(condition, true);
      fail("Should have thrown");
    } catch (IllegalStateException e) { // THEN Good
      verify(condition, times(1)).evaluate(anyInt(), anyInt());
    }
  }