Package net.jodah.concurrentunit

Examples of net.jodah.concurrentunit.Waiter


  /**
   * Asserts that a retryable invocation blocked on connection closure is interrupted by a
   * connection closure.
   */
  public void closeShouldInterruptWaitersOnRetryableClosure() throws Throwable {
    Waiter waiter = new Waiter();
    performInvocation(retryableConnectionShutdownSignal(), waiter);
  }
View Full Code Here


  /**
   * Asserts that a non-retryable invocation blocked on connection closure throws immediately.
   */
  public void closeShouldInterruptWaitersOnNonRetryableClosure() throws Throwable {
    Waiter waiter = new Waiter();
    performInvocation(nonRetryableConnectionShutdownSignal(), waiter);
  }
View Full Code Here

  void performRecovery(RetryableResource initialResource, RetryableResource recoveryResource,
      int expectedConnectionRecoveryAttempts, int expectedChannelRecoveryAttempts) throws Throwable {
    createResources();
    int expectedResumes = expectedConnectionRecoveryAttempts + expectedChannelRecoveryAttempts;

    final Waiter waiter = new Waiter();
    waiter.expectResumes(expectedResumes);
    config.withConnectionListeners(new DefaultConnectionListener() {
      @Override
      public void onChannelRecovery(Connection connection) {
        waiter.resume();
      }

      @Override
      public void onRecoveryFailure(Connection connection, Throwable failure) {
        waiter.resume();
      }
    });

    config.withChannelListeners(new DefaultChannelListener() {
      @Override
      public void onRecovery(Channel channel) {
        waiter.resume();
      }

      @Override
      public void onRecoveryFailure(Channel channel, Throwable failure) {
        waiter.resume();
      }
    });

    // Mock recovery handling
    mockRecovery(recoveryResource instanceof ConnectionHandler ? connectionShutdownSignal()
        : channelShutdownSignal(), recoveryResource);

    // Call initial shutdown listener
    callShutdownListener(initialResource,
        initialResource instanceof ConnectionHandler ? connectionShutdownSignal()
            : channelShutdownSignal());
    if (expectedResumes > 0)
      waiter.await(1000);
    Thread.sleep(100);
  }
View Full Code Here

    mockConnection();
    mockInvocation(invocationFailure);
    if (recoveryFailure != null)
      mockRecovery(recoveryFailure);

    final Waiter waiter = new Waiter();
    waiter.expectResume();
    runInThread(new Runnable() {
      public void run() {
        try {
          performInvocation();
          waiter.resume();
        } catch (Throwable t) {
          waiter.fail(t);
        }
      }
    });

    waiter.await(1000);
  }
View Full Code Here

  /**
   * Asserts that a retryable invocation blocked on channel closure is interrupted by a channel
   * closure.
   */
  public void closeShouldInterruptInvocationsOnRetryableChannelClosure() throws Throwable {
    Waiter waiter = new Waiter();
    performInvocation(retryableChannelShutdownSignal(), waiter);
  }
View Full Code Here

  /**
   * Asserts that a non-retryable invocation failure blocked on channel closure throws immediately.
   */
  public void closeShouldInterruptWaitersOnNonRetryableChannelClosure() throws Throwable {
    Waiter waiter = new Waiter();
    performInvocation(nonRetryableChannelShutdownSignal(), waiter);
  }
View Full Code Here

  /**
   * Asserts that a retryable invocation blocked on connection closure is interrupted by a channel
   * closure.
   */
  public void closeShouldInterruptWaitersOnRetryableConnectionClosure() throws Throwable {
    Waiter waiter = new Waiter();
    performInvocation(retryableConnectionShutdownSignal(), waiter);
  }
View Full Code Here

  /**
   * Asserts that a non-retryable invocation blocked on connection closure throws immediately.
   */
  public void closeShouldInterruptWaitersOnNonRetryableConnectionClosure() throws Throwable {
    Waiter waiter = new Waiter();
    performInvocation(nonRetryableConnectionShutdownSignal(), waiter);
  }
View Full Code Here

@Test
public class InterruptableWaiterTest {
  public void shouldInteruptForeverWaiters() throws Throwable {
    final InterruptableWaiter iw = new InterruptableWaiter();
    final Waiter waiter = new Waiter();
    waiter.expectResumes(3);

    for (int i = 0; i < 3; i++)
      new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            iw.await();
          } catch (InterruptedException expected) {
            waiter.resume();
          }
        }
      }).start();

    Thread.sleep(100);
    iw.interruptWaiters();
    waiter.await(500);
  }
View Full Code Here

    waiter.await(500);
  }

  public void shouldInterruptTimedWaiters() throws Throwable {
    final InterruptableWaiter iw = new InterruptableWaiter();
    final Waiter waiter = new Waiter();
    waiter.expectResumes(3);
   
    for (int i = 0; i < 3; i++)
      new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            iw.await(Duration.mins(1));
          } catch (InterruptedException expected) {
            waiter.resume();
          }
        }
      }).start();

    Thread.sleep(100);
    iw.interruptWaiters();
    waiter.await(500);
  }
View Full Code Here

TOP

Related Classes of net.jodah.concurrentunit.Waiter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.