Search in sources :

Example 1 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 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 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 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) Source(org.apache.qpid.proton.amqp.messaging.Source) ReceiverSettleMode(org.apache.qpid.proton.amqp.transport.ReceiverSettleMode) Target(org.apache.qpid.proton.amqp.messaging.Target) 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 2 with ErrorCondition

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

the class AmqpReceiveHandlerTest 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 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 RECEIVE_TAG;
        }

        @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 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 Event.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 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) Source(org.apache.qpid.proton.amqp.messaging.Source) ReceiverSettleMode(org.apache.qpid.proton.amqp.transport.ReceiverSettleMode) Target(org.apache.qpid.proton.amqp.messaging.Target) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) 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 3 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project hono by eclipse.

the class MessageForwardingEndpointTest method testOnLinkAttachClosesLinkIfDownstreamIsNotAvailable.

/**
 * Verifies that the endpoint does not open a link with a client if the
 * downstream messaging network is not available.
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testOnLinkAttachClosesLinkIfDownstreamIsNotAvailable() {
    // GIVEN an endpoint without a connection to the downstream messaging network
    final ResourceIdentifier targetAddress = ResourceIdentifier.fromString("telemetry/tenant");
    final ProtonConnection connection = mock(ProtonConnection.class);
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_MOST_ONCE);
    final DownstreamAdapter adapter = mock(DownstreamAdapter.class);
    doAnswer(invocation -> {
        final Handler<AsyncResult<Void>> handler = invocation.getArgument(1);
        handler.handle(Future.failedFuture("downstream not available"));
        return null;
    }).when(adapter).onClientAttach(any(UpstreamReceiver.class), any(Handler.class));
    final MessageForwardingEndpoint<HonoMessagingConfigProperties> endpoint = getEndpoint();
    endpoint.setDownstreamAdapter(adapter);
    // WHEN a client tries to attach
    endpoint.onLinkAttach(connection, receiver, targetAddress);
    // THEN the endpoint closes the link
    final ArgumentCaptor<ErrorCondition> errorCondition = ArgumentCaptor.forClass(ErrorCondition.class);
    verify(receiver).setCondition(errorCondition.capture());
    assertThat(errorCondition.getValue().getCondition(), is(AmqpError.PRECONDITION_FAILED));
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ProtonConnection(io.vertx.proton.ProtonConnection) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Handler(io.vertx.core.Handler) AsyncResult(io.vertx.core.AsyncResult) Test(org.junit.Test)

Example 4 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project hono by eclipse.

the class MessageForwardingEndpointTest method testOnLinkAttachClosesLinkIfClientWantsToUseUnsupportedDeliveryMode.

/**
 * Verifies that the endpoint does not open a link with a client that uses an unsupported
 * delivery mode.
 */
@Test
public void testOnLinkAttachClosesLinkIfClientWantsToUseUnsupportedDeliveryMode() {
    // GIVEN an endpoint
    MessageForwardingEndpoint<HonoMessagingConfigProperties> endpoint = getEndpoint();
    // WHEN a client tries to attach using an unsupported delivery mode
    final ProtonConnection connection = mock(ProtonConnection.class);
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    final ResourceIdentifier targetAddress = ResourceIdentifier.fromString("telemetry/tenant");
    when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_LEAST_ONCE);
    endpoint.onLinkAttach(connection, receiver, targetAddress);
    // THEN the endpoint closes the link
    final ArgumentCaptor<ErrorCondition> errorCondition = ArgumentCaptor.forClass(ErrorCondition.class);
    verify(receiver).setCondition(errorCondition.capture());
    assertThat(errorCondition.getValue(), is(ErrorConditions.ERROR_UNSUPPORTED_DELIVERY_MODE));
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonConnection(io.vertx.proton.ProtonConnection) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Test(org.junit.Test)

Example 5 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project hono by eclipse.

the class AbstractHonoClient method onRemoteDetach.

private static void onRemoteDetach(final ProtonSender sender, final String remoteContainer, final boolean closed, final Handler<String> closeHook) {
    final ErrorCondition error = sender.getRemoteCondition();
    if (error == null) {
        LOG.debug("sender [{}] detached (with closed={}) by peer [{}]", sender.getTarget().getAddress(), closed, remoteContainer);
    } else {
        LOG.debug("sender [{}] detached (with closed={}) by peer [{}]: {} - {}", sender.getTarget().getAddress(), closed, remoteContainer, error.getCondition(), error.getDescription());
    }
    sender.close();
    final boolean linkEstablished = sender.attachments().get(KEY_LINK_ESTABLISHED, Boolean.class);
    if (linkEstablished && closeHook != null) {
        closeHook.handle(sender.getTarget().getAddress());
    }
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Aggregations

ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)65 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)16 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