@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: .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()); }
@GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") public void getPartition( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, @PathParam("partitionId") Integer partitionId) { CompletableFuture<GetPartitionResponse> response = partitionManager.get() .getPartition(clusterId, topicName, partitionId) .thenApply(partition -> partition.orElseThrow(NotFoundException::new)) .thenApply(partition -> GetPartitionResponse.create(toPartitionData(partition))); AsyncResponses.asyncResume(asyncResponse, response); }
PartitionsResource { @GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") public void getPartition( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, @PathParam("partitionId") Integer partitionId) { CompletableFuture<GetPartitionResponse> response = partitionManager.get() .getPartition(clusterId, topicName, partitionId) .thenApply(partition -> partition.orElseThrow(NotFoundException::new)) .thenApply(partition -> GetPartitionResponse.create(toPartitionData(partition))); AsyncResponses.asyncResume(asyncResponse, response); } }
PartitionsResource { @GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") public void getPartition( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, @PathParam("partitionId") Integer partitionId) { CompletableFuture<GetPartitionResponse> response = partitionManager.get() .getPartition(clusterId, topicName, partitionId) .thenApply(partition -> partition.orElseThrow(NotFoundException::new)) .thenApply(partition -> GetPartitionResponse.create(toPartitionData(partition))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  PartitionsResource(
      Provider<PartitionManager> partitionManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
PartitionsResource { @GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") public void getPartition( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, @PathParam("partitionId") Integer partitionId) { CompletableFuture<GetPartitionResponse> response = partitionManager.get() .getPartition(clusterId, topicName, partitionId) .thenApply(partition -> partition.orElseThrow(NotFoundException::new)) .thenApply(partition -> GetPartitionResponse.create(toPartitionData(partition))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  PartitionsResource(
      Provider<PartitionManager> partitionManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") void listPartitions(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName); @GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") void getPartition(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName,
      @PathParam("partitionId") Integer partitionId); }
PartitionsResource { @GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") public void getPartition( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, @PathParam("partitionId") Integer partitionId) { CompletableFuture<GetPartitionResponse> response = partitionManager.get() .getPartition(clusterId, topicName, partitionId) .thenApply(partition -> partition.orElseThrow(NotFoundException::new)) .thenApply(partition -> GetPartitionResponse.create(toPartitionData(partition))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  PartitionsResource(
      Provider<PartitionManager> partitionManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") void listPartitions(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName); @GET @Path("/{partitionId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.get") void getPartition(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName,
      @PathParam("partitionId") Integer partitionId);  }