Search in sources :

Example 1 with GetPartitionResponse

use of io.confluent.kafkarest.entities.v3.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);
}
Also used : ListPartitionsResponse(io.confluent.kafkarest.entities.v3.ListPartitionsResponse) Response(javax.ws.rs.core.Response) GetPartitionResponse(io.confluent.kafkarest.entities.v3.GetPartitionResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v3.GetPartitionResponse) Test(org.junit.jupiter.api.Test)

Example 2 with GetPartitionResponse

use of io.confluent.kafkarest.entities.v3.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());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v3.GetPartitionResponse) Test(org.junit.jupiter.api.Test)

Example 3 with GetPartitionResponse

use of io.confluent.kafkarest.entities.v3.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);
}
Also used : GetTopicResponse(io.confluent.kafkarest.entities.v2.GetTopicResponse) TestUtils.assertOKResponse(io.confluent.kafkarest.TestUtils.assertOKResponse) Response(javax.ws.rs.core.Response) TestUtils.assertErrorResponse(io.confluent.kafkarest.TestUtils.assertErrorResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v2.GetPartitionResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v2.GetPartitionResponse) Test(org.junit.jupiter.api.Test)

Example 4 with GetPartitionResponse

use of io.confluent.kafkarest.entities.v3.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());
    }
}
Also used : GetTopicResponse(io.confluent.kafkarest.entities.v2.GetTopicResponse) TestUtils.assertOKResponse(io.confluent.kafkarest.TestUtils.assertOKResponse) Response(javax.ws.rs.core.Response) TestUtils.assertErrorResponse(io.confluent.kafkarest.TestUtils.assertErrorResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v2.GetPartitionResponse) GetPartitionResponse(io.confluent.kafkarest.entities.v2.GetPartitionResponse) BrokerList(io.confluent.kafkarest.entities.v2.BrokerList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Aggregations

Response (javax.ws.rs.core.Response)3 Test (org.junit.jupiter.api.Test)3 TestUtils.assertErrorResponse (io.confluent.kafkarest.TestUtils.assertErrorResponse)2 TestUtils.assertOKResponse (io.confluent.kafkarest.TestUtils.assertOKResponse)2 GetPartitionResponse (io.confluent.kafkarest.entities.v2.GetPartitionResponse)2 GetTopicResponse (io.confluent.kafkarest.entities.v2.GetTopicResponse)2 GetPartitionResponse (io.confluent.kafkarest.entities.v3.GetPartitionResponse)2 BrokerList (io.confluent.kafkarest.entities.v2.BrokerList)1 ListPartitionsResponse (io.confluent.kafkarest.entities.v3.ListPartitionsResponse)1 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1