EC2ToTurbineInstance { public com.netflix.turbine.discovery.Instance convert(final Instance ec2) { final boolean state = InstanceStateName.fromValue( ec2.getState().getName() ) == InstanceStateName.Running; return new com.netflix.turbine.discovery.Instance( ec2.getPrivateIpAddress(), this.cluster, state ); } EC2ToTurbineInstance(String cluster); com.netflix.turbine.discovery.Instance convert(final Instance ec2);  }
@Test public void convertsRunningInstances() { final String ip = "172.13.131.215"; final String cluster = "blah"; final Instance ec2 = new Instance() .withPrivateIpAddress(ip) .withState(new InstanceState().withName(InstanceStateName.Running)); Assertions.assertThat(new EC2ToTurbineInstance(cluster).convert(ec2)) .isNotNull() .matches(instance -> instance.getHostname().equals(ip)) .matches(com.netflix.turbine.discovery.Instance::isUp); }
@Test public void convertsRunningInstancesWithInvalidName() { final String ip = "172.13.131.215"; final String name = "asdasdasdasdasda"; final String cluster = "blah"; final Instance ec2 = new Instance() .withPrivateIpAddress(ip) .withTags(new Tag("Name", name)) .withState(new InstanceState().withName(InstanceStateName.Running)); Assertions.assertThat(new EC2ToTurbineInstance(cluster).convert(ec2)) .isNotNull() .matches(instance -> instance.getHostname().equals(ip)) .matches(com.netflix.turbine.discovery.Instance::isUp); }
@Test public void convertsNonRunningInstances() { final String ip = "177.12.43.123"; final String cluster = "blah"; final Instance ec2 = new Instance() .withPrivateIpAddress(ip) .withState(new InstanceState().withName(InstanceStateName.Pending)); Assertions.assertThat(new EC2ToTurbineInstance(cluster).convert(ec2)) .isNotNull() .matches(instance -> instance.getHostname().equals(ip)) .matches(instance -> !instance.isUp()); }