use of io.scalecube.transport.Address in project scalecube by scalecube.
the class FailureDetectorTest method assertStatus.
/**
* @param address target member to expect on
* @param status expected listen status
* @param events events collection of failure detector events
* @param expected expected members of the given listenStatus
*/
private void assertStatus(Address address, MemberStatus status, Collection<FailureDetectorEvent> events, Address... expected) {
List<Address> actual = events.stream().filter(event -> event.status() == status).map(FailureDetectorEvent::member).map(Member::address).collect(Collectors.toList());
String msg1 = String.format("Node %s expected %s %s members %s, but was: %s", address, expected.length, status, Arrays.toString(expected), events);
assertEquals(msg1, expected.length, actual.size());
for (Address member : expected) {
String msg2 = String.format("Node %s expected as %s %s, but was: %s", address, status, member, events);
assertTrue(msg2, actual.contains(member));
}
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolImpl method memberAddress.
/**
* Returns the accessible member address, either from the transport or the overridden variables.
* @param transport transport
* @param config membership config parameters
* @return Accessible member address
*/
protected static Address memberAddress(Transport transport, MembershipConfig config) {
Address memberAddress = transport.address();
if (config.getMemberHost() != null) {
int memberPort = config.getMemberPort() != null ? config.getMemberPort() : memberAddress.port();
memberAddress = Address.create(config.getMemberHost(), memberPort);
}
return memberAddress;
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolImpl method doInitialSync.
// ================================================
// ============== Action Methods ==================
// ================================================
private CompletableFuture<Void> doInitialSync() {
LOGGER.debug("Making initial Sync to all seed members: {}", seedMembers);
if (seedMembers.isEmpty()) {
schedulePeriodicSync();
return CompletableFuture.completedFuture(null);
}
CompletableFuture<Void> syncResponseFuture = new CompletableFuture<>();
// Listen initial Sync Ack
String cid = memberRef.get().id();
transport.listen().observeOn(scheduler).filter(msg -> SYNC_ACK.equals(msg.qualifier())).filter(msg -> cid.equals(msg.correlationId())).filter(this::checkSyncGroup).take(1).timeout(config.getSyncTimeout(), TimeUnit.MILLISECONDS, scheduler).subscribe(message -> {
SyncData syncData = message.data();
LOGGER.info("Joined cluster '{}': {}", syncData.getSyncGroup(), syncData.getMembership());
onSyncAck(message, true);
schedulePeriodicSync();
syncResponseFuture.complete(null);
}, throwable -> {
LOGGER.info("Timeout getting initial SyncAck from seed members: {}", seedMembers);
schedulePeriodicSync();
syncResponseFuture.complete(null);
});
Message syncMsg = prepareSyncDataMsg(SYNC, cid);
seedMembers.forEach(address -> transport.send(address, syncMsg));
return syncResponseFuture;
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ServiceReferenceTest method test_ServiceReference.
@Test
public void test_ServiceReference() {
Address addr = Address.create("localhost", 4000);
ServiceReference reference = new ServiceReference("a", "b", null, addr);
assertTrue(reference.address().equals(addr));
assertTrue(reference.memberId().equals("a"));
assertTrue(reference.serviceName().equals("b"));
ServiceReference aref = new ServiceReference("a", "b", null, addr);
ServiceReference bref = new ServiceReference("a", "b", null, addr);
assertEquals(aref, aref);
assertEquals(aref, bref);
assertNotEquals(aref, null);
assertEquals(reference.toString(), "ServiceReference [memberId=a, qualifier=b, address=localhost:4000]");
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ClientStreamProcessorTest method setUp.
@Before
public void setUp() {
bootstrap = new Bootstrap().group(new NioEventLoopGroup(0)).channel(NioSocketChannel.class).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MILLIS).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.SO_REUSEADDR, true);
clientStream = ClientStream.newClientStream(bootstrap);
clientStreamProcessorFactory = new ClientStreamProcessorFactory(clientStream);
listeningServerStream = ListeningServerStream.newListeningServerStream().withListenAddress("localhost");
address = listeningServerStream.bindAwait();
// setup echo service
listeningServerStream.listenReadSuccess().map(Event::getMessageOrThrow).filter(message -> "q/echo".equalsIgnoreCase(message.qualifier())).subscribe(message -> {
// send original message back to client then send onCompleted
listeningServerStream.send(from(message).build());
listeningServerStream.send(from(message).qualifier(Qualifier.Q_ON_COMPLETED).build());
});
// setup echo service replying with void
listeningServerStream.listenReadSuccess().map(Event::getMessageOrThrow).filter(message -> "q/echoVoid".equalsIgnoreCase(message.qualifier())).subscribe(message -> {
// just send onCompleted
listeningServerStream.send(from(message).qualifier(Qualifier.Q_ON_COMPLETED).build());
});
// setup error service
listeningServerStream.listenReadSuccess().map(Event::getMessageOrThrow).filter(message -> "q/echoError".equalsIgnoreCase(message.qualifier())).subscribe(message -> {
// respond with error
listeningServerStream.send(from(message).qualifier(Qualifier.Q_GENERAL_FAILURE).build());
});
// setup service with several responses with onCompleted message following everyting sent
listeningServerStream.listenReadSuccess().map(Event::getMessageOrThrow).filter(message -> "q/echoStream".equalsIgnoreCase(message.qualifier())).subscribe(message -> {
// respond with several response messages then send onCompleted
IntStream.rangeClosed(1, 42).forEach(i -> listeningServerStream.send(from(message).qualifier("q/" + i).build()));
listeningServerStream.send(from(message).qualifier(Qualifier.Q_ON_COMPLETED).build());
});
}
Aggregations