Search in sources :

Example 21 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testBuilder_AddNull.

@Test
public void testBuilder_AddNull() {
    final Builder builder = RuleSet.newBuilder(LIMITER_NAME, Duration.ofMillis(2L));
    builder.addRule(null);
    builder.addRules(null);
    final RuleSet ruleSet = builder.build();
    assertNotNull(ruleSet);
    final ConnectionSlot connection1 = ruleSet.register(newConnection());
    assertNotNull(connection1);
    final ConnectionSlot connection2 = ruleSet.register(newConnection());
    assertNotNull(connection2);
    connection1.free();
    connection2.free();
}
Also used : ConnectionSlot(org.apache.qpid.server.security.limit.ConnectionSlot) Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder) Test(org.junit.Test)

Example 22 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testUserConnectionCountLimit.

private void testUserConnectionCountLimit(Duration duration, Integer frequencyLimit) {
    if (frequencyLimit != null && frequencyLimit < 3) {
        frequencyLimit = 3;
    }
    final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
    builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_USER, 2, null, duration));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_USER, 2, frequencyLimit, duration));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1, 1, duration));
    builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1, 1, duration));
    builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
    testConnectionCountLimit2(builder.build());
    testConnectionCountLimit2(builder.logAllMessages(true).build());
    testConnectionCountLimit2(builder.logAllMessages(false).build());
}
Also used : Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)

Aggregations

Builder (org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)22 Duration (java.time.Duration)7 ConnectionLimitException (org.apache.qpid.server.security.limit.ConnectionLimitException)4 Test (org.junit.Test)3 ConnectionSlot (org.apache.qpid.server.security.limit.ConnectionSlot)2 Instant (java.time.Instant)1