io.nats.client.Options Java Examples

The following examples show how to use io.nats.client.Options. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReconnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testURISchemeNoIPTLSConnection() throws Exception {
    //System.setProperty("javax.net.debug", "all");
    TestSSLUtils.setKeystoreSystemParameters();
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tls_noip.conf", false)) {
        Options options = new Options.Builder().
                            server("tls://localhost:"+ts.getPort()).
                            maxReconnects(0).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #2
Source File: RequestTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequireCleanupOnCancel() throws IOException, ExecutionException, TimeoutException, InterruptedException {
    try (NatsTestServer ts = new NatsTestServer(false)) {
        Options options = new Options.Builder().server(ts.getURI()).requestCleanupInterval(Duration.ofHours(1)).build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
            
            Future<Message> incoming = nc.request("subject", null);
            incoming.cancel(true);

            assertEquals(1, ((NatsStatistics)nc.getStatistics()).getOutstandingRequests());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #3
Source File: RequestTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequireCleanupOnTimeout() throws IOException, ExecutionException, InterruptedException {
    try (NatsTestServer ts = new NatsTestServer(false)) {
        Options options = new Options.Builder().server(ts.getURI()).requestCleanupInterval(Duration.ofHours(1)).build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
            
            Future<Message> incoming = nc.request("subject", null);
            Message msg = null;
            
            try {
                msg = incoming.get(100, TimeUnit.MILLISECONDS);
                assertFalse(true);
            } catch(TimeoutException e) {
                assertTrue(true);
            }

            assertNull(msg);
            assertEquals(1, ((NatsStatistics)nc.getStatistics()).getOutstandingRequests());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #4
Source File: ConnectionListenerTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseCount() throws Exception {
    try (NatsTestServer ts = new NatsTestServer(false)) {
        TestHandler handler = new TestHandler();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            connectionListener(handler).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
            assertEquals(ts.getURI(), nc.getConnectedUrl());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            assertNull(nc.getConnectedUrl());
        }
        assertEquals(1, handler.getEventCount(Events.CLOSED));
    }
}
 
Example #5
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IOException.class)
public void testClientSecureServerNotMismatch() throws Exception {
    Connection nc = null;
    try (NatsTestServer ts = new NatsTestServer()) {
        SSLContext ctx = TestSSLUtils.createTestSSLContext();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            sslContext(ctx).
                            build();
        try {
            nc = Nats.connect(options);
        } finally {
            if (nc != null) {
                nc.close();
                assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            }
        }
    }
}
 
Example #6
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IOException.class)
public void testServerSecureClientNotMismatch() throws Exception {
    Connection nc = null;
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tlsverify.conf", false)) {
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            build();
        try {
            nc = Nats.connect(options);
        } finally {
            if (nc != null) {
                nc.close();
                assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            }
        }
    }
}
 
Example #7
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IOException.class)
public void testDisconnectOnUpgrade() throws Exception {
    Connection nc = null;
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tlsverify.conf", false)) {
        SSLContext ctx = TestSSLUtils.createTestSSLContext();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            dataPortType(CloseOnUpgradeAttempt.class.getCanonicalName()).
                            sslContext(ctx).
                            build();
        try {
            nc = Nats.connect(options);
        } finally {
            if (nc != null) {
                nc.close();
                assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            }
        }
    }
}
 
Example #8
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IOException.class)
public void testClientServerCertMismatch() throws Exception {
    Connection nc = null;
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tlsverify.conf", false)) {
        SSLContext ctx = TestSSLUtils.createEmptySSLContext();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            sslContext(ctx).
                            build();
        try {
            nc = Nats.connect(options);
        } finally {
            if (nc != null) {
                nc.close();
                assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            }
        }
    }
}
 
Example #9
Source File: ReconnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testURISchemeNoIPOpenTLSConnection() throws Exception {
    //System.setProperty("javax.net.debug", "all");
    TestSSLUtils.setKeystoreSystemParameters();
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tls_noip.conf", false)) {
        Options options = new Options.Builder().
                            server("opentls://localhost:"+ts.getPort()).
                            maxReconnects(0).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #10
Source File: PingTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testPingTimer() throws IOException, InterruptedException {
    try (NatsTestServer ts = new NatsTestServer(false)) {
        Options options = new Options.Builder().server(ts.getURI()).pingInterval(Duration.ofMillis(5)).build();
        NatsConnection nc = (NatsConnection) Nats.connect(options);
        NatsStatistics stats = nc.getNatsStatistics();

        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
            try {
                Thread.sleep(200); // should get 10+ pings
            } catch (Exception exp)
            {
                //Ignore
            }
            assertTrue("got pings", stats.getPings() > 10);
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #11
Source File: PingTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testPingFailsWhenClosed() throws Exception {
    try (NatsServerProtocolMock ts = new NatsServerProtocolMock(ExitAt.NO_EXIT)) {
        Options options = new Options.Builder().
                                        server(ts.getURI()).
                                        pingInterval(Duration.ofMillis(10)).
                                        maxPingsOut(5).
                                        maxReconnects(0).
                                        build();
        NatsConnection nc = (NatsConnection) Nats.connect(options);

        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
        }

        Future<Boolean> pong = nc.sendPing();

        assertFalse(pong.get(10,TimeUnit.MILLISECONDS));
    }
}
 
Example #12
Source File: PingTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMaxPingsOut() throws Exception {
    try (NatsServerProtocolMock ts = new NatsServerProtocolMock(ExitAt.NO_EXIT)) {
        Options options = new Options.Builder().
                                        server(ts.getURI()).
                                        pingInterval(Duration.ofSeconds(10)). // Avoid auto pings
                                        maxPingsOut(2).
                                        maxReconnects(0).
                                        build();
        NatsConnection nc = (NatsConnection) Nats.connect(options);

        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
            nc.sendPing();
            nc.sendPing();
            assertNull("No future returned when past max", nc.sendPing());
        } finally {
            nc.close();
        }
    }
}
 
Example #13
Source File: PingTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=TimeoutException.class)
public void testFlushTimeoutDisconnected() throws Exception {
    TestHandler handler = new TestHandler();
    try (NatsTestServer ts = new NatsTestServer(false)) {
        Options options = new Options.Builder().connectionListener(handler).server(ts.getURI()).build();
        NatsConnection nc = (NatsConnection) Nats.connect(options);

        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
            nc.flush(Duration.ofSeconds(2));
            handler.prepForStatusChange(Events.DISCONNECTED);
            ts.close();
            handler.waitForStatusChange(2, TimeUnit.SECONDS);
            nc.flush(Duration.ofSeconds(2));
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #14
Source File: ErrorListenerTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorOnNoAuth() throws Exception {
    String[] customArgs = {"--user","stephen","--pass","password"};
    TestHandler handler = new TestHandler();
    Connection nc = null;
    try (NatsTestServer ts = new NatsTestServer(customArgs, false)) {
        // See config file for user/pass
        Options options = new Options.Builder().
                    server(ts.getURI()).
                    maxReconnects(0).
                    errorListener(handler).
                    // skip this so we get an error userInfo("stephen", "password").
                    build();
        try {
            nc = Nats.connect(options);
        } catch(IOException e) {
            assertTrue(handler.getCount() > 0);
            assertEquals(1, handler.getErrorCount("Authorization Violation"));
        } finally {
            if (nc != null) {
                nc.close();
                assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            }
        }
    }
}
 
Example #15
Source File: ErrorListenerTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionInErrorHandler() throws Exception {
    String[] customArgs = {"--user","stephen","--pass","password"};
    BadHandler handler = new BadHandler();
    Connection nc = null;
    try (NatsTestServer ts = new NatsTestServer(customArgs, false)) {
        // See config file for user/pass
        Options options = new Options.Builder().
                    server(ts.getURI()).
                    maxReconnects(0).
                    errorListener(handler).
                    // skip this so we get an error userInfo("stephen", "password").
                    build();
        try {
            nc = Nats.connect(options);
            assertFalse(true);
        } catch(IOException e) {
            assertTrue(true);
        } finally {
            if (nc != null) {
                nc.close();
                assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
            }
        }
    }
}
 
Example #16
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testURISchemeOpenTLSConnection() throws Exception {
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tls.conf", false)) {
        Options options = new Options.Builder().
                            server("opentls://localhost:"+ts.getPort()).
                            maxReconnects(0).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #17
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testURISchemeIPTLSConnection() throws Exception {
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tlsverify.conf", false)) {
        Options options = new Options.Builder().
                            server("tls://127.0.0.1:"+ts.getPort()).
                            sslContext(TestSSLUtils.createTestSSLContext()). // override the custom one
                            maxReconnects(0).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #18
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testURISchemeTLSConnection() throws Exception {
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tlsverify.conf", false)) {
        Options options = new Options.Builder().
                            server("tls://localhost:"+ts.getPort()).
                            sslContext(TestSSLUtils.createTestSSLContext()). // override the custom one
                            maxReconnects(0).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #19
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenTLSConnection() throws Exception {
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tls.conf", false)) {
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            opentls().
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #20
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testVerifiedTLSConnection() throws Exception {
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tlsverify.conf", false)) {
        SSLContext ctx = TestSSLUtils.createTestSSLContext();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            sslContext(ctx).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #21
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleIPTLSConnection() throws Exception {
    //System.setProperty("javax.net.debug", "all");
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tls.conf", false)) {
        SSLContext ctx = TestSSLUtils.createTestSSLContext();
        Options options = new Options.Builder().
                            server("127.0.0.1:" + ts.getPort()).
                            maxReconnects(0).
                            sslContext(ctx).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #22
Source File: TLSConnectTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTLSConnection() throws Exception {
    //System.setProperty("javax.net.debug", "all");
    try (NatsTestServer ts = new NatsTestServer("src/test/resources/tls.conf", false)) {
        SSLContext ctx = TestSSLUtils.createTestSSLContext();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            maxReconnects(0).
                            sslContext(ctx).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
    }
}
 
Example #23
Source File: ParseTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testProtocolLineTooLong() throws Exception {
    try (NatsTestServer ts = new NatsTestServer(false);
            NatsConnection nc = (NatsConnection) Nats.connect(new Options.Builder().
                                                                server(ts.getURI()).
                                                                maxControlLine(1024).
                                                                build())) {
        NatsConnectionReader reader = nc.getReader();
        StringBuilder longString = new StringBuilder();

        longString.append("INFO ");
        for (int i=0;i<500;i++ ){
            longString.append("helloworld");
        }

        byte[] bytes = longString.toString().getBytes(StandardCharsets.US_ASCII);
        reader.fakeReadForTest(bytes);
        reader.gatherOp(bytes.length);
        reader.gatherProtocol(bytes.length);
        reader.parseProtocolMessage();
        assertFalse(true);
    }
}
 
Example #24
Source File: ParseTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IOException.class)
public void testMessageLineTooLong() throws Exception {
    try (NatsTestServer ts = new NatsTestServer(false);
            NatsConnection nc = (NatsConnection) Nats.connect(new Options.Builder().
                                                                server(ts.getURI()).
                                                                maxControlLine(16).
                                                                build())) {
        NatsConnectionReader reader = nc.getReader();
        byte[] bytes = ("MSG reallylongsubjectobreakthelength 1 1\r\n").getBytes(StandardCharsets.US_ASCII);
        reader.fakeReadForTest(bytes);
        reader.gatherOp(bytes.length);
        reader.gatherMessageProtocol(bytes.length);
        reader.parseProtocolMessage();
        assertFalse(true);
    }
}
 
Example #25
Source File: ConnectionListenerTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionInConnectionListener() throws Exception {
    try (NatsTestServer ts = new NatsTestServer(false)) {
        BadHandler handler = new BadHandler();
        Options options = new Options.Builder().
                            server(ts.getURI()).
                            connectionListener(handler).
                            build();
        Connection nc = Nats.connect(options);
        try {
            assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        } finally {
            nc.close();
            assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
        }
        assertTrue(((NatsConnection)nc).getNatsStatistics().getExceptions() > 0);
    }
}
 
Example #26
Source File: ErrorListenerTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionInSlowConsumerHandler() throws Exception {
    BadHandler handler = new BadHandler();
    try (NatsTestServer ts = new NatsTestServer(false);
            NatsConnection nc = (NatsConnection) Nats.connect(new Options.Builder().
                                                                server(ts.getURI()).
                                                                errorListener(handler).
                                                                build())) {
        
        Subscription sub = nc.subscribe("subject");
        sub.setPendingLimits(1, -1);

        nc.publish("subject", null);
        nc.publish("subject", null);
        nc.publish("subject", null);
        nc.publish("subject", null);

        nc.flush(Duration.ofMillis(5000));

        assertEquals(3, sub.getDroppedCount());

        nc.close(); // should force the exception handler through
        
        assertTrue(((NatsConnection)nc).getNatsStatistics().getExceptions()>0);
    }
}
 
Example #27
Source File: NatsMessageTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testBigProtocolLineWithBody() throws Exception {
    byte[] body = new byte[10];
    String subject = "subject";
    String replyTo = "reply";

    while (subject.length() <= Options.DEFAULT_MAX_CONTROL_LINE) {
        subject = subject + subject;
    }

    try (NatsServerProtocolMock ts = new NatsServerProtocolMock(ExitAt.NO_EXIT);
                NatsConnection nc = (NatsConnection) Nats.connect(ts.getURI())) {
        assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        
        nc.publish(subject, replyTo, body);
        assertFalse(true);
    }
}
 
Example #28
Source File: NatsMessageTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testBigProtocolLineWithoutBody() throws Exception {
    String subject = "subject";

    while (subject.length() <= Options.DEFAULT_MAX_CONTROL_LINE) {
        subject = subject + subject;
    }

    try (NatsServerProtocolMock ts = new NatsServerProtocolMock(ExitAt.NO_EXIT);
                NatsConnection nc = (NatsConnection) Nats.connect(ts.getURI())) {
        assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
        
        nc.subscribe(subject);
        assertFalse(true);
    }
}
 
Example #29
Source File: DrainTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testCreateDispatcherDuringDrainThrows() throws Exception {
    try (NatsTestServer ts = new NatsTestServer(false);
            Connection subCon = Nats.connect(new Options.Builder().server(ts.getURI()).maxReconnects(0).build());
            Connection pubCon = Nats.connect(new Options.Builder().server(ts.getURI()).maxReconnects(0).build())) {
        assertTrue("Connected Status", Connection.Status.CONNECTED == subCon.getStatus());
        assertTrue("Connected Status", Connection.Status.CONNECTED == pubCon.getStatus());

        subCon.subscribe("draintest");
        subCon.flush(Duration.ofSeconds(1)); // Get the sub to the server

        pubCon.publish("draintest", null);
        pubCon.publish("draintest", null);
        pubCon.flush(Duration.ofSeconds(1));

        subCon.flush(Duration.ofSeconds(1));

        CompletableFuture<Boolean> tracker = subCon.drain(Duration.ofSeconds(500));

        subCon.createDispatcher((msg) -> {
        });
        assertTrue(tracker.get(1000, TimeUnit.SECONDS));
    }
}
 
Example #30
Source File: DrainTests.java    From nats.java with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testSubDuringDrainThrows() throws Exception {
    try (NatsTestServer ts = new NatsTestServer(false);
            Connection subCon = Nats.connect(new Options.Builder().server(ts.getURI()).maxReconnects(0).build());
            Connection pubCon = Nats.connect(new Options.Builder().server(ts.getURI()).maxReconnects(0).build())) {
        assertTrue("Connected Status", Connection.Status.CONNECTED == subCon.getStatus());
        assertTrue("Connected Status", Connection.Status.CONNECTED == pubCon.getStatus());

        subCon.subscribe("draintest");
        subCon.flush(Duration.ofSeconds(1)); // Get the sub to the server

        pubCon.publish("draintest", null);
        pubCon.publish("draintest", null);
        pubCon.flush(Duration.ofSeconds(1));

        subCon.flush(Duration.ofSeconds(1));

        CompletableFuture<Boolean> tracker = subCon.drain(Duration.ofSeconds(500));

        // Try to subscribe while we are draining the sub
        subCon.subscribe("another"); // Should throw
        assertTrue(tracker.get(1000, TimeUnit.SECONDS));
    }
}