use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketRefresherIntegrationTest method pollsForNewConfigs.
@Test
void pollsForNewConfigs() {
Core core = Core.create(env, authenticator(), seedNodes());
ProposedBucketConfigInspectingProvider inspectingProvider = new ProposedBucketConfigInspectingProvider(core.configurationProvider());
KeyValueBucketRefresher refresher = new KeyValueBucketRefresher(inspectingProvider, core) {
@Override
protected Duration pollerInterval() {
// fire quickly to speed up the integration test.
return Duration.ofMillis(10);
}
};
core.openBucket(config().bucketname());
refresher.register(config().bucketname()).block();
long expected = env.ioConfig().configPollInterval().toNanos();
Util.waitUntilCondition(() -> {
List<ProposedConfigAndTimestamp> configs = new ArrayList<>(inspectingProvider.proposedConfigs());
int size = configs.size();
if (size < 2) {
// we need at least 2 records to compare
return false;
}
return configs.get(size - 1).nanosSince(configs.get(size - 2)) >= expected;
});
refresher.deregister(config().bucketname()).block();
for (ProposedConfigAndTimestamp configAndTimestamp : inspectingProvider.proposedConfigs()) {
assertEquals(config().bucketname(), configAndTimestamp.proposedConfig().bucketName());
assertNotNull(configAndTimestamp.proposedConfig());
}
refresher.shutdown().block();
inspectingProvider.shutdown().block();
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class KeyValueMessageHandlerTest method setup.
@BeforeAll
static void setup() {
ENV = CoreEnvironment.builder().eventBus(new SimpleEventBus(true)).build();
Core core = mock(Core.class);
CoreContext coreContext = new CoreContext(core, 1, ENV, PasswordAuthenticator.create("foo", "bar"));
ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class);
when(configurationProvider.collectionMap()).thenReturn(new CollectionMap());
when(core.configurationProvider()).thenReturn(configurationProvider);
CTX = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class RequestContextTest method requestCancellation.
@Test
void requestCancellation() {
Request<?> request = mock(Request.class);
Core core = mock(Core.class);
RequestContext ctx = new RequestContext(new CoreContext(core, 1, null, mock(Authenticator.class)), request);
ctx.cancel();
verify(request, times(1)).cancel(CancellationReason.CANCELLED_VIA_CONTEXT);
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method ignoreProposedConfigWithLowerOrEqualRev.
@Test
void ignoreProposedConfigWithLowerOrEqualRev() {
Core core = mock(Core.class);
when(core.context()).thenReturn(new CoreContext(core, 1, ENVIRONMENT, mock(Authenticator.class)));
DefaultConfigurationProvider provider = new DefaultConfigurationProvider(core, SeedNode.LOCALHOST);
final AtomicInteger configsPushed = new AtomicInteger(0);
provider.configs().skip(// ignore initial empty config
1).subscribe((c) -> configsPushed.incrementAndGet());
assertTrue(provider.config().bucketConfigs().isEmpty());
String bucket = "default";
String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
assertEquals(1, configsPushed.get());
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
assertEquals(1, configsPushed.get());
assertFalse(provider.config().bucketConfigs().isEmpty());
assertEquals(1073, provider.config().bucketConfig("default").rev());
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method ignoreProposedConfigOnceShutdown.
@Test
void ignoreProposedConfigOnceShutdown() {
Core core = mock(Core.class);
when(core.context()).thenReturn(new CoreContext(core, 1, ENVIRONMENT, mock(Authenticator.class)));
DefaultConfigurationProvider provider = new DefaultConfigurationProvider(core, SeedNode.LOCALHOST);
final AtomicInteger configsPushed = new AtomicInteger(0);
provider.configs().skip(// ignore initial empty config
1).subscribe((c) -> configsPushed.incrementAndGet());
assertTrue(provider.config().bucketConfigs().isEmpty());
String bucket = "default";
String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
assertEquals(1, configsPushed.get());
String newConfig = readResource("config_with_external_higher_rev.json", DefaultConfigurationProviderTest.class);
provider.shutdown().block();
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, newConfig, ORIGIN));
assertEquals(3, configsPushed.get());
assertTrue(provider.config().bucketConfigs().isEmpty());
}
Aggregations