Search in sources :

Example 76 with FrameTransport

use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.

the class CloseExistingPolicy method existingConnectionClosed.

@Test
public void existingConnectionClosed() throws Exception {
    try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction1 = transport1.newInteraction();
        interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().consumeResponse(Open.class);
        try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
            final Interaction interaction2 = transport2.newInteraction();
            interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().sync();
            final Close close1 = interaction1.consumeResponse().getLatestResponse(Close.class);
            assertThat(close1.getError(), is(notNullValue()));
            assertThat(close1.getError().getCondition(), is(equalTo(AmqpError.RESOURCE_LOCKED)));
            assertThat(close1.getError().getInfo(), is(equalTo(Collections.singletonMap(Symbol.valueOf("sole-connection-enforcement"), true))));
            final Open responseOpen2 = interaction2.consumeResponse().getLatestResponse(Open.class);
            assertThat(Arrays.asList(responseOpen2.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
            if (responseOpen2.getProperties().containsKey(SOLE_CONNECTION_DETECTION_POLICY)) {
                assertThat(responseOpen2.getProperties().get(SOLE_CONNECTION_DETECTION_POLICY), isIn(new UnsignedInteger[] { SoleConnectionDetectionPolicy.STRONG.getValue(), SoleConnectionDetectionPolicy.WEAK.getValue() }));
            }
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) 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)

Example 77 with FrameTransport

use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.

the class CloseExistingPolicy method strongDetection.

@Test
public void strongDetection() throws Exception {
    try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction1 = transport1.newInteraction();
        Open responseOpen = interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().consumeResponse().getLatestResponse(Open.class);
        assertThat(Arrays.asList(responseOpen.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
        if (responseOpen.getProperties().containsKey(SOLE_CONNECTION_DETECTION_POLICY)) {
            assumeThat(responseOpen.getProperties().get(SOLE_CONNECTION_DETECTION_POLICY), is(equalTo(SoleConnectionDetectionPolicy.STRONG.getValue())));
        }
        try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
            final Interaction interaction2 = transport2.newInteraction();
            // Omit setting the desired capability to test strong detection
            interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().sync();
            final Close close1 = interaction1.consumeResponse().getLatestResponse(Close.class);
            assertThat(close1.getError(), is(notNullValue()));
            assertThat(close1.getError().getCondition(), is(equalTo(AmqpError.RESOURCE_LOCKED)));
            assertThat(close1.getError().getInfo(), is(equalTo(Collections.singletonMap(Symbol.valueOf("sole-connection-enforcement"), true))));
            final Open responseOpen2 = interaction2.consumeResponse().getLatestResponse(Open.class);
            assertThat(Arrays.asList(responseOpen2.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
            if (responseOpen2.getProperties().containsKey(SOLE_CONNECTION_DETECTION_POLICY)) {
                assertThat(responseOpen2.getProperties().get(SOLE_CONNECTION_DETECTION_POLICY), isIn(new UnsignedInteger[] { SoleConnectionDetectionPolicy.STRONG.getValue(), SoleConnectionDetectionPolicy.WEAK.getValue() }));
            }
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) 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)

Example 78 with FrameTransport

use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.

the class MixedPolicy method firstCloseThenRefuse.

@Test
public void firstCloseThenRefuse() throws Exception {
    try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction1 = transport1.newInteraction();
        interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().consumeResponse(Open.class);
        try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
            final Interaction interaction2 = transport2.newInteraction();
            interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, REFUSE_CONNECTION)).open().sync();
            interaction1.consumeResponse(Close.class);
            interaction2.consumeResponse(Open.class);
            try (FrameTransport transport3 = new FrameTransport(_brokerAddress).connect()) {
                final Interaction interaction3 = transport3.newInteraction();
                interaction3.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().consumeResponse(Open.class).consumeResponse(Close.class);
            }
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test)

Example 79 with FrameTransport

use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.

the class RefuseConnectionPolicy method weakDetection.

@Test
public void weakDetection() throws Exception {
    try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction1 = transport1.newInteraction();
        // Omit setting the desired capability to test weak detection
        interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().consumeResponse(Open.class);
        try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
            final Interaction interaction2 = transport2.newInteraction();
            final Open responseOpen2 = interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, REFUSE_CONNECTION)).open().consumeResponse().getLatestResponse(Open.class);
            assertThat(Arrays.asList(responseOpen2.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
            assertThat(responseOpen2.getProperties(), hasKey(Symbol.valueOf("amqp:connection-establishment-failed")));
            assertThat(responseOpen2.getProperties().get(Symbol.valueOf("amqp:connection-establishment-failed")), is(true));
            final Close close2 = interaction2.consumeResponse().getLatestResponse(Close.class);
            assertThat(close2.getError(), is(notNullValue()));
            assertThat(close2.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
            assertThat(close2.getError().getInfo(), is(equalTo(Collections.singletonMap(Symbol.valueOf("invalid-field"), Symbol.valueOf("container-id")))));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test)

Example 80 with FrameTransport

use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.

the class RefuseConnectionPolicy method refuseIsDefault.

@Test
public void refuseIsDefault() throws Exception {
    try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction1 = transport1.newInteraction();
        // Omit setting the enforcement policy explicitly. The default is refuse.
        interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).open().consumeResponse(Open.class);
        try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
            final Interaction interaction2 = transport2.newInteraction();
            // Omit setting the enforcement policy explicitly. The default is refuse.
            final Open responseOpen2 = interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).open().consumeResponse().getLatestResponse(Open.class);
            assertThat(Arrays.asList(responseOpen2.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
            assertThat(responseOpen2.getProperties(), hasKey(Symbol.valueOf("amqp:connection-establishment-failed")));
            assertThat(responseOpen2.getProperties().get(Symbol.valueOf("amqp:connection-establishment-failed")), is(true));
            final Close close2 = interaction2.consumeResponse().getLatestResponse(Close.class);
            assertThat(close2.getError(), is(notNullValue()));
            assertThat(close2.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
            assertThat(close2.getError().getInfo(), is(equalTo(Collections.singletonMap(Symbol.valueOf("invalid-field"), Symbol.valueOf("container-id")))));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)136 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)125 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)116 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)100 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)57 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)56 InetSocketAddress (java.net.InetSocketAddress)45 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)39 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)37 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)35 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)32 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)29 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)18 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)16 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)14 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)11 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10