コード例 #1
0
  @Test
  public void testInitialResource() {
    Disposable r = mock(Disposable.class);
    AsyncSubscription as = new AsyncSubscription(r);

    as.cancel();

    verify(r).dispose();
  }
コード例 #2
0
  @Test
  public void testReplaceResourceAfterCancel() {
    AsyncSubscription as = new AsyncSubscription();
    as.cancel();

    Disposable r = mock(Disposable.class);

    assertFalse(as.replaceResource(r));

    verify(r).dispose();
  }
コード例 #3
0
  @Test
  public void testSetResource() {
    AsyncSubscription as = new AsyncSubscription();

    Disposable r = mock(Disposable.class);

    assertTrue(as.setResource(r));

    as.cancel();

    verify(r).dispose();
  }
コード例 #4
0
  @Test
  public void testCancelBeforeSet() {
    AsyncSubscription as = new AsyncSubscription();

    Subscription s = mock(Subscription.class);

    as.request(1);
    as.cancel();

    assertFalse(as.setSubscription(s));

    verify(s, never()).request(1);
    verify(s).cancel();
  }
コード例 #5
0
  @Test
  public void testNoResource() {
    AsyncSubscription as = new AsyncSubscription();

    Subscription s = mock(Subscription.class);

    assertTrue(as.setSubscription(s));

    as.request(1);

    as.cancel();

    verify(s).request(1);
    verify(s).cancel();
  }
コード例 #6
0
  @Test
  public void testSingleSet() {
    AsyncSubscription as = new AsyncSubscription();

    Subscription s = mock(Subscription.class);

    assertTrue(as.setSubscription(s));

    Subscription s1 = mock(Subscription.class);

    assertTrue(as.setSubscription(s1));

    assertSame(as.actual, s);

    verify(s1).cancel();
  }
コード例 #7
0
  @Test
  public void testCancelOnce() {
    Disposable r = mock(Disposable.class);
    AsyncSubscription as = new AsyncSubscription(r);
    Subscription s = mock(Subscription.class);

    assertTrue(as.setSubscription(s));

    as.cancel();
    as.cancel();
    as.cancel();

    verify(s, never()).request(anyLong());
    verify(s).cancel();
    verify(r).dispose();
  }
コード例 #8
0
  @Test
  public void testReplaceResource2() {
    AsyncSubscription as = new AsyncSubscription();

    Disposable r = mock(Disposable.class);

    assertTrue(as.replaceResource(r));

    Disposable r2 = mock(Disposable.class);

    assertTrue(as.replaceResource(r2));

    as.cancel();

    verify(r, never()).dispose();
    verify(r2).dispose();
  }
コード例 #9
0
    @Override
    public void run() {

      try {
        logger.trace("NATS Subscriber ({}):  Subscribing to subject: {}", id, subject);

        io.nats.client.Connection c = new ConnectionFactory().createConnection();

        AsyncSubscription s = c.subscribeAsync(subject, this);
        s.start();

        setReady();

        logger.debug("NATS Subscriber ({}):  Subscribing to subject: {}", id, subject);

        waitForCompletion();

        s.unsubscribe();

        logger.debug("NATS Subscriber ({}):  Exiting.", id);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }