@Test(expected=IOException.class) public void testLongProtocolOpThrows() throws Exception { try (NatsTestServer ts = new NatsTestServer(false); NatsConnection nc = (NatsConnection) Nats.connect(ts.getURI())) { NatsConnectionReader reader = nc.getReader(); byte[] bytes = ("thisistoolong\r\n").getBytes(StandardCharsets.US_ASCII); reader.fakeReadForTest(bytes); reader.gatherOp(bytes.length); assertFalse(true); } }
@Test(expected = IllegalArgumentException.class) public void testThrowsWithoutSubject() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.publish(null, null); assertFalse(true); } }
@Test(expected=IllegalArgumentException.class) public void testThrowOnEmptyQueue() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.subscribe("subject", ""); assertFalse(true); } }
@Test(expected=IllegalArgumentException.class) public void testThrowOnNullSubjectWithQueue() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.subscribe(null, "quque"); assertFalse(true); } }
@Test(expected=IllegalArgumentException.class) public void testThrowOnEmptySubjectWithQueue() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.subscribe("", "quque"); assertFalse(true); } }
@Test(expected = IllegalArgumentException.class) public void testThrowsEmptySubject() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.request("", null); assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void throwsIfClosedOnPublish() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.close(); nc.publish("subject", "replyto", null); assertFalse(true); } }
@Test(expected=IllegalArgumentException.class) public void testThrowOnEmptySubject() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { Dispatcher d = nc.createDispatcher((msg) -> {}); d.subscribe(""); assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void throwsOnSubscribeIfClosed() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.close(); nc.subscribe("subject"); assertFalse(true); } }
@Test(expected=IllegalArgumentException.class) public void testThrowOnAsyncWithoutListener() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false)) { Options options = new Options.Builder(). server(ts.getURI()). build(); Nats.connectAsynchronously(options, false); } }
@Test(expected = IllegalStateException.class) public void throwsOnCreateIfClosed() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.close(); nc.createDispatcher((msg) -> {}); assertFalse(true); } }
@Test(expected=IllegalArgumentException.class) public void testThrowOnNullSubjectInUnsub() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { Dispatcher d = nc.createDispatcher((msg) -> {}); d.unsubscribe(null); assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void throwsIfClosed() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { nc.close(); nc.request("subject", null); assertFalse(true); } }
@Test(expected=IllegalStateException.class) public void testThrowOnConnClosed() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { Dispatcher d = nc.createDispatcher((msg) -> {}); nc.close(); nc.closeDispatcher(d); assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void throwsOnUnsubscribeIfClosed() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { Subscription sub = nc.subscribe("subject"); nc.close(); sub.unsubscribe(); assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void throwsOnSubscribeIfClosed() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { Dispatcher d = nc.createDispatcher((msg) -> {}); nc.close(); d.subscribe("subject"); assertFalse(true); } }
@Test(expected=IllegalStateException.class) public void testThrowOnSubscribeWhenClosed() throws IOException, InterruptedException, TimeoutException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { Dispatcher d = nc.createDispatcher((msg) -> {}); nc.closeDispatcher(d); d.subscribe("foo"); assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void testOnlyOneUnsubscribe() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus()); Subscription sub = nc.subscribe("subject"); sub.unsubscribe(); sub.unsubscribe(); // Will throw an exception assertFalse(true); } }
@Test(expected = IllegalStateException.class) public void throwsOnAutoUnsubscribeIfClosed() throws IOException, InterruptedException { try (NatsTestServer ts = new NatsTestServer(false); Connection nc = Nats.connect(ts.getURI())) { assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus()); Subscription sub = nc.subscribe("subject"); nc.close(); sub.unsubscribe(1); assertFalse(true); } }
@Test public void testDefaultPendingLimits() throws Exception { try (NatsTestServer ts = new NatsTestServer(false); NatsConnection nc = (NatsConnection) Nats.connect(ts.getURI())) { Subscription sub = nc.subscribe("subject"); Dispatcher d = nc.createDispatcher((Message m) -> {}); assertEquals(sub.getPendingMessageLimit(), Consumer.DEFAULT_MAX_MESSAGES); assertEquals(sub.getPendingByteLimit(), Consumer.DEFAULT_MAX_BYTES); assertEquals(d.getPendingMessageLimit(), Consumer.DEFAULT_MAX_MESSAGES); assertEquals(d.getPendingByteLimit(), Consumer.DEFAULT_MAX_BYTES); } }