use of com.couchbase.client.core.config.ProposedBucketConfigContext in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderIntegrationTest method loadConfigViaCarrierPublication.
/**
* This is a very simplistic test that makes sure that we can "round trip" in the
* {@link KeyValueBucketLoader} by grabbing a JSON decodable config through the full stack.
*/
@Test
void loadConfigViaCarrierPublication() {
TestNodeConfig config = config().firstNodeWith(Services.KV).get();
Core core = Core.create(env, authenticator(), seedNodes());
KeyValueBucketLoader loader = new KeyValueBucketLoader(core);
ProposedBucketConfigContext loaded = loader.load(new NodeIdentifier(config.hostname(), config.ports().get(Services.MANAGER)), config.ports().get(Services.KV), config().bucketname(), Optional.empty()).block();
assertNotNull(loaded);
assertEquals(config().bucketname(), loaded.bucketName());
core.shutdown().block();
}
use of com.couchbase.client.core.config.ProposedBucketConfigContext in project couchbase-jvm-clients by couchbase.
the class KeyValueMessageHandler method handleNotMyVbucket.
/**
* Helper method to handle a "not my vbucket" response.
*
* @param request the request to retry.
* @param response the response to extract the config from, potentially.
*/
private void handleNotMyVbucket(final KeyValueRequest<Response> request, final ByteBuf response) {
request.indicateRejectedWithNotMyVbucket();
eventBus.publish(new NotMyVbucketReceivedEvent(ioContext, request.partition()));
final String origin = request.context().lastDispatchedTo() != null ? request.context().lastDispatchedTo().hostname() : null;
RetryOrchestrator.maybeRetry(ioContext, request, RetryReason.KV_NOT_MY_VBUCKET);
body(response).map(b -> b.toString(UTF_8).trim()).filter(c -> c.startsWith("{")).ifPresent(c -> ioContext.core().configurationProvider().proposeBucketConfig(new ProposedBucketConfigContext(request.bucket(), c, origin)));
}
use of com.couchbase.client.core.config.ProposedBucketConfigContext in project couchbase-jvm-clients by couchbase.
the class BaseBucketLoaderTest method loadsAndParsesConfig.
@Test
void loadsAndParsesConfig() {
BucketLoader loader = new BaseBucketLoader(core, SERVICE) {
@Override
protected Mono<byte[]> discoverConfig(NodeIdentifier seed, String bucket) {
return Mono.just(readResource("../config_with_external.json", BaseBucketLoaderTest.class).getBytes(UTF_8));
}
};
when(core.ensureServiceAt(eq(SEED), eq(SERVICE), eq(PORT), eq(Optional.of(BUCKET)), eq(Optional.empty()))).thenReturn(Mono.empty());
when(core.serviceState(eq(SEED), eq(SERVICE), eq(Optional.of(BUCKET)))).thenReturn(Optional.of(Flux.empty()));
ProposedBucketConfigContext ctx = loader.load(SEED, PORT, BUCKET, Optional.empty()).block();
BucketConfig config = BucketConfigParser.parse(ctx.config(), core.context().environment(), ctx.origin());
assertEquals("default", config.name());
assertEquals(1073, config.rev());
}
use of com.couchbase.client.core.config.ProposedBucketConfigContext in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketRefresher method maybeUpdateBucket.
/**
* If needed, fetches a configuration (and otherwise ignores this attempt).
*
* <p>This method makes sure that individual errors are logged but swallowed so they do
* not interrupt anything else in progress.</p>
*
* @param name the name of the bucket.
* @return a {@link Mono} either with a new config or nothing to ignore.
*/
private Mono<ProposedBucketConfigContext> maybeUpdateBucket(final String name) {
Long last = registrations.get(name);
boolean overInterval = last != null && (System.nanoTime() - last) >= configPollIntervalNanos;
boolean allowed = tainted.contains(name) || overInterval;
return allowed ? fetchConfigPerNode(name, filterEligibleNodes(name)).next().doOnSuccess(ctx -> registrations.replace(name, System.nanoTime())) : Mono.empty();
}
use of com.couchbase.client.core.config.ProposedBucketConfigContext in project couchbase-jvm-clients by couchbase.
the class ClusterManagerBucketLoaderIntegrationTest method loadConfigViaClusterManagerHttp.
/**
* This is a very simplistic test that makes sure that we can "round trip" in the
* {@link ClusterManagerBucketLoader} by grabbing a JSON decodable config through the full stack.
*/
@Test
// @Disabled
void loadConfigViaClusterManagerHttp() {
TestNodeConfig config = config().firstNodeWith(Services.MANAGER).get();
Core core = Core.create(env, authenticator(), seedNodes());
ClusterManagerBucketLoader loader = new ClusterManagerBucketLoader(core);
int port = config.ports().get(Services.MANAGER);
ProposedBucketConfigContext ctx = loader.load(new NodeIdentifier(config.hostname(), port), port, config().bucketname(), Optional.empty()).block();
BucketConfig loaded = BucketConfigParser.parse(ctx.config(), env, ctx.origin());
assertNotNull(loaded);
assertEquals(config().bucketname(), loaded.name());
core.shutdown().block();
}
Aggregations