use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class ViewLocatorTest method dispatchesOnlyToHostsWithPrimaryPartitionsEnabled.
@Test
void dispatchesOnlyToHostsWithPrimaryPartitionsEnabled() {
ViewLocator locator = new ViewLocator();
ViewRequest request = mock(ViewRequest.class);
when(request.bucket()).thenReturn("bucket");
CouchbaseBucketConfig bucketConfig = mock(CouchbaseBucketConfig.class);
ClusterConfig config = mock(ClusterConfig.class);
when(config.bucketConfig("bucket")).thenReturn(bucketConfig);
when(bucketConfig.hasPrimaryPartitionsOnNode("1.2.3.4")).thenReturn(true);
when(bucketConfig.hasPrimaryPartitionsOnNode("1.2.3.5")).thenReturn(false);
Node node1 = mock(Node.class);
when(node1.identifier()).thenReturn(new NodeIdentifier("1.2.3.4", 1234));
assertTrue(locator.nodeCanBeUsed(node1, request, config));
Node node2 = mock(Node.class);
when(node2.identifier()).thenReturn(new NodeIdentifier("1.2.3.5", 1234));
assertFalse(locator.nodeCanBeUsed(node2, request, config));
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class AsyncScopeTest method shouldReuseAsyncCollection.
@Test
void shouldReuseAsyncCollection() {
Core core = mock(Core.class);
ConfigurationProvider configProvider = mock(ConfigurationProvider.class);
Flux<ClusterConfig> configs = (Flux<ClusterConfig>) mock(Flux.class);
when(configProvider.configs()).thenReturn(configs);
when(core.configurationProvider()).thenReturn(configProvider);
AsyncScope scope = new AsyncScope("scope", "bucket", core, mock(ClusterEnvironment.class));
AsyncCollection collection1 = scope.defaultCollection();
AsyncCollection collection2 = scope.defaultCollection();
AsyncCollection collection3 = scope.collection("foo");
AsyncCollection collection4 = scope.collection("foo");
assertEquals(collection1, collection2);
assertEquals(collection3, collection4);
assertNotEquals(collection1, collection3);
assertNotEquals(collection2, collection4);
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class CoreTest method addNodesAndServicesOnNewConfig.
/**
* This test initializes with a first config and then pushes a second one, making sure that
* the difference in services and nodes is enabled.
*/
@Test
@SuppressWarnings({ "unchecked" })
void addNodesAndServicesOnNewConfig() {
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 oneNodeConfig = BucketConfigParser.parse(readResource("one_node_config.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(oneNodeConfig);
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, never()).addService(ServiceType.VIEWS, 8092, Optional.empty());
verify(mock102, never()).addService(ServiceType.MANAGER, 8091, Optional.empty());
verify(mock102, never()).addService(ServiceType.QUERY, 8093, Optional.empty());
verify(mock102, never()).addService(ServiceType.KV, 11210, Optional.of("travel-sample"));
BucketConfig twoNodeConfig = BucketConfigParser.parse(readResource("two_nodes_config.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(twoNodeConfig);
configs.onNext(clusterConfig);
verify(mock101, times(2)).addService(ServiceType.VIEWS, 8092, Optional.empty());
verify(mock101, times(2)).addService(ServiceType.MANAGER, 8091, Optional.empty());
verify(mock101, times(2)).addService(ServiceType.QUERY, 8093, Optional.empty());
verify(mock101, times(2)).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"));
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class CoreTest method addServicesOnNewConfig.
@Test
@SuppressWarnings("unchecked")
void addServicesOnNewConfig() {
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.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"));
BucketConfig twoNodesConfigMore = BucketConfigParser.parse(readResource("two_nodes_config_more_services.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(twoNodesConfigMore);
configs.onNext(clusterConfig);
verify(mock101, times(2)).addService(ServiceType.VIEWS, 8092, Optional.empty());
verify(mock101, times(2)).addService(ServiceType.MANAGER, 8091, Optional.empty());
verify(mock101, times(2)).addService(ServiceType.QUERY, 8093, Optional.empty());
verify(mock101, times(2)).addService(ServiceType.KV, 11210, Optional.of("travel-sample"));
verify(mock102, times(2)).addService(ServiceType.VIEWS, 8092, Optional.empty());
verify(mock102, times(2)).addService(ServiceType.MANAGER, 8091, Optional.empty());
verify(mock102, times(2)).addService(ServiceType.QUERY, 8093, Optional.empty());
verify(mock102, times(2)).addService(ServiceType.KV, 11210, Optional.of("travel-sample"));
verify(mock102, times(1)).addService(ServiceType.SEARCH, 8094, Optional.empty());
}
use of com.couchbase.client.core.config.ClusterConfig in project couchbase-jvm-clients by couchbase.
the class CoreTest method removesNodeIfNotPresentInConfigAnymore.
@Test
@SuppressWarnings("unchecked")
void removesNodeIfNotPresentInConfigAnymore() {
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("one_node_config.json", CoreTest.class), ENV, LOCALHOST);
clusterConfig.setBucketConfig(twoNodesLessServices);
configs.onNext(clusterConfig);
verify(mock102, times(1)).disconnect();
}
Aggregations