Search in sources :

Example 21 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ServiceRegistryTest method test_added_removed_registration_events.

@ParameterizedTest
@MethodSource("metadataCodecSource")
public void test_added_removed_registration_events(MetadataCodec metadataCodec) {
    Sinks.Many<ServiceDiscoveryEvent> events = Sinks.many().replay().all();
    Microservices seed = Microservices.builder().discovery(defServiceDiscovery(metadataCodec)).transport(RSocketServiceTransport::new).startAwait();
    seed.listenDiscovery().subscribe(events::tryEmitNext, events::tryEmitError, events::tryEmitComplete);
    Address seedAddress = seed.discovery().address();
    Microservices ms1 = Microservices.builder().discovery(defServiceDiscovery(seedAddress, metadataCodec)).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl()).startAwait();
    Microservices ms2 = Microservices.builder().discovery(defServiceDiscovery(seedAddress, metadataCodec)).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl()).startAwait();
    StepVerifier.create(events.asFlux().onBackpressureBuffer()).assertNext(event -> assertEquals(ENDPOINT_ADDED, event.type())).assertNext(event -> assertEquals(ENDPOINT_ADDED, event.type())).then(() -> Mono.whenDelayError(ms1.shutdown(), ms2.shutdown()).block(TIMEOUT)).assertNext(event -> assertEquals(ENDPOINT_LEAVING, event.type())).assertNext(event -> assertEquals(ENDPOINT_LEAVING, event.type())).assertNext(event -> assertEquals(ENDPOINT_REMOVED, event.type())).assertNext(event -> assertEquals(ENDPOINT_REMOVED, event.type())).then(() -> seed.shutdown().block(TIMEOUT)).thenCancel().verify(TIMEOUT);
}
Also used : Sinks(reactor.core.publisher.Sinks) ENDPOINT_LEAVING(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type.ENDPOINT_LEAVING) StepVerifier(reactor.test.StepVerifier) MetadataCodec(io.scalecube.cluster.metadata.MetadataCodec) JdkMetadataCodec(io.scalecube.cluster.metadata.JdkMetadataCodec) ENDPOINT_ADDED(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type.ENDPOINT_ADDED) Duration(java.time.Duration) ServiceDiscoveryEvent(io.scalecube.services.discovery.api.ServiceDiscoveryEvent) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) MethodSource(org.junit.jupiter.params.provider.MethodSource) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ENDPOINT_REMOVED(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type.ENDPOINT_REMOVED) JacksonMetadataCodec(io.scalecube.cluster.codec.jackson.JacksonMetadataCodec) Mono(reactor.core.publisher.Mono) Arguments(org.junit.jupiter.params.provider.Arguments) AnnotationService(io.scalecube.services.sut.AnnotationService) AnnotationServiceImpl(io.scalecube.services.sut.AnnotationServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) ServiceDiscoveryFactory(io.scalecube.services.discovery.api.ServiceDiscoveryFactory) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Sinks(reactor.core.publisher.Sinks) Address(io.scalecube.net.Address) ServiceDiscoveryEvent(io.scalecube.services.discovery.api.ServiceDiscoveryEvent) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class StreamingServiceTest method setup.

@BeforeAll
public static void setup() {
    gateway = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).defaultDataDecoder(ServiceMessageCodec::decodeData).startAwait();
    final Address gatewayAddress = gateway.discovery().address();
    node = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).defaultDataDecoder(ServiceMessageCodec::decodeData).services(new SimpleQuoteService()).startAwait();
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Disposable(reactor.core.Disposable) SimpleQuoteService(io.scalecube.services.sut.SimpleQuoteService) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ServiceMessageCodec(io.scalecube.services.transport.api.ServiceMessageCodec) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Duration(java.time.Duration) QuoteService(io.scalecube.services.sut.QuoteService) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) ServiceMessage(io.scalecube.services.api.ServiceMessage) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Address(io.scalecube.net.Address) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) SimpleQuoteService(io.scalecube.services.sut.SimpleQuoteService) ServiceMessageCodec(io.scalecube.services.transport.api.ServiceMessageCodec) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 23 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ServiceRemoteTest method test_services_contribute_to_cluster_metadata.

@Test
public void test_services_contribute_to_cluster_metadata() {
    Map<String, String> tags = new HashMap<>();
    tags.put("HOSTNAME", "host1");
    Microservices ms = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).tags(tags).services(new GreetingServiceImpl()).startAwait();
    assertTrue(ms.serviceEndpoint().tags().containsKey("HOSTNAME"));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sinks(reactor.core.publisher.Sinks) StepVerifier(reactor.test.StepVerifier) CoarseGrainedServiceImpl(io.scalecube.services.sut.CoarseGrainedServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) Hooks(reactor.core.publisher.Hooks) GreetingResponse(io.scalecube.services.sut.GreetingResponse) HashMap(java.util.HashMap) Disabled(org.junit.jupiter.api.Disabled) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) CoarseGrainedService(io.scalecube.services.sut.CoarseGrainedService) Duration(java.time.Duration) Map(java.util.Map) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) EmptyGreetingResponse(io.scalecube.services.sut.EmptyGreetingResponse) InternalServiceException(io.scalecube.services.exceptions.InternalServiceException) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GreetingService(io.scalecube.services.sut.GreetingService) EmptyGreetingRequest(io.scalecube.services.sut.EmptyGreetingRequest) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) ServiceMessage(io.scalecube.services.api.ServiceMessage) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) HashMap(java.util.HashMap) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) Test(org.junit.jupiter.api.Test)

Example 24 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ServiceRemoteTest method test_remote_serviceA_calls_serviceB_using_setter.

@Test
public void test_remote_serviceA_calls_serviceB_using_setter() {
    // Create microservices instance cluster.
    // noinspection unused
    Microservices provider = Microservices.builder().discovery(ServiceRemoteTest::serviceDiscovery).transport(RSocketServiceTransport::new).services(// add service a and b
    new CoarseGrainedServiceImpl()).startAwait();
    // Get a proxy to the service api.
    CoarseGrainedService service = gateway.call().api(CoarseGrainedService.class);
    Publisher<String> future = service.callGreeting("joe");
    assertEquals(" hello to: joe", Mono.from(future).block(Duration.ofSeconds(1)));
    provider.shutdown().then(Mono.delay(TIMEOUT2)).block();
}
Also used : CoarseGrainedServiceImpl(io.scalecube.services.sut.CoarseGrainedServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) CoarseGrainedService(io.scalecube.services.sut.CoarseGrainedService) Test(org.junit.jupiter.api.Test)

Example 25 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ServiceRemoteTest method test_remote_serviceA_calls_serviceB.

@Test
public void test_remote_serviceA_calls_serviceB() {
    // getting proxy from any node at any given time.
    CoarseGrainedServiceImpl another = new CoarseGrainedServiceImpl();
    // Create microservices instance cluster.
    // noinspection unused
    Microservices provider = Microservices.builder().discovery(ServiceRemoteTest::serviceDiscovery).transport(RSocketServiceTransport::new).services(another).startAwait();
    // Get a proxy to the service api.
    CoarseGrainedService service = gateway.call().api(CoarseGrainedService.class);
    Publisher<String> future = service.callGreeting("joe");
    assertEquals(" hello to: joe", Mono.from(future).block(Duration.ofSeconds(1)));
    provider.shutdown().then(Mono.delay(TIMEOUT2)).block();
}
Also used : CoarseGrainedServiceImpl(io.scalecube.services.sut.CoarseGrainedServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) CoarseGrainedService(io.scalecube.services.sut.CoarseGrainedService) Test(org.junit.jupiter.api.Test)

Aggregations

RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)26 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)22 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)22 Mono (reactor.core.publisher.Mono)18 Address (io.scalecube.net.Address)16 Microservices (io.scalecube.services.Microservices)13 Duration (java.time.Duration)12 Test (org.junit.jupiter.api.Test)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 ServiceMessage (io.scalecube.services.api.ServiceMessage)8 GreetingServiceImpl (io.scalecube.services.sut.GreetingServiceImpl)8 StepVerifier (reactor.test.StepVerifier)8 BeforeAll (org.junit.jupiter.api.BeforeAll)7 AfterAll (org.junit.jupiter.api.AfterAll)6 GreetingResponse (io.scalecube.services.sut.GreetingResponse)5 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Publisher (org.reactivestreams.Publisher)5 ServiceInfo (io.scalecube.services.ServiceInfo)4 Authenticator (io.scalecube.services.auth.Authenticator)4