use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolTest method testNetworkPartitionThenRecovery.
@Test
public void testNetworkPartitionThenRecovery() {
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);
// Block traffic
a.networkEmulator().block(members);
b.networkEmulator().block(members);
c.networkEmulator().block(members);
try {
awaitSeconds(6);
assertTrusted(cm_a, a.address());
assertNoSuspected(cm_a);
assertTrusted(cm_b, b.address());
assertNoSuspected(cm_b);
assertTrusted(cm_c, c.address());
assertNoSuspected(cm_c);
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
c.networkEmulator().unblockAll();
awaitSeconds(6);
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 testMemberAddressOverrides.
@Test
public void testMemberAddressOverrides() {
Transport t = Transport.bindAwait(true);
String host = "host1";
// Default behavior
Address address = MembershipProtocolImpl.memberAddress(t, testConfig(Collections.emptyList()).build());
assertEquals(t.address(), address);
// Override host only
address = MembershipProtocolImpl.memberAddress(t, testConfig(Collections.emptyList()).memberHost(host).build());
assertEquals(Address.create(host, t.address().port()), address);
// Override host and port
address = MembershipProtocolImpl.memberAddress(t, testConfig(Collections.emptyList()).memberHost(host).memberPort(80).build());
assertEquals(Address.create(host, 80), address);
// Override port only (override is ignored)
address = MembershipProtocolImpl.memberAddress(t, testConfig(Collections.emptyList()).memberPort(8080).build());
assertEquals(t.address(), address);
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class DefaultEventStreamTest method testChannelContextCreateIfAbsentConsumerCalled.
@Test
public void testChannelContextCreateIfAbsentConsumerCalled() {
String id = "fadsj89fuasd89fa";
Address address = Address.from("localhost:8080");
AtomicBoolean consumerCalled = new AtomicBoolean();
// create context on top of unseen previously context attributes => result new object created
ChannelContext.createIfAbsent(id, address, input -> consumerCalled.set(true));
assertTrue(consumerCalled.get());
}
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 FailureDetectorTest method testTrustedDespiteDifferentPingTimings.
@Test
public void testTrustedDespiteDifferentPingTimings() 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);
FailureDetectorConfig fd_b_config = ClusterConfig.builder().pingTimeout(500).pingInterval(1000).build();
FailureDetectorImpl fd_b = createFD(b, members, fd_b_config);
FailureDetectorImpl fd_c = createFD(c, members, ClusterConfig.defaultConfig());
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);
}
}
Aggregations