Search in sources :

Example 71 with FakeAsyncResponse

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

the class ConsumerLagsResourceTest method getConsumerLag_returnsConsumerLag.

@Test
public void getConsumerLag_returnsConsumerLag() {
    expect(consumerLagManager.getConsumerLag(CLUSTER_ID, CONSUMER_GROUP_ID, TOPIC, 1)).andReturn(completedFuture(Optional.of(CONSUMER_LAG_1)));
    replay(consumerLagManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerLagsResource.getConsumerLag(response, CLUSTER_ID, CONSUMER_GROUP_ID, TOPIC, 1);
    GetConsumerLagResponse expected = GetConsumerLagResponse.create(ConsumerLagData.fromConsumerLag(CONSUMER_LAG_1).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/" + "lags/topic-1/partitions/1").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1/" + "lag=topic-1/partition=1").build()).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetConsumerLagResponse(io.confluent.kafkarest.entities.v3.GetConsumerLagResponse) Test(org.junit.jupiter.api.Test)

Example 72 with FakeAsyncResponse

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

the class ConsumerLagsResourceTest method getConsumerLag_nonExistingConsumerLag_throwsNotFound.

@Test
public void getConsumerLag_nonExistingConsumerLag_throwsNotFound() {
    expect(consumerLagManager.getConsumerLag(CLUSTER_ID, CONSUMER_GROUP_ID, TOPIC, 1)).andReturn(completedFuture(Optional.empty()));
    replay(consumerLagManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumerLagsResource.getConsumerLag(response, CLUSTER_ID, CONSUMER_GROUP_ID, TOPIC, 1);
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 73 with FakeAsyncResponse

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

the class ConsumersResourceTest method listConsumers_returnsConsumers.

@Test
public void listConsumers_returnsConsumers() {
    expect(consumerManager.listConsumers(CLUSTER_ID, CONSUMER_GROUP.getConsumerGroupId())).andReturn(completedFuture(Arrays.asList(CONSUMERS)));
    replay(consumerManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumersResource.listConsumers(response, CLUSTER_ID, CONSUMER_GROUP.getConsumerGroupId());
    ListConsumersResponse expected = ListConsumersResponse.create(ConsumerDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1/consumers").build()).setData(Arrays.asList(ConsumerData.fromConsumer(CONSUMERS[0]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1" + "/consumer=consumer-1").build()).setAssignments(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1/assignments")).build(), ConsumerData.fromConsumer(CONSUMERS[1]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-2").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1" + "/consumer=consumer-2").build()).setAssignments(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-2/assignments")).build(), ConsumerData.fromConsumer(CONSUMERS[2]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-3").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1" + "/consumer=consumer-3").build()).setAssignments(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-3/assignments")).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListConsumersResponse(io.confluent.kafkarest.entities.v3.ListConsumersResponse) Test(org.junit.jupiter.api.Test)

Example 74 with FakeAsyncResponse

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

the class ConsumersResourceTest method getConsumer_returnsConsumer.

@Test
public void getConsumer_returnsConsumer() {
    expect(consumerManager.getConsumer(CLUSTER_ID, CONSUMER_GROUP.getConsumerGroupId(), CONSUMERS[0].getConsumerId())).andReturn(completedFuture(Optional.of(CONSUMERS[0])));
    replay(consumerManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    consumersResource.getConsumer(response, CLUSTER_ID, CONSUMER_GROUP.getConsumerGroupId(), CONSUMERS[0].getConsumerId());
    GetConsumerResponse expected = GetConsumerResponse.create(ConsumerData.fromConsumer(CONSUMERS[0]).setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1").setResourceName("crn:///kafka=cluster-1/consumer-group=consumer-group-1" + "/consumer=consumer-1").build()).setAssignments(Relationship.create("/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1/assignments")).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetConsumerResponse(io.confluent.kafkarest.entities.v3.GetConsumerResponse) Test(org.junit.jupiter.api.Test)

Example 75 with FakeAsyncResponse

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

the class ListAllBrokersConfigsActionTest method listAllBrokerConfigs_nonExistingCluster_throwsNotFound.

@Test
public void listAllBrokerConfigs_nonExistingCluster_throwsNotFound() {
    expect(brokerManager.listBrokers(CLUSTER_ID)).andReturn(failedFuture(new NotFoundException()));
    replay(brokerManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    allBrokersConfigsAction.listBrokersConfigs(response, CLUSTER_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)

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