use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolImpl method doSync.
private void doSync() {
try {
Address syncMember = selectSyncAddress();
if (syncMember == null) {
return;
}
Message syncMsg = prepareSyncDataMsg(SYNC, null);
transport.send(syncMember, syncMsg);
LOGGER.debug("Send Sync to {}: {}", syncMember, syncMsg);
} catch (Exception cause) {
LOGGER.error("Unhandled exception: {}", cause, cause);
}
}
use of io.scalecube.transport.Address 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.Address 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);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolTest method testNetworkDisabledThenRecovered.
@Test
public void testNetworkDisabledThenRecovered() {
Transport a = Transport.bindAwait(true);
Transport b = Transport.bindAwait(true);
Transport c = Transport.bindAwait(true);
List<Address> members = ImmutableList.of(a.address(), b.address(), c.address());
MembershipProtocolImpl cm_a = createMembership(a, members);
MembershipProtocolImpl cm_b = createMembership(b, members);
MembershipProtocolImpl cm_c = createMembership(c, members);
try {
awaitSeconds(1);
assertTrusted(cm_a, a.address(), b.address(), c.address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, a.address(), b.address(), c.address());
assertNoSuspected(cm_b);
assertTrusted(cm_c, a.address(), b.address(), c.address());
assertNoSuspected(cm_c);
a.networkEmulator().block(members);
b.networkEmulator().block(members);
c.networkEmulator().block(members);
awaitSeconds(1);
assertTrusted(cm_a, a.address());
assertSuspected(cm_a, b.address(), c.address());
assertTrusted(cm_b, b.address());
assertSuspected(cm_b, a.address(), c.address());
assertTrusted(cm_c, c.address());
assertSuspected(cm_c, a.address(), b.address());
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
c.networkEmulator().unblockAll();
awaitSeconds(1);
assertTrusted(cm_a, a.address(), b.address(), c.address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, a.address(), b.address(), c.address());
assertNoSuspected(cm_b);
assertTrusted(cm_c, a.address(), b.address(), c.address());
assertNoSuspected(cm_c);
} finally {
stopAll(cm_a, cm_b, cm_c);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolTest method assertSuspected.
private void assertSuspected(MembershipProtocolImpl membership, Address... expected) {
List<Address> actual = getAddressesWithStatus(membership, MemberStatus.SUSPECT);
assertEquals("Expected " + expected.length + " suspect members " + Arrays.toString(expected) + ", but actual: " + actual, expected.length, actual.size());
for (Address member : expected) {
assertTrue("Expected to suspect " + member + ", but actual: " + actual, actual.contains(member));
}
}
Aggregations