use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method testMemberStatusChangeAfterNetworkRecovery.
@Test
public void testMemberStatusChangeAfterNetworkRecovery() throws Exception {
// Create transports
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
List<Address> members = Arrays.asList(a.address(), b.address());
// Create failure detectors
FailureDetectorImpl fd_a = createFD(a, members);
FailureDetectorImpl fd_b = createFD(b, members);
List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b);
// Traffic is blocked initially on both sides: A--X-->B, B--X-->A
a.networkEmulator().block(b.address());
b.networkEmulator().block(a.address());
Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
try {
start(fdetectors);
assertStatus(a.address(), SUSPECT, awaitEvents(list_a), b.address());
assertStatus(b.address(), SUSPECT, awaitEvents(list_b), a.address());
// Unblock A and B members: A-->B, B-->A
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
TimeUnit.SECONDS.sleep(2);
// Check that members recover
list_a = listenNextEventFor(fd_a, members);
list_b = listenNextEventFor(fd_b, members);
assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address());
assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address());
} finally {
stop(fdetectors);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method testStatusChangeAfterMemberRestart.
@Test
public void testStatusChangeAfterMemberRestart() throws Exception {
// Create transports
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport x = Transport.bindAwait(true);
List<Address> members = Arrays.asList(a.address(), b.address(), x.address());
// Create failure detectors
FailureDetectorImpl fd_a = createFD(a, members);
FailureDetectorImpl fd_b = createFD(b, members);
FailureDetectorImpl fd_x = createFD(x, members);
List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_x);
Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
Future<List<FailureDetectorEvent>> list_x = listenNextEventFor(fd_x, members);
// Restarted member attributes are not initialized
Transport xx;
FailureDetectorImpl fd_xx;
try {
start(fdetectors);
assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), x.address());
assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), x.address());
assertStatus(x.address(), ALIVE, awaitEvents(list_x), a.address(), b.address());
// stop node X
stop(Lists.newArrayList(fd_x));
TimeUnit.SECONDS.sleep(2);
// restart node X as XX
xx = Transport.bindAwait(TransportConfig.builder().port(x.address().port()).portAutoIncrement(false).useNetworkEmulator(true).build());
assertEquals(x.address(), xx.address());
fdetectors = Arrays.asList(fd_a, fd_b, fd_xx = createFD(xx, members));
// actual restart here
fd_xx.start();
TimeUnit.SECONDS.sleep(2);
list_a = listenNextEventFor(fd_a, members);
list_b = listenNextEventFor(fd_b, members);
Future<List<FailureDetectorEvent>> list_xx = listenNextEventFor(fd_xx, members);
// TODO [AK]: It would be more correct to consider restarted member as a new member, so x is still suspected!
assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), xx.address());
assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), xx.address());
assertStatus(xx.address(), ALIVE, awaitEvents(list_xx), a.address(), b.address());
} finally {
stop(fdetectors);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method testTrusted.
@Test
public void testTrusted() {
// 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);
try {
start(fdetectors);
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);
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 testSuspected.
@Test
public void testSuspected() {
// 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);
// block all traffic
a.networkEmulator().block(members);
b.networkEmulator().block(members);
c.networkEmulator().block(members);
try {
start(fdetectors);
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);
assertStatus(a.address(), SUSPECT, awaitEvents(list_a), b.address(), c.address());
assertStatus(b.address(), SUSPECT, awaitEvents(list_b), a.address(), c.address());
assertStatus(c.address(), SUSPECT, awaitEvents(list_c), a.address(), b.address());
} finally {
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
c.networkEmulator().unblockAll();
stop(fdetectors);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method listenNextEventFor.
private Future<List<FailureDetectorEvent>> listenNextEventFor(FailureDetectorImpl fd, List<Address> addresses) {
addresses = new ArrayList<>(addresses);
// exclude self
addresses.remove(fd.getTransport().address());
checkArgument(!addresses.isEmpty());
List<CompletableFuture<FailureDetectorEvent>> resultFuture = new ArrayList<>();
for (final Address member : addresses) {
final CompletableFuture<FailureDetectorEvent> future = new CompletableFuture<>();
fd.listen().filter(event -> event.member().address() == member).subscribe(future::complete);
resultFuture.add(future);
}
return allOf(resultFuture);
}
Aggregations