Search in sources :

Example 36 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class ClusterConfigResourceTest method getClusterConfig_nonExistingCluster_throwsNotFound.

@Test
public void getClusterConfig_nonExistingCluster_throwsNotFound() {
    expect(clusterConfigManager.getClusterConfig(CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName())).andReturn(failedFuture(new NotFoundException()));
    replay(clusterConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clusterConfigsResource.getClusterConfig(response, CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName());
    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 37 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class ConsumerAssignmentsResourceTest method getConsumer_nonExistingConsumer_throwsNotFound.

@Test
public void getConsumer_nonExistingConsumer_throwsNotFound() {
    expect(consumerAssignmentManager.getConsumerAssignment(CLUSTER_ID, CONSUMER_GROUP_ID, CONSUMER_ID, "topic-1", 1)).andReturn(completedFuture(Optional.empty()));
    replay(consumerAssignmentManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerAssignmentsResource.getConsumerAssignment(response, CLUSTER_ID, CONSUMER_GROUP_ID, CONSUMER_ID, "topic-1", 1);
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 38 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class ConsumerAssignmentsResourceTest method getConsumer_returnsConsumer.

@Test
public void getConsumer_returnsConsumer() {
    expect(consumerAssignmentManager.getConsumerAssignment(CLUSTER_ID, CONSUMER_GROUP_ID, CONSUMER_ID, "topic-1", 1)).andReturn(completedFuture(Optional.of(CONSUMER_ASSIGNMENT_1)));
    replay(consumerAssignmentManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerAssignmentsResource.getConsumerAssignment(response, CLUSTER_ID, CONSUMER_GROUP_ID, CONSUMER_ID, "topic-1", 1);
    GetConsumerAssignmentResponse expected = GetConsumerAssignmentResponse.create(ConsumerAssignmentData.fromConsumerAssignment(CONSUMER_ASSIGNMENT_1).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1" + "/assignments/topic-1/partitions/1").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1" + "/consumer=consumer-1" + "/assignment=topic-1/partition=1").build()).setPartition(Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/1")).setLag(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/lags" + "/topic-1/partitions/1")).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetConsumerAssignmentResponse(io.confluent.kafkarest.entities.v3.GetConsumerAssignmentResponse) Test(org.junit.jupiter.api.Test)

Example 39 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class ConsumerGroupsResourceTest method getConsumerGroup_returnsConsumerGroup.

@Test
public void getConsumerGroup_returnsConsumerGroup() {
    expect(consumerGroupManager.getConsumerGroup(CLUSTER_ID, CONSUMER_GROUPS[0].getConsumerGroupId())).andReturn(completedFuture(Optional.of(CONSUMER_GROUPS[0])));
    replay(consumerGroupManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerGroupsResource.getConsumerGroup(response, CLUSTER_ID, CONSUMER_GROUPS[0].getConsumerGroupId());
    GetConsumerGroupResponse expected = GetConsumerGroupResponse.create(ConsumerGroupData.fromConsumerGroup(CONSUMER_GROUPS[0]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1").build()).setCoordinator(Relationship.create("/v3/clusters/cluster-1/brokers/1")).setConsumers(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/consumers")).setLagSummary(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/lag-summary")).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetConsumerGroupResponse(io.confluent.kafkarest.entities.v3.GetConsumerGroupResponse) Test(org.junit.jupiter.api.Test)

Example 40 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class ConsumerGroupsResourceTest method listConsumerGroups_returnsConsumerGroups.

@Test
public void listConsumerGroups_returnsConsumerGroups() {
    expect(consumerGroupManager.listConsumerGroups(CLUSTER_ID)).andReturn(completedFuture(Arrays.asList(CONSUMER_GROUPS)));
    replay(consumerGroupManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerGroupsResource.listConsumerGroups(response, CLUSTER_ID);
    ListConsumerGroupsResponse expected = ListConsumerGroupsResponse.create(ConsumerGroupDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups").build()).setData(Arrays.asList(ConsumerGroupData.fromConsumerGroup(CONSUMER_GROUPS[0]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1").build()).setCoordinator(Relationship.create("/v3/clusters/cluster-1/brokers/1")).setConsumers(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers")).setLagSummary(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/lag-summary")).build(), ConsumerGroupData.fromConsumerGroup(CONSUMER_GROUPS[1]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-2").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-2").build()).setCoordinator(Relationship.create("/v3/clusters/cluster-1/brokers/2")).setConsumers(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-2" + "/consumers")).setLagSummary(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-2" + "/lag-summary")).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListConsumerGroupsResponse(io.confluent.kafkarest.entities.v3.ListConsumerGroupsResponse) 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