Search in sources :

Example 1 with DescribeLogDirsResponseData

use of org.apache.kafka.common.message.DescribeLogDirsResponseData in project kafka by apache.

the class KafkaAdminClientTest method testDescribeReplicaLogDirsUnexpected.

@Test
public void testDescribeReplicaLogDirsUnexpected() throws ExecutionException, InterruptedException {
    TopicPartitionReplica expected = new TopicPartitionReplica("topic", 12, 1);
    TopicPartitionReplica unexpected = new TopicPartitionReplica("topic", 12, 2);
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        String broker1log0 = "/var/data/kafka0";
        String broker1log1 = "/var/data/kafka1";
        int broker1Log0PartitionSize = 987654321;
        int broker1Log0OffsetLag = 24;
        int broker1Log1PartitionSize = 123456789;
        int broker1Log1OffsetLag = 4321;
        env.kafkaClient().prepareResponseFrom(new DescribeLogDirsResponse(new DescribeLogDirsResponseData().setResults(asList(prepareDescribeLogDirsResult(expected, broker1log0, broker1Log0PartitionSize, broker1Log0OffsetLag, false), prepareDescribeLogDirsResult(unexpected, broker1log1, broker1Log1PartitionSize, broker1Log1OffsetLag, true)))), env.cluster().nodeById(expected.brokerId()));
        DescribeReplicaLogDirsResult result = env.adminClient().describeReplicaLogDirs(asList(expected));
        Map<TopicPartitionReplica, KafkaFuture<DescribeReplicaLogDirsResult.ReplicaLogDirInfo>> values = result.values();
        assertEquals(TestUtils.toSet(asList(expected)), values.keySet());
        assertNotNull(values.get(expected));
        assertEquals(broker1log0, values.get(expected).get().getCurrentReplicaLogDir());
        assertEquals(broker1Log0OffsetLag, values.get(expected).get().getCurrentReplicaOffsetLag());
        assertEquals(broker1log1, values.get(expected).get().getFutureReplicaLogDir());
        assertEquals(broker1Log1OffsetLag, values.get(expected).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)

Example 2 with DescribeLogDirsResponseData

use of org.apache.kafka.common.message.DescribeLogDirsResponseData 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

KafkaFuture (org.apache.kafka.common.KafkaFuture)2 TopicPartitionReplica (org.apache.kafka.common.TopicPartitionReplica)2 DescribeLogDirsResponseData (org.apache.kafka.common.message.DescribeLogDirsResponseData)2 DescribeLogDirsResponse (org.apache.kafka.common.requests.DescribeLogDirsResponse)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2