use of com.couchbase.client.core.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class ClusterManagerBucketLoaderTest method setup.
@BeforeEach
void setup() {
CoreEnvironment env = mock(CoreEnvironment.class);
when(env.timeoutConfig()).thenReturn(TimeoutConfig.create());
when(env.retryStrategy()).thenReturn(BestEffortRetryStrategy.INSTANCE);
core = mock(Core.class);
CoreContext ctx = new CoreContext(core, 1, env, mock(Authenticator.class));
when(core.context()).thenReturn(ctx);
loader = new ClusterManagerBucketLoader(core);
}
use of com.couchbase.client.core.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class KeyValueBucketLoaderTest method setup.
@BeforeEach
void setup() {
CoreEnvironment env = mock(CoreEnvironment.class);
when(env.timeoutConfig()).thenReturn(TimeoutConfig.create());
when(env.retryStrategy()).thenReturn(BestEffortRetryStrategy.INSTANCE);
core = mock(Core.class);
CoreContext ctx = new CoreContext(core, 1, env, mock(Authenticator.class));
when(core.context()).thenReturn(ctx);
loader = new KeyValueBucketLoader(core);
}
use of com.couchbase.client.core.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method forceDefaultModeIfDefault.
@Test
void forceDefaultModeIfDefault() {
Core core = mock(Core.class);
CoreEnvironment environment = CoreEnvironment.builder().ioConfig(IoConfig.networkResolution(NetworkResolution.DEFAULT)).build();
CoreContext ctx = new CoreContext(core, 1, environment, PasswordAuthenticator.create("user", "pw"));
when(core.context()).thenReturn(ctx);
Set<SeedNode> seedNodes = new HashSet<>(Collections.singletonList(SeedNode.create("192.168.132.234")));
DefaultConfigurationProvider provider = new DefaultConfigurationProvider(core, seedNodes);
assertTrue(provider.config().bucketConfigs().isEmpty());
assertEquals(1, provider.currentSeedNodes().size());
String bucket = "default";
String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
assertEquals(Optional.empty(), ctx.alternateAddress());
environment.shutdown();
}
use of com.couchbase.client.core.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method beforeEach.
@BeforeEach
@Override
protected void beforeEach() {
super.beforeEach();
CoreEnvironment env = mock(CoreEnvironment.class);
TimeoutConfig timeoutConfig = mock(TimeoutConfig.class);
when(env.eventBus()).thenReturn(eventBus);
when(env.timeoutConfig()).thenReturn(timeoutConfig);
when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(1000));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
endpointContext = 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.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class ReplicaHelper method getAllReplicasRequests.
/**
* Helper method to assemble a stream of requests to the active and all replicas
*
* @param core the core to execute the request
* @param collectionIdentifier the collection containing the document
* @param documentId the ID of the document
* @param clientContext (nullable) client context info
* @param retryStrategy the retry strategy to use
* @param timeout the timeout until we need to stop the get all replicas
* @param parent the "get all/any replicas" request span
* @return a stream of requests.
*/
public static CompletableFuture<Stream<GetRequest>> getAllReplicasRequests(final Core core, final CollectionIdentifier collectionIdentifier, final String documentId, final Map<String, Object> clientContext, final RetryStrategy retryStrategy, final Duration timeout, final RequestSpan parent) {
notNullOrEmpty(documentId, "Id");
final CoreContext coreContext = core.context();
final CoreEnvironment environment = coreContext.environment();
final BucketConfig config = core.clusterConfig().bucketConfig(collectionIdentifier.bucket());
if (config instanceof CouchbaseBucketConfig) {
int numReplicas = ((CouchbaseBucketConfig) config).numberOfReplicas();
List<GetRequest> requests = new ArrayList<>(numReplicas + 1);
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_GET, parent);
GetRequest activeRequest = new GetRequest(documentId, timeout, coreContext, collectionIdentifier, retryStrategy, span);
activeRequest.context().clientContext(clientContext);
requests.add(activeRequest);
for (short replica = 1; replica <= numReplicas; replica++) {
RequestSpan replicaSpan = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_GET_REPLICA, parent);
ReplicaGetRequest replicaRequest = new ReplicaGetRequest(documentId, timeout, coreContext, collectionIdentifier, retryStrategy, replica, replicaSpan);
replicaRequest.context().clientContext(clientContext);
requests.add(replicaRequest);
}
return CompletableFuture.completedFuture(requests.stream());
} else if (config == null) {
// no bucket config found, it might be in-flight being opened so we need to reschedule the operation until
// the timeout fires!
final Duration retryDelay = Duration.ofMillis(100);
final CompletableFuture<Stream<GetRequest>> future = new CompletableFuture<>();
coreContext.environment().timer().schedule(() -> {
getAllReplicasRequests(core, collectionIdentifier, documentId, clientContext, retryStrategy, timeout.minus(retryDelay), parent).whenComplete((getRequestStream, throwable) -> {
if (throwable != null) {
future.completeExceptionally(throwable);
} else {
future.complete(getRequestStream);
}
});
}, retryDelay);
return future;
} else {
final CompletableFuture<Stream<GetRequest>> future = new CompletableFuture<>();
future.completeExceptionally(CommonExceptions.getFromReplicaNotCouchbaseBucket());
return future;
}
}
Aggregations