Search in sources :

Example 16 with FakeAsyncResponse

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());
}
Also used : GetReplicaResponse(io.confluent.kafkarest.entities.v3.GetReplicaResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 17 with FakeAsyncResponse

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());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 18 with FakeAsyncResponse

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());
}
Also used : SearchReplicasByBrokerResponse(io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 19 with FakeAsyncResponse

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());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListTopicsResponse(io.confluent.kafkarest.entities.v3.ListTopicsResponse) Test(org.junit.jupiter.api.Test)

Example 20 with FakeAsyncResponse

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());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) CreateTopicResponse(io.confluent.kafkarest.entities.v3.CreateTopicResponse) Test(org.junit.jupiter.api.Test)

Aggregations

FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)107 Test (org.junit.jupiter.api.Test)107 NotFoundException (javax.ws.rs.NotFoundException)35 ProduceRequest (io.confluent.kafkarest.entities.v3.ProduceRequest)6 RequestRateLimiter (io.confluent.kafkarest.ratelimit.RequestRateLimiter)6 ChunkedOutputFactory (io.confluent.kafkarest.response.ChunkedOutputFactory)6 Properties (java.util.Properties)6 ResultOrError (io.confluent.kafkarest.response.StreamingResponse.ResultOrError)5 CreateTopicResponse (io.confluent.kafkarest.entities.v3.CreateTopicResponse)4 ProduceResponse (io.confluent.kafkarest.entities.v3.ProduceResponse)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConfigSynonymData (io.confluent.kafkarest.entities.v3.ConfigSynonymData)3 ListBrokerConfigsResponse (io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse)3 ListTopicConfigsResponse (io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse)3 ErrorResponse (io.confluent.kafkarest.exceptions.v3.ErrorResponse)3 BrokerConfig (io.confluent.kafkarest.entities.BrokerConfig)2 TopicConfig (io.confluent.kafkarest.entities.TopicConfig)2 RateLimitExceededException (io.confluent.kafkarest.ratelimit.RateLimitExceededException)2 TimeoutException (org.apache.kafka.common.errors.TimeoutException)2