@Test public void listPartitions_existingTopic_returnsPartitions() { expect(partitionManager.listPartitions(CLUSTER_ID, TOPIC_NAME)) .andReturn( CompletableFuture.completedFuture( Arrays.asList(PARTITION_1, PARTITION_2, PARTITION_3))); replay(partitionManager); FakeAsyncResponse response = new FakeAsyncResponse(); partitionsResource.listPartitions(response, CLUSTER_ID, TOPIC_NAME); ListPartitionsResponse expected = ListPartitionsResponse.create( PartitionDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions") .build()) .setData( Arrays.asList( 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(), PartitionData.builder() .setMetadata( Resource.Metadata.builder() .setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/1") .setResourceName( "crn: .build()) .setClusterId(CLUSTER_ID) .setTopicName(TOPIC_NAME) .setPartitionId(PARTITION_2.getPartitionId()) .setLeader( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/1" + "/replicas/2")) .setReplicas( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/1/replicas")) .setReassignment( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/1" + "/reassignment")) .build(), PartitionData.builder() .setMetadata( Resource.Metadata.builder() .setSelf("/v3/clusters/cluster-1/topics/topic-1/partitions/2") .setResourceName( "crn: .build()) .setClusterId(CLUSTER_ID) .setTopicName(TOPIC_NAME) .setPartitionId(PARTITION_3.getPartitionId()) .setLeader( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/2" + "/replicas/3")) .setReplicas( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/2/replicas")) .setReassignment( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/2/reassignment")) .build())) .build()); assertEquals(expected, response.getValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") public void listPartitions( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName) { CompletableFuture<ListPartitionsResponse> response = partitionManager.get() .listPartitions(clusterId, topicName) .thenApply( partitions -> ListPartitionsResponse.create( PartitionDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "topics", topicName, "partitions")) .build()) .setData( partitions.stream() .map(this::toPartitionData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
PartitionsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") public void listPartitions( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName) { CompletableFuture<ListPartitionsResponse> response = partitionManager.get() .listPartitions(clusterId, topicName) .thenApply( partitions -> ListPartitionsResponse.create( PartitionDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "topics", topicName, "partitions")) .build()) .setData( partitions.stream() .map(this::toPartitionData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
PartitionsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") public void listPartitions( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName) { CompletableFuture<ListPartitionsResponse> response = partitionManager.get() .listPartitions(clusterId, topicName) .thenApply( partitions -> ListPartitionsResponse.create( PartitionDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "topics", topicName, "partitions")) .build()) .setData( partitions.stream() .map(this::toPartitionData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  PartitionsResource(
      Provider<PartitionManager> partitionManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
PartitionsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") public void listPartitions( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName) { CompletableFuture<ListPartitionsResponse> response = partitionManager.get() .listPartitions(clusterId, topicName) .thenApply( partitions -> ListPartitionsResponse.create( PartitionDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "topics", topicName, "partitions")) .build()) .setData( partitions.stream() .map(this::toPartitionData) .collect(Collectors.toList())) .build())); 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 @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.partitions.list") public void listPartitions( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName) { CompletableFuture<ListPartitionsResponse> response = partitionManager.get() .listPartitions(clusterId, topicName) .thenApply( partitions -> ListPartitionsResponse.create( PartitionDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "topics", topicName, "partitions")) .build()) .setData( partitions.stream() .map(this::toPartitionData) .collect(Collectors.toList())) .build())); 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);  }