Search in sources :

Example 1 with SearchReplicasByBrokerResponse

use of io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse in project kafka-rest by confluentinc.

the class SearchReplicasByBrokerActionTest method searchReplicasByBroker_existingBroker_returnsReplicas.

@Test
public void searchReplicasByBroker_existingBroker_returnsReplicas() {
    expect(replicaManager.searchReplicasByBrokerId(CLUSTER_ID, BROKER_ID)).andReturn(completedFuture(Arrays.asList(REPLICA_1, REPLICA_2)));
    replay(replicaManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    searchReplicasByBrokerAction.searchReplicasByBroker(response, CLUSTER_ID, BROKER_ID);
    SearchReplicasByBrokerResponse expected = SearchReplicasByBrokerResponse.create(ReplicaDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/partition-replicas").build()).setData(Arrays.asList(ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/1" + "/replicas/1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=1" + "/replica=1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(REPLICA_1.getPartitionId()).setBrokerId(BROKER_ID).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/2" + "/replicas/1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/partition=2" + "/replica=1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setPartitionId(REPLICA_2.getPartitionId()).setBrokerId(BROKER_ID).setLeader(false).setInSync(false).setBroker(Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : SearchReplicasByBrokerResponse(io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 2 with SearchReplicasByBrokerResponse

use of io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse in project kafka-rest by confluentinc.

the class SearchReplicasByBrokerActionIntegrationTest method searchReplicasByBroker_existingBroker_returnsReplicas.

@Test
public void searchReplicasByBroker_existingBroker_returnsReplicas() {
    String baseUrl = restConnect;
    String clusterId = getClusterId();
    SearchReplicasByBrokerResponse expected = SearchReplicasByBrokerResponse.create(ReplicaDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + BROKER_ID + "/partition-replicas").build()).setData(Arrays.asList(ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/0/replicas/" + BROKER_ID).setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_NAME + "/partition=0/replica=" + BROKER_ID).build()).setClusterId(clusterId).setTopicName(TOPIC_NAME).setPartitionId(0).setBrokerId(BROKER_ID).setLeader(true).setInSync(true).setBroker(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + BROKER_ID)).build(), ReplicaData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/1/replicas/" + BROKER_ID).setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_NAME + "/partition=1/replica=" + BROKER_ID).build()).setClusterId(clusterId).setTopicName(TOPIC_NAME).setPartitionId(1).setBrokerId(BROKER_ID).setLeader(false).setInSync(true).setBroker(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + BROKER_ID)).build())).build());
    Response response = request("/v3/clusters/" + clusterId + "/brokers/" + BROKER_ID + "/partition-replicas").accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    SearchReplicasByBrokerResponse actual = response.readEntity(SearchReplicasByBrokerResponse.class);
    assertEquals(expected, actual);
}
Also used : SearchReplicasByBrokerResponse(io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse) Response(javax.ws.rs.core.Response) SearchReplicasByBrokerResponse(io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse) Test(org.junit.jupiter.api.Test)

Aggregations

SearchReplicasByBrokerResponse (io.confluent.kafkarest.entities.v3.SearchReplicasByBrokerResponse)2 Test (org.junit.jupiter.api.Test)2 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 Response (javax.ws.rs.core.Response)1