use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class RoundRobinLocatorTest method skipNodeWithoutServiceEnabled.
@Test
void skipNodeWithoutServiceEnabled() {
Locator locator = new RoundRobinLocator(ServiceType.QUERY, 0);
QueryRequest request = mock(QueryRequest.class);
ClusterConfig configMock = mock(ClusterConfig.class);
when(configMock.hasClusterOrBucketConfig()).thenReturn(true);
Node node1Mock = mock(Node.class);
when(node1Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.101", 8091));
when(node1Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(false);
Node node2Mock = mock(Node.class);
when(node2Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.102", 8091));
when(node2Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(true);
Node node3Mock = mock(Node.class);
when(node3Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.103", 8091));
when(node3Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(false);
List<Node> nodes = new ArrayList<>(Arrays.asList(node1Mock, node2Mock, node3Mock));
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(1)).send(request);
verify(node3Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(2)).send(request);
verify(node3Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(3)).send(request);
verify(node3Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(4)).send(request);
verify(node3Mock, never()).send(request);
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class RoundRobinLocatorTest method selectNextNode.
@Test
void selectNextNode() {
Locator locator = new RoundRobinLocator(ServiceType.QUERY, 0);
QueryRequest request = mock(QueryRequest.class);
ClusterConfig configMock = mock(ClusterConfig.class);
when(configMock.hasClusterOrBucketConfig()).thenReturn(true);
Node node1Mock = mock(Node.class);
when(node1Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(true);
when(node1Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.101", 8091));
Node node2Mock = mock(Node.class);
when(node2Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(true);
when(node2Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.102", 8091));
List<Node> nodes = new ArrayList<>(Arrays.asList(node1Mock, node2Mock));
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, times(1)).send(request);
verify(node2Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, times(1)).send(request);
verify(node2Mock, times(1)).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, times(2)).send(request);
verify(node2Mock, times(1)).send(request);
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class Core method reconfigure.
/**
* Reconfigures the SDK topology to align with the current server configuration.
*
* <p>When reconfigure is called, it will grab a current configuration and then add/remove
* nodes/services to mirror the current topology and configuration settings.</p>
*
* <p>This is a eventually consistent process, so in-flight operations might still be rescheduled
* and then picked up later (or cancelled, depending on the strategy). For those coming from 1.x,
* it works very similar.</p>
*/
private void reconfigure() {
if (reconfigureInProgress.compareAndSet(false, true)) {
final ClusterConfig configForThisAttempt = currentConfig;
if (configForThisAttempt.bucketConfigs().isEmpty() && configForThisAttempt.globalConfig() == null) {
reconfigureDisconnectAll();
return;
}
final long start = System.nanoTime();
Flux<BucketConfig> bucketConfigFlux = Flux.just(configForThisAttempt).flatMap(cc -> Flux.fromIterable(cc.bucketConfigs().values()));
reconfigureBuckets(bucketConfigFlux).then(reconfigureGlobal(configForThisAttempt.globalConfig())).then(Mono.defer(() -> Flux.fromIterable(new ArrayList<>(nodes)).flatMap(n -> maybeRemoveNode(n, configForThisAttempt)).then())).subscribe(v -> {
}, e -> {
clearReconfigureInProgress();
eventBus.publish(new ReconfigurationErrorDetectedEvent(context(), e));
}, () -> {
clearReconfigureInProgress();
eventBus.publish(new ReconfigurationCompletedEvent(Duration.ofNanos(System.nanoTime() - start), coreContext));
});
} else {
moreConfigsPending.set(true);
eventBus.publish(new ReconfigurationIgnoredEvent(coreContext));
}
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class KeyValueLocatorTest method pickCurrentIfNoFFMapAndNmvbSeen.
@Test
@SuppressWarnings("unchecked")
void pickCurrentIfNoFFMapAndNmvbSeen() {
Locator locator = new KeyValueLocator();
// Setup 2 nodes
NodeInfo nodeInfo1 = new NodeInfo("http://foo:1234", "192.168.56.101:8091", Collections.EMPTY_MAP, null);
NodeInfo nodeInfo2 = new NodeInfo("http://foo:1234", "192.168.56.102:8091", Collections.EMPTY_MAP, null);
Node node1Mock = mock(Node.class);
when(node1Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.101", 8091));
Node node2Mock = mock(Node.class);
when(node2Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.102", 8091));
List<Node> nodes = new ArrayList<>(Arrays.asList(node1Mock, node2Mock));
// Configure Cluster and Bucket config
ClusterConfig configMock = mock(ClusterConfig.class);
CouchbaseBucketConfig bucketMock = mock(CouchbaseBucketConfig.class);
when(configMock.bucketConfig("bucket")).thenReturn(bucketMock);
when(bucketMock.nodes()).thenReturn(Arrays.asList(nodeInfo1, nodeInfo2));
when(bucketMock.numberOfPartitions()).thenReturn(1024);
when(bucketMock.nodeAtIndex(0)).thenReturn(nodeInfo1);
when(bucketMock.nodeAtIndex(1)).thenReturn(nodeInfo2);
when(bucketMock.hasFastForwardMap()).thenReturn(false);
// Fake a vbucket move in ffwd map from node 0 to node 1
when(bucketMock.nodeIndexForActive(656, false)).thenReturn((short) 0);
when(bucketMock.nodeIndexForActive(656, true)).thenReturn((short) 1);
// Create Request
GetRequest getRequest = mock(GetRequest.class);
when(getRequest.bucket()).thenReturn("bucket");
when(getRequest.key()).thenReturn("key".getBytes(UTF_8));
RequestContext requestCtx = mock(RequestContext.class);
when(getRequest.context()).thenReturn(requestCtx);
when(getRequest.rejectedWithNotMyVbucket()).thenReturn(9);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(1)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
when(getRequest.rejectedWithNotMyVbucket()).thenReturn(1);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(2)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class RoundRobinLocatorTest method shouldDistributeFairlyUnderMDS.
@Test
void shouldDistributeFairlyUnderMDS() {
Locator locator = new RoundRobinLocator(ServiceType.QUERY, 0);
QueryRequest request = mock(QueryRequest.class);
ClusterConfig configMock = mock(ClusterConfig.class);
when(configMock.hasClusterOrBucketConfig()).thenReturn(true);
Node node1Mock = mock(Node.class);
when(node1Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.101", 8091));
when(node1Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(false);
Node node2Mock = mock(Node.class);
when(node2Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.102", 8091));
when(node2Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(false);
Node node3Mock = mock(Node.class);
when(node3Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.103", 8091));
when(node3Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(true);
Node node4Mock = mock(Node.class);
when(node4Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.104", 8091));
when(node4Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(true);
List<Node> nodes = new ArrayList<>(Arrays.asList(node1Mock, node2Mock, node3Mock, node4Mock));
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, never()).send(request);
verify(node3Mock, times(1)).send(request);
verify(node4Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, never()).send(request);
verify(node3Mock, times(1)).send(request);
verify(node4Mock, times(1)).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, never()).send(request);
verify(node3Mock, times(2)).send(request);
verify(node4Mock, times(1)).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, never()).send(request);
verify(node3Mock, times(2)).send(request);
verify(node4Mock, times(2)).send(request);
}
Aggregations