use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class GetListOffsetsCallsBenchmark method setup.
@Setup(Level.Trial)
public void setup() {
MetadataResponseData data = new MetadataResponseData();
List<MetadataResponseTopic> mrTopicList = new ArrayList<>();
Set<String> topics = new HashSet<>();
for (int topicIndex = 0; topicIndex < topicCount; topicIndex++) {
Uuid topicId = Uuid.randomUuid();
String topicName = "topic-" + topicIndex;
MetadataResponseTopic mrTopic = new MetadataResponseTopic().setTopicId(topicId).setName(topicName).setErrorCode((short) 0).setIsInternal(false);
List<MetadataResponsePartition> mrPartitionList = new ArrayList<>();
for (int partition = 0; partition < partitionCount; partition++) {
TopicPartition tp = new TopicPartition(topicName, partition);
topics.add(tp.topic());
futures.put(tp, new KafkaFutureImpl<>());
topicPartitionOffsets.put(tp, OffsetSpec.latest());
MetadataResponsePartition mrPartition = new MetadataResponsePartition().setLeaderId(partition % numNodes).setPartitionIndex(partition).setIsrNodes(Arrays.asList(0, 1, 2)).setReplicaNodes(Arrays.asList(0, 1, 2)).setOfflineReplicas(Collections.emptyList()).setErrorCode((short) 0);
mrPartitionList.add(mrPartition);
}
mrTopic.setPartitions(mrPartitionList);
mrTopicList.add(mrTopic);
}
data.setTopics(new MetadataResponseData.MetadataResponseTopicCollection(mrTopicList.listIterator()));
long deadline = 0L;
short version = 0;
context = new MetadataOperationContext<>(topics, new ListOffsetsOptions(), deadline, futures);
context.setResponse(Optional.of(new MetadataResponse(data, version)));
AdminClientUnitTestEnv adminEnv = new AdminClientUnitTestEnv(mockCluster());
admin = (KafkaAdminClient) adminEnv.adminClient();
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldReturnEmptyMapWhenPartitionsSetIsNull.
@Test
public void endOffsetsShouldReturnEmptyMapWhenPartitionsSetIsNull() {
String topicName = "myTopic";
Cluster cluster = createCluster(1, topicName, 1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Map<TopicPartition, Long> offsets = admin.endOffsets(Collections.emptySet());
assertTrue(offsets.isEmpty());
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method returnEmptyWithClusterAuthorizationFailureOnCreate.
@Test
public void returnEmptyWithClusterAuthorizationFailureOnCreate() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().prepareResponse(createTopicResponseWithClusterAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
assertFalse(admin.createTopic(newTopic));
env.kafkaClient().prepareResponse(createTopicResponseWithClusterAuthorizationException(newTopic));
assertTrue(admin.createOrFindTopics(newTopic).isEmpty());
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method endOffsetsShouldReturnOffsetsForMultiplePartitions.
@Test
public void endOffsetsShouldReturnOffsetsForMultiplePartitions() {
String topicName = "myTopic";
TopicPartition tp1 = new TopicPartition(topicName, 0);
TopicPartition tp2 = new TopicPartition(topicName, 1);
Set<TopicPartition> tps = new HashSet<>(Arrays.asList(tp1, tp2));
long offset1 = 1001;
long offset2 = 1002;
Cluster cluster = createCluster(1, topicName, 2);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(prepareMetadataResponse(cluster, Errors.NONE));
env.kafkaClient().prepareResponse(listOffsetsResult(tp1, offset1, tp2, offset2));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
Map<TopicPartition, Long> offsets = admin.endOffsets(tps);
assertEquals(2, offsets.size());
assertEquals(Long.valueOf(offset1), offsets.get(tp1));
assertEquals(Long.valueOf(offset2), offsets.get(tp2));
}
}
use of org.apache.kafka.clients.admin.AdminClientUnitTestEnv in project kafka by apache.
the class TopicAdminTest method verifyingTopicCleanupPolicyShouldReturnFalseWhenTopicAuthorizationError.
@Test
public void verifyingTopicCleanupPolicyShouldReturnFalseWhenTopicAuthorizationError() {
final NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
Cluster cluster = createCluster(1);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(new MockTime(), cluster)) {
env.kafkaClient().prepareResponse(describeConfigsResponseWithTopicAuthorizationException(newTopic));
TopicAdmin admin = new TopicAdmin(null, env.adminClient());
boolean result = admin.verifyTopicCleanupPolicyOnlyCompact("myTopic", "worker.topic", "purpose");
assertFalse(result);
}
}
Aggregations