use of org.apache.kafka.common.requests.DescribeLogDirsResponse in project kafka by apache.
the class KafkaAdminClientTest method testDescribeReplicaLogDirs.
@Test
public void testDescribeReplicaLogDirs() throws ExecutionException, InterruptedException {
TopicPartitionReplica tpr1 = new TopicPartitionReplica("topic", 12, 1);
TopicPartitionReplica tpr2 = new TopicPartitionReplica("topic", 12, 2);
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
String broker1log0 = "/var/data/kafka0";
String broker1log1 = "/var/data/kafka1";
String broker2log0 = "/var/data/kafka2";
int broker1Log0OffsetLag = 24;
int broker1Log0PartitionSize = 987654321;
int broker1Log1PartitionSize = 123456789;
int broker1Log1OffsetLag = 4321;
env.kafkaClient().prepareResponseFrom(new DescribeLogDirsResponse(new DescribeLogDirsResponseData().setResults(asList(prepareDescribeLogDirsResult(tpr1, broker1log0, broker1Log0PartitionSize, broker1Log0OffsetLag, false), prepareDescribeLogDirsResult(tpr1, broker1log1, broker1Log1PartitionSize, broker1Log1OffsetLag, true)))), env.cluster().nodeById(tpr1.brokerId()));
env.kafkaClient().prepareResponseFrom(prepareDescribeLogDirsResponse(Errors.KAFKA_STORAGE_ERROR, broker2log0), env.cluster().nodeById(tpr2.brokerId()));
DescribeReplicaLogDirsResult result = env.adminClient().describeReplicaLogDirs(asList(tpr1, tpr2));
Map<TopicPartitionReplica, KafkaFuture<DescribeReplicaLogDirsResult.ReplicaLogDirInfo>> values = result.values();
assertEquals(TestUtils.toSet(asList(tpr1, tpr2)), values.keySet());
assertNotNull(values.get(tpr1));
assertEquals(broker1log0, values.get(tpr1).get().getCurrentReplicaLogDir());
assertEquals(broker1Log0OffsetLag, values.get(tpr1).get().getCurrentReplicaOffsetLag());
assertEquals(broker1log1, values.get(tpr1).get().getFutureReplicaLogDir());
assertEquals(broker1Log1OffsetLag, values.get(tpr1).get().getFutureReplicaOffsetLag());
assertNotNull(values.get(tpr2));
assertNull(values.get(tpr2).get().getCurrentReplicaLogDir());
assertEquals(-1, values.get(tpr2).get().getCurrentReplicaOffsetLag());
assertNull(values.get(tpr2).get().getFutureReplicaLogDir());
assertEquals(-1, values.get(tpr2).get().getFutureReplicaOffsetLag());
}
}
Aggregations