use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class ClusterManagerBucketLoaderTest method loadsConfigSuccessfully.
@Test
void loadsConfigSuccessfully() {
byte[] expectedConfig = "config".getBytes(UTF_8);
BucketConfigResponse response = mock(BucketConfigResponse.class);
when(response.status()).thenReturn(ResponseStatus.SUCCESS);
when(response.config()).thenReturn(expectedConfig);
doAnswer(i -> {
((BucketConfigRequest) i.getArgument(0)).succeed(response);
return null;
}).when(core).send(any(BucketConfigRequest.class));
byte[] config = loader.discoverConfig(SEED, BUCKET).block();
assertArrayEquals(expectedConfig, config);
}
use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class ClusterManagerBucketLoaderTest method cancelRequestOnceUnsubscribed.
/**
* Since the client may run many loaders in parallel, once a good config is found the other
* attempts will be stopped.
*
* <p>This test makes sure that if an operation is ongoing but the downstream listener
* unsubscribes, it gets cancelled so we are not performing any loader ops that are not needed
* anymore.</p>
*/
@Test
void cancelRequestOnceUnsubscribed() {
final AtomicReference<BucketConfigRequest> request = new AtomicReference<>();
doAnswer(i -> {
request.set(i.getArgument(0));
return null;
}).when(core).send(any(BucketConfigRequest.class));
Disposable disposable = loader.discoverConfig(SEED, BUCKET).subscribe();
disposable.dispose();
assertTrue(request.get().completed());
assertTrue(request.get().cancelled());
assertEquals(CancellationReason.STOPPED_LISTENING, request.get().cancellationReason());
}
use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class ManagerEndpointIntegrationTest method fetchTerseConfig.
/**
* This integration test attempts to load a "terse" bucket config from the cluster manager.
*
* <p>Note that the actual response is not checked here, since this handles at the higher levels. We just make sure
* that the config returned is not empty.</p>
*/
@Test
void fetchTerseConfig() throws Exception {
TestNodeConfig node = config().nodes().get(0);
ManagerEndpoint endpoint = new ManagerEndpoint(serviceContext, node.hostname(), node.ports().get(Services.MANAGER));
endpoint.connect();
waitUntilCondition(() -> endpoint.state() == EndpointState.CONNECTED);
BucketConfigRequest request = new BucketConfigRequest(Duration.ofSeconds(1), serviceContext, null, config().bucketname(), serviceContext.authenticator(), null);
assertTrue(request.id() > 0);
endpoint.send(request);
BucketConfigResponse response = request.response().get(1, TimeUnit.SECONDS);
assertTrue(response.status().success());
assertTrue(response.config().length > 0);
endpoint.disconnect();
waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
}
use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class ClusterManagerBucketLoaderTest method errorsIfNonSuccessful.
@Test
void errorsIfNonSuccessful() {
BucketConfigResponse response = mock(BucketConfigResponse.class);
when(response.status()).thenReturn(ResponseStatus.UNKNOWN);
doAnswer(i -> {
((BucketConfigRequest) i.getArgument(0)).succeed(response);
return null;
}).when(core).send(any(BucketConfigRequest.class));
assertThrows(ConfigException.class, () -> loader.discoverConfig(SEED, BUCKET).block());
}
Aggregations