Search in sources :

Example 51 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.

the class ProtonClientTest method remoteCloseDefaultSessionTestImpl.

private void remoteCloseDefaultSessionTestImpl(TestContext context, boolean sessionError) throws InterruptedException, ExecutionException {
    server.close();
    Async async = context.async();
    ProtonServer protonServer = null;
    try {
        protonServer = createServer(serverConnection -> {
            Promise<ProtonSession> sessionPromise = Promise.<ProtonSession>promise();
            // Expect a session to open, when the sender is created by the client
            serverConnection.sessionOpenHandler(serverSession -> {
                LOG.trace("Server session open");
                serverSession.open();
                sessionPromise.complete(serverSession);
            });
            // Expect a receiver link, then close the session after opening it.
            serverConnection.receiverOpenHandler(serverReceiver -> {
                LOG.trace("Server receiver open");
                serverReceiver.open();
                context.assertTrue(sessionPromise.future().succeeded(), "Session future not [yet] succeeded");
                LOG.trace("Server session close");
                ProtonSession s = sessionPromise.future().result();
                if (sessionError) {
                    ErrorCondition error = new ErrorCondition();
                    error.setCondition(AmqpError.INTERNAL_ERROR);
                    error.setDescription("error description");
                    s.setCondition(error);
                }
                s.close();
            });
            serverConnection.openHandler(result -> {
                LOG.trace("Server connection open");
                serverConnection.open();
            });
        });
        // ===== Client Handling =====
        ProtonClient client = ProtonClient.create(vertx);
        client.connect("localhost", protonServer.actualPort(), res -> {
            context.assertTrue(res.succeeded());
            ProtonConnection connection = res.result();
            connection.openHandler(x -> {
                context.assertTrue(x.succeeded(), "Connection open failed");
                LOG.trace("Client connection opened");
                // Create a sender to provoke creation (and subsequent
                // closure of by the server) the connections default session
                connection.createSender(null).open();
            });
            connection.closeHandler(x -> {
                LOG.trace("Connection close handler called (as espected): " + x.cause());
                async.complete();
            });
            connection.open();
        });
        async.awaitSuccess();
    } finally {
        if (protonServer != null) {
            protonServer.close();
        }
    }
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) LinkedHashMap(java.util.LinkedHashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Modified(org.apache.qpid.proton.amqp.messaging.Modified) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProtonHelper.message(io.vertx.proton.ProtonHelper.message) Target(org.apache.qpid.proton.amqp.transport.Target) Map(java.util.Map) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) WritableBuffer(org.apache.qpid.proton.codec.WritableBuffer) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Message(org.apache.qpid.proton.message.Message) AsyncResult(io.vertx.core.AsyncResult) Binary(org.apache.qpid.proton.amqp.Binary) AmqpError(org.apache.qpid.proton.amqp.transport.AmqpError) Logger(io.vertx.core.impl.logging.Logger) Data(org.apache.qpid.proton.amqp.messaging.Data) ProtonServerImpl(io.vertx.proton.impl.ProtonServerImpl) LinkError(org.apache.qpid.proton.amqp.transport.LinkError) Promise(io.vertx.core.Promise) ProtonMetaDataSupportImpl(io.vertx.proton.impl.ProtonMetaDataSupportImpl) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) Proton(org.apache.qpid.proton.Proton) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Source(org.apache.qpid.proton.amqp.messaging.Source) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Mockito(org.mockito.Mockito) Section(org.apache.qpid.proton.amqp.messaging.Section) NetServer(io.vertx.core.net.NetServer) ProtonConnectionImpl(io.vertx.proton.impl.ProtonConnectionImpl) Handler(io.vertx.core.Handler) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) Collections(java.util.Collections) Promise(io.vertx.core.Promise) Async(io.vertx.ext.unit.Async) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Example 52 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.

the class MessagePublisherVerificationTckTest method createServer.

private TestServer createServer() throws Exception {
    return new TestServer(vertx, (connection) -> {
        connection.openHandler(res -> {
            LOG.trace("Client connected: " + connection.getRemoteContainer());
            connection.open();
        }).closeHandler(c -> {
            LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
            connection.close();
            connection.disconnect();
        }).disconnectHandler(c -> {
            LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
            connection.disconnect();
        }).sessionOpenHandler(session -> session.open());
        connection.senderOpenHandler(sender -> {
            if (!server.getDetachLink()) {
                LOG.trace("Sending to client from: " + sender.getRemoteSource().getAddress());
                // This is rather naive, for example use only, proper
                sender.setSource(sender.getRemoteSource());
                // servers should ensure that they advertise their own
                // Source settings that actually reflect what is in place.
                // The request may have also been for a dynamic address.
                AtomicLong count = new AtomicLong();
                AtomicLong outstanding = new AtomicLong();
                sender.sendQueueDrainHandler(s -> {
                    while (!s.sendQueueFull()) {
                        LOG.trace("Sending message to client");
                        Message m = message("Hello World from Server!" + count.incrementAndGet());
                        outstanding.incrementAndGet();
                        s.send(m, delivery -> {
                            LOG.trace("The message was received by the client.");
                        });
                    }
                });
                sender.closeHandler(s -> {
                    s.result().close();
                });
            }
            sender.open();
            if (server.getDetachLink()) {
                sender.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Publisher Requested"), ""));
                sender.close();
            }
        });
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonStreams(io.vertx.proton.streams.ProtonStreams) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) MockServer(io.vertx.proton.MockServer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProtonPublisherWrapperImpl(io.vertx.proton.streams.impl.ProtonPublisherWrapperImpl) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProtonHelper.message(io.vertx.proton.ProtonHelper.message) Symbol(org.apache.qpid.proton.amqp.Symbol) PublisherVerification(org.reactivestreams.tck.PublisherVerification) Message(org.apache.qpid.proton.message.Message) Method(java.lang.reflect.Method) Logger(io.vertx.core.impl.logging.Logger) Publisher(org.reactivestreams.Publisher) BeforeMethod(org.testng.annotations.BeforeMethod) Vertx(io.vertx.core.Vertx) ProtonClient(io.vertx.proton.ProtonClient) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) TestEnvironment(org.reactivestreams.tck.TestEnvironment) ProtonPublisher(io.vertx.proton.streams.ProtonPublisher) Handler(io.vertx.core.Handler) AtomicLong(java.util.concurrent.atomic.AtomicLong) Message(org.apache.qpid.proton.message.Message) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Example 53 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.

the class ProtonReceiverImpl method handleMaxMessageSizeExceeded.

private void handleMaxMessageSizeExceeded(final UnsignedLong maxMessageSize, final Receiver receiver) {
    try {
        LOG.debug("delivery received exceeding max-message-size of " + maxMessageSize + " bytes");
        if (maxMessageSizeExceededHandler != null) {
            maxMessageSizeExceededHandler.handle(this);
        }
    } finally {
        // Detach link if handler has not sent a detach frame already
        if (!receiver.detached() && isOpen()) {
            LOG.debug("detaching link with error condition " + LinkError.MESSAGE_SIZE_EXCEEDED);
            setCondition(new ErrorCondition(LinkError.MESSAGE_SIZE_EXCEEDED, "exceeded max-message-size of " + maxMessageSize + " bytes "));
            detach();
        }
    }
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Example 54 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.

the class DeliveryPublisherVerificationTckTest method createServer.

private TestServer createServer() throws Exception {
    return new TestServer(vertx, (connection) -> {
        connection.openHandler(res -> {
            LOG.trace("Client connected: " + connection.getRemoteContainer());
            connection.open();
        }).closeHandler(c -> {
            LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
            connection.close();
            connection.disconnect();
        }).disconnectHandler(c -> {
            LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
            connection.disconnect();
        }).sessionOpenHandler(session -> session.open());
        connection.senderOpenHandler(sender -> {
            if (!server.getDetachLink()) {
                LOG.trace("Sending to client from: " + sender.getRemoteSource().getAddress());
                // This is rather naive, for example use only, proper
                sender.setSource(sender.getRemoteSource());
                // servers should ensure that they advertise their own
                // Source settings that actually reflect what is in place.
                // The request may have also been for a dynamic address.
                AtomicLong count = new AtomicLong();
                AtomicLong outstanding = new AtomicLong();
                sender.sendQueueDrainHandler(s -> {
                    while (!s.sendQueueFull()) {
                        LOG.trace("Sending message to client");
                        Message m = message("Hello World from Server!" + count.incrementAndGet());
                        outstanding.incrementAndGet();
                        s.send(m, delivery -> {
                            LOG.trace("The message was received by the client.");
                        });
                    }
                });
                sender.closeHandler(s -> {
                    s.result().close();
                });
            }
            sender.open();
            if (server.getDetachLink()) {
                sender.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Publisher Requested"), ""));
                sender.close();
            }
        });
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonStreams(io.vertx.proton.streams.ProtonStreams) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) MockServer(io.vertx.proton.MockServer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) Delivery(io.vertx.proton.streams.Delivery) ProtonHelper.message(io.vertx.proton.ProtonHelper.message) Symbol(org.apache.qpid.proton.amqp.Symbol) PublisherVerification(org.reactivestreams.tck.PublisherVerification) Message(org.apache.qpid.proton.message.Message) Method(java.lang.reflect.Method) Logger(io.vertx.core.impl.logging.Logger) Publisher(org.reactivestreams.Publisher) BeforeMethod(org.testng.annotations.BeforeMethod) Vertx(io.vertx.core.Vertx) ProtonClient(io.vertx.proton.ProtonClient) ProtonPublisherImpl(io.vertx.proton.streams.impl.ProtonPublisherImpl) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) TestEnvironment(org.reactivestreams.tck.TestEnvironment) ProtonPublisher(io.vertx.proton.streams.ProtonPublisher) Handler(io.vertx.core.Handler) AtomicLong(java.util.concurrent.atomic.AtomicLong) Message(org.apache.qpid.proton.message.Message) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Example 55 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.

the class TrackerSubscriberWhiteboxVerificationTckTest method createServer.

private TestServer createServer() throws Exception {
    return new TestServer(vertx, (connection) -> {
        connection.openHandler(res -> {
            LOG.trace("Client connected: " + connection.getRemoteContainer());
            connection.open();
        }).closeHandler(c -> {
            LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
            connection.close();
            connection.disconnect();
        }).disconnectHandler(c -> {
            LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
            connection.disconnect();
        }).sessionOpenHandler(session -> session.open());
        connection.receiverOpenHandler(receiver -> {
            if (!server.getDetachLink()) {
                LOG.trace("Receiving from client to: " + receiver.getRemoteTarget().getAddress());
                // This is rather naive, for example use only, proper
                receiver.setTarget(receiver.getRemoteTarget());
                // servers should ensure that they advertise their own
                // Target settings that actually reflect what is in place.
                // The request may have also been for a dynamic address.
                receiver.handler((delivery, msg) -> {
                    String address = msg.getAddress();
                    if (address == null) {
                        address = receiver.getRemoteTarget().getAddress();
                    }
                    Section body = msg.getBody();
                    String content = "unknown";
                    if (body instanceof AmqpValue) {
                        content = (String) ((AmqpValue) body).getValue();
                    }
                    LOG.trace("message to:" + address + ", body: " + content);
                });
                receiver.closeHandler(s -> {
                    s.result().close();
                });
            }
            receiver.open();
            if (server.getDetachLink()) {
                receiver.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Subscriber Requested"), ""));
                receiver.close();
            }
        });
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) SubscriberWhiteboxVerification(org.reactivestreams.tck.SubscriberWhiteboxVerification) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) MockServer(io.vertx.proton.MockServer) ProtonSubscriberImpl(io.vertx.proton.streams.impl.ProtonSubscriberImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) Symbol(org.apache.qpid.proton.amqp.Symbol) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Message(org.apache.qpid.proton.message.Message) Subscriber(org.reactivestreams.Subscriber) Logger(io.vertx.core.impl.logging.Logger) Tracker(io.vertx.proton.streams.Tracker) BeforeMethod(org.testng.annotations.BeforeMethod) Vertx(io.vertx.core.Vertx) ProtonClient(io.vertx.proton.ProtonClient) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Proton(org.apache.qpid.proton.Proton) CountDownLatch(java.util.concurrent.CountDownLatch) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Section(org.apache.qpid.proton.amqp.messaging.Section) ProtonSubscriber(io.vertx.proton.streams.ProtonSubscriber) TestEnvironment(org.reactivestreams.tck.TestEnvironment) Subscription(org.reactivestreams.Subscription) ProtonConnectionImpl(io.vertx.proton.impl.ProtonConnectionImpl) Handler(io.vertx.core.Handler) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Section(org.apache.qpid.proton.amqp.messaging.Section) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue)

Aggregations

ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)67 Handler (io.vertx.core.Handler)22 ProtonConnection (io.vertx.proton.ProtonConnection)20 Symbol (org.apache.qpid.proton.amqp.Symbol)20 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)17 Message (org.apache.qpid.proton.message.Message)17 TimeUnit (java.util.concurrent.TimeUnit)14 Vertx (io.vertx.core.Vertx)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 UnsignedLong (org.apache.qpid.proton.amqp.UnsignedLong)12 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)12 ProtonReceiver (io.vertx.proton.ProtonReceiver)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Test (org.junit.Test)11 Future (io.vertx.core.Future)10 Promise (io.vertx.core.Promise)10 ProtonSender (io.vertx.proton.ProtonSender)10 AsyncResult (io.vertx.core.AsyncResult)9 Map (java.util.Map)9