Search in sources :

Example 1 with ConnectionSlot

use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.

the class StrongConnectionEstablishmentLimiterTest method testAnotherConnectionType.

@Test
public void testAnotherConnectionType() {
    final AMQPConnection<?> connection = Mockito.mock(AMQPConnection.class);
    final ConnectionSlot slot = _limiter.register(connection);
    assertTrue(_registry.isRegistered(connection));
    slot.free();
    assertFalse(_registry.isRegistered(connection));
    assertTrue(_registry.hasBeenRegistered(connection));
    Mockito.verifyNoInteractions(connection);
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Example 2 with ConnectionSlot

use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.

the class StrongConnectionEstablishmentLimiterTest method testNewConnectionWithPolicy_ClosedExisting.

@Test
public void testNewConnectionWithPolicy_ClosedExisting() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
    Mockito.doReturn(false).when(connection1).isClosing();
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    Mockito.doReturn(true).when(connection1).isClosing();
    final AMQPConnection_1_0<?> connection2 = newConnection("C", null);
    final ConnectionSlot slot2 = _limiter.register(connection2);
    assertTrue(_registry.isRegistered(connection2));
    final AMQPConnection_1_0<?> connection3 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
    try {
        _limiter.register(connection3);
        fail("A sole connection enforcement policy exception is expected");
    } catch (SoleConnectionEnforcementPolicyException e) {
        assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'close-existing'", e.getMessage());
        assertEquals(1, e.getExistingConnections().size());
        assertTrue(e.getExistingConnections().contains(connection2));
        assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING, e.getPolicy());
    }
    slot2.free();
    assertFalse(_registry.isRegistered(connection2));
    assertTrue(_registry.hasBeenRegistered(connection2));
    slot1.free();
    assertFalse(_registry.isRegistered(connection1));
    assertTrue(_registry.hasBeenRegistered(connection1));
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Example 3 with ConnectionSlot

use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.

the class StrongConnectionEstablishmentLimiterTest method testMultipleIndependentConnections.

@Test
public void testMultipleIndependentConnections() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C1", null);
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    final AMQPConnection_1_0<?> connection2 = newConnection("C2", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
    final ConnectionSlot slot2 = _limiter.register(connection2);
    assertTrue(_registry.isRegistered(connection2));
    final AMQPConnection_1_0<?> connection3 = newConnection("C3", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
    final ConnectionSlot slot3 = _limiter.register(connection3);
    assertTrue(_registry.isRegistered(connection3));
    slot3.free();
    assertFalse(_registry.isRegistered(connection3));
    assertTrue(_registry.hasBeenRegistered(connection3));
    slot2.free();
    assertFalse(_registry.isRegistered(connection2));
    assertTrue(_registry.hasBeenRegistered(connection2));
    slot1.free();
    assertFalse(_registry.isRegistered(connection1));
    assertTrue(_registry.hasBeenRegistered(connection1));
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Example 4 with ConnectionSlot

use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.

the class StrongConnectionEstablishmentLimiterTest method testMultipleIndependentConnections2.

@Test
public void testMultipleIndependentConnections2() {
    final AMQPConnection_1_0<?> connection1 = newConnection(null, null);
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    final AMQPConnection_1_0<?> connection2 = newConnection(null, null);
    final ConnectionSlot slot2 = _limiter.register(connection2);
    assertTrue(_registry.isRegistered(connection2));
    final AMQPConnection_1_0<?> connection3 = newConnection(null, null);
    final ConnectionSlot slot3 = _limiter.register(connection3);
    assertTrue(_registry.isRegistered(connection3));
    slot3.free();
    assertFalse(_registry.isRegistered(connection3));
    assertTrue(_registry.hasBeenRegistered(connection3));
    slot2.free();
    assertFalse(_registry.isRegistered(connection2));
    assertTrue(_registry.hasBeenRegistered(connection2));
    slot1.free();
    assertFalse(_registry.isRegistered(connection1));
    assertTrue(_registry.hasBeenRegistered(connection1));
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Example 5 with ConnectionSlot

use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.

the class StrongConnectionEstablishmentLimiterTest method testNewConnectionWithPolicy2_ClosedExisting.

@Test
public void testNewConnectionWithPolicy2_ClosedExisting() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
    Mockito.doReturn(false).when(connection1).isClosing();
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    Mockito.doReturn(true).when(connection1).isClosing();
    final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
    final ConnectionSlot slot2 = _limiter.register(connection2);
    assertTrue(_registry.isRegistered(connection2));
    final AMQPConnection_1_0<?> connection3 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
    try {
        _limiter.register(connection3);
        fail("A sole connection enforcement policy exception is expected");
    } catch (SoleConnectionEnforcementPolicyException e) {
        assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'refuse-connection'", e.getMessage());
        assertEquals(1, e.getExistingConnections().size());
        assertTrue(e.getExistingConnections().contains(connection2));
        assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION, e.getPolicy());
    }
    slot2.free();
    assertFalse(_registry.isRegistered(connection2));
    assertTrue(_registry.hasBeenRegistered(connection2));
    slot1.free();
    assertFalse(_registry.isRegistered(connection1));
    assertTrue(_registry.hasBeenRegistered(connection1));
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Aggregations

ConnectionSlot (org.apache.qpid.server.security.limit.ConnectionSlot)15 Test (org.junit.Test)11 ConnectionLimitException (org.apache.qpid.server.security.limit.ConnectionLimitException)4 Builder (org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)2