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