Search in sources :

Example 66 with FakeAsyncResponse

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

the class ClustersResourceTest method listClusters_returnsArrayWithOwnClusters.

@Test
public void listClusters_returnsArrayWithOwnClusters() {
    expect(clusterManager.listClusters()).andReturn(CompletableFuture.completedFuture(singletonList(CLUSTER_1)));
    replay(clusterManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clustersResource.listClusters(response);
    ListClustersResponse expected = ListClustersResponse.create(ClusterDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters").build()).setData(singletonList(ClusterData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1").setResourceName("crn:///kafka=cluster-1").build()).setClusterId("cluster-1").setController(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).setAcls(Resource.Relationship.create("/v3/clusters/cluster-1/acls")).setBrokers(Resource.Relationship.create("/v3/clusters/cluster-1/brokers")).setBrokerConfigs(Resource.Relationship.create("/v3/clusters/cluster-1/broker-configs")).setConsumerGroups(Resource.Relationship.create("/v3/clusters/cluster-1/consumer-groups")).setTopics(Resource.Relationship.create("/v3/clusters/cluster-1/topics")).setPartitionReassignments(Resource.Relationship.create("/v3/clusters/cluster-1/topics/-/partitions/-/reassignment")).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListClustersResponse(io.confluent.kafkarest.entities.v3.ListClustersResponse) Test(org.junit.jupiter.api.Test)

Example 67 with FakeAsyncResponse

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

the class ClustersResourceTest method getCluster_timeoutException_returnsTimeoutException.

@Test
public void getCluster_timeoutException_returnsTimeoutException() {
    expect(clusterManager.getCluster(CLUSTER_1.getClusterId())).andReturn(failedFuture(new TimeoutException()));
    replay(clusterManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clustersResource.getCluster(response, CLUSTER_1.getClusterId());
    assertEquals(TimeoutException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 68 with FakeAsyncResponse

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

the class ClustersResourceTest method getCluster_ownCluster_returnsCluster.

@Test
public void getCluster_ownCluster_returnsCluster() {
    expect(clusterManager.getCluster(CLUSTER_1.getClusterId())).andReturn(CompletableFuture.completedFuture(Optional.of(CLUSTER_1)));
    replay(clusterManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clustersResource.getCluster(response, CLUSTER_1.getClusterId());
    GetClusterResponse expected = GetClusterResponse.create(ClusterData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1").setResourceName("crn:///kafka=cluster-1").build()).setClusterId("cluster-1").setController(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).setAcls(Resource.Relationship.create("/v3/clusters/cluster-1/acls")).setBrokers(Resource.Relationship.create("/v3/clusters/cluster-1/brokers")).setBrokerConfigs(Resource.Relationship.create("/v3/clusters/cluster-1/broker-configs")).setConsumerGroups(Resource.Relationship.create("/v3/clusters/cluster-1/consumer-groups")).setTopics(Resource.Relationship.create("/v3/clusters/cluster-1/topics")).setPartitionReassignments(Resource.Relationship.create("/v3/clusters/cluster-1/topics/-/partitions" + "/-/reassignment")).build());
    assertEquals(expected, response.getValue());
}
Also used : GetClusterResponse(io.confluent.kafkarest.entities.v3.GetClusterResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 69 with FakeAsyncResponse

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

the class ConsumerGroupLagSummariesResourceTest method getConsumerGroupLagSummary_nonExistingConsumerGroupLagSummary_throwsNotFound.

@Test
public void getConsumerGroupLagSummary_nonExistingConsumerGroupLagSummary_throwsNotFound() {
    expect(consumerGroupLagSummaryManager.getConsumerGroupLagSummary(CLUSTER_ID, CONSUMER_GROUP_ID)).andReturn(completedFuture(Optional.empty()));
    replay(consumerGroupLagSummaryManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerGroupLagSummariesResource.getConsumerGroupLagSummary(response, CLUSTER_ID, CONSUMER_GROUP_ID);
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 70 with FakeAsyncResponse

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

the class ConsumerGroupLagSummariesResourceTest method getConsumerGroupLagSummary_returnsConsumerGroupLagSummary.

@Test
public void getConsumerGroupLagSummary_returnsConsumerGroupLagSummary() {
    expect(consumerGroupLagSummaryManager.getConsumerGroupLagSummary(CLUSTER_ID, CONSUMER_GROUP_ID)).andReturn(completedFuture(Optional.of(CONSUMER_GROUP_LAG_1)));
    replay(consumerGroupLagSummaryManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerGroupLagSummariesResource.getConsumerGroupLagSummary(response, CLUSTER_ID, CONSUMER_GROUP_ID);
    GetConsumerGroupLagSummaryResponse expected = GetConsumerGroupLagSummaryResponse.create(ConsumerGroupLagSummaryData.fromConsumerGroupLagSummary(CONSUMER_GROUP_LAG_1).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/lag-summary").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1/lag-summary").build()).setMaxLagConsumer(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/" + "consumers/consumer-1")).setMaxLagPartition(Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/1")).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetConsumerGroupLagSummaryResponse(io.confluent.kafkarest.entities.v3.GetConsumerGroupLagSummaryResponse) 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