Search in sources :

Example 51 with FakeAsyncResponse

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

the class ReplicasResourceTest method listReplicas_nonExistingPartitionOrTopicOrCluster_throwsNotFound.

@Test
public void listReplicas_nonExistingPartitionOrTopicOrCluster_throwsNotFound() {
    expect(replicaManager.listReplicas(CLUSTER_ID, TOPIC_NAME, PARTITION_ID)).andReturn(failedFuture(new NotFoundException()));
    replay(replicaManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    replicasResource.listReplicas(response, CLUSTER_ID, TOPIC_NAME, PARTITION_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)

Example 52 with FakeAsyncResponse

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

the class ReplicasResourceTest method listReplicas_existingPartition_returnsReplicas.

@Test
public void listReplicas_existingPartition_returnsReplicas() {
    expect(replicaManager.listReplicas(CLUSTER_ID, TOPIC_NAME, PARTITION_ID)).andReturn(completedFuture(Arrays.asList(REPLICA_1, REPLICA_2, REPLICA_3)));
    replay(replicaManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    replicasResource.listReplicas(response, CLUSTER_ID, TOPIC_NAME, PARTITION_ID);
    ListReplicasResponse expected = ListReplicasResponse.create(ReplicaDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/0/replicas").build()).setData(Arrays.asList(ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/0" + "/replicas/1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=0" + "/replica=1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(PARTITION_ID).setBrokerId(REPLICA_1.getBrokerId()).setLeader(true).setInSync(true).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).build(), ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/0" + "/replicas/2").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=0" + "/replica=2").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(PARTITION_ID).setBrokerId(REPLICA_2.getBrokerId()).setLeader(false).setInSync(true).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/2")).build(), ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/0" + "/replicas/3").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=0" + "/replica=3").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(PARTITION_ID).setBrokerId(REPLICA_3.getBrokerId()).setLeader(false).setInSync(false).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/3")).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : ListReplicasResponse(io.confluent.kafkarest.entities.v3.ListReplicasResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 53 with FakeAsyncResponse

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

the class AlterBrokerConfigBatchActionTest method alterBrokerConfigs_existingConfig_alterConfigs.

@Test
public void alterBrokerConfigs_existingConfig_alterConfigs() {
    expect(brokerConfigManager.alterBrokerConfigs(CLUSTER_ID, BROKER_ID, Arrays.asList(AlterConfigCommand.set(CONFIG_1.getName(), "newValue"), AlterConfigCommand.delete(CONFIG_2.getName())))).andReturn(completedFuture(null));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    alterBrokerConfigBatchAction.alterBrokerConfigBatch(response, CLUSTER_ID, BROKER_ID, AlterBrokerConfigBatchRequest.create(AlterConfigBatchRequestData.create(Arrays.asList(AlterEntry.builder().setName(CONFIG_1.getName()).setValue("newValue").build(), AlterEntry.builder().setName(CONFIG_2.getName()).setOperation(AlterOperation.DELETE).build()))));
    assertNull(response.getValue());
    assertNull(response.getException());
    assertTrue(response.isDone());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 54 with FakeAsyncResponse

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

the class AlterBrokerConfigBatchActionTest method alterBrokerConfigs_nonExistingCluster_throwsNotFound.

@Test
public void alterBrokerConfigs_nonExistingCluster_throwsNotFound() {
    expect(brokerConfigManager.alterBrokerConfigs(CLUSTER_ID, BROKER_ID, Arrays.asList(AlterConfigCommand.set(CONFIG_1.getName(), "newValue"), AlterConfigCommand.delete(CONFIG_2.getName())))).andReturn(failedFuture(new NotFoundException()));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    alterBrokerConfigBatchAction.alterBrokerConfigBatch(response, CLUSTER_ID, BROKER_ID, AlterBrokerConfigBatchRequest.create(AlterConfigBatchRequestData.create(Arrays.asList(AlterEntry.builder().setName(CONFIG_1.getName()).setValue("newValue").build(), AlterEntry.builder().setName(CONFIG_2.getName()).setOperation(AlterOperation.DELETE).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)

Example 55 with FakeAsyncResponse

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

the class ClusterConfigResourceTest method updateConfig_nonExistingCluster_throwsNotFound.

@Test
public void updateConfig_nonExistingCluster_throwsNotFound() {
    expect(clusterConfigManager.upsertClusterConfig(CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName(), "new-value")).andReturn(failedFuture(new NotFoundException()));
    replay(clusterConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clusterConfigsResource.upsertClusterConfig(response, CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName(), UpdateClusterConfigRequest.create("new-value"));
    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