use of com.couchbase.client.core.msg.query.QueryRequest in project couchbase-jvm-clients by couchbase.
the class ClusterLevelQueryIntegrationTest method performsClusterLevelQueryWithoutOpenBucket.
@Test
void performsClusterLevelQueryWithoutOpenBucket() throws Exception {
String query = "{\"statement\": \"select 1=1\"}";
QueryRequest request = new QueryRequest(env.timeoutConfig().queryTimeout(), core.context(), env.retryStrategy(), core.context().authenticator(), "select 1=1", query.getBytes(StandardCharsets.UTF_8), true, null, null, null, null, null);
core.send(request);
QueryResponse response = request.response().get();
assertNotNull(response.header().requestId());
List<QueryChunkRow> rows = response.rows().collectList().block();
assertNotNull(rows);
assertEquals(1, rows.size());
}
use of com.couchbase.client.core.msg.query.QueryRequest in project couchbase-jvm-clients by couchbase.
the class QueryMessageHandlerTest method reportsCompletionOnlyOnceStreamingEnds.
/**
* To avoid accidentally pipelining requests, we need to make sure that the handler only reports completion
* once the streaming is fully completed, and not just the response completable future initially completed.
*
* <p>We send a request, make sure it is encoded correctly and then stream back the chunks, making sure the
* final completion is only signaled once the last chunk arrived.</p>
*/
@Test
void reportsCompletionOnlyOnceStreamingEnds() {
BaseEndpoint endpoint = mock(BaseEndpoint.class);
EmbeddedChannel channel = new EmbeddedChannel(new QueryMessageHandler(endpoint, ENDPOINT_CTX));
byte[] query = "doesn'tmatter".getBytes(CharsetUtil.UTF_8);
QueryRequest request = new QueryRequest(ENV.timeoutConfig().queryTimeout(), CORE_CTX, ENV.retryStrategy(), CORE_CTX.authenticator(), "statement", query, false, null, null, null, null, null);
channel.writeAndFlush(request);
FullHttpRequest encodedRequest = channel.readOutbound();
assertEquals("doesn'tmatter", encodedRequest.content().toString(CharsetUtil.UTF_8));
ReferenceCountUtil.release(encodedRequest);
verify(endpoint, never()).markRequestCompletion();
assertFalse(request.response().isDone());
ByteBuf fullResponse = Unpooled.copiedBuffer(readResource("success_response.json", QueryMessageHandlerTest.class), CharsetUtil.UTF_8);
// send the header back first
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
channel.writeInbound(response);
assertFalse(request.response().isDone());
// send first chunk, should complete the future but not mark the endpoint completion
HttpContent firstChunk = new DefaultHttpContent(fullResponse.readBytes(500));
channel.writeInbound(firstChunk);
assertTrue(request.response().isDone());
verify(endpoint, never()).markRequestCompletion();
// send the second chunk, no change
HttpContent secondChunk = new DefaultHttpContent(fullResponse.readBytes(500));
channel.writeInbound(secondChunk);
verify(endpoint, never()).markRequestCompletion();
// send the last chunk, mark for completion finally
LastHttpContent lastChunk = new DefaultLastHttpContent(fullResponse.readBytes(fullResponse.readableBytes()));
channel.writeInbound(lastChunk);
verify(endpoint, times(1)).markRequestCompletion();
channel.finishAndReleaseAll();
}
use of com.couchbase.client.core.msg.query.QueryRequest in project couchbase-jvm-clients by couchbase.
the class NodeTest method sendsToFoundGlobalService.
@Test
void sendsToFoundGlobalService() {
final Service s = mock(Service.class);
Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {
@Override
protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
when(s.state()).thenReturn(ServiceState.CONNECTED);
when(s.type()).thenReturn(serviceType);
when(s.states()).thenReturn(DirectProcessor.create());
return s;
}
};
node.addService(ServiceType.QUERY, 8091, Optional.empty()).block();
QueryRequest r = mock(QueryRequest.class);
when(r.serviceType()).thenReturn(ServiceType.QUERY);
when(r.context()).thenReturn(new RequestContext(CTX, r));
node.send(r);
verify(s, times(1)).send(eq(r));
}
use of com.couchbase.client.core.msg.query.QueryRequest in project couchbase-jvm-clients by couchbase.
the class NodeTest method retriesIfGlobalServiceNotFound.
@Test
void retriesIfGlobalServiceNotFound() {
final Service s = mock(Service.class);
final AtomicReference<Request<?>> retried = new AtomicReference<>();
Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {
@Override
protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
when(s.state()).thenReturn(ServiceState.CONNECTED);
when(s.states()).thenReturn(DirectProcessor.create());
when(s.type()).thenReturn(serviceType);
return s;
}
@Override
protected <R extends Request<? extends Response>> void sendIntoRetry(R request) {
retried.set(request);
}
};
QueryRequest r = mock(QueryRequest.class);
when(r.serviceType()).thenReturn(ServiceType.QUERY);
node.send(r);
verify(s, never()).send(eq(r));
assertEquals(r, retried.get());
}
use of com.couchbase.client.core.msg.query.QueryRequest in project couchbase-jvm-clients by couchbase.
the class RoundRobinLocatorTest method skipNodeWithoutServiceEnabled.
@Test
void skipNodeWithoutServiceEnabled() {
Locator locator = new RoundRobinLocator(ServiceType.QUERY, 0);
QueryRequest request = mock(QueryRequest.class);
ClusterConfig configMock = mock(ClusterConfig.class);
when(configMock.hasClusterOrBucketConfig()).thenReturn(true);
Node node1Mock = mock(Node.class);
when(node1Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.101", 8091));
when(node1Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(false);
Node node2Mock = mock(Node.class);
when(node2Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.102", 8091));
when(node2Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(true);
Node node3Mock = mock(Node.class);
when(node3Mock.identifier()).thenReturn(new NodeIdentifier("192.168.56.103", 8091));
when(node3Mock.serviceEnabled(ServiceType.QUERY)).thenReturn(false);
List<Node> nodes = new ArrayList<>(Arrays.asList(node1Mock, node2Mock, node3Mock));
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(1)).send(request);
verify(node3Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(2)).send(request);
verify(node3Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(3)).send(request);
verify(node3Mock, never()).send(request);
locator.dispatch(request, nodes, configMock, null);
verify(node1Mock, never()).send(request);
verify(node2Mock, times(4)).send(request);
verify(node3Mock, never()).send(request);
}
Aggregations