InstanceList { public List<Instance> get() { final ClusterTag tag = new ClusterTag(this.cluster, this.config); final String name = tag.name(); final String value = tag.value(); InstanceList.LOGGER.info( String.format( "Looking for instances for '%s' filtering with '%s'='%s'", this.cluster, name, value ) ); final EC2ToTurbineInstance converter = new EC2ToTurbineInstance( this.cluster ); return this.provider.client() .describeInstances(this.request(name, value)) .getReservations() .parallelStream() .map(Reservation::getInstances) .flatMap(List::stream) .map(converter::convert) .collect(Collectors.toList()); } InstanceList(
        final String cluster,
        final Config config,
        final EC2ClientProvider provider
    ); List<Instance> get();  }
@Test public void listsInstances() { Mockito.when( this.client.describeInstances( Mockito.any(DescribeInstancesRequest.class) ) ).thenReturn( new DescribeInstancesResult() .withReservations( Collections.singletonList(this.fakeReservation()) ) ); final List<Instance> instances = new InstanceList( "blah", this.fakeConfig(), this.provider ).get(); Assertions.assertThat(instances).hasSize(1); }
@Test public void listsInstancesFromMultipleReservartions() { Mockito.when( this.client.describeInstances( Mockito.any(DescribeInstancesRequest.class) ) ).thenReturn( new DescribeInstancesResult() .withReservations( Arrays.asList( this.fakeReservation(), this.fakeReservation(), this.fakeReservation(), this.fakeReservation() ) ) ); final List<Instance> instances = new InstanceList( "blah", this.fakeConfig(), this.provider ).get(); Assertions.assertThat(instances).hasSize(4); }