Search in sources :

Example 21 with FakeAsyncResponse

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

the class TopicsResourceTest method createTopic_nonExistingTopic_createsTopic.

@Test
public void createTopic_nonExistingTopic_createsTopic() {
    expect(topicManager.createTopic(CLUSTER_ID, TOPIC_1.getName(), Optional.of(TOPIC_1.getPartitions().size()), 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()).setPartitionsCount(TOPIC_1.getPartitions().size()).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)

Example 22 with FakeAsyncResponse

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

the class TopicsResourceTest method deleteTopic_nonExistingTopic_throwsUnknownTopicOfPartitionException.

@Test
public void deleteTopic_nonExistingTopic_throwsUnknownTopicOfPartitionException() {
    expect(topicManager.deleteTopic(CLUSTER_ID, TOPIC_1.getName())).andReturn(failedFuture(new UnknownTopicOrPartitionException("")));
    replay(topicManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    topicsResource.deleteTopic(response, TOPIC_1.getClusterId(), TOPIC_1.getName());
    assertEquals(UnknownTopicOrPartitionException.class, response.getException().getClass());
}
Also used : UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 23 with FakeAsyncResponse

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

the class TopicsResourceTest method listTopics_nonExistingCluster_returnsNotFound.

@Test
public void listTopics_nonExistingCluster_returnsNotFound() {
    expect(topicManager.listTopics(CLUSTER_ID, false)).andReturn(failedFuture(new NotFoundException()));
    replay(topicManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    topicsResource.listTopics(response, CLUSTER_ID, false);
    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 24 with FakeAsyncResponse

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

the class TopicsResourceTest method createTopic_existingTopic_throwsTopicExists.

@Test
public void createTopic_existingTopic_throwsTopicExists() {
    expect(topicManager.createTopic(CLUSTER_ID, TOPIC_1.getName(), Optional.of(TOPIC_1.getPartitions().size()), Optional.of(TOPIC_1.getReplicationFactor()), /* replicasAssignments= */
    Collections.emptyMap(), singletonMap("cleanup.policy", Optional.of("compact")))).andReturn(failedFuture(new TopicExistsException("")));
    replay(topicManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    topicsResource.createTopic(response, TOPIC_1.getClusterId(), CreateTopicRequest.builder().setTopicName(TOPIC_1.getName()).setPartitionsCount(TOPIC_1.getPartitions().size()).setReplicationFactor(TOPIC_1.getReplicationFactor()).setConfigs(singletonList(CreateTopicRequest.ConfigEntry.create("cleanup.policy", "compact"))).build());
    assertEquals(TopicExistsException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) Test(org.junit.jupiter.api.Test)

Example 25 with FakeAsyncResponse

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

the class TopicsResourceTest method createTopic_nonExistingCluster_throwsNotFound.

@Test
public void createTopic_nonExistingCluster_throwsNotFound() {
    expect(topicManager.createTopic(CLUSTER_ID, TOPIC_1.getName(), Optional.of(TOPIC_1.getPartitions().size()), Optional.of(TOPIC_1.getReplicationFactor()), /* replicasAssignments= */
    Collections.emptyMap(), singletonMap("cleanup.policy", Optional.of("compact")))).andReturn(failedFuture(new NotFoundException()));
    replay(topicManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    topicsResource.createTopic(response, TOPIC_1.getClusterId(), CreateTopicRequest.builder().setTopicName(TOPIC_1.getName()).setPartitionsCount(TOPIC_1.getPartitions().size()).setReplicationFactor(TOPIC_1.getReplicationFactor()).setConfigs(singletonList(CreateTopicRequest.ConfigEntry.create("cleanup.policy", "compact"))).build());
    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