use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.
the class SqlClientService method fetchAsync.
public void fetchAsync(Connection connection, QueryId queryId, int cursorBufferSize, SqlClientResult res) {
ClientMessage requestMessage = SqlFetchCodec.encodeRequest(queryId, cursorBufferSize);
ClientInvocationFuture future = invokeAsync(requestMessage, connection);
future.whenComplete(withTryCatch(logger, (message, error) -> handleFetchResponse(connection, res, message, error)));
}
use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.
the class QueryClientStateRegistry method registerAndFetch.
public SqlPage registerAndFetch(UUID clientId, AbstractSqlResult result, int cursorBufferSize, InternalSerializationService serializationService) {
QueryId queryId = result.getQueryId();
QueryClientState clientCursor = new QueryClientState(clientId, queryId, result, false);
boolean delete = false;
try {
// Register the cursor.
QueryClientState previousClientCursor = clientCursors.putIfAbsent(queryId, clientCursor);
// Check if the cursor is already closed.
if (previousClientCursor != null) {
assert previousClientCursor.isClosed();
delete = true;
QueryException error = QueryException.cancelledByUser();
result.close(error);
throw error;
}
// Fetch the next page.
SqlPage page = fetchInternal(clientCursor, cursorBufferSize, serializationService, result.isInfiniteRows());
delete = page.isLast();
return page;
} catch (Exception e) {
delete = true;
throw e;
} finally {
if (delete) {
deleteClientCursor(queryId);
}
}
}
use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.
the class SqlClientExecuteCloseRaceTest method testExecuteClose.
@Test
public void testExecuteClose() {
QueryId queryId = QueryId.create(UUID.randomUUID());
// Send "execute"
Connection connection = clientService.getQueryConnection();
ClientMessage executeResponse = sendExecuteRequest(connection, queryId);
checkExecuteResponse(executeResponse, true);
assertEquals(1, memberService.getInternalService().getClientStateRegistry().getCursorCount());
// Send "close"
ClientMessage closeRequest = SqlCloseCodec.encodeRequest(queryId);
clientService.invokeOnConnection(connection, closeRequest);
assertEquals(0, memberService.getInternalService().getClientStateRegistry().getCursorCount());
}
use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.
the class SqlNoDeserializationTest method testClient.
@Test
public void testClient() {
int pageSize = KEY_COUNT / 2;
SqlClientService clientService = (SqlClientService) client().getSql();
ClientConnection connection = clientService.getQueryConnection();
// Get the first page through the "execute" request
QueryId queryId = QueryId.create(connection.getRemoteUuid());
ClientMessage executeRequest = SqlExecuteCodec.encodeRequest(SQL, Collections.emptyList(), Long.MAX_VALUE, pageSize, null, SqlExpectedResultType.ROWS.getId(), queryId, false);
SqlExecuteCodec.ResponseParameters executeResponse = SqlExecuteCodec.decodeResponse(clientService.invokeOnConnection(connection, executeRequest));
if (executeResponse.error != null) {
fail(executeResponse.error.getMessage());
}
assertNotNull(executeResponse.rowPage);
assertEquals(pageSize, executeResponse.rowPage.getRowCount());
// Get the second page through the "execute" request
ClientMessage fetchRequest = SqlFetchCodec.encodeRequest(queryId, pageSize);
SqlFetchCodec.ResponseParameters fetchResponse = SqlFetchCodec.decodeResponse(clientService.invokeOnConnection(connection, fetchRequest));
if (fetchResponse.error != null) {
fail(fetchResponse.error.getMessage());
}
assertNotNull(fetchResponse.rowPage);
assertEquals(pageSize, fetchResponse.rowPage.getRowCount());
}
use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.
the class SqlClientExecuteCloseRaceTest method testCloseExecute.
@Test
public void testCloseExecute() {
QueryId queryId = QueryId.create(UUID.randomUUID());
// Send "close"
Connection connection = clientService.getQueryConnection();
ClientMessage closeRequest = SqlCloseCodec.encodeRequest(queryId);
clientService.invokeOnConnection(connection, closeRequest);
assertEquals(1, memberService.getInternalService().getClientStateRegistry().getCursorCount());
// Send "execute"
ClientMessage executeResponse = sendExecuteRequest(connection, queryId);
assertEquals(0, memberService.getInternalService().getClientStateRegistry().getCursorCount());
checkExecuteResponse(executeResponse, false);
}
Aggregations