@Test public void listPartitions_nonExistingTopicOrCluster_throwsNotFound() { expect(partitionManager.listPartitions(CLUSTER_ID, TOPIC_NAME)) .andReturn(failedFuture(new NotFoundException())); replay(partitionManager); FakeAsyncResponse response = new FakeAsyncResponse(); partitionsResource.listPartitions(response, CLUSTER_ID, TOPIC_NAME); assertEquals(NotFoundException.class, response.getException().getClass()); }
@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);  }