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();
});
}
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));
}
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));
}
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());
}
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());
}
Aggregations