@Test public void listBrokers_existingCluster_returnsBrokers() { expect(brokerManager.listBrokers(CLUSTER_ID)) .andReturn(CompletableFuture.completedFuture(Arrays.asList(BROKER_1, BROKER_2, BROKER_3))); replay(brokerManager); FakeAsyncResponse response = new FakeAsyncResponse(); brokersResource.listBrokers(response, CLUSTER_ID); ListBrokersResponse expected = ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf("/v3/clusters/cluster-1/brokers") .build()) .setData( Arrays.asList( BrokerData.builder() .setMetadata( Resource.Metadata.builder() .setSelf("/v3/clusters/cluster-1/brokers/1") .setResourceName("crn: .build()) .setClusterId(CLUSTER_ID) .setBrokerId(BROKER_1.getBrokerId()) .setHost(BROKER_1.getHost()) .setPort(BROKER_1.getPort()) .setRack(BROKER_1.getRack()) .setConfigs( Resource.Relationship.create( "/v3/clusters/cluster-1/brokers/1/configs")) .setPartitionReplicas( Resource.Relationship.create( "/v3/clusters/cluster-1/brokers/1/partition-replicas")) .build(), BrokerData.builder() .setMetadata( Resource.Metadata.builder() .setSelf("/v3/clusters/cluster-1/brokers/2") .setResourceName("crn: .build()) .setClusterId(CLUSTER_ID) .setBrokerId(BROKER_2.getBrokerId()) .setHost(BROKER_2.getHost()) .setPort(BROKER_2.getPort()) .setRack(BROKER_2.getRack()) .setConfigs( Resource.Relationship.create( "/v3/clusters/cluster-1/brokers/2/configs")) .setPartitionReplicas( Resource.Relationship.create( "/v3/clusters/cluster-1/brokers/2/partition-replicas")) .build(), BrokerData.builder() .setMetadata( Metadata.builder() .setSelf("/v3/clusters/cluster-1/brokers/3") .setResourceName("crn: .build()) .setClusterId(CLUSTER_ID) .setBrokerId(BROKER_3.getBrokerId()) .setHost(BROKER_3.getHost()) .setPort(BROKER_3.getPort()) .setRack(BROKER_3.getRack()) .setConfigs( Resource.Relationship.create( "/v3/clusters/cluster-1/brokers/3/configs")) .setPartitionReplicas( Resource.Relationship.create( "/v3/clusters/cluster-1/brokers/3/partition-replicas")) .build())) .build()); assertEquals(expected, response.getValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") void listBrokers(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") void getBroker(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("brokerId") Integer brokerId
  ); }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") void listBrokers(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") void getBroker(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("brokerId") Integer brokerId
  );  }