Search in sources :

Example 1 with Service

use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.

the class Node method removeService.

private synchronized Mono<Void> removeService(final ServiceType type, final Optional<String> bucket, boolean ignoreDisconnect) {
    return Mono.defer(() -> {
        if (disconnect.get() && !ignoreDisconnect) {
            ctx.environment().eventBus().publish(new ServiceRemoveIgnoredEvent(Event.Severity.DEBUG, ServiceRemoveIgnoredEvent.Reason.DISCONNECTED, ctx));
            return Mono.empty();
        }
        String name = type.scope() == ServiceScope.CLUSTER ? GLOBAL_SCOPE : bucket.orElse(BUCKET_GLOBAL_SCOPE);
        Map<ServiceType, Service> localMap = services.get(name);
        if (localMap == null || !localMap.containsKey(type)) {
            ctx.environment().eventBus().publish(new ServiceRemoveIgnoredEvent(Event.Severity.DEBUG, ServiceRemoveIgnoredEvent.Reason.NOT_PRESENT, ctx));
            return Mono.empty();
        }
        Service service = localMap.remove(type);
        serviceStates.deregister(service);
        long start = System.nanoTime();
        if (serviceCanBeDisabled(service.type())) {
            enabledServices.set(enabledServices.get() & ~(1 << service.type().ordinal()));
        }
        // todo: only return once the service is disconnected?
        service.disconnect();
        long end = System.nanoTime();
        ctx.environment().eventBus().publish(new ServiceRemovedEvent(Duration.ofNanos(end - start), service.context()));
        return Mono.empty();
    });
}
Also used : ServiceRemoveIgnoredEvent(com.couchbase.client.core.cnc.events.service.ServiceRemoveIgnoredEvent) ServiceRemovedEvent(com.couchbase.client.core.cnc.events.service.ServiceRemovedEvent) ServiceType(com.couchbase.client.core.service.ServiceType) ManagerService(com.couchbase.client.core.service.ManagerService) AnalyticsService(com.couchbase.client.core.service.AnalyticsService) SearchService(com.couchbase.client.core.service.SearchService) EventingService(com.couchbase.client.core.service.EventingService) KeyValueService(com.couchbase.client.core.service.KeyValueService) QueryService(com.couchbase.client.core.service.QueryService) Service(com.couchbase.client.core.service.Service) ViewService(com.couchbase.client.core.service.ViewService) BackupService(com.couchbase.client.core.service.BackupService)

Example 2 with Service

use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.

the class NodeTest method sendsToFoundGlobalService.

@Test
void sendsToFoundGlobalService() {
    final Service s = mock(Service.class);
    Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {

        @Override
        protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
            when(s.state()).thenReturn(ServiceState.CONNECTED);
            when(s.type()).thenReturn(serviceType);
            when(s.states()).thenReturn(DirectProcessor.create());
            return s;
        }
    };
    node.addService(ServiceType.QUERY, 8091, Optional.empty()).block();
    QueryRequest r = mock(QueryRequest.class);
    when(r.serviceType()).thenReturn(ServiceType.QUERY);
    when(r.context()).thenReturn(new RequestContext(CTX, r));
    node.send(r);
    verify(s, times(1)).send(eq(r));
}
Also used : Optional(java.util.Optional) QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) ServiceType(com.couchbase.client.core.service.ServiceType) Service(com.couchbase.client.core.service.Service) RequestContext(com.couchbase.client.core.msg.RequestContext) Test(org.junit.jupiter.api.Test)

Example 3 with Service

use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.

the class NodeTest method doesNotPrematurelyDisableService.

/**
 * Regression test for JVMCBC-882.
 */
@Test
void doesNotPrematurelyDisableService() {
    Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {

        @Override
        protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
            Service s = mock(Service.class);
            when(s.state()).thenReturn(ServiceState.CONNECTED);
            when(s.states()).thenReturn(DirectProcessor.create());
            when(s.type()).thenReturn(serviceType);
            return s;
        }
    };
    assertFalse(node.serviceEnabled(ServiceType.KV));
    node.addService(ServiceType.KV, 11210, Optional.empty()).block();
    assertTrue(node.serviceEnabled(ServiceType.KV));
    node.addService(ServiceType.KV, 11210, Optional.of("bucket")).block();
    assertTrue(node.serviceEnabled(ServiceType.KV));
    node.removeService(ServiceType.KV, Optional.empty()).block();
    assertTrue(node.serviceEnabled(ServiceType.KV));
    node.removeService(ServiceType.KV, Optional.of("bucket")).block();
    assertFalse(node.serviceEnabled(ServiceType.KV));
}
Also used : Optional(java.util.Optional) ServiceType(com.couchbase.client.core.service.ServiceType) Service(com.couchbase.client.core.service.Service) Test(org.junit.jupiter.api.Test)

Example 4 with Service

use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.

the class NodeTest method disconnectingIfAllDisconnecting.

@Test
void disconnectingIfAllDisconnecting() {
    Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {

        @Override
        protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
            Service s = mock(Service.class);
            when(s.state()).thenReturn(ServiceState.DISCONNECTING);
            when(s.states()).thenReturn(DirectProcessor.create());
            return s;
        }
    };
    assertEquals(NodeState.DISCONNECTED, node.state());
    assertFalse(node.serviceEnabled(ServiceType.KV));
    node.addService(ServiceType.KV, 11210, Optional.of("bucket")).block();
    assertTrue(node.serviceEnabled(ServiceType.KV));
    assertFalse(node.serviceEnabled(ServiceType.QUERY));
    node.addService(ServiceType.QUERY, 8091, Optional.empty()).block();
    assertTrue(node.serviceEnabled(ServiceType.QUERY));
    assertEquals(NodeState.DISCONNECTING, node.state());
}
Also used : Optional(java.util.Optional) ServiceType(com.couchbase.client.core.service.ServiceType) Service(com.couchbase.client.core.service.Service) Test(org.junit.jupiter.api.Test)

Example 5 with Service

use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.

the class NodeTest method retriesIfGlobalServiceNotFound.

@Test
void retriesIfGlobalServiceNotFound() {
    final Service s = mock(Service.class);
    final AtomicReference<Request<?>> retried = new AtomicReference<>();
    Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {

        @Override
        protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
            when(s.state()).thenReturn(ServiceState.CONNECTED);
            when(s.states()).thenReturn(DirectProcessor.create());
            when(s.type()).thenReturn(serviceType);
            return s;
        }

        @Override
        protected <R extends Request<? extends Response>> void sendIntoRetry(R request) {
            retried.set(request);
        }
    };
    QueryRequest r = mock(QueryRequest.class);
    when(r.serviceType()).thenReturn(ServiceType.QUERY);
    node.send(r);
    verify(s, never()).send(eq(r));
    assertEquals(r, retried.get());
}
Also used : Response(com.couchbase.client.core.msg.Response) Optional(java.util.Optional) QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) ServiceType(com.couchbase.client.core.service.ServiceType) QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) Request(com.couchbase.client.core.msg.Request) KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) Service(com.couchbase.client.core.service.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

Service (com.couchbase.client.core.service.Service)18 ServiceType (com.couchbase.client.core.service.ServiceType)18 Optional (java.util.Optional)15 Test (org.junit.jupiter.api.Test)15 KeyValueRequest (com.couchbase.client.core.msg.kv.KeyValueRequest)3 QueryRequest (com.couchbase.client.core.msg.query.QueryRequest)3 AnalyticsService (com.couchbase.client.core.service.AnalyticsService)3 BackupService (com.couchbase.client.core.service.BackupService)3 EventingService (com.couchbase.client.core.service.EventingService)3 KeyValueService (com.couchbase.client.core.service.KeyValueService)3 ManagerService (com.couchbase.client.core.service.ManagerService)3 QueryService (com.couchbase.client.core.service.QueryService)3 SearchService (com.couchbase.client.core.service.SearchService)3 ViewService (com.couchbase.client.core.service.ViewService)3 ServiceAddIgnoredEvent (com.couchbase.client.core.cnc.events.service.ServiceAddIgnoredEvent)2 ServiceAddedEvent (com.couchbase.client.core.cnc.events.service.ServiceAddedEvent)2 ServiceRemoveIgnoredEvent (com.couchbase.client.core.cnc.events.service.ServiceRemoveIgnoredEvent)2 ServiceRemovedEvent (com.couchbase.client.core.cnc.events.service.ServiceRemovedEvent)2 Request (com.couchbase.client.core.msg.Request)2 RequestContext (com.couchbase.client.core.msg.RequestContext)2