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;
}
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));
}
Aggregations