@Test public void getPartition_nonExistingPartition_throwsNotFound() { expect(partitionManager.getPartition(CLUSTER_ID, TOPIC_NAME, PARTITION_1.getPartitionId())) .andReturn(CompletableFuture.completedFuture(Optional.empty())); replay(partitionManager); FakeAsyncResponse response = new FakeAsyncResponse(); partitionsResource.getPartition(response, CLUSTER_ID, TOPIC_NAME, PARTITION_1.getPartitionId()); assertEquals(NotFoundException.class, response.getException().getClass()); }
@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);  }