Search in sources :

Example 11 with ClientConnection

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());
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) SqlFetchCodec(com.hazelcast.client.impl.protocol.codec.SqlFetchCodec) SqlClientService(com.hazelcast.sql.impl.client.SqlClientService) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) SqlExecuteCodec(com.hazelcast.client.impl.protocol.codec.SqlExecuteCodec) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with ClientConnection

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;
}
Also used : ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 13 with ClientConnection

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;
    }
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) ArrayList(java.util.ArrayList) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QueryException(com.hazelcast.sql.impl.QueryException) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) AccessControlException(java.security.AccessControlException) Nonnull(javax.annotation.Nonnull)

Example 14 with ClientConnection

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));
}
Also used : ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with ClientConnection

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;
}
Also used : ClientConnection(com.hazelcast.client.impl.connection.ClientConnection)

Aggregations

ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)15 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 EventHandler (com.hazelcast.client.impl.spi.EventHandler)3 Map (java.util.Map)3 UUID (java.util.UUID)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)2 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)2 Member (com.hazelcast.cluster.Member)2 Connection (com.hazelcast.internal.nio.Connection)2 QueryId (com.hazelcast.sql.impl.QueryId)2 Nonnull (javax.annotation.Nonnull)2 HazelcastClientOfflineException (com.hazelcast.client.HazelcastClientOfflineException)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 SqlExecuteCodec (com.hazelcast.client.impl.protocol.codec.SqlExecuteCodec)1 SqlFetchCodec (com.hazelcast.client.impl.protocol.codec.SqlFetchCodec)1