use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.
the class NodeTest method idleIfAllIdle.
@Test
void idleIfAllIdle() {
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.IDLE);
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.IDLE, node.state());
}
use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.
the class NodeTest method connectedIfAllConnected.
@Test
void connectedIfAllConnected() {
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());
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.CONNECTED, node.state());
}
use of com.couchbase.client.core.service.Service in project couchbase-jvm-clients by couchbase.
the class NodeTest method connectedIfSomeIdleAndRestConnected.
@Test
void connectedIfSomeIdleAndRestConnected() {
Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {
final AtomicInteger counter = new AtomicInteger();
@Override
protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
Service s = mock(Service.class);
when(s.state()).thenReturn(counter.incrementAndGet() % 2 == 0 ? ServiceState.IDLE : ServiceState.CONNECTED);
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, 8093, Optional.empty()).block();
assertTrue(node.serviceEnabled(ServiceType.QUERY));
assertFalse(node.serviceEnabled(ServiceType.VIEWS));
node.addService(ServiceType.VIEWS, 8092, Optional.empty()).block();
assertTrue(node.serviceEnabled(ServiceType.VIEWS));
assertEquals(NodeState.CONNECTED, node.state());
}
Aggregations