use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MicroservicesExample method main.
public static void main(String[] args) throws Exception {
Address providerAddress = onProvider();
onConsumer(providerAddress);
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolTest method testInitialPhaseOk.
@Test
public void testInitialPhaseOk() {
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);
} finally {
stopAll(cm_a, cm_b, cm_c);
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolTest method testDoublePartitionThenRecover.
@Test
public void testDoublePartitionThenRecover() {
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);
// Check all trusted
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);
// Node b lost network
b.networkEmulator().block(Arrays.asList(a.address(), c.address()));
a.networkEmulator().block(b.address());
c.networkEmulator().block(b.address());
awaitSeconds(1);
// Check partition: {b}, {a, c}
assertTrusted(cm_a, a.address(), c.address());
assertSuspected(cm_a, b.address());
assertTrusted(cm_b, b.address());
assertSuspected(cm_b, a.address(), c.address());
assertTrusted(cm_c, a.address(), c.address());
assertSuspected(cm_c, b.address());
// Node a and c lost network
a.networkEmulator().block(c.address());
c.networkEmulator().block(a.address());
awaitSeconds(1);
// Check partition: {a}, {b}, {c}
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, b.address(), a.address());
// Recover network
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
c.networkEmulator().unblockAll();
awaitSeconds(1);
// Check all trusted again
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 testMemberLostNetworkThenRecover.
@Test
public void testMemberLostNetworkThenRecover() {
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);
// Check all trusted
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);
// Node b lost network
b.networkEmulator().block(Arrays.asList(a.address(), c.address()));
a.networkEmulator().block(b.address());
c.networkEmulator().block(b.address());
awaitSeconds(1);
// Check partition: {b}, {a, c}
assertTrusted(cm_a, a.address(), c.address());
assertSuspected(cm_a, b.address());
assertTrusted(cm_b, b.address());
assertSuspected(cm_b, a.address(), c.address());
assertTrusted(cm_c, a.address(), c.address());
assertSuspected(cm_c, b.address());
// Node b recover network
a.networkEmulator().unblockAll();
b.networkEmulator().unblockAll();
c.networkEmulator().unblockAll();
awaitSeconds(1);
// Check all trusted again
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 ListeningServerStream method bind.
/**
* Binds asynchronously according to config object that is present at the moment of bind operation.
*
* @return listening server address
*/
public CompletableFuture<Address> bind() {
CompletableFuture<Address> promise = new CompletableFuture<>();
NettyServerTransport serverTransport = new NettyServerTransport(config, serverStream::subscribe);
serverTransport.bind().whenComplete((serverTransport1, throwable) -> {
if (serverTransport1 != null) {
// register cleanup process upfront
serverStream.listenClose(aVoid -> serverTransport1.unbind());
// complete promise
serverTransport1.getServerAddress().ifPresent(promise::complete);
}
if (throwable != null) {
promise.completeExceptionally(throwable);
}
});
return promise;
}
Aggregations