Search in sources :

Example 61 with FakeAsyncResponse

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

the class BrokerConfigResourceTest method getBrokerConfig_nonExistingConfig_throwsNotFound.

@Test
public void getBrokerConfig_nonExistingConfig_throwsNotFound() {
    expect(brokerConfigManager.getBrokerConfig(CLUSTER_ID, BROKER_ID, CONFIG_1.getName())).andReturn(failedFuture(new NotFoundException()));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.getBrokerConfig(response, CLUSTER_ID, BROKER_ID, CONFIG_1.getName());
    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 62 with FakeAsyncResponse

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

the class BrokerConfigResourceTest method updateBrokerConfig_existingConfig_updatesConfig.

@Test
public void updateBrokerConfig_existingConfig_updatesConfig() {
    expect(brokerConfigManager.updateBrokerConfig(CLUSTER_ID, BROKER_ID, CONFIG_1.getName(), "new-value")).andReturn(completedFuture(null));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.updateBrokerConfig(response, CLUSTER_ID, BROKER_ID, CONFIG_1.getName(), UpdateBrokerConfigRequest.create("new-value"));
    assertNull(response.getValue());
    assertNull(response.getException());
    assertTrue(response.isDone());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 63 with FakeAsyncResponse

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

the class BrokerConfigResourceTest method resetBrokerConfig_existingConfig_resetsConfig.

@Test
public void resetBrokerConfig_existingConfig_resetsConfig() {
    expect(brokerConfigManager.resetBrokerConfig(CLUSTER_ID, BROKER_ID, CONFIG_1.getName())).andReturn(completedFuture(null));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.resetBrokerConfig(response, CLUSTER_ID, BROKER_ID, CONFIG_1.getName());
    assertNull(response.getValue());
    assertNull(response.getException());
    assertTrue(response.isDone());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 64 with FakeAsyncResponse

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

the class BrokerConfigResourceTest method listBrokerConfigs_existingBroker_returnsConfigs.

@Test
public void listBrokerConfigs_existingBroker_returnsConfigs() {
    expect(brokerConfigManager.listBrokerConfigs(CLUSTER_ID, BROKER_ID)).andReturn(completedFuture(Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3)));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.listBrokerConfigs(response, CLUSTER_ID, BROKER_ID);
    ListBrokerConfigsResponse expected = ListBrokerConfigsResponse.create(BrokerConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs").build()).setData(Arrays.asList(BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-1").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-1").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_1.getName()).setValue(CONFIG_1.getValue()).setDefault(CONFIG_1.isDefault()).setReadOnly(CONFIG_1.isReadOnly()).setSensitive(CONFIG_1.isSensitive()).setSource(CONFIG_1.getSource()).setSynonyms(CONFIG_1.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build(), BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-2").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-2").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_2.getName()).setValue(CONFIG_2.getValue()).setDefault(CONFIG_2.isDefault()).setReadOnly(CONFIG_2.isReadOnly()).setSensitive(CONFIG_2.isSensitive()).setSource(CONFIG_2.getSource()).setSynonyms(CONFIG_2.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build(), BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-3").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-3").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_3.getName()).setValue(CONFIG_3.getValue()).setDefault(CONFIG_3.isDefault()).setReadOnly(CONFIG_3.isReadOnly()).setSensitive(CONFIG_3.isSensitive()).setSource(CONFIG_3.getSource()).setSynonyms(CONFIG_3.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Test(org.junit.jupiter.api.Test)

Example 65 with FakeAsyncResponse

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

the class ClustersResourceTest method getCluster_otherCluster_returnsNotFoundException.

@Test
public void getCluster_otherCluster_returnsNotFoundException() {
    expect(clusterManager.getCluster("foobar")).andReturn(CompletableFuture.completedFuture(Optional.empty()));
    replay(clusterManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clustersResource.getCluster(response, "foobar");
    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