Search in sources :

Example 1 with ViewRequest

use of com.couchbase.client.core.msg.view.ViewRequest in project couchbase-jvm-clients by couchbase.

the class AsyncBucket method viewRequest.

ViewRequest viewRequest(final String designDoc, final String viewName, final ViewOptions.Built opts) {
    notNullOrEmpty(designDoc, "DesignDoc", () -> new ReducedViewErrorContext(designDoc, viewName, name));
    notNullOrEmpty(viewName, "ViewName", () -> new ReducedViewErrorContext(designDoc, viewName, name));
    String query = opts.query();
    Optional<byte[]> keysJson = Optional.ofNullable(opts.keys()).map(s -> s.getBytes(StandardCharsets.UTF_8));
    boolean development = opts.development();
    Duration timeout = opts.timeout().orElse(environment.timeoutConfig().viewTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_VIEWS, opts.parentSpan().orElse(null));
    ViewRequest request = new ViewRequest(timeout, core.context(), retryStrategy, authenticator, name, designDoc, viewName, query, keysJson, development, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : ReducedViewErrorContext(com.couchbase.client.core.error.context.ReducedViewErrorContext) Duration(java.time.Duration) ViewRequest(com.couchbase.client.core.msg.view.ViewRequest) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 2 with ViewRequest

use of com.couchbase.client.core.msg.view.ViewRequest in project couchbase-jvm-clients by couchbase.

the class ViewLocatorTest method dispatchesOnlyToHostsWithPrimaryPartitionsEnabled.

@Test
void dispatchesOnlyToHostsWithPrimaryPartitionsEnabled() {
    ViewLocator locator = new ViewLocator();
    ViewRequest request = mock(ViewRequest.class);
    when(request.bucket()).thenReturn("bucket");
    CouchbaseBucketConfig bucketConfig = mock(CouchbaseBucketConfig.class);
    ClusterConfig config = mock(ClusterConfig.class);
    when(config.bucketConfig("bucket")).thenReturn(bucketConfig);
    when(bucketConfig.hasPrimaryPartitionsOnNode("1.2.3.4")).thenReturn(true);
    when(bucketConfig.hasPrimaryPartitionsOnNode("1.2.3.5")).thenReturn(false);
    Node node1 = mock(Node.class);
    when(node1.identifier()).thenReturn(new NodeIdentifier("1.2.3.4", 1234));
    assertTrue(locator.nodeCanBeUsed(node1, request, config));
    Node node2 = mock(Node.class);
    when(node2.identifier()).thenReturn(new NodeIdentifier("1.2.3.5", 1234));
    assertFalse(locator.nodeCanBeUsed(node2, request, config));
}
Also used : CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) ViewRequest(com.couchbase.client.core.msg.view.ViewRequest) ClusterConfig(com.couchbase.client.core.config.ClusterConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ViewRequest (com.couchbase.client.core.msg.view.ViewRequest)2 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)1 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)1 ReducedViewErrorContext (com.couchbase.client.core.error.context.ReducedViewErrorContext)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1