Search in sources :

Example 26 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method rejectNewDeliveryWhilstUnsettledIncomplete.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.7.3", description = "If set to true [incomplete-unsettled] indicates that the unsettled map provided is not complete. " + "When the map is incomplete the recipient of the map cannot take the absence of a delivery tag from " + "the map as evidence of settlement. On receipt of an incomplete unsettled map a sending endpoint MUST " + "NOT send any new deliveries (i.e. deliveries where resume is not set to true) to its partner (and " + "a receiving endpoint which sent an incomplete unsettled map MUST detach with an error on " + "receiving a transfer which does not have the resume flag set to true).")
public void rejectNewDeliveryWhilstUnsettledIncomplete() throws Exception {
    final String destination = BrokerAdmin.TEST_QUEUE_NAME;
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse();
        // 0. Open connection with small max-frame-size
        final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().getLatestResponse(Open.class);
        interaction.begin().consumeResponse(Begin.class);
        // 1. attach with ReceiverSettleMode.SECOND
        final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        // 2. send enough unsettled deliverys to cause incomplete-unsettled to be true
        // assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
        interaction.transferHandle(linkHandle1).transferPayloadData(TEST_MESSAGE_CONTENT);
        Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
        for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
            final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
            final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
            assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
            assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
            localUnsettled.put(deliveryTag, null);
        }
        // 3. detach the link
        interaction.detach().consumeResponse(Detach.class);
        // 4. resume the link
        final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
        Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
        final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
        assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
        // 5. ensure attach has incomplete-unsettled
        final Attach responseAttach = (Attach) latestResponse.getBody();
        assertThat(responseAttach.getIncompleteUnsettled(), is(equalTo(true)));
        // 6. send new transfer
        final Binary newDeliveryTag = new Binary("newTransfer".getBytes(StandardCharsets.UTF_8));
        final Detach detachWithError = interaction.transferHandle(linkHandle2).transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(newDeliveryTag).transfer().consumeResponse().getLatestResponse(Detach.class);
        assertThat(detachWithError.getError(), is(notNullValue()));
        final Error detachError = detachWithError.getError();
        assertThat(detachError.getCondition(), is(equalTo(AmqpError.ILLEGAL_STATE)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 27 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class SaslTest method saslUnsuccessfulAuthentication.

@Test
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation")
public void saslUnsuccessfulAuthentication() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
    try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
        final Interaction interaction = transport.newInteraction();
        final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
        assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));
        SaslMechanisms saslMechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
        assertThat(Arrays.asList(saslMechanismsResponse.getSaslServerMechanisms()), hasItem(PLAIN));
        final Binary initialResponse = new Binary(String.format("\0%s\0badpassword", _username).getBytes(StandardCharsets.US_ASCII));
        SaslOutcome saslOutcome = interaction.saslMechanism(PLAIN).saslInitialResponse(initialResponse).saslInit().consumeResponse().getLatestResponse(SaslOutcome.class);
        assertThat(saslOutcome.getCode(), equalTo(SaslCode.AUTH));
        transport.assertNoMoreResponsesAndChannelClosed();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) SaslOutcome(org.apache.qpid.server.protocol.v1_0.type.security.SaslOutcome) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) SaslMechanisms(org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 28 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class SaslTest method saslSuccessfulAuthentication.

@Test
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation [...] challenge/response step occurs zero times")
public void saslSuccessfulAuthentication() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
    try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
        final Interaction interaction = transport.newInteraction();
        final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
        assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));
        SaslMechanisms saslMechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
        assertThat(Arrays.asList(saslMechanismsResponse.getSaslServerMechanisms()), hasItem(PLAIN));
        final Binary initialResponse = new Binary(String.format("\0%s\0%s", _username, _password).getBytes(StandardCharsets.US_ASCII));
        SaslOutcome saslOutcome = interaction.saslMechanism(PLAIN).saslInitialResponse(initialResponse).saslInit().consumeResponse().getLatestResponse(SaslOutcome.class);
        assertThat(saslOutcome.getCode(), equalTo(SaslCode.OK));
        final byte[] headerResponse = interaction.protocolHeader(AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
        assertThat(headerResponse, is(equalTo(AMQP_HEADER_BYTES)));
        transport.assertNoMoreResponses();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) SaslOutcome(org.apache.qpid.server.protocol.v1_0.type.security.SaslOutcome) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) SaslMechanisms(org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 29 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class SaslTest method clientSendsSaslChallenge.

@Test
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation")
public void clientSendsSaslChallenge() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
    try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
        SaslChallenge saslChallenge = new SaslChallenge();
        saslChallenge.setChallenge(new Binary(new byte[] {}));
        transport.newInteraction().protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().consumeResponse(SaslMechanisms.class).sendPerformative(saslChallenge).sync();
        transport.assertNoMoreResponsesAndChannelClosed();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) SaslChallenge(org.apache.qpid.server.protocol.v1_0.type.security.SaslChallenge) InetSocketAddress(java.net.InetSocketAddress) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 30 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class MultiTransferTest method abortMultiTransferMessage.

// 
@Test
@SpecificationTest(section = "2.6.14", description = "The sender MAY indicate an aborted attempt to deliver a message by setting the abort flag on the last transfer." + "In this case the receiver MUST discard the message data that was transferred prior to the abort.")
public void abortMultiTransferMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
        final UnsignedInteger deliveryId = UnsignedInteger.ZERO;
        final Binary deliveryTag = new Binary("testTransfer".getBytes(UTF_8));
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(payloads[0]).transferDeliveryId(deliveryId).transferDeliveryTag(deliveryTag).transferMore(true).transfer().sync().transferPayload(null).transferMore(null).transferAborted(true).transfer();
        for (final QpidByteBuffer payload : payloads) {
            payload.dispose();
        }
        Response<?> latestResponse = interaction.consumeResponse(new Class<?>[] { null }).getLatestResponse();
        assertThat(latestResponse, is(nullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)104 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)46 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)45 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)43 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)42 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)37 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)29 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)29 Test (org.junit.Test)29 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)28 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)23 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)22 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)19 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)16 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)13 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 HashMap (java.util.HashMap)11