@Test public void listTopics_timeoutException_returnsTimeoutException() { expect(topicManager.listTopics(CLUSTER_ID)) .andReturn(failedFuture(new TimeoutException())); replay(topicManager); FakeAsyncResponse response = new FakeAsyncResponse(); topicsResource.listTopics(response, CLUSTER_ID); assertEquals(TimeoutException.class, response.getException().getClass()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") public void listTopics( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListTopicsResponse> response = topicManager.get() .listTopics(clusterId) .thenApply( topics -> ListTopicsResponse.create( TopicDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "topics")) .build()) .setData( topics.stream() .sorted(Comparator.comparing(Topic::getName)) .map(this::toTopicData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
TopicsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") public void listTopics( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListTopicsResponse> response = topicManager.get() .listTopics(clusterId) .thenApply( topics -> ListTopicsResponse.create( TopicDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "topics")) .build()) .setData( topics.stream() .sorted(Comparator.comparing(Topic::getName)) .map(this::toTopicData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
TopicsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") public void listTopics( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListTopicsResponse> response = topicManager.get() .listTopics(clusterId) .thenApply( topics -> ListTopicsResponse.create( TopicDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "topics")) .build()) .setData( topics.stream() .sorted(Comparator.comparing(Topic::getName)) .map(this::toTopicData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  TopicsResource(
      Provider<TopicManager> topicManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
TopicsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") public void listTopics( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListTopicsResponse> response = topicManager.get() .listTopics(clusterId) .thenApply( topics -> ListTopicsResponse.create( TopicDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "topics")) .build()) .setData( topics.stream() .sorted(Comparator.comparing(Topic::getName)) .map(this::toTopicData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  TopicsResource(
      Provider<TopicManager> topicManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") void listTopics(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") void getTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  ); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.create") void createTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @Valid CreateTopicRequest request
  ); @DELETE @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.delete") void deleteTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  ); }
TopicsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") public void listTopics( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListTopicsResponse> response = topicManager.get() .listTopics(clusterId) .thenApply( topics -> ListTopicsResponse.create( TopicDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "topics")) .build()) .setData( topics.stream() .sorted(Comparator.comparing(Topic::getName)) .map(this::toTopicData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  TopicsResource(
      Provider<TopicManager> topicManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") void listTopics(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") void getTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  ); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.create") void createTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @Valid CreateTopicRequest request
  ); @DELETE @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.delete") void deleteTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  );  }