use of com.couchbase.client.core.msg.query.QueryResponse 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.QueryResponse in project couchbase-jvm-clients by couchbase.
the class QueryMessageHandlerBackpressureTest method requestRecordsExplicitly.
/**
* This test makes sure that even if the server returns a good bunch of data, each individual
* chunk is requested by the caller explicitly.
*/
@Test
void requestRecordsExplicitly() throws Exception {
EndpointContext endpointContext = new EndpointContext(core.context(), new HostAndPort("127.0.0.1", 1234), NoopCircuitBreaker.INSTANCE, ServiceType.QUERY, Optional.empty(), Optional.empty(), Optional.empty());
BaseEndpoint endpoint = mock(BaseEndpoint.class);
when(endpoint.pipelined()).thenReturn(false);
Bootstrap client = new Bootstrap().channel(LocalChannel.class).group(new DefaultEventLoopGroup()).remoteAddress(new LocalAddress("s1")).handler(new ChannelInitializer<LocalChannel>() {
@Override
protected void initChannel(LocalChannel ch) {
ch.pipeline().addLast(new HttpClientCodec()).addLast(new QueryMessageHandler(endpoint, endpointContext));
}
});
Channel channel = client.connect().awaitUninterruptibly().channel();
final List<byte[]> rows = Collections.synchronizedList(new ArrayList<>());
QueryRequest request = new QueryRequest(Duration.ofSeconds(1), endpointContext, BestEffortRetryStrategy.INSTANCE, endpointContext.authenticator(), "select 1=1", "myquery".getBytes(UTF_8), true, null, null, null, null, null);
channel.writeAndFlush(request);
final QueryResponse response = request.response().get();
assertEquals(0, rows.size());
StepVerifier.create(response.rows().map(v -> new String(v.data(), UTF_8)), 0).thenRequest(1).expectNext("{\"foo\":1}").thenRequest(1).expectNext("{\"bar\":1}").thenRequest(2).expectNext("{\"faz\":1}", "{\"baz\":1}").thenRequest(4).expectNext("{\"fazz\":1}", "{\"bazz\":1}", "{\"fizz\":1}", "{\"bizz\":1}").expectComplete().verify();
}
Aggregations