InboundPortsUtils { public static Collection<Integer> getRequiredOpenPorts(Entity entity, Boolean portsAutoInfer, String portRegex) { return getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), portsAutoInfer, portRegex); }  static Collection<Integer> getRequiredOpenPorts(Entity entity, Boolean portsAutoInfer, String portRegex); static Collection<Integer> getRequiredOpenPorts(Entity entity, Set<ConfigKey<?>> extraConfigKeys, Boolean portsAutoInfer, String portRegex);  }
@Test public void testGetRequiredOpenPortsGetsDynamicallyAddedKeys() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); Collection<Integer> defaultRequiredOpenPorts = InboundPortsUtils.getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), true, null); Assert.assertEquals(defaultRequiredOpenPorts, ImmutableSet.of(), "Expected no ports"); ConfigKey<Integer> newTestConfigKeyPort = ConfigKeys.newIntegerConfigKey("new.test.config.key.port"); ConfigKey<String> newTestConfigKeyString = ConfigKeys.newStringConfigKey("new.test.config.key.string"); entity.config().set(newTestConfigKeyPort, 9999); entity.config().set(newTestConfigKeyString, "foo.bar"); Collection<Integer> dynamicRequiredOpenPorts = InboundPortsUtils.getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), true, null); Assert.assertEquals(dynamicRequiredOpenPorts, ImmutableSet.of(9999), "Expected new port to be added"); }
@Test public void testGetRequiredOpenPortsGetsDynamicallyAddedPortBasedKeys() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); PortAttributeSensorAndConfigKey newTestConfigKeyPort = ConfigKeys.newPortSensorAndConfigKey("new.test.config.port.string.first", "port", "7777+"); PortAttributeSensorAndConfigKey newTestConfigKeyPort2 = ConfigKeys.newPortSensorAndConfigKey("new.test.config.port.string.second", "port"); ConfigKey<Object> newTestConfigKeyObject = ConfigKeys.newConfigKey(Object.class, "new.test.config.object"); ConfigKey<String> newTestConfigKeyString = ConfigKeys.newStringConfigKey("new.test.config.key.string"); entity.config().set(newTestConfigKeyPort, PortRanges.fromString("8888+")); entity.config().set(newTestConfigKeyPort2, PortRanges.fromInteger(9999)); entity.config().set(newTestConfigKeyObject, PortRanges.fromInteger(2222)); entity.config().set(newTestConfigKeyString, "foo.bar"); Collection<Integer> dynamicRequiredOpenPorts = InboundPortsUtils.getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), true, null); Assert.assertTrue(dynamicRequiredOpenPorts.contains(8888)); Assert.assertTrue(dynamicRequiredOpenPorts.contains(9999)); Assert.assertTrue(dynamicRequiredOpenPorts.contains(2222)); }