Search in sources :

Example 1 with EndpointSelectionStrategy

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

the class PartitionSelectionStrategyTest method selectNullIfPinedIsNotConnected.

@Test
void selectNullIfPinedIsNotConnected() {
    EndpointSelectionStrategy strategy = new PartitionSelectionStrategy();
    Endpoint endpoint1 = mock(Endpoint.class);
    Endpoint endpoint2 = mock(Endpoint.class);
    Endpoint endpoint3 = mock(Endpoint.class);
    when(endpoint1.state()).thenReturn(EndpointState.DISCONNECTED);
    when(endpoint2.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint3.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint1.freeToWrite()).thenReturn(true);
    when(endpoint2.freeToWrite()).thenReturn(true);
    when(endpoint3.freeToWrite()).thenReturn(true);
    List<Endpoint> endpoints = Arrays.asList(endpoint1, endpoint2, endpoint3);
    GetRequest request = mock(GetRequest.class);
    when(request.partition()).thenReturn((short) 12);
    Endpoint selected = strategy.select(request, endpoints);
    for (int i = 0; i < 1000; i++) {
        assertNull(selected);
    }
}
Also used : Endpoint(com.couchbase.client.core.endpoint.Endpoint) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) EndpointSelectionStrategy(com.couchbase.client.core.service.EndpointSelectionStrategy) Endpoint(com.couchbase.client.core.endpoint.Endpoint) Test(org.junit.jupiter.api.Test)

Example 2 with EndpointSelectionStrategy

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

the class PartitionSelectionStrategyTest method selectPinnedForBinaryWithKey.

@Test
void selectPinnedForBinaryWithKey() {
    EndpointSelectionStrategy strategy = new PartitionSelectionStrategy();
    Endpoint endpoint1 = mock(Endpoint.class);
    Endpoint endpoint2 = mock(Endpoint.class);
    Endpoint endpoint3 = mock(Endpoint.class);
    when(endpoint1.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint2.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint3.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint1.freeToWrite()).thenReturn(true);
    when(endpoint2.freeToWrite()).thenReturn(true);
    when(endpoint3.freeToWrite()).thenReturn(true);
    List<Endpoint> endpoints = Arrays.asList(endpoint1, endpoint2, endpoint3);
    GetRequest request = mock(GetRequest.class);
    when(request.partition()).thenReturn((short) 12);
    Endpoint selected = strategy.select(request, endpoints);
    for (int i = 0; i < 1000; i++) {
        assertNotNull(selected);
        assertEquals(selected, endpoint1);
    }
}
Also used : Endpoint(com.couchbase.client.core.endpoint.Endpoint) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) EndpointSelectionStrategy(com.couchbase.client.core.service.EndpointSelectionStrategy) Endpoint(com.couchbase.client.core.endpoint.Endpoint) Test(org.junit.jupiter.api.Test)

Example 3 with EndpointSelectionStrategy

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

the class PartitionSelectionStrategyTest method returnNullIfEmptyEndpointList.

@Test
@SuppressWarnings("unchecked")
void returnNullIfEmptyEndpointList() {
    EndpointSelectionStrategy strategy = new PartitionSelectionStrategy();
    Endpoint selected = strategy.select(mock(Request.class), Collections.emptyList());
    assertNull(selected);
}
Also used : Endpoint(com.couchbase.client.core.endpoint.Endpoint) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) Request(com.couchbase.client.core.msg.Request) EndpointSelectionStrategy(com.couchbase.client.core.service.EndpointSelectionStrategy) Test(org.junit.jupiter.api.Test)

Aggregations

Endpoint (com.couchbase.client.core.endpoint.Endpoint)3 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)3 EndpointSelectionStrategy (com.couchbase.client.core.service.EndpointSelectionStrategy)3 Test (org.junit.jupiter.api.Test)3 Request (com.couchbase.client.core.msg.Request)1