/** * <pre> * Construct an Executor Object * Note: port should be a within unsigned 2 byte * integer range * </pre> */ public Executor(final int id, final String host, final int port, final boolean isActive) { if (!Utils.isValidPort(port)) { throw new IllegalArgumentException(String.format( "Invalid port number %d for host %s, executor_id %d", port, host, id)); } this.id = id; this.host = host; this.port = port; this.isActive = isActive; }
@Test public void testValidPort() { Assert.assertTrue(Utils.isValidPort(1023)); Assert.assertTrue(Utils.isValidPort(10000)); Assert.assertTrue(Utils.isValidPort(3030)); Assert.assertTrue(Utils.isValidPort(1045)); }
@Test public void testOverflowPort() { Assert.assertFalse(Utils.isValidPort(70000)); Assert.assertFalse(Utils.isValidPort(65536)); }
@Test public void testNegativePort() { Assert.assertFalse(Utils.isValidPort(-1)); Assert.assertFalse(Utils.isValidPort(-10)); }
@Test public void testZeroPort() { Assert.assertFalse(Utils.isValidPort(0)); }
/** * <pre> * Construct an Executor Object * Note: port should be a within unsigned 2 byte * integer range * </pre> */ public Executor(final int id, final String host, final int port, final boolean isActive) { if (!Utils.isValidPort(port)) { throw new IllegalArgumentException(String.format( "Invalid port number %d for host %s, executor_id %d", port, host, id)); } this.id = id; this.host = host; this.port = port; this.isActive = isActive; }