Search in sources :

Example 16 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project azure-iot-sdk-java by Azure.

the class AmqpFileUploadNotificationReceivedHandlerTest method createProtonObjects.

private void createProtonObjects() {
    final String exceptionMessage = "Not expected function called";
    message = Proton.message();
    receiver = new Receiver() {

        @Override
        public void flow(int i) {
        }

        @Override
        public ReadableBuffer recv() {
            return readBuf;
        }

        @Override
        public int recv(byte[] bytes, int i, int i1) {
            return 0;
        }

        @Override
        public int recv(WritableBuffer writableBuffer) {
            return 0;
        }

        @Override
        public void drain(int i) {
        }

        @Override
        public boolean advance() {
            return false;
        }

        @Override
        public boolean draining() {
            return false;
        }

        @Override
        public void setDrain(boolean b) {
        }

        @Override
        public String getName() {
            return "filenotificationreceiver";
        }

        @Override
        public Delivery delivery(byte[] bytes) {
            return null;
        }

        @Override
        public Delivery delivery(byte[] bytes, int i, int i1) {
            return null;
        }

        @Override
        public Delivery head() {
            return null;
        }

        @Override
        public Delivery current() {
            return delivery;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Source getSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getTarget() {
            return null;
        }

        @Override
        public void setSource(org.apache.qpid.proton.amqp.transport.Source source) {
        }

        @Override
        public void setTarget(org.apache.qpid.proton.amqp.transport.Target target) {
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Source getRemoteSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getRemoteTarget() {
            return null;
        }

        @Override
        public Link next(EnumSet<EndpointState> enumSet, EnumSet<EndpointState> enumSet1) {
            return null;
        }

        @Override
        public int getCredit() {
            return 0;
        }

        @Override
        public int getQueued() {
            return 0;
        }

        @Override
        public int getUnsettled() {
            return 0;
        }

        @Override
        public Session getSession() {
            return session;
        }

        @Override
        public SenderSettleMode getSenderSettleMode() {
            return null;
        }

        @Override
        public void setSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public SenderSettleMode getRemoteSenderSettleMode() {
            return null;
        }

        @Override
        public ReceiverSettleMode getReceiverSettleMode() {
            return null;
        }

        @Override
        public void setReceiverSettleMode(ReceiverSettleMode receiverSettleMode) {
        }

        @Override
        public ReceiverSettleMode getRemoteReceiverSettleMode() {
            return null;
        }

        @Override
        public void setRemoteSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public Map<Symbol, Object> getProperties() {
            return null;
        }

        @Override
        public void setProperties(Map<Symbol, Object> map) {
        }

        @Override
        public Map<Symbol, Object> getRemoteProperties() {
            return null;
        }

        @Override
        public int drained() {
            return 0;
        }

        @Override
        public int getRemoteCredit() {
            return 0;
        }

        @Override
        public boolean getDrain() {
            return false;
        }

        @Override
        public void detach() {
        }

        @Override
        public boolean detached() {
            return false;
        }

        @Override
        public void setOfferedCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public void setDesiredCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public void setMaxMessageSize(UnsignedLong unsignedLong) {
        }

        @Override
        public UnsignedLong getMaxMessageSize() {
            return null;
        }

        @Override
        public UnsignedLong getRemoteMaxMessageSize() {
            return null;
        }

        @Override
        public EndpointState getLocalState() {
            return null;
        }

        @Override
        public EndpointState getRemoteState() {
            return null;
        }

        @Override
        public ErrorCondition getCondition() {
            return null;
        }

        @Override
        public void setCondition(ErrorCondition errorCondition) {
        }

        @Override
        public ErrorCondition getRemoteCondition() {
            return null;
        }

        @Override
        public void free() {
        }

        @Override
        public void open() {
        }

        @Override
        public void close() {
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public Record attachments() {
            return null;
        }
    };
    event = new Event() {

        @Override
        public EventType getEventType() {
            return null;
        }

        @Override
        public Type getType() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Object getContext() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Handler getRootHandler() {
            return null;
        }

        @Override
        public void dispatch(Handler hndlr) throws HandlerException {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public void redispatch(EventType eventType, Handler handler) throws HandlerException {
        }

        @Override
        public void delegate() throws HandlerException {
        }

        @Override
        public Connection getConnection() {
            return connection;
        }

        @Override
        public Session getSession() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Link getLink() {
            return receiver;
        }

        @Override
        public Sender getSender() {
            return null;
        }

        @Override
        public Receiver getReceiver() {
            return null;
        }

        @Override
        public Delivery getDelivery() {
            return delivery;
        }

        @Override
        public Transport getTransport() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Reactor getReactor() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Selectable getSelectable() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Task getTask() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Event copy() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Record attachments() {
            throw new UnsupportedOperationException(exceptionMessage);
        }
    };
    delivery = new Delivery() {

        @Override
        public byte[] getTag() {
            return new byte[0];
        }

        @Override
        public Link getLink() {
            return receiver;
        }

        @Override
        public DeliveryState getLocalState() {
            return null;
        }

        @Override
        public DeliveryState getRemoteState() {
            return null;
        }

        @Override
        public int getMessageFormat() {
            return 0;
        }

        @Override
        public int available() {
            return 0;
        }

        @Override
        public void disposition(DeliveryState deliveryState) {
        }

        @Override
        public void settle() {
        }

        @Override
        public boolean isSettled() {
            return false;
        }

        @Override
        public boolean isAborted() {
            return false;
        }

        @Override
        public boolean remotelySettled() {
            return false;
        }

        @Override
        public void free() {
        }

        @Override
        public Delivery getWorkNext() {
            return null;
        }

        @Override
        public Delivery next() {
            return null;
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public boolean isReadable() {
            return true;
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public boolean isUpdated() {
            return false;
        }

        @Override
        public void clear() {
        }

        @Override
        public boolean isPartial() {
            return false;
        }

        @Override
        public int pending() {
            return 0;
        }

        @Override
        public boolean isBuffered() {
            return false;
        }

        @Override
        public void setDefaultDeliveryState(DeliveryState deliveryState) {
        }

        @Override
        public DeliveryState getDefaultDeliveryState() {
            return null;
        }

        @Override
        public void setMessageFormat(int i) {
        }

        @Override
        public Record attachments() {
            return null;
        }
    };
}
Also used : Symbol(org.apache.qpid.proton.amqp.Symbol) ReadableBuffer(org.apache.qpid.proton.codec.ReadableBuffer) Source(org.apache.qpid.proton.amqp.messaging.Source) ReceiverSettleMode(org.apache.qpid.proton.amqp.transport.ReceiverSettleMode) Target(org.apache.qpid.proton.amqp.messaging.Target) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpFileUploadNotificationReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceivedHandler) SenderSettleMode(org.apache.qpid.proton.amqp.transport.SenderSettleMode) WritableBuffer(org.apache.qpid.proton.codec.WritableBuffer) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) AmqpFeedbackReceivedEvent(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedEvent) Map(java.util.Map)

Example 17 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project azure-iot-sdk-java by Azure.

the class ProtonJExceptionParser method getTransportExceptionFromProtonEndpoints.

private void getTransportExceptionFromProtonEndpoints(Endpoint... endpoints) {
    for (Endpoint endpoint : endpoints) {
        if (endpoint == null) {
            continue;
        }
        ErrorCondition errorCondition = getErrorConditionFromEndpoint(endpoint);
        if (errorCondition == null || errorCondition.getCondition() == null) {
            continue;
        }
        error = errorCondition.getCondition().toString();
        if (errorCondition.getDescription() != null) {
            errorDescription = errorCondition.getDescription();
        } else {
            // log statements can assume that if error != null, errorDescription != null, too.
            errorDescription = DEFAULT_ERROR_DESCRIPTION;
        }
    }
}
Also used : Endpoint(org.apache.qpid.proton.engine.Endpoint) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Example 18 with ErrorCondition

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

the class ProtonReceiverImplTest method testSingleTransferExceedingMaxMessageSizeResultsInLinkBeingDetached.

/**
 * Verifies that the receiver detaches the link with an
 * amqp:link:message-size-exceeded error code when receiving a single-transfer message that
 * exceeds the link's max-message-size.
 */
@Test
public void testSingleTransferExceedingMaxMessageSizeResultsInLinkBeingDetached() {
    int maxFrameSize = 800;
    long maxMessageSize = 500;
    Transport transport = mock(Transport.class);
    when(transport.getMaxFrameSize()).thenReturn(maxFrameSize);
    Connection con = mock(Connection.class);
    ProtonConnectionImpl conImpl = new ProtonConnectionImpl(mock(Vertx.class), "hostname", mock(ContextInternal.class));
    when(con.getTransport()).thenReturn(transport);
    when(con.getContext()).thenReturn(conImpl);
    Session session = mock(Session.class);
    ProtonSessionImpl sessionImpl = new ProtonSessionImpl(session);
    when(session.getConnection()).thenReturn(con);
    when(session.getContext()).thenReturn(sessionImpl);
    when(session.getIncomingCapacity()).thenReturn(10_000);
    when(session.getIncomingBytes()).thenReturn(10_000);
    Receiver r = mock(Receiver.class);
    when(r.getLocalState()).thenReturn(EndpointState.ACTIVE);
    when(r.getSession()).thenReturn(session);
    when(r.getMaxMessageSize()).thenReturn(new UnsignedLong(maxMessageSize));
    ProtonReceiverImpl recImpl = new ProtonReceiverImpl(r);
    when(r.getContext()).thenReturn(recImpl);
    ProtonMessageHandler messageHandler = mock(ProtonMessageHandler.class);
    ProtonReceiverImpl receiver = new ProtonReceiverImpl(r);
    receiver.handler(messageHandler);
    byte[] encodedMessage = createEncodedMessage(700);
    assertTrue(encodedMessage.length <= maxFrameSize);
    assertTrue(encodedMessage.length > maxMessageSize);
    ReadableBuffer frame0 = ReadableBuffer.ByteBufferReader.wrap(encodedMessage);
    Delivery delivery0 = mock(Delivery.class);
    when(delivery0.getLink()).thenReturn(r);
    when(delivery0.isPartial()).thenReturn(false);
    when(delivery0.available()).thenReturn(encodedMessage.length);
    when(delivery0.isSettled()).thenReturn(false);
    when(r.current()).thenReturn(delivery0);
    when(r.recv()).thenReturn(frame0);
    // WHEN delivering the message in a single transfer frame
    receiver.onDelivery();
    // THEN the receiver is being detached with the expected error condition
    verify(r).detach();
    ArgumentCaptor<ErrorCondition> conditionCapture = ArgumentCaptor.forClass(ErrorCondition.class);
    verify(r).setCondition(conditionCapture.capture());
    ErrorCondition errorCondition = conditionCapture.getValue();
    assertNotNull(errorCondition);
    assertEquals("Unxpected error condition", LinkError.MESSAGE_SIZE_EXCEEDED, errorCondition.getCondition());
    // and the message is not being delivered to the application layer
    verify(messageHandler, never()).handle(any(ProtonDelivery.class), any(Message.class));
}
Also used : UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) ProtonDelivery(io.vertx.proton.ProtonDelivery) Message(org.apache.qpid.proton.message.Message) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Connection(org.apache.qpid.proton.engine.Connection) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) ContextInternal(io.vertx.core.impl.ContextInternal) Vertx(io.vertx.core.Vertx) ReadableBuffer(org.apache.qpid.proton.codec.ReadableBuffer) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Delivery(org.apache.qpid.proton.engine.Delivery) ProtonDelivery(io.vertx.proton.ProtonDelivery) Transport(org.apache.qpid.proton.engine.Transport) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 19 with ErrorCondition

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

the class MessageSubscriberBlackboxVerificationTckTest 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) 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) 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) ProtonSubscriberWrapperImpl(io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl) 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) SubscriberBlackboxVerification(org.reactivestreams.tck.SubscriberBlackboxVerification) ProtonSubscriber(io.vertx.proton.streams.ProtonSubscriber) TestEnvironment(org.reactivestreams.tck.TestEnvironment) 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)

Example 20 with ErrorCondition

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

the class TrackerSubscriberBlackboxVerificationTckTest 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) ProtonStreams(io.vertx.proton.streams.ProtonStreams) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) ProtonSubscriberImpl(io.vertx.proton.streams.impl.ProtonSubscriberImpl) MockServer(io.vertx.proton.MockServer) 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) SubscriberBlackboxVerification(org.reactivestreams.tck.SubscriberBlackboxVerification) ProtonSubscriber(io.vertx.proton.streams.ProtonSubscriber) TestEnvironment(org.reactivestreams.tck.TestEnvironment) 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)45 Symbol (org.apache.qpid.proton.amqp.Symbol)13 Test (org.junit.Test)11 Handler (io.vertx.core.Handler)10 ProtonConnection (io.vertx.proton.ProtonConnection)10 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)10 Message (org.apache.qpid.proton.message.Message)10 Vertx (io.vertx.core.Vertx)8 Logger (io.vertx.core.impl.logging.Logger)8 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)8 ExecutionException (java.util.concurrent.ExecutionException)8 TimeUnit (java.util.concurrent.TimeUnit)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)8 ProtonClient (io.vertx.proton.ProtonClient)7 Map (java.util.Map)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 MockServer (io.vertx.proton.MockServer)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Proton (org.apache.qpid.proton.Proton)6