use of com.couchbase.client.core.msg.kv.CarrierBucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderTest method errorsIfNonSuccessful.
@Test
void errorsIfNonSuccessful() {
CarrierBucketConfigResponse response = mock(CarrierBucketConfigResponse.class);
when(response.status()).thenReturn(ResponseStatus.UNKNOWN);
doAnswer(i -> {
((CarrierBucketConfigRequest) i.getArgument(0)).succeed(response);
return null;
}).when(core).send(any(CarrierBucketConfigRequest.class));
assertThrows(ConfigException.class, () -> loader.discoverConfig(SEED, BUCKET).block());
}
use of com.couchbase.client.core.msg.kv.CarrierBucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderTest 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<CarrierBucketConfigRequest> request = new AtomicReference<>();
doAnswer(i -> {
request.set(i.getArgument(0));
return null;
}).when(core).send(any(CarrierBucketConfigRequest.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.kv.CarrierBucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderTest method loadsConfigSuccessfully.
@Test
void loadsConfigSuccessfully() {
byte[] expectedConfig = "config".getBytes(UTF_8);
CarrierBucketConfigResponse response = mock(CarrierBucketConfigResponse.class);
when(response.status()).thenReturn(ResponseStatus.SUCCESS);
when(response.content()).thenReturn(expectedConfig);
doAnswer(i -> {
((CarrierBucketConfigRequest) i.getArgument(0)).succeed(response);
return null;
}).when(core).send(any(CarrierBucketConfigRequest.class));
byte[] config = loader.discoverConfig(SEED, BUCKET).block();
assertArrayEquals(expectedConfig, config);
}
use of com.couchbase.client.core.msg.kv.CarrierBucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketRefresher method fetchConfigPerNode.
/**
* Helper method to fetch a config per node provided.
*
* <p>Note that the bucket config request sent here has a fail fast strategy, so that if nodes are offline they
* do not circle the system forever (given they have a specific node target). Since the refresher polls every
* fixed interval anyways, fresh requests will flood the system eventually and there is no point in keeping
* the old ones around.</p>
*
* <p>Also, the timeout is set to the poll interval since it does not make sense to keep them around any
* longer.</p>
*
* @param name the bucket name.
* @param nodes the flux of nodes that can be used to fetch a config.
* @return returns configs for each node if found.
*/
private Flux<ProposedBucketConfigContext> fetchConfigPerNode(final String name, final Flux<NodeInfo> nodes) {
return nodes.flatMap(nodeInfo -> {
CoreContext ctx = core.context();
CarrierBucketConfigRequest request = new CarrierBucketConfigRequest(configRequestTimeout, ctx, new CollectionIdentifier(name, Optional.empty(), Optional.empty()), FailFastRetryStrategy.INSTANCE, nodeInfo.identifier());
core.send(request);
return Reactor.wrap(request, request.response(), true).filter(response -> {
if (!response.status().success()) {
eventBus.publish(new BucketConfigRefreshFailedEvent(core.context(), BucketConfigRefreshFailedEvent.RefresherType.KV, BucketConfigRefreshFailedEvent.Reason.INDIVIDUAL_REQUEST_FAILED, Optional.of(response)));
}
return response.status().success();
}).map(response -> new ProposedBucketConfigContext(name, new String(response.content(), UTF_8), nodeInfo.hostname())).onErrorResume(t -> {
eventBus.publish(new BucketConfigRefreshFailedEvent(core.context(), BucketConfigRefreshFailedEvent.RefresherType.KV, BucketConfigRefreshFailedEvent.Reason.INDIVIDUAL_REQUEST_FAILED, Optional.of(t)));
return Mono.empty();
});
});
}
use of com.couchbase.client.core.msg.kv.CarrierBucketConfigRequest in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderTest method errorsIfUnsupported.
@Test
void errorsIfUnsupported() {
CarrierBucketConfigResponse response = mock(CarrierBucketConfigResponse.class);
when(response.status()).thenReturn(ResponseStatus.UNSUPPORTED);
doAnswer(i -> {
((CarrierBucketConfigRequest) i.getArgument(0)).succeed(response);
return null;
}).when(core).send(any(CarrierBucketConfigRequest.class));
assertThrows(UnsupportedConfigMechanismException.class, () -> loader.discoverConfig(SEED, BUCKET).block());
}
Aggregations