use of io.scalecube.transport.Address in project scalecube by scalecube.
the class AddressTest method testParseUnknownHostPort.
@Test
public void testParseUnknownHostPort() throws Exception {
Address address = Address.from("host:1111");
assertEquals(1111, address.port());
assertEquals("host", address.host());
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ServiceInstanceTest method test_localService_instance.
@Test
public void test_localService_instance() {
Address address = Address.create("localhost", 4000);
ServiceConfig conf = new ServiceConfig(new GreetingServiceImpl());
LocalServiceInstance instance = new LocalServiceInstance(conf, address, "a", "b", new HashMap<>());
assertEquals(instance.toString(), "LocalServiceInstance [serviceObject=GreetingServiceImpl [], memberId=a]");
assertTrue(instance.tags().isEmpty());
assertEquals(instance.memberId(), "a");
assertEquals(instance.serviceName(), "b");
try {
new LocalServiceInstance(null, address, "a", "b", new HashMap<>());
} catch (Exception ex) {
assertEquals(ex.toString(), "java.lang.IllegalArgumentException: serviceConfig can't be null");
}
try {
new LocalServiceInstance(conf, null, "a", "b", new HashMap<>());
} catch (Exception ex) {
assertEquals(ex.toString(), "java.lang.IllegalArgumentException: address can't be null");
}
try {
new LocalServiceInstance(conf, address, null, "b", new HashMap<>());
} catch (Exception ex) {
assertEquals(ex.toString(), "java.lang.IllegalArgumentException: memberId can't be null");
}
try {
new LocalServiceInstance(conf, address, "a", null, new HashMap<>());
} catch (Exception ex) {
assertEquals(ex.toString(), "java.lang.IllegalArgumentException: serviceName can't be null");
}
try {
new LocalServiceInstance(conf, address, "a", "b", null);
} catch (Exception ex) {
assertEquals(ex.toString(), "java.lang.IllegalArgumentException: methods can't be null");
}
try {
new LocalServiceInstance(conf, address, "a", "b", new HashMap<>()).invoke(null);
} catch (Exception ex) {
assertEquals(ex.toString(), "java.lang.IllegalArgumentException: message can't be null");
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method testSuspectedMemberWithNormalNetworkGetsPartitioned.
@Test
public void testSuspectedMemberWithNormalNetworkGetsPartitioned() throws Exception {
// Create transports
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
Transport d = Transport.bindAwait(true);
List<Address> members = Arrays.asList(a.address(), b.address(), c.address(), d.address());
// Create failure detectors
FailureDetectorImpl fd_a = createFD(a, members);
FailureDetectorImpl fd_b = createFD(b, members);
FailureDetectorImpl fd_c = createFD(c, members);
FailureDetectorImpl fd_d = createFD(d, members);
List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c, fd_d);
// Block traffic to node D on other members
a.networkEmulator().block(d.address());
b.networkEmulator().block(d.address());
c.networkEmulator().block(d.address());
try {
Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
Future<List<FailureDetectorEvent>> list_c = listenNextEventFor(fd_c, members);
Future<List<FailureDetectorEvent>> list_d = listenNextEventFor(fd_d, members);
start(fdetectors);
assertStatus(a.address(), SUSPECT, awaitEvents(list_a), d.address());
assertStatus(b.address(), SUSPECT, awaitEvents(list_b), d.address());
assertStatus(c.address(), SUSPECT, awaitEvents(list_c), d.address());
// node D
assertStatus(d.address(), SUSPECT, awaitEvents(list_d), a.address(), b.address(), c.address());
// partitioned
// Unblock traffic to member D on other members
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
c.networkEmulator().unblockAll();
TimeUnit.SECONDS.sleep(4);
list_a = listenNextEventFor(fd_a, members);
list_b = listenNextEventFor(fd_b, members);
list_c = listenNextEventFor(fd_c, members);
list_d = listenNextEventFor(fd_d, members);
// Check member D recovers
assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), c.address(), d.address());
assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), c.address(), d.address());
assertStatus(c.address(), ALIVE, awaitEvents(list_c), a.address(), b.address(), d.address());
assertStatus(d.address(), ALIVE, awaitEvents(list_d), a.address(), b.address(), c.address());
} finally {
stop(fdetectors);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method testTrustedDespiteBadNetwork.
@Test
public void testTrustedDespiteBadNetwork() throws Exception {
// Create transports
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
List<Address> members = Arrays.asList(a.address(), b.address(), c.address());
// Create failure detectors
FailureDetectorImpl fd_a = createFD(a, members);
FailureDetectorImpl fd_b = createFD(b, members);
FailureDetectorImpl fd_c = createFD(c, members);
List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c);
// Traffic issue at connection A -> B
a.networkEmulator().block(b.address());
Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
Future<List<FailureDetectorEvent>> list_c = listenNextEventFor(fd_c, members);
try {
start(fdetectors);
assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), c.address());
assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), c.address());
assertStatus(c.address(), ALIVE, awaitEvents(list_c), a.address(), b.address());
} finally {
stop(fdetectors);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method testSuspectedMemberWithBadNetworkGetsPartitioned.
@Test
public void testSuspectedMemberWithBadNetworkGetsPartitioned() throws Exception {
// Create transports
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
Transport d = Transport.bindAwait(true);
List<Address> members = Arrays.asList(a.address(), b.address(), c.address(), d.address());
// Create failure detectors
FailureDetectorImpl fd_a = createFD(a, members);
FailureDetectorImpl fd_b = createFD(b, members);
FailureDetectorImpl fd_c = createFD(c, members);
FailureDetectorImpl fd_d = createFD(d, members);
List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c, fd_d);
// Block traffic on member A to all cluster members
a.networkEmulator().block(members);
try {
Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
Future<List<FailureDetectorEvent>> list_c = listenNextEventFor(fd_c, members);
Future<List<FailureDetectorEvent>> list_d = listenNextEventFor(fd_d, members);
start(fdetectors);
// node A
assertStatus(a.address(), SUSPECT, awaitEvents(list_a), b.address(), c.address(), d.address());
// partitioned
assertStatus(b.address(), SUSPECT, awaitEvents(list_b), a.address());
assertStatus(c.address(), SUSPECT, awaitEvents(list_c), a.address());
assertStatus(d.address(), SUSPECT, awaitEvents(list_d), a.address());
// Unblock traffic on member A
a.networkEmulator().unblockAll();
TimeUnit.SECONDS.sleep(4);
list_a = listenNextEventFor(fd_a, members);
list_b = listenNextEventFor(fd_b, members);
list_c = listenNextEventFor(fd_c, members);
list_d = listenNextEventFor(fd_d, members);
// Check member A recovers
assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), c.address(), d.address());
assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), c.address(), d.address());
assertStatus(c.address(), ALIVE, awaitEvents(list_c), a.address(), b.address(), d.address());
assertStatus(d.address(), ALIVE, awaitEvents(list_d), a.address(), b.address(), c.address());
} finally {
stop(fdetectors);
}
}
Aggregations