@Test public void testInitialResource() { Disposable r = mock(Disposable.class); AsyncSubscription as = new AsyncSubscription(r); as.cancel(); verify(r).dispose(); }
@Test public void testReplaceResourceAfterCancel() { AsyncSubscription as = new AsyncSubscription(); as.cancel(); Disposable r = mock(Disposable.class); assertFalse(as.replaceResource(r)); verify(r).dispose(); }
@Test public void testSetResource() { AsyncSubscription as = new AsyncSubscription(); Disposable r = mock(Disposable.class); assertTrue(as.setResource(r)); as.cancel(); verify(r).dispose(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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(); }
@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(); } }