From fb3603de6ac69f837337d1a99a21e66c84fac732 Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Mon, 25 Oct 2021 13:57:09 +0300 Subject: [PATCH] Enhance microservices builder (#823) * Added "default" shortcut id for discovery --- .../services/methods/ReflectTest.java | 7 ++---- .../auth/PrincipalMapperAuthExample.java | 7 +++--- .../auth/ServiceTransportAuthExample.java | 5 ++-- .../services/examples/codecs/Example1.java | 6 ++--- .../exceptions/ExceptionMapperExample.java | 4 +--- .../examples/helloworld/Example1.java | 5 ++-- .../examples/helloworld/Example2.java | 3 +-- .../examples/helloworld/Example3.java | 6 ++--- .../services/examples/services/Example1.java | 5 +--- .../services/examples/services/Example2.java | 5 +--- .../io/scalecube/services/Microservices.java | 14 +++++++++++ .../io/scalecube/services/ErrorFlowTest.java | 4 +--- .../services/ServiceAuthRemoteTest.java | 15 +++++------- .../services/ServiceCallLocalTest.java | 1 - .../services/ServiceCallRemoteTest.java | 4 +--- .../services/ServiceRegistryTest.java | 24 +++++++++---------- .../scalecube/services/ServiceRemoteTest.java | 14 +++++------ .../services/StreamingServiceTest.java | 4 +--- .../services/routings/RoutersTest.java | 6 +---- .../services/routings/ServiceTagsExample.java | 5 +--- ...ocketNettyColocatedEventLoopGroupTest.java | 8 ++----- .../rsocket/RSocketServiceTransportTest.java | 4 +--- 22 files changed, 63 insertions(+), 93 deletions(-) diff --git a/services-api/src/test/java/io/scalecube/services/methods/ReflectTest.java b/services-api/src/test/java/io/scalecube/services/methods/ReflectTest.java index e042425d0..993e67d5a 100644 --- a/services-api/src/test/java/io/scalecube/services/methods/ReflectTest.java +++ b/services-api/src/test/java/io/scalecube/services/methods/ReflectTest.java @@ -123,9 +123,7 @@ public String name() { } } - private class SubServiceImpl extends ServiceImpl { - - } + private class SubServiceImpl extends ServiceImpl {} @Test public void testSubServiceInterfaces() { @@ -134,7 +132,6 @@ public void testSubServiceInterfaces() { Stream> interfaces = Reflect.serviceInterfaces(new SubServiceImpl()); // Then: Assertions.assertEquals( - 1, - interfaces.count(), "serviceInterfaces(..) should detect interfaces in SubServiceImpl"); + 1, interfaces.count(), "serviceInterfaces(..) should detect interfaces in SubServiceImpl"); } } diff --git a/services-examples/src/main/java/io/scalecube/services/examples/auth/PrincipalMapperAuthExample.java b/services-examples/src/main/java/io/scalecube/services/examples/auth/PrincipalMapperAuthExample.java index 84336b3f2..9931c26de 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/auth/PrincipalMapperAuthExample.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/auth/PrincipalMapperAuthExample.java @@ -26,7 +26,6 @@ public static void main(String[] args) { Microservices service = Microservices.builder() .discovery( - "service", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -44,7 +43,7 @@ public static void main(String[] args) { Microservices userProfileCaller = Microservices.builder() - .discovery("caller", endpoint -> discovery(service, endpoint)) + .discovery(endpoint -> discovery(service, endpoint)) .transport( () -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())) .startAwait(); @@ -60,7 +59,7 @@ public static void main(String[] args) { Microservices apiKeyCaller = Microservices.builder() - .discovery("caller", endpoint -> discovery(service, endpoint)) + .discovery(endpoint -> discovery(service, endpoint)) .transport( () -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())) .startAwait(); @@ -161,6 +160,6 @@ private static ScalecubeServiceDiscovery discovery( return new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) .options(opts -> opts.metadata(endpoint)) - .membership(opts -> opts.seedMembers(service.discovery("service").address())); + .membership(opts -> opts.seedMembers(service.discovery().address())); } } diff --git a/services-examples/src/main/java/io/scalecube/services/examples/auth/ServiceTransportAuthExample.java b/services-examples/src/main/java/io/scalecube/services/examples/auth/ServiceTransportAuthExample.java index 8be3441ff..d8cdf07c5 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/auth/ServiceTransportAuthExample.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/auth/ServiceTransportAuthExample.java @@ -24,7 +24,6 @@ public static void main(String[] args) { Microservices service = Microservices.builder() .discovery( - "service", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -35,7 +34,7 @@ public static void main(String[] args) { Microservices caller = Microservices.builder() - .discovery("caller", endpoint -> discovery(service, endpoint)) + .discovery(endpoint -> discovery(service, endpoint)) .transport(() -> new RSocketServiceTransport().credentialsSupplier(credsSupplier())) .startAwait(); @@ -80,6 +79,6 @@ private static ScalecubeServiceDiscovery discovery( return new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) .options(opts -> opts.metadata(endpoint)) - .membership(opts -> opts.seedMembers(service.discovery("service").address())); + .membership(opts -> opts.seedMembers(service.discovery().address())); } } diff --git a/services-examples/src/main/java/io/scalecube/services/examples/codecs/Example1.java b/services-examples/src/main/java/io/scalecube/services/examples/codecs/Example1.java index d5cbddc2d..6ed92d9a1 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/codecs/Example1.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/codecs/Example1.java @@ -20,11 +20,10 @@ public class Example1 { * @param args ignored */ public static void main(String[] args) { - // ScaleCube Node node with no members + // ScaleCube Node with no members Microservices seed = Microservices.builder() .discovery( - "seed", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -33,13 +32,12 @@ public static void main(String[] args) { .defaultContentType(PROTOSTUFF) // set explicit default data format .startAwait(); - final Address seedAddress = seed.discovery("seed").address(); + final Address seedAddress = seed.discovery().address(); // Construct a ScaleCube node which joins the cluster hosting the Greeting Service Microservices ms = Microservices.builder() .discovery( - "ms", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services-examples/src/main/java/io/scalecube/services/examples/exceptions/ExceptionMapperExample.java b/services-examples/src/main/java/io/scalecube/services/examples/exceptions/ExceptionMapperExample.java index efb236a74..f416540d5 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/exceptions/ExceptionMapperExample.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/exceptions/ExceptionMapperExample.java @@ -20,7 +20,6 @@ public static void main(String[] args) throws InterruptedException { Microservices ms1 = Microservices.builder() .discovery( - "ms1", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -35,12 +34,11 @@ public static void main(String[] args) throws InterruptedException { System.err.println("ms1 started: " + ms1.serviceAddress()); - final Address address1 = ms1.discovery("ms1").address(); + final Address address1 = ms1.discovery().address(); Microservices ms2 = Microservices.builder() .discovery( - "ms2", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example1.java b/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example1.java index 10138f97c..b1bb228db 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example1.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example1.java @@ -25,11 +25,10 @@ public class Example1 { * @param args ignored */ public static void main(String[] args) { - // ScaleCube Node node with no members + // ScaleCube Node with no members Microservices seed = Microservices.builder() .discovery( - "seed", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -37,7 +36,7 @@ public static void main(String[] args) { .transport(RSocketServiceTransport::new) .startAwait(); - final Address seedAddress = seed.discovery("seed").address(); + final Address seedAddress = seed.discovery().address(); // Construct a ScaleCube node which joins the cluster hosting the Greeting Service Microservices ms = diff --git a/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example2.java b/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example2.java index 9ff15c12b..72e55ea05 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example2.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example2.java @@ -45,12 +45,11 @@ public static void main(String[] args) { .startAwait(); // Construct a ScaleCube node which joins the cluster hosting the Greeting Service - final Address seedAddress = seed.discovery("seed").address(); + final Address seedAddress = seed.discovery().address(); Microservices ms = Microservices.builder() .discovery( - "ms", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example3.java b/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example3.java index da15491f4..1e7080692 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example3.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/helloworld/Example3.java @@ -26,11 +26,10 @@ public class Example3 { * @param args ignored */ public static void main(String[] args) { - // ScaleCube Node node with no members + // ScaleCube Node with no members Microservices seed = Microservices.builder() .discovery( - "seed", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -38,13 +37,12 @@ public static void main(String[] args) { .transport(RSocketServiceTransport::new) .startAwait(); - final Address seedAddress = seed.discovery("seed").address(); + final Address seedAddress = seed.discovery().address(); // Construct a ScaleCube node which joins the cluster hosting the Greeting Service Microservices ms = Microservices.builder() .discovery( - "ms", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services-examples/src/main/java/io/scalecube/services/examples/services/Example1.java b/services-examples/src/main/java/io/scalecube/services/examples/services/Example1.java index af34e47bc..775bb9dcd 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/services/Example1.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/services/Example1.java @@ -19,7 +19,6 @@ public static void main(String[] args) { Microservices gateway = Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -27,12 +26,11 @@ public static void main(String[] args) { .transport(RSocketServiceTransport::new) .startAwait(); - final Address gatewayAddress = gateway.discovery("gateway").address(); + final Address gatewayAddress = gateway.discovery().address(); Microservices service2Node = Microservices.builder() .discovery( - "service2Node", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -45,7 +43,6 @@ public static void main(String[] args) { Microservices service1Node = Microservices.builder() .discovery( - "service1Node", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services-examples/src/main/java/io/scalecube/services/examples/services/Example2.java b/services-examples/src/main/java/io/scalecube/services/examples/services/Example2.java index 6621d5608..7bd2a800c 100644 --- a/services-examples/src/main/java/io/scalecube/services/examples/services/Example2.java +++ b/services-examples/src/main/java/io/scalecube/services/examples/services/Example2.java @@ -19,7 +19,6 @@ public static void main(String[] args) { Microservices gateway = Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -27,12 +26,11 @@ public static void main(String[] args) { .transport(RSocketServiceTransport::new) .startAwait(); - final Address gatewayAddress = gateway.discovery("gateway").address(); + final Address gatewayAddress = gateway.discovery().address(); Microservices service2Node = Microservices.builder() .discovery( - "service2Node", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -45,7 +43,6 @@ public static void main(String[] args) { Microservices service1Node = Microservices.builder() .discovery( - "service1Node", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/main/java/io/scalecube/services/Microservices.java b/services/src/main/java/io/scalecube/services/Microservices.java index 3446def6a..615e37444 100644 --- a/services/src/main/java/io/scalecube/services/Microservices.java +++ b/services/src/main/java/io/scalecube/services/Microservices.java @@ -312,6 +312,16 @@ public List serviceEndpoints() { return serviceRegistry.listServiceEndpoints(); } + /** + * Returns default service discovery context. + * + * @see Microservices.Builder#discovery(String, ServiceDiscoveryFactory) + * @return service discovery context + */ + public ServiceDiscoveryContext discovery() { + return discovery("default"); + } + /** * Returns service discovery context by id. * @@ -459,6 +469,10 @@ public Builder methodRegistry(ServiceMethodRegistry methodRegistry) { return this; } + public Builder discovery(ServiceDiscoveryFactory discoveryFactory) { + return discovery("default", discoveryFactory); + } + public Builder discovery(String id, ServiceDiscoveryFactory discoveryFactory) { this.compositeDiscovery.addOperator(opts -> opts.id(id).discoveryFactory(discoveryFactory)); return this; diff --git a/services/src/test/java/io/scalecube/services/ErrorFlowTest.java b/services/src/test/java/io/scalecube/services/ErrorFlowTest.java index 68d63bf77..40533d2cb 100644 --- a/services/src/test/java/io/scalecube/services/ErrorFlowTest.java +++ b/services/src/test/java/io/scalecube/services/ErrorFlowTest.java @@ -33,7 +33,6 @@ public static void initNodes() { provider = Microservices.builder() .discovery( - "provider", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -43,12 +42,11 @@ public static void initNodes() { .services(new GreetingServiceImpl()) .startAwait(); - final Address seedAddress = provider.discovery("provider").address(); + final Address seedAddress = provider.discovery().address(); consumer = Microservices.builder() .discovery( - "consumer", endpoint -> new ScalecubeServiceDiscovery() .membership(cfg -> cfg.seedMembers(seedAddress)) diff --git a/services/src/test/java/io/scalecube/services/ServiceAuthRemoteTest.java b/services/src/test/java/io/scalecube/services/ServiceAuthRemoteTest.java index 1ebe0408c..bffc29829 100644 --- a/services/src/test/java/io/scalecube/services/ServiceAuthRemoteTest.java +++ b/services/src/test/java/io/scalecube/services/ServiceAuthRemoteTest.java @@ -77,7 +77,6 @@ static void beforeAll() { service = Microservices.builder() .discovery( - "service", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -92,7 +91,6 @@ static void beforeAll() { serviceWithoutAuthenticator = Microservices.builder() .discovery( - "service", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -107,7 +105,6 @@ static void beforeAll() { partiallySecuredService = Microservices.builder() .discovery( - "service", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -285,7 +282,7 @@ void successfulCallOfPublicMethodWithoutAuthentication() { private static Microservices newCaller() { return Microservices.builder() - .discovery("caller", ServiceAuthRemoteTest::serviceDiscovery) + .discovery(ServiceAuthRemoteTest::serviceDiscovery) .transport( () -> new RSocketServiceTransport() @@ -295,14 +292,14 @@ private static Microservices newCaller() { private static Microservices newEmptyCredentialsCaller() { return Microservices.builder() - .discovery("caller", ServiceAuthRemoteTest::serviceDiscovery) + .discovery(ServiceAuthRemoteTest::serviceDiscovery) .transport(RSocketServiceTransport::new) .startAwait(); } private static Microservices newInvalidCredentialsCaller() { return Microservices.builder() - .discovery("caller", ServiceAuthRemoteTest::serviceDiscovery) + .discovery(ServiceAuthRemoteTest::serviceDiscovery) .transport( () -> new RSocketServiceTransport() @@ -339,8 +336,8 @@ private static ServiceDiscovery serviceDiscovery(ServiceEndpoint endpoint) { .membership( opts -> opts.seedMembers( - service.discovery("service").address(), - serviceWithoutAuthenticator.discovery("service").address(), - partiallySecuredService.discovery("service").address())); + service.discovery().address(), + serviceWithoutAuthenticator.discovery().address(), + partiallySecuredService.discovery().address())); } } diff --git a/services/src/test/java/io/scalecube/services/ServiceCallLocalTest.java b/services/src/test/java/io/scalecube/services/ServiceCallLocalTest.java index 3719dcdaf..807e32514 100644 --- a/services/src/test/java/io/scalecube/services/ServiceCallLocalTest.java +++ b/services/src/test/java/io/scalecube/services/ServiceCallLocalTest.java @@ -74,7 +74,6 @@ public void test_local_async_no_params() { private static Microservices serviceProvider() { return Microservices.builder() .discovery( - "serviceProvider", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/ServiceCallRemoteTest.java b/services/src/test/java/io/scalecube/services/ServiceCallRemoteTest.java index ec1374933..0f44dbdb0 100644 --- a/services/src/test/java/io/scalecube/services/ServiceCallRemoteTest.java +++ b/services/src/test/java/io/scalecube/services/ServiceCallRemoteTest.java @@ -75,12 +75,11 @@ public static void tearDown() { private static Microservices serviceProvider(Object service) { return Microservices.builder() .discovery( - "serviceProvider", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) .options(opts -> opts.metadata(endpoint)) - .membership(cfg -> cfg.seedMembers(gateway.discovery("gateway").address()))) + .membership(cfg -> cfg.seedMembers(gateway.discovery().address()))) .transport(RSocketServiceTransport::new) .services(service) .startAwait(); @@ -302,7 +301,6 @@ private static Optional route( private static Microservices gateway() { return Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/ServiceRegistryTest.java b/services/src/test/java/io/scalecube/services/ServiceRegistryTest.java index 02fd79d75..de43cba96 100644 --- a/services/src/test/java/io/scalecube/services/ServiceRegistryTest.java +++ b/services/src/test/java/io/scalecube/services/ServiceRegistryTest.java @@ -44,25 +44,25 @@ public void test_added_removed_registration_events(MetadataCodec metadataCodec) Microservices seed = Microservices.builder() - .discovery("seed", defServiceDiscovery(metadataCodec)) + .discovery(defServiceDiscovery(metadataCodec)) .transport(RSocketServiceTransport::new) .startAwait(); seed.listenDiscovery() .subscribe(events::tryEmitNext, events::tryEmitError, events::tryEmitComplete); - Address seedAddress = seed.discovery("seed").address(); + Address seedAddress = seed.discovery().address(); Microservices ms1 = Microservices.builder() - .discovery("ms1", defServiceDiscovery(seedAddress, metadataCodec)) + .discovery(defServiceDiscovery(seedAddress, metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); Microservices ms2 = Microservices.builder() - .discovery("ms2", defServiceDiscovery(seedAddress, metadataCodec)) + .discovery(defServiceDiscovery(seedAddress, metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); @@ -89,7 +89,7 @@ public void test_listen_to_discovery_events(MetadataCodec metadataCodec) { Microservices seed = Microservices.builder() - .discovery("seed", defServiceDiscovery(metadataCodec)) + .discovery(defServiceDiscovery(metadataCodec)) .transport(RSocketServiceTransport::new) .services(new AnnotationServiceImpl()) .startAwait(); @@ -98,14 +98,14 @@ public void test_listen_to_discovery_events(MetadataCodec metadataCodec) { seed.listenDiscovery() .subscribe(processor::tryEmitNext, processor::tryEmitError, processor::tryEmitComplete); - Address seedAddress = seed.discovery("seed").address(); + Address seedAddress = seed.discovery().address(); StepVerifier.create(processor.asFlux().onBackpressureBuffer()) .then( () -> { Microservices ms1 = Microservices.builder() - .discovery("ms1", defServiceDiscovery(seedAddress, metadataCodec)) + .discovery(defServiceDiscovery(seedAddress, metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); @@ -116,7 +116,7 @@ public void test_listen_to_discovery_events(MetadataCodec metadataCodec) { () -> { Microservices ms2 = Microservices.builder() - .discovery("ms2", defServiceDiscovery(seedAddress, metadataCodec)) + .discovery(defServiceDiscovery(seedAddress, metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); @@ -155,7 +155,7 @@ public void test_delayed_listen_to_discovery_events(MetadataCodec metadataCodec) Microservices seed = Microservices.builder() - .discovery("seed", defServiceDiscovery(metadataCodec)) + .discovery(defServiceDiscovery(metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); @@ -164,14 +164,14 @@ public void test_delayed_listen_to_discovery_events(MetadataCodec metadataCodec) seed.listenDiscovery() .subscribe(processor::tryEmitNext, processor::tryEmitError, processor::tryEmitComplete); - Address seedAddress = seed.discovery("seed").address(); + Address seedAddress = seed.discovery().address(); StepVerifier.create(processor.asFlux().onBackpressureBuffer()) .then( () -> { Microservices ms1 = Microservices.builder() - .discovery("ms1", defServiceDiscovery(seedAddress, metadataCodec)) + .discovery(defServiceDiscovery(seedAddress, metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl(), new AnnotationServiceImpl()) .startAwait(); @@ -182,7 +182,7 @@ public void test_delayed_listen_to_discovery_events(MetadataCodec metadataCodec) () -> { Microservices ms2 = Microservices.builder() - .discovery("ms2", defServiceDiscovery(seedAddress, metadataCodec)) + .discovery(defServiceDiscovery(seedAddress, metadataCodec)) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); diff --git a/services/src/test/java/io/scalecube/services/ServiceRemoteTest.java b/services/src/test/java/io/scalecube/services/ServiceRemoteTest.java index df13ce517..72f7a4289 100644 --- a/services/src/test/java/io/scalecube/services/ServiceRemoteTest.java +++ b/services/src/test/java/io/scalecube/services/ServiceRemoteTest.java @@ -48,7 +48,7 @@ public class ServiceRemoteTest extends BaseTest { public static void setup() { Hooks.onOperatorDebug(); gateway = gateway(); - gatewayAddress = gateway.discovery("gateway").address(); + gatewayAddress = gateway.discovery().address(); provider = serviceProvider(); } @@ -70,7 +70,6 @@ public static void tearDown() { private static Microservices gateway() { return Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -81,7 +80,7 @@ private static Microservices gateway() { private static Microservices serviceProvider() { return Microservices.builder() - .discovery("serviceProvider", ServiceRemoteTest::serviceDiscovery) + .discovery(ServiceRemoteTest::serviceDiscovery) .transport(RSocketServiceTransport::new) .services(new GreetingServiceImpl()) .startAwait(); @@ -277,7 +276,7 @@ public void test_remote_serviceA_calls_serviceB_using_setter() { // noinspection unused Microservices provider = Microservices.builder() - .discovery("provider", ServiceRemoteTest::serviceDiscovery) + .discovery(ServiceRemoteTest::serviceDiscovery) .transport(RSocketServiceTransport::new) .services(new CoarseGrainedServiceImpl()) // add service a and b .startAwait(); @@ -300,7 +299,7 @@ public void test_remote_serviceA_calls_serviceB() { // noinspection unused Microservices provider = Microservices.builder() - .discovery("provider", ServiceRemoteTest::serviceDiscovery) + .discovery(ServiceRemoteTest::serviceDiscovery) .transport(RSocketServiceTransport::new) .services(another) .startAwait(); @@ -320,7 +319,7 @@ public void test_remote_serviceA_calls_serviceB_with_timeout() { // Create microservices instance cluster. Microservices ms = Microservices.builder() - .discovery("ms", ServiceRemoteTest::serviceDiscovery) + .discovery(ServiceRemoteTest::serviceDiscovery) .transport(RSocketServiceTransport::new) .services(another) // add service a and b .startAwait(); @@ -345,7 +344,7 @@ public void test_remote_serviceA_calls_serviceB_with_dispatcher() { // Create microservices instance cluster. Microservices provider = Microservices.builder() - .discovery("provider", ServiceRemoteTest::serviceDiscovery) + .discovery(ServiceRemoteTest::serviceDiscovery) .transport(RSocketServiceTransport::new) .services(another) // add service a and b .startAwait(); @@ -508,7 +507,6 @@ public void test_services_contribute_to_cluster_metadata() { Microservices ms = Microservices.builder() .discovery( - "ms", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/StreamingServiceTest.java b/services/src/test/java/io/scalecube/services/StreamingServiceTest.java index 1a3f46d88..f676c2c82 100644 --- a/services/src/test/java/io/scalecube/services/StreamingServiceTest.java +++ b/services/src/test/java/io/scalecube/services/StreamingServiceTest.java @@ -31,7 +31,6 @@ public static void setup() { gateway = Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -40,12 +39,11 @@ public static void setup() { .defaultDataDecoder(ServiceMessageCodec::decodeData) .startAwait(); - final Address gatewayAddress = gateway.discovery("gateway").address(); + final Address gatewayAddress = gateway.discovery().address(); node = Microservices.builder() .discovery( - "node", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/routings/RoutersTest.java b/services/src/test/java/io/scalecube/services/routings/RoutersTest.java index 146090516..456305d20 100644 --- a/services/src/test/java/io/scalecube/services/routings/RoutersTest.java +++ b/services/src/test/java/io/scalecube/services/routings/RoutersTest.java @@ -58,7 +58,6 @@ public static void setup() { gateway = Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -66,13 +65,12 @@ public static void setup() { .transport(RSocketServiceTransport::new) .startAwait(); - gatewayAddress = gateway.discovery("gateway").address(); + gatewayAddress = gateway.discovery().address(); // Create microservices instance cluster. provider1 = Microservices.builder() .discovery( - "provider1", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -93,7 +91,6 @@ public static void setup() { provider2 = Microservices.builder() .discovery( - "provider2", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -114,7 +111,6 @@ public static void setup() { provider3 = Microservices.builder() .discovery( - "provider3", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/routings/ServiceTagsExample.java b/services/src/test/java/io/scalecube/services/routings/ServiceTagsExample.java index fec831d3e..547873131 100644 --- a/services/src/test/java/io/scalecube/services/routings/ServiceTagsExample.java +++ b/services/src/test/java/io/scalecube/services/routings/ServiceTagsExample.java @@ -24,7 +24,6 @@ public static void main(String[] args) { Microservices gateway = Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -32,12 +31,11 @@ public static void main(String[] args) { .transport(RSocketServiceTransport::new) .startAwait(); - Address seedAddress = gateway.discovery("gateway").address(); + Address seedAddress = gateway.discovery().address(); Microservices services1 = Microservices.builder() .discovery( - "services1", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -53,7 +51,6 @@ public static void main(String[] args) { Microservices services2 = Microservices.builder() .discovery( - "services2", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketNettyColocatedEventLoopGroupTest.java b/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketNettyColocatedEventLoopGroupTest.java index f65bce290..fe4d95602 100644 --- a/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketNettyColocatedEventLoopGroupTest.java +++ b/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketNettyColocatedEventLoopGroupTest.java @@ -30,7 +30,6 @@ public void setUp() { this.gateway = Microservices.builder() .discovery( - "gateway", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -38,12 +37,11 @@ public void setUp() { .transport(RSocketServiceTransport::new) .startAwait(); - final Address gatewayAddress = this.gateway.discovery("gateway").address(); + final Address gatewayAddress = this.gateway.discovery().address(); Microservices facade = Microservices.builder() .discovery( - "facade", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -53,12 +51,11 @@ public void setUp() { .services(new Facade()) .startAwait(); - final Address facadeAddress = facade.discovery("facade").address(); + final Address facadeAddress = facade.discovery().address(); this.ping = Microservices.builder() .discovery( - "ping", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -71,7 +68,6 @@ public void setUp() { this.pong = Microservices.builder() .discovery( - "pong", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) diff --git a/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketServiceTransportTest.java b/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketServiceTransportTest.java index 73d871e24..c54bee927 100644 --- a/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketServiceTransportTest.java +++ b/services/src/test/java/io/scalecube/services/transport/rsocket/RSocketServiceTransportTest.java @@ -42,7 +42,6 @@ public void setUp() { gateway = Microservices.builder() .discovery( - "gateway", endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) @@ -50,12 +49,11 @@ public void setUp() { .transport(RSocketServiceTransport::new) .startAwait(); - final Address gatewayAddress = this.gateway.discovery("gateway").address(); + final Address gatewayAddress = this.gateway.discovery().address(); serviceNode = Microservices.builder() .discovery( - "serviceNode", serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory()))