use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class CoreTest method removeNodesAndServicesOnNewConfig.
@Test
@SuppressWarnings("unchecked")
void removeNodesAndServicesOnNewConfig() {
final ConfigurationProvider configProvider = mock(ConfigurationProvider.class);
DirectProcessor<ClusterConfig> configs = DirectProcessor.create();
ClusterConfig clusterConfig = new ClusterConfig();
when(configProvider.configs()).thenReturn(configs);
when(configProvider.config()).thenReturn(clusterConfig);
Node mock101 = mock(Node.class);
when(mock101.identifier()).thenReturn(new NodeIdentifier("10.143.190.101", 8091));
when(mock101.addService(any(ServiceType.class), anyInt(), any(Optional.class))).thenReturn(Mono.empty());
when(mock101.removeService(any(ServiceType.class), any(Optional.class))).thenReturn(Mono.empty());
when(mock101.serviceEnabled(any(ServiceType.class))).thenReturn(true);
when(mock101.disconnect()).thenReturn(Mono.empty());
Node mock102 = mock(Node.class);
when(mock102.identifier()).thenReturn(new NodeIdentifier("10.143.190.102", 8091));
when(mock102.addService(any(ServiceType.class), anyInt(), any(Optional.class))).thenReturn(Mono.empty());
when(mock102.removeService(any(ServiceType.class), any(Optional.class))).thenReturn(Mono.empty());
when(mock102.serviceEnabled(any(ServiceType.class))).thenReturn(true);
when(mock102.disconnect()).thenReturn(Mono.empty());
final Map<String, Node> mocks = new HashMap<>();
mocks.put("10.143.190.101", mock101);
mocks.put("10.143.190.102", mock102);
new Core(ENV, AUTHENTICATOR, SeedNode.LOCALHOST) {
@Override
public ConfigurationProvider createConfigurationProvider() {
return configProvider;
}
@Override
protected Node createNode(final NodeIdentifier target, final Optional<String> alternate) {
return mocks.get(target.address());
}
};
configs.onNext(clusterConfig);
BucketConfig twoNodesConfig = BucketConfigParser.parse(readResource("two_nodes_config_more_services.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(twoNodesConfig);
configs.onNext(clusterConfig);
verify(mock101, times(1)).addService(ServiceType.VIEWS, 8092, Optional.empty());
verify(mock101, times(1)).addService(ServiceType.MANAGER, 8091, Optional.empty());
verify(mock101, times(1)).addService(ServiceType.QUERY, 8093, Optional.empty());
verify(mock101, times(1)).addService(ServiceType.KV, 11210, Optional.of("travel-sample"));
verify(mock102, times(1)).addService(ServiceType.VIEWS, 8092, Optional.empty());
verify(mock102, times(1)).addService(ServiceType.MANAGER, 8091, Optional.empty());
verify(mock102, times(1)).addService(ServiceType.QUERY, 8093, Optional.empty());
verify(mock102, times(1)).addService(ServiceType.KV, 11210, Optional.of("travel-sample"));
verify(mock102, times(1)).addService(ServiceType.SEARCH, 8094, Optional.empty());
BucketConfig twoNodesLessServices = BucketConfigParser.parse(readResource("two_nodes_config.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(twoNodesLessServices);
configs.onNext(clusterConfig);
verify(mock102, times(1)).removeService(ServiceType.SEARCH, Optional.empty());
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class CoreTest method addsSecondNodeIfBothSameHostname.
/**
* With cluster_run it is possible to run more than one node on the same hostname. So we need to make sure that
* the node is identified by a tuple of hostname and manager port, and this should work.
*/
@Test
@SuppressWarnings("unchecked")
void addsSecondNodeIfBothSameHostname() {
final ConfigurationProvider configProvider = mock(ConfigurationProvider.class);
DirectProcessor<ClusterConfig> configs = DirectProcessor.create();
ClusterConfig clusterConfig = new ClusterConfig();
when(configProvider.configs()).thenReturn(configs);
when(configProvider.config()).thenReturn(clusterConfig);
Node mock101 = mock(Node.class);
when(mock101.identifier()).thenReturn(new NodeIdentifier(LOCALHOST, 9000));
when(mock101.addService(any(ServiceType.class), anyInt(), any(Optional.class))).thenReturn(Mono.empty());
when(mock101.removeService(any(ServiceType.class), any(Optional.class))).thenReturn(Mono.empty());
when(mock101.serviceEnabled(any(ServiceType.class))).thenReturn(true);
when(mock101.disconnect()).thenReturn(Mono.empty());
Node mock102 = mock(Node.class);
when(mock102.identifier()).thenReturn(new NodeIdentifier(LOCALHOST, 9001));
when(mock102.addService(any(ServiceType.class), anyInt(), any(Optional.class))).thenReturn(Mono.empty());
when(mock102.removeService(any(ServiceType.class), any(Optional.class))).thenReturn(Mono.empty());
when(mock102.serviceEnabled(any(ServiceType.class))).thenReturn(true);
when(mock102.disconnect()).thenReturn(Mono.empty());
final Map<String, Node> mocks = new HashMap<>();
mocks.put("127.0.0.1:9000", mock101);
mocks.put("127.0.0.1:9001", mock102);
new Core(ENV, AUTHENTICATOR, SeedNode.LOCALHOST) {
@Override
public ConfigurationProvider createConfigurationProvider() {
return configProvider;
}
@Override
protected Node createNode(final NodeIdentifier target, final Optional<String> alternate) {
return mocks.get(target.address() + ":" + target.managerPort());
}
};
configs.onNext(clusterConfig);
BucketConfig oneNodeConfig = BucketConfigParser.parse(readResource("cluster_run_two_nodes.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(oneNodeConfig);
configs.onNext(clusterConfig);
verify(mock101, times(1)).addService(ServiceType.VIEWS, 9500, Optional.empty());
verify(mock101, times(1)).addService(ServiceType.MANAGER, 9000, Optional.empty());
verify(mock101, times(1)).addService(ServiceType.KV, 12000, Optional.of("default"));
verify(mock102, times(1)).addService(ServiceType.VIEWS, 9501, Optional.empty());
verify(mock102, times(1)).addService(ServiceType.MANAGER, 9001, Optional.empty());
verify(mock102, times(1)).addService(ServiceType.KV, 12002, Optional.of("default"));
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class KeyValueLocatorTest method locateGetRequestForCouchbaseBucket.
@Test
@SuppressWarnings("unchecked")
void locateGetRequestForCouchbaseBucket() {
Locator locator = new KeyValueLocator();
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);
GetRequest getRequestMock = mock(GetRequest.class);
ClusterConfig configMock = mock(ClusterConfig.class);
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));
CouchbaseBucketConfig bucketMock = mock(CouchbaseBucketConfig.class);
when(getRequestMock.bucket()).thenReturn("bucket");
when(getRequestMock.key()).thenReturn("key".getBytes(UTF_8));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, mock(CoreEnvironment.class), mock(Authenticator.class));
when(getRequestMock.context()).thenReturn(new RequestContext(coreContext, getRequestMock));
when(configMock.bucketConfig("bucket")).thenReturn(bucketMock);
when(bucketMock.nodes()).thenReturn(Arrays.asList(nodeInfo1, nodeInfo2));
when(bucketMock.numberOfPartitions()).thenReturn(1024);
when(bucketMock.nodeIndexForActive(656, false)).thenReturn((short) 0);
when(bucketMock.nodeAtIndex(0)).thenReturn(nodeInfo1);
locator.dispatch(getRequestMock, nodes, configMock, null);
verify(node1Mock, times(1)).send(getRequestMock);
verify(node2Mock, never()).send(getRequestMock);
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class KeyValueLocatorTest method pickFastForwardIfAvailableAndNmvbSeen.
@Test
@SuppressWarnings("unchecked")
void pickFastForwardIfAvailableAndNmvbSeen() {
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(true);
// 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);
// Dispatch with retry 0
when(requestCtx.retryAttempts()).thenReturn(0);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(1)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
// Dispatch with retry 1 but no nmvb seen, still go to the active
when(requestCtx.retryAttempts()).thenReturn(1);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(2)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
// Dispatch with retry 2, now we see a NMVB
when(requestCtx.retryAttempts()).thenReturn(2);
when(getRequest.rejectedWithNotMyVbucket()).thenReturn(1);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(2)).send(getRequest);
verify(node2Mock, times(1)).send(getRequest);
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class KeyValueLocatorTest method pickCurrentIfNoFFMapAndRetry.
@Test
@SuppressWarnings("unchecked")
void pickCurrentIfNoFFMapAndRetry() {
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);
// Dispatch with retry 0
when(requestCtx.retryAttempts()).thenReturn(0);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(1)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
// Dispatch with retry 1
when(requestCtx.retryAttempts()).thenReturn(1);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(2)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
// Dispatch with retry 5
when(requestCtx.retryAttempts()).thenReturn(5);
locator.dispatch(getRequest, nodes, configMock, null);
verify(node1Mock, times(3)).send(getRequest);
verify(node2Mock, never()).send(getRequest);
}
Aggregations