Search in sources :

Example 46 with FakeAsyncResponse

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

the class GetReassignmentActionTest method getReassignment_existingClusterTopicPartition_returnsReassignment.

@Test
public void getReassignment_existingClusterTopicPartition_returnsReassignment() throws Exception {
    expect(reassignmentManager.getReassignment(CLUSTER_ID, TOPIC_1, PARTITION_ID_1)).andReturn(CompletableFuture.completedFuture(Optional.of(REASSIGNMENT_1)));
    replay(reassignmentManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    getReassignmentAction.getReassignment(response, CLUSTER_ID, TOPIC_1, PARTITION_ID_1);
    GetReassignmentResponse expected = GetReassignmentResponse.create(ReassignmentData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/1" + "/reassignment").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=1/reassignment").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_1).setPartitionId(PARTITION_ID_1).setAddingReplicas(ADDING_REPLICAS_1).setRemovingReplicas(REMOVING_REPLICAS_1).setReplicas(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/1/replicas")).build());
    assertEquals(expected, response.getValue());
}
Also used : GetReassignmentResponse(io.confluent.kafkarest.entities.v3.GetReassignmentResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 47 with FakeAsyncResponse

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

the class ListAllReassignmentsActionTest method listAllReassignments_existingCluster_returnsReassignments.

@Test
public void listAllReassignments_existingCluster_returnsReassignments() {
    expect(reassignmentManager.listReassignments(CLUSTER_ID)).andReturn(CompletableFuture.completedFuture(asList(REASSIGNMENT_1, REASSIGNMENT_2, REASSIGNMENT_3)));
    replay(reassignmentManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    listAllReassignmentsAction.listReassignments(response, CLUSTER_ID);
    ListAllReassignmentsResponse expected = ListAllReassignmentsResponse.create(ReassignmentDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/-/partitions/-/reassignments").build()).setData(Arrays.asList(ReassignmentData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/1" + "/reassignments").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=1" + "/reassignments").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_1).setPartitionId(PARTITION_ID_1).setAddingReplicas(ADDING_REPLICAS_1).setRemovingReplicas(REMOVING_REPLICAS_1).setReplicas(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/1/replicas")).build(), ReassignmentData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/2" + "/reassignments").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=2" + "/reassignments").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_1).setPartitionId(PARTITION_ID_2).setAddingReplicas(ADDING_REPLICAS_2).setRemovingReplicas(REMOVING_REPLICAS_2).setReplicas(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/2/replicas")).build(), ReassignmentData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/3" + "/reassignments").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=3" + "/reassignments").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_1).setPartitionId(PARTITION_ID_3).setAddingReplicas(ADDING_REPLICAS_3).setRemovingReplicas(REMOVING_REPLICAS_3).setReplicas(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/3/replicas")).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : ListAllReassignmentsResponse(io.confluent.kafkarest.entities.v3.ListAllReassignmentsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 48 with FakeAsyncResponse

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

the class PartitionsResourceTest method getPartition_existingPartition_returnsPartition.

@Test
public void getPartition_existingPartition_returnsPartition() {
    expect(partitionManager.getPartition(CLUSTER_ID, TOPIC_NAME, PARTITION_1.getPartitionId())).andReturn(CompletableFuture.completedFuture(Optional.of(PARTITION_1)));
    replay(partitionManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    partitionsResource.getPartition(response, CLUSTER_ID, TOPIC_NAME, PARTITION_1.getPartitionId());
    GetPartitionResponse expected = GetPartitionResponse.create(PartitionData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/0").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=0").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(PARTITION_1.getPartitionId()).setLeader(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/0/replicas/1")).setReplicas(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/0/replicas")).setReassignment(Resource.Relationship.create("/v3/clusters/cluster-1/topics/topic-1/partitions/0/reassignment")).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v3.GetPartitionResponse) Test(org.junit.jupiter.api.Test)

Example 49 with FakeAsyncResponse

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

the class PartitionsResourceTest method listPartitions_nonExistingTopicOrCluster_throwsNotFound.

@Test
public void listPartitions_nonExistingTopicOrCluster_throwsNotFound() {
    expect(partitionManager.listPartitions(CLUSTER_ID, TOPIC_NAME)).andReturn(failedFuture(new NotFoundException()));
    replay(partitionManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    partitionsResource.listPartitions(response, CLUSTER_ID, TOPIC_NAME);
    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 50 with FakeAsyncResponse

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

the class ReplicasResourceTest method getReplica_nonExistingReplica_throwNotFound.

@Test
public void getReplica_nonExistingReplica_throwNotFound() {
    expect(replicaManager.getReplica(CLUSTER_ID, TOPIC_NAME, PARTITION_ID, REPLICA_1.getBrokerId())).andReturn(completedFuture(Optional.empty()));
    replay(replicaManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    replicasResource.getReplica(response, CLUSTER_ID, TOPIC_NAME, PARTITION_ID, REPLICA_1.getBrokerId());
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) 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