use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.
the class ReplicasResourceTest method getReplica_existingReplica_returnsReplica.
@Test
public void getReplica_existingReplica_returnsReplica() {
expect(replicaManager.getReplica(CLUSTER_ID, TOPIC_NAME, PARTITION_ID, REPLICA_1.getBrokerId())).andReturn(completedFuture(Optional.of(REPLICA_1)));
replay(replicaManager);
FakeAsyncResponse response = new FakeAsyncResponse();
replicasResource.getReplica(response, CLUSTER_ID, TOPIC_NAME, PARTITION_ID, REPLICA_1.getBrokerId());
GetReplicaResponse expected = GetReplicaResponse.create(ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/0/replicas/1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=0/replica=1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(PARTITION_ID).setBrokerId(REPLICA_1.getBrokerId()).setLeader(true).setInSync(true).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).build());
assertEquals(expected, response.getValue());
}
use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.
the class SearchReplicasByBrokerActionTest method searchReplicasByBroker_nonExistingBroker_returnsNotFound.
@Test
public void searchReplicasByBroker_nonExistingBroker_returnsNotFound() {
expect(replicaManager.searchReplicasByBrokerId(CLUSTER_ID, BROKER_ID)).andReturn(failedFuture(new NotFoundException()));
replay(replicaManager);
FakeAsyncResponse response = new FakeAsyncResponse();
searchReplicasByBrokerAction.searchReplicasByBroker(response, CLUSTER_ID, BROKER_ID);
assertEquals(NotFoundException.class, response.getException().getClass());
}
use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.
the class SearchReplicasByBrokerActionTest method searchReplicasByBroker_existingBroker_returnsReplicas.
@Test
public void searchReplicasByBroker_existingBroker_returnsReplicas() {
expect(replicaManager.searchReplicasByBrokerId(CLUSTER_ID, BROKER_ID)).andReturn(completedFuture(Arrays.asList(REPLICA_1, REPLICA_2)));
replay(replicaManager);
FakeAsyncResponse response = new FakeAsyncResponse();
searchReplicasByBrokerAction.searchReplicasByBroker(response, CLUSTER_ID, BROKER_ID);
SearchReplicasByBrokerResponse expected = SearchReplicasByBrokerResponse.create(ReplicaDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/partition-replicas").build()).setData(Arrays.asList(ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/1" + "/replicas/1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=1" + "/replica=1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(REPLICA_1.getPartitionId()).setBrokerId(BROKER_ID).setLeader(true).setInSync(true).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).build(), ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/2" + "/replicas/1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=2" + "/replica=1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(REPLICA_2.getPartitionId()).setBrokerId(BROKER_ID).setLeader(false).setInSync(false).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).build())).build());
assertEquals(expected, response.getValue());
}
use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.
the class TopicsResourceTest method listTopics_existingCluster_returnsTopics.
@Test
public void listTopics_existingCluster_returnsTopics() {
expect(topicManager.listTopics(CLUSTER_ID, false)).andReturn(completedFuture(Arrays.asList(TOPIC_1, TOPIC_2, TOPIC_3)));
replay(topicManager);
FakeAsyncResponse response = new FakeAsyncResponse();
topicsResource.listTopics(response, CLUSTER_ID, false);
ListTopicsResponse expected = ListTopicsResponse.create(TopicDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics").build()).setData(Arrays.asList(newTopicData("topic-1", true, 3, 3), newTopicData("topic-2", true, 3, 3), newTopicData("topic-3", false, 3, 3))).build());
assertEquals(expected, response.getValue());
}
use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.
the class TopicsResourceTest method createTopic_nonExistingTopic_defaultPartitionsCount_createsTopic.
@Test
public void createTopic_nonExistingTopic_defaultPartitionsCount_createsTopic() {
expect(topicManager.createTopic(CLUSTER_ID, TOPIC_1.getName(), /* partitionsCount= */
Optional.empty(), Optional.of(TOPIC_1.getReplicationFactor()), /* replicasAssignments= */
Collections.emptyMap(), singletonMap("cleanup.policy", Optional.of("compact")))).andReturn(completedFuture(null));
replay(topicManager);
FakeAsyncResponse response = new FakeAsyncResponse();
topicsResource.createTopic(response, TOPIC_1.getClusterId(), CreateTopicRequest.builder().setTopicName(TOPIC_1.getName()).setReplicationFactor(TOPIC_1.getReplicationFactor()).setConfigs(singletonList(CreateTopicRequest.ConfigEntry.create("cleanup.policy", "compact"))).build());
CreateTopicResponse expected = CreateTopicResponse.create(newTopicData("topic-1", false, 3, 0));
assertEquals(expected, response.getValue());
}
Aggregations