use of io.confluent.kafkarest.entities.v2.GetPartitionResponse in project kafka-rest by confluentinc.
the class PartitionsResourceIntegrationTest method getPartition_existingPartition_returnPartition.
@Test
public void getPartition_existingPartition_returnPartition() throws Exception {
String baseUrl = restConnect;
String clusterId = getClusterId();
GetPartitionResponse expected = GetPartitionResponse.create(PartitionData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/0").setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_NAME + "/partition=0").build()).setClusterId(clusterId).setTopicName(TOPIC_NAME).setPartitionId(0).setLeader(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/0/replicas/0")).setReplicas(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/0/replicas")).setReassignment(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/0/reassignment")).build());
Response response = request("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/partitions/0").accept(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
GetPartitionResponse actual = response.readEntity(GetPartitionResponse.class);
assertEquals(expected, actual);
}
use of io.confluent.kafkarest.entities.v2.GetPartitionResponse 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());
}
use of io.confluent.kafkarest.entities.v2.GetPartitionResponse in project kafka-rest by confluentinc.
the class MetadataAPITest method testPartitionsList.
@Test
public void testPartitionsList() throws InterruptedException {
// Listing
testWithRetry(() -> verifyPartitionGet(topic1Name, 2, 1));
testWithRetry(() -> verifyPartitionGet(topic2Name, 2, 2));
// Get single partition
// No need to retry, because we know the topic has been made by this point as the above
// assertions pass
Response response = request("/topics/" + topic1Name + "/partitions/0").get();
assertOKResponse(response, Versions.KAFKA_V2_JSON);
final GetPartitionResponse getPartitionResponse = tryReadEntityOrLog(response, GetPartitionResponse.class);
assertEquals((Integer) 0, getPartitionResponse.getPartition());
assertEquals(numReplicas, getPartitionResponse.getReplicas().size());
// Get invalid partition
final Response invalidResponse = request("/topics/topic1/partitions/1000").get();
assertErrorResponse(Response.Status.NOT_FOUND, invalidResponse, Errors.PARTITION_NOT_FOUND_ERROR_CODE, Errors.PARTITION_NOT_FOUND_MESSAGE, Versions.KAFKA_V2_JSON);
}
use of io.confluent.kafkarest.entities.v2.GetPartitionResponse in project kafka-rest by confluentinc.
the class MetadataAPITest method verifyPartitionGet.
private void verifyPartitionGet(String topicName, int numReplicas, int numPartitions) {
Response response = request("/topics/" + topicName + "/partitions").get();
assertOKResponse(response, Versions.KAFKA_V2_JSON);
List<GetPartitionResponse> partitionsResponse = tryReadEntityOrLog(response, new GenericType<List<GetPartitionResponse>>() {
});
// Just verify some basic properties because the exact values can vary based on replica
// assignment, leader election
assertEquals(numPartitions, partitionsResponse.size());
for (int i = 0; i < numPartitions; i++) {
assertEquals(numReplicas, partitionsResponse.get(i).getReplicas().size());
}
}
Aggregations