Search in sources :

Example 16 with Service

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());
}
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 17 with Service

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());
}
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 18 with Service

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());
}
Also used : Optional(java.util.Optional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceType(com.couchbase.client.core.service.ServiceType) Service(com.couchbase.client.core.service.Service) 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