Search in sources :

Example 1 with ClientQuotaFilter

use of org.apache.kafka.common.quota.ClientQuotaFilter in project kafka by apache.

the class KafkaAdminClientTest method testDescribeClientQuotas.

@Test
public void testDescribeClientQuotas() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        final String value = "value";
        Map<ClientQuotaEntity, Map<String, Double>> responseData = new HashMap<>();
        ClientQuotaEntity entity1 = newClientQuotaEntity(ClientQuotaEntity.USER, "user-1", ClientQuotaEntity.CLIENT_ID, value);
        ClientQuotaEntity entity2 = newClientQuotaEntity(ClientQuotaEntity.USER, "user-2", ClientQuotaEntity.CLIENT_ID, value);
        responseData.put(entity1, Collections.singletonMap("consumer_byte_rate", 10000.0));
        responseData.put(entity2, Collections.singletonMap("producer_byte_rate", 20000.0));
        env.kafkaClient().prepareResponse(DescribeClientQuotasResponse.fromQuotaEntities(responseData, 0));
        ClientQuotaFilter filter = ClientQuotaFilter.contains(asList(ClientQuotaFilterComponent.ofEntity(ClientQuotaEntity.USER, value)));
        DescribeClientQuotasResult result = env.adminClient().describeClientQuotas(filter);
        Map<ClientQuotaEntity, Map<String, Double>> resultData = result.entities().get();
        assertEquals(resultData.size(), 2);
        assertTrue(resultData.containsKey(entity1));
        Map<String, Double> config1 = resultData.get(entity1);
        assertEquals(config1.size(), 1);
        assertEquals(config1.get("consumer_byte_rate"), 10000.0, 1e-6);
        assertTrue(resultData.containsKey(entity2));
        Map<String, Double> config2 = resultData.get(entity2);
        assertEquals(config2.size(), 1);
        assertEquals(config2.get("producer_byte_rate"), 20000.0, 1e-6);
    }
}
Also used : ClientQuotaFilter(org.apache.kafka.common.quota.ClientQuotaFilter) HashMap(java.util.HashMap) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) Map(java.util.Map) HashMap(java.util.HashMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClientQuotaEntity (org.apache.kafka.common.quota.ClientQuotaEntity)1 ClientQuotaFilter (org.apache.kafka.common.quota.ClientQuotaFilter)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1