Search in sources :

Example 6 with DescribeLogDirsResponse

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());
    }
}
Also used : TopicPartitionReplica(org.apache.kafka.common.TopicPartitionReplica) KafkaFuture(org.apache.kafka.common.KafkaFuture) DescribeLogDirsResponseData(org.apache.kafka.common.message.DescribeLogDirsResponseData) DescribeLogDirsResponse(org.apache.kafka.common.requests.DescribeLogDirsResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

DescribeLogDirsResponse (org.apache.kafka.common.requests.DescribeLogDirsResponse)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 KafkaFuture (org.apache.kafka.common.KafkaFuture)4 TopicPartitionReplica (org.apache.kafka.common.TopicPartitionReplica)4 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)4 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)4 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)4 DescribeLogDirsRequest (org.apache.kafka.common.requests.DescribeLogDirsRequest)4 ReplicaLogDirInfo (org.apache.kafka.clients.admin.DescribeReplicaLogDirsResult.ReplicaLogDirInfo)3 TreeMap (java.util.TreeMap)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 DescribeLogDirsRequestData (org.apache.kafka.common.message.DescribeLogDirsRequestData)2 DescribeLogDirsResponseData (org.apache.kafka.common.message.DescribeLogDirsResponseData)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1