Search in sources :

Example 11 with ConnectionSlot

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

the class StrongConnectionEstablishmentLimiterTest method testExistingConnectionWithPolicy.

@Test
public void testExistingConnectionWithPolicy() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
    try {
        _limiter.register(connection2);
        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(connection1));
        assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING, e.getPolicy());
    }
    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 12 with ConnectionSlot

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

the class StrongConnectionEstablishmentLimiterTest method testClosedConnection.

@Test
public void testClosedConnection() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
    Mockito.doReturn(true).when(connection1).isClosing();
    final ConnectionSlot slot2 = _limiter.register(connection2);
    assertTrue(_registry.isRegistered(connection2));
    slot1.free();
    assertFalse(_registry.isRegistered(connection1));
    assertTrue(_registry.hasBeenRegistered(connection1));
    slot2.free();
    assertFalse(_registry.isRegistered(connection2));
    assertTrue(_registry.hasBeenRegistered(connection2));
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Example 13 with ConnectionSlot

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

the class StrongConnectionEstablishmentLimiterTest method testNewConnectionWithPolicy.

@Test
public void testNewConnectionWithPolicy() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", null);
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    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.REFUSE_CONNECTION);
    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(2, e.getExistingConnections().size());
        assertTrue(e.getExistingConnections().contains(connection1));
        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)

Example 14 with ConnectionSlot

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

the class StrongConnectionEstablishmentLimiterTest method testExistingClosedConnectionWithPolicy.

@Test
public void testExistingClosedConnectionWithPolicy() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
    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.CLOSE_EXISTING);
    final ConnectionSlot slot2 = _limiter.register(connection2);
    assertTrue(_registry.isRegistered(connection2));
    slot1.free();
    assertFalse(_registry.isRegistered(connection1));
    assertTrue(_registry.hasBeenRegistered(connection1));
    slot2.free();
    assertFalse(_registry.isRegistered(connection2));
    assertTrue(_registry.hasBeenRegistered(connection2));
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Test(org.junit.Test)

Example 15 with ConnectionSlot

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

the class StrongConnectionEstablishmentLimiterTest method testNoPolicy.

@Test
public void testNoPolicy() {
    final AMQPConnection_1_0<?> connection1 = newConnection("C", null);
    final ConnectionSlot slot1 = _limiter.register(connection1);
    assertTrue(_registry.isRegistered(connection1));
    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", 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)

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