use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class GossipProtocolTest method computeMessageLostStats.
private LongSummaryStatistics computeMessageLostStats(List<GossipProtocolImpl> gossipProtocols) {
List<Long> messageLostPerNode = new ArrayList<>(gossipProtocols.size());
for (GossipProtocolImpl gossipProtocol : gossipProtocols) {
Transport transport = gossipProtocol.getTransport();
messageLostPerNode.add(transport.networkEmulator().totalMessageLostCount());
}
return messageLostPerNode.stream().mapToLong(v -> v).summaryStatistics();
}
use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class GossipProtocolTest method initTransports.
private List<Transport> initTransports(int count, int lostPercent, int meanDelay) {
List<Transport> transports = new ArrayList<>(count);
int startPort = TransportConfig.DEFAULT_PORT;
for (int i = 0; i < count; i++) {
TransportConfig transportConfig = TransportConfig.builder().useNetworkEmulator(true).port(startPort).portCount(1000).build();
Transport transport = Transport.bindAwait(transportConfig);
transport.networkEmulator().setDefaultLinkSettings(lostPercent, meanDelay);
transports.add(transport);
startPort = transport.address().port() + 1;
}
return transports;
}
use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class MembershipProtocolTest method testLongNetworkPartitionNoRecovery.
@Test
public void testLongNetworkPartitionNoRecovery() {
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
Transport d = Transport.bindAwait(true);
List<Address> members = ImmutableList.of(a.address(), b.address(), c.address(), d.address());
MembershipProtocolImpl cm_a = createMembership(a, members);
MembershipProtocolImpl cm_b = createMembership(b, members);
MembershipProtocolImpl cm_c = createMembership(c, members);
MembershipProtocolImpl cm_d = createMembership(d, members);
try {
awaitSeconds(1);
assertTrusted(cm_a, a.address(), b.address(), c.address(), d.address());
assertTrusted(cm_b, a.address(), b.address(), c.address(), d.address());
assertTrusted(cm_c, a.address(), b.address(), c.address(), d.address());
assertTrusted(cm_d, a.address(), b.address(), c.address(), d.address());
a.networkEmulator().block(Arrays.asList(c.address(), d.address()));
b.networkEmulator().block(Arrays.asList(c.address(), d.address()));
c.networkEmulator().block(Arrays.asList(a.address(), b.address()));
d.networkEmulator().block(Arrays.asList(a.address(), b.address()));
awaitSeconds(2);
assertTrusted(cm_a, a.address(), b.address());
assertSuspected(cm_a, c.address(), d.address());
assertTrusted(cm_b, a.address(), b.address());
assertSuspected(cm_b, c.address(), d.address());
assertTrusted(cm_c, c.address(), d.address());
assertSuspected(cm_c, a.address(), b.address());
assertTrusted(cm_d, c.address(), d.address());
assertSuspected(cm_d, a.address(), b.address());
long suspicionTimeoutSec = ClusterMath.suspicionTimeout(ClusterConfig.DEFAULT_SUSPICION_MULT, 4, TEST_PING_INTERVAL) / 1000;
// > max suspect time
awaitSeconds(suspicionTimeoutSec + 1);
assertTrusted(cm_a, a.address(), b.address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, a.address(), b.address());
assertNoSuspected(cm_b);
assertTrusted(cm_c, c.address(), d.address());
assertNoSuspected(cm_c);
assertTrusted(cm_d, c.address(), d.address());
assertNoSuspected(cm_d);
} finally {
stopAll(cm_a, cm_b, cm_c, cm_d);
}
}
use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class MembershipProtocolTest method testOverrideMemberAddress.
@Test
public void testOverrideMemberAddress() throws UnknownHostException {
String localAddress = InetAddress.getLocalHost().getHostName();
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
Transport d = Transport.bindAwait(true);
Transport e = Transport.bindAwait(true);
MembershipProtocolImpl cm_a = createMembership(a, testConfig(Collections.emptyList()).memberHost(localAddress).build());
MembershipProtocolImpl cm_b = createMembership(b, testConfig(Collections.singletonList(a.address())).memberHost(localAddress).build());
MembershipProtocolImpl cm_c = createMembership(c, testConfig(Collections.singletonList(a.address())).memberHost(localAddress).build());
MembershipProtocolImpl cm_d = createMembership(d, testConfig(Collections.singletonList(b.address())).memberHost(localAddress).build());
MembershipProtocolImpl cm_e = createMembership(e, testConfig(Collections.singletonList(b.address())).memberHost(localAddress).build());
try {
awaitSeconds(3);
assertTrusted(cm_a, cm_a.member().address(), cm_b.member().address(), cm_c.member().address(), cm_d.member().address(), cm_e.member().address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, cm_a.member().address(), cm_b.member().address(), cm_c.member().address(), cm_d.member().address(), cm_e.member().address());
assertNoSuspected(cm_b);
assertTrusted(cm_c, cm_a.member().address(), cm_b.member().address(), cm_c.member().address(), cm_d.member().address(), cm_e.member().address());
assertNoSuspected(cm_c);
assertTrusted(cm_d, cm_a.member().address(), cm_b.member().address(), cm_c.member().address(), cm_d.member().address(), cm_e.member().address());
assertNoSuspected(cm_d);
assertTrusted(cm_e, cm_a.member().address(), cm_b.member().address(), cm_c.member().address(), cm_d.member().address(), cm_e.member().address());
assertNoSuspected(cm_e);
} finally {
stopAll(cm_a, cm_b, cm_c, cm_d, cm_e);
}
}
use of io.scalecube.transport.Transport in project scalecube by scalecube.
the class MembershipProtocolTest method testRestartFailedMembers.
@Test
public void testRestartFailedMembers() {
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
Transport d = Transport.bindAwait(true);
List<Address> members = ImmutableList.of(a.address(), b.address(), c.address(), d.address());
MembershipProtocolImpl cm_a = createMembership(a, members);
MembershipProtocolImpl cm_b = createMembership(b, members);
MembershipProtocolImpl cm_c = createMembership(c, members);
MembershipProtocolImpl cm_d = createMembership(d, members);
MembershipProtocolImpl cm_restartedC = null;
MembershipProtocolImpl cm_restartedD = null;
try {
awaitSeconds(1);
assertTrusted(cm_a, a.address(), b.address(), c.address(), d.address());
assertTrusted(cm_b, a.address(), b.address(), c.address(), d.address());
assertTrusted(cm_c, a.address(), b.address(), c.address(), d.address());
assertTrusted(cm_d, a.address(), b.address(), c.address(), d.address());
stop(cm_c);
stop(cm_d);
awaitSeconds(1);
assertTrusted(cm_a, a.address(), b.address());
assertSuspected(cm_a, c.address(), d.address());
assertTrusted(cm_b, a.address(), b.address());
assertSuspected(cm_b, c.address(), d.address());
long suspicionTimeoutSec = ClusterMath.suspicionTimeout(ClusterConfig.DEFAULT_SUSPICION_MULT, 4, TEST_PING_INTERVAL) / 1000;
// > max suspect time
awaitSeconds(suspicionTimeoutSec + 1);
assertTrusted(cm_a, a.address(), b.address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, a.address(), b.address());
assertNoSuspected(cm_b);
c = Transport.bindAwait(true);
d = Transport.bindAwait(true);
cm_restartedC = createMembership(c, Arrays.asList(a.address(), b.address()));
cm_restartedD = createMembership(d, Arrays.asList(a.address(), b.address()));
awaitSeconds(1);
assertTrusted(cm_restartedC, a.address(), b.address(), c.address(), d.address());
assertNoSuspected(cm_restartedC);
assertTrusted(cm_restartedD, a.address(), b.address(), c.address(), d.address());
assertNoSuspected(cm_restartedD);
assertTrusted(cm_a, a.address(), b.address(), c.address(), d.address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, a.address(), b.address(), c.address(), d.address());
assertNoSuspected(cm_b);
} finally {
stopAll(cm_a, cm_b, cm_restartedC, cm_restartedD);
}
}
Aggregations