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);
}
}
Aggregations