Search in sources :

Example 1 with ClusterConfig

use of io.scalecube.cluster.ClusterConfig in project scalecube by scalecube.

the class ServiceTest method test_services_contribute_to_cluster_metadata.

@Test
public void test_services_contribute_to_cluster_metadata() {
    Map<String, String> metadata = new HashMap<>();
    metadata.put("HOSTNAME", "host1");
    Builder clusterConfig = ClusterConfig.builder().metadata(metadata);
    Microservices ms = Microservices.builder().clusterConfig(clusterConfig).services(new GreetingServiceImpl()).build();
    assertTrue(ms.cluster().member().metadata().containsKey("HOSTNAME"));
    assertTrue(ServiceInfo.from(ms.cluster().member().metadata().entrySet().stream().filter(item -> item.getValue().equals("service")).findFirst().get().getKey()).getServiceName().equals("io.scalecube.services.GreetingService"));
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) CanaryTestingRouter(io.scalecube.services.a.b.testing.CanaryTestingRouter) GreetingServiceImplA(io.scalecube.services.a.b.testing.GreetingServiceImplA) Assert.assertTrue(org.junit.Assert.assertTrue) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) GreetingServiceImplB(io.scalecube.services.a.b.testing.GreetingServiceImplB) Executors(java.util.concurrent.Executors) Builder(io.scalecube.cluster.ClusterConfig.Builder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterConfig(io.scalecube.cluster.ClusterConfig) CanaryService(io.scalecube.services.a.b.testing.CanaryService) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) Message(io.scalecube.transport.Message) BaseTest(io.scalecube.testlib.BaseTest) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) Builder(io.scalecube.cluster.ClusterConfig.Builder) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 2 with ClusterConfig

use of io.scalecube.cluster.ClusterConfig in project scalecube by scalecube.

the class ClusterJoinExamples method main.

/**
 * Main method.
 */
public static void main(String[] args) throws Exception {
    // Start seed member Alice
    Cluster alice = Cluster.joinAwait();
    // Join Bob to cluster with Alice
    Cluster bob = Cluster.joinAwait(alice.address());
    // Join Carol to cluster with metadata
    Map<String, String> metadata = ImmutableMap.of("name", "Carol");
    Cluster carol = Cluster.joinAwait(metadata, alice.address());
    // Start Dan on port 3000
    ClusterConfig configWithFixedPort = ClusterConfig.builder().seedMembers(alice.address()).portAutoIncrement(false).port(3000).build();
    Cluster dan = Cluster.joinAwait(configWithFixedPort);
    // Start Eve in separate cluster (separate sync group)
    ClusterConfig configWithSyncGroup = ClusterConfig.builder().seedMembers(alice.address(), bob.address(), carol.address(), // won't join anyway
    dan.address()).syncGroup("another cluster").build();
    Cluster eve = Cluster.joinAwait(configWithSyncGroup);
    // Print cluster members of each node
    System.out.println("Alice (" + alice.address() + ") cluster: " + alice.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
    System.out.println("Bob (" + bob.address() + ") cluster: " + bob.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
    System.out.println("Carol (" + carol.address() + ") cluster: " + carol.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
    System.out.println("Dan (" + dan.address() + ") cluster: " + dan.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
    System.out.println(// alone in cluster
    "Eve (" + eve.address() + ") cluster: " + eve.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
}
Also used : Cluster(io.scalecube.cluster.Cluster) ClusterConfig(io.scalecube.cluster.ClusterConfig)

Aggregations

ClusterConfig (io.scalecube.cluster.ClusterConfig)2 Cluster (io.scalecube.cluster.Cluster)1 Builder (io.scalecube.cluster.ClusterConfig.Builder)1 CanaryService (io.scalecube.services.a.b.testing.CanaryService)1 CanaryTestingRouter (io.scalecube.services.a.b.testing.CanaryTestingRouter)1 GreetingServiceImplA (io.scalecube.services.a.b.testing.GreetingServiceImplA)1 GreetingServiceImplB (io.scalecube.services.a.b.testing.GreetingServiceImplB)1 BaseTest (io.scalecube.testlib.BaseTest)1 Message (io.scalecube.transport.Message)1 Duration (java.time.Duration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 Executors (java.util.concurrent.Executors)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1