Search in sources :

Example 1 with ClientDeliveryStateException

use of org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException in project qpid-protonj2 by apache.

the class SenderTest method testWaitForAcceptanceFailsIfRemoteSendsRejected.

@Test
void testWaitForAcceptanceFailsIfRemoteSendsRejected() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectTransfer().withNonNullPayload().withMore(false).respond().withSettled(true).withState().rejected();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        Sender sender = connection.openSender("test-queue").openFuture().get();
        Tracker tracker = sender.send(Message.create("Hello World"));
        try {
            tracker.awaitAccepted(10, TimeUnit.SECONDS);
            fail("Should not succeed since remote sent something other than Accepted");
        } catch (ClientDeliveryStateException dlvEx) {
        // Expected
        }
        assertTrue(tracker.remoteSettled());
        assertFalse(tracker.remoteState().isAccepted());
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectDetach().respond();
        peer.expectClose().respond();
        sender.closeAsync().get();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) ClientDeliveryStateException(org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 2 with ClientDeliveryStateException

use of org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException in project qpid-protonj2 by apache.

the class SenderTest method testWaitForAcceptanceFailsIfRemoteSendsNoDisposition.

@Test
void testWaitForAcceptanceFailsIfRemoteSendsNoDisposition() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectTransfer().withNonNullPayload().withMore(false).respond().withSettled(true);
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        Sender sender = connection.openSender("test-queue").openFuture().get();
        Tracker tracker = sender.send(Message.create("Hello World"));
        try {
            tracker.awaitAccepted(10, TimeUnit.SECONDS);
            fail("Should not succeed since remote sent something other than Accepted");
        } catch (ClientDeliveryStateException dlvEx) {
        // Expected
        }
        assertTrue(tracker.remoteSettled());
        assertNull(tracker.remoteState());
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectDetach().respond();
        peer.expectClose().respond();
        sender.closeAsync().get();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) ClientDeliveryStateException(org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

URI (java.net.URI)2 Client (org.apache.qpid.protonj2.client.Client)2 Connection (org.apache.qpid.protonj2.client.Connection)2 Sender (org.apache.qpid.protonj2.client.Sender)2 Tracker (org.apache.qpid.protonj2.client.Tracker)2 ClientDeliveryStateException (org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException)2 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)2 Test (org.junit.jupiter.api.Test)2