use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class ClusterImpl method join0.
public CompletableFuture<Cluster> join0() {
CompletableFuture<Transport> transportFuture = Transport.bind(config.getTransportConfig());
CompletableFuture<Void> clusterFuture = transportFuture.thenCompose(boundTransport -> {
transport = boundTransport;
messageObservable = transport.listen().filter(// filter out system gossips
msg -> !SYSTEM_MESSAGES.contains(msg.qualifier()));
membership = new MembershipProtocolImpl(transport, config);
gossip = new GossipProtocolImpl(transport, membership, config);
failureDetector = new FailureDetectorImpl(transport, membership, config);
membership.setFailureDetector(failureDetector);
membership.setGossipProtocol(gossip);
Member localMember = membership.member();
onMemberAdded(localMember);
membership.listen().filter(MembershipEvent::isAdded).map(MembershipEvent::member).subscribe(this::onMemberAdded, this::onError);
membership.listen().filter(MembershipEvent::isRemoved).map(MembershipEvent::member).subscribe(this::onMemberRemoved, this::onError);
membership.listen().filter(MembershipEvent::isUpdated).map(MembershipEvent::member).subscribe(this::onMemberUpdated, this::onError);
failureDetector.start();
gossip.start();
gossipObservable = gossip.listen().filter(// filter out system gossips
msg -> !SYSTEM_GOSSIPS.contains(msg.qualifier()));
return membership.start();
});
return clusterFuture.thenApply(aVoid -> ClusterImpl.this);
}
use of io.scalecube.transport.Transport 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.Transport 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.Transport 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);
}
}
use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class GossipProtocolTest method initGossipProtocols.
private List<GossipProtocolImpl> initGossipProtocols(int count, int lostPercent, int meanDelay) {
final List<Transport> transports = initTransports(count, lostPercent, meanDelay);
List<Address> members = new ArrayList<>();
for (Transport transport : transports) {
members.add(transport.address());
}
List<GossipProtocolImpl> gossipProtocols = new ArrayList<>();
for (Transport transport : transports) {
gossipProtocols.add(initGossipProtocol(transport, members));
}
return gossipProtocols;
}
Aggregations