use of com.hazelcast.client.impl.connection.ClientConnection 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.client.impl.connection.ClientConnection in project hazelcast by hazelcast.
the class TcpClientConnectionManager method getConnectionForSql.
@Override
public ClientConnection getConnectionForSql() {
if (isSmartRoutingEnabled) {
// we might be lucky...
for (int i = 0; i < SQL_CONNECTION_RANDOM_ATTEMPTS; i++) {
Member member = QueryUtils.memberOfLargerSameVersionGroup(client.getClientClusterService().getMemberList(), null);
if (member == null) {
break;
}
ClientConnection connection = activeConnections.get(member.getUuid());
if (connection != null) {
return connection;
}
}
}
// Otherwise iterate over connections and return the first one that's not to a lite member
ClientConnection firstConnection = null;
for (Map.Entry<UUID, TcpClientConnection> connectionEntry : activeConnections.entrySet()) {
if (firstConnection == null) {
firstConnection = connectionEntry.getValue();
}
UUID memberId = connectionEntry.getKey();
Member member = client.getClientClusterService().getMember(memberId);
if (member == null || member.isLiteMember()) {
continue;
}
return connectionEntry.getValue();
}
// Failed to get a connection to a data member
return firstConnection;
}
use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.
the class SqlClientService method execute.
@Nonnull
@Override
public SqlResult execute(@Nonnull SqlStatement statement) {
ClientConnection connection = getQueryConnection();
QueryId id = QueryId.create(connection.getRemoteUuid());
List<Object> params = statement.getParameters();
List<Data> params0 = new ArrayList<>(params.size());
for (Object param : params) {
params0.add(serializeParameter(param));
}
ClientMessage requestMessage = SqlExecuteCodec.encodeRequest(statement.getSql(), params0, statement.getTimeoutMillis(), statement.getCursorBufferSize(), statement.getSchema(), statement.getExpectedResultType().getId(), id, skipUpdateStatistics);
SqlClientResult res = new SqlClientResult(this, connection, id, statement.getCursorBufferSize());
try {
ClientMessage message = invoke(requestMessage, connection);
handleExecuteResponse(res, message);
return res;
} catch (Exception e) {
RuntimeException error = rethrow(e, connection);
res.onExecuteError(error);
throw error;
}
}
use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.
the class ClientInvocationServiceImplTest method testInvocation_willNotBeNotifiedForOldStalledResponse_afterARetry.
@Test
public void testInvocation_willNotBeNotifiedForOldStalledResponse_afterARetry() {
ClientConnection connection = client.getConnectionManager().getRandomConnection();
ClientInvocation invocation = new ClientInvocation(client, ClientPingCodec.encodeRequest(), null, connection);
// Do all the steps necessary to invoke a connection but do not put it in the write queue
ClientInvocationServiceImpl invocationService = (ClientInvocationServiceImpl) client.getInvocationService();
long correlationId = invocationService.getCallIdSequence().next();
invocation.getClientMessage().setCorrelationId(correlationId);
invocationService.registerInvocation(invocation, connection);
invocation.setSentConnection(connection);
// Sent connection dies
assertTrue(invocation.getPermissionToNotifyForDeadConnection(connection));
// simulate a retry
invocationService.deRegisterInvocation(correlationId);
long retryCorrelationId = invocationService.getCallIdSequence().next();
invocation.getClientMessage().setCorrelationId(retryCorrelationId);
invocationService.registerInvocation(invocation, connection);
invocation.setSentConnection(connection);
// Simulate the stalled old response trying to notify the invocation
assertFalse(invocation.getPermissionToNotify(correlationId));
}
use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.
the class ClientInvocationServiceImplTest method closedConnection.
private ClientConnection closedConnection() {
ClientConnection conn = mock(ClientConnection.class, RETURNS_DEEP_STUBS);
when(conn.isAlive()).thenReturn(false);
return conn;
}
Aggregations