Search in sources :

Example 6 with JdbcThinTcpIo

use of org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo in project ignite by apache.

the class JdbcThinPartitionAwarenessReconnectionAndFailoverSelfTest method testFailoverOnAllNodes.

/**
 * Check that all possible sub-connections are used.
 *
 * <ol>
 * <li>Create {@code JdbcThinConnection} to all existing nodes.</li>
 * <li>Stop all nodes.</li>
 * <li>Submit arbitrary sql query.</li>
 * <li>Several retries are expected. Exact number of retries should be equal to the number of originally
 * established connections. At the very end, after trying to establish brand new connections {@code SQLException}
 * with message: 'Failed to connect to server' should be thrown.</li>
 * </ol>
 *
 * @throws Exception If failed.
 */
@SuppressWarnings("ThrowableNotThrown")
@Test
public void testFailoverOnAllNodes() throws Exception {
    try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800..10802?partitionAwareness=true")) {
        Map<UUID, JdbcThinTcpIo> ios = GridTestUtils.getFieldValue(conn, "ios");
        assertConnectionsCount(ios, 3);
        stopAllGrids();
        logHnd.records.clear();
        GridTestUtils.assertThrows(null, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.createStatement().execute("select 1");
                return null;
            }
        }, SQLException.class, "Failed to connect to server [url=jdbc:ignite:thin://127.0.0.1:10800..10802]");
    }
    assertEquals("Unexpected log records count.", 3, logHnd.records.size());
    for (LogRecord record : logHnd.records) {
        assertEquals("Unexpected log record text.", "Exception during sending an sql request.", record.getMessage());
        assertEquals("Unexpected log level", Level.FINE, record.getLevel());
    }
    startGridsMultiThreaded(INITIAL_NODES_CNT);
}
Also used : LogRecord(java.util.logging.LogRecord) Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) UUID(java.util.UUID) SQLException(java.sql.SQLException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Test(org.junit.Test)

Example 7 with JdbcThinTcpIo

use of org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo in project ignite by apache.

the class JdbcThinConnectionSelfTest method assertHints.

/**
 * Assert hints.
 *
 * @param conn Connection.
 * @param distributedJoins Distributed joins.
 * @param enforceJoinOrder Enforce join order.
 * @param collocated Co-located.
 * @param replicatedOnly Replicated only.
 * @param lazy Lazy.
 * @param skipReducerOnUpdate Skip reducer on update.
 * @throws Exception If failed.
 */
private void assertHints(Connection conn, boolean distributedJoins, boolean enforceJoinOrder, boolean collocated, boolean replicatedOnly, boolean lazy, boolean skipReducerOnUpdate, boolean partitionAwarenessEnabled) throws Exception {
    for (JdbcThinTcpIo io : ios(conn)) {
        assertEquals(distributedJoins, io.connectionProperties().isDistributedJoins());
        assertEquals(enforceJoinOrder, io.connectionProperties().isEnforceJoinOrder());
        assertEquals(collocated, io.connectionProperties().isCollocated());
        assertEquals(replicatedOnly, io.connectionProperties().isReplicatedOnly());
        assertEquals(lazy, io.connectionProperties().isLazy());
        assertEquals(skipReducerOnUpdate, io.connectionProperties().isSkipReducerOnUpdate());
        assertEquals(partitionAwarenessEnabled, io.connectionProperties().isPartitionAwareness());
    }
}
Also used : JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo)

Example 8 with JdbcThinTcpIo

use of org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo in project ignite by apache.

the class JdbcThinConnectionSelfTest method testAutoCloseServerCursorProperty.

/**
 * Test autoCloseServerCursor property handling.
 *
 * @throws Exception If failed.
 */
@Test
public void testAutoCloseServerCursorProperty() throws Exception {
    String url = urlWithPartitionAwarenessProp + "&autoCloseServerCursor";
    String err = "Invalid property value. [name=autoCloseServerCursor";
    assertInvalid(url + "=0", err);
    assertInvalid(url + "=1", err);
    assertInvalid(url + "=false1", err);
    assertInvalid(url + "=true1", err);
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isAutoCloseServerCursor());
    }
    try (Connection conn = DriverManager.getConnection(url + "=true")) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isAutoCloseServerCursor());
    }
    try (Connection conn = DriverManager.getConnection(url + "=True")) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isAutoCloseServerCursor());
    }
    try (Connection conn = DriverManager.getConnection(url + "=false")) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isAutoCloseServerCursor());
    }
    try (Connection conn = DriverManager.getConnection(url + "=False")) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isAutoCloseServerCursor());
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) Test(org.junit.Test)

Example 9 with JdbcThinTcpIo

use of org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo in project ignite by apache.

the class JdbcThinConnectionSelfTest method testTcpNoDelaySemicolon.

/**
 * Test TCP no delay property handling with semicolon.
 *
 * @throws Exception If failed.
 */
@Test
public void testTcpNoDelaySemicolon() throws Exception {
    assertInvalid(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=0", "Invalid property value. [name=tcpNoDelay, val=0, choices=[true, false]]");
    assertInvalid(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=1", "Invalid property value. [name=tcpNoDelay, val=1, choices=[true, false]]");
    assertInvalid(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=false1", "Invalid property value. [name=tcpNoDelay, val=false1, choices=[true, false]]");
    assertInvalid(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=true1", "Invalid property value. [name=tcpNoDelay, val=true1, choices=[true, false]]");
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=true")) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=True")) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=false")) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";tcpNoDelay=False")) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay());
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) Test(org.junit.Test)

Example 10 with JdbcThinTcpIo

use of org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo in project ignite by apache.

the class JdbcThinDataSourceSelfTest method ios.

/**
 * Get client endpoints for connection.
 *
 * @param conn Connection.
 * @return Collection of endpoints.
 * @throws Exception If failed.
 */
private static Collection<JdbcThinTcpIo> ios(Connection conn) throws Exception {
    JdbcThinConnection conn0 = conn.unwrap(JdbcThinConnection.class);
    Collection<JdbcThinTcpIo> ios = partitionAwareness ? ((Map<UUID, JdbcThinTcpIo>) GridTestUtils.getFieldValue(conn0, JdbcThinConnection.class, "ios")).values() : Collections.singleton(GridTestUtils.getFieldValue(conn0, JdbcThinConnection.class, "singleIo"));
    assert !ios.isEmpty();
    return ios;
}
Also used : JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) UUID(java.util.UUID) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)

Aggregations

JdbcThinTcpIo (org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo)25 Test (org.junit.Test)19 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)18 Connection (java.sql.Connection)16 UUID (java.util.UUID)9 SQLException (java.sql.SQLException)5 ConnectionPropertiesImpl (org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl)4 InetSocketAddress (java.net.InetSocketAddress)3 LogRecord (java.util.logging.LogRecord)3 IgniteJdbcThinDataSource (org.apache.ignite.IgniteJdbcThinDataSource)3 Savepoint (java.sql.Savepoint)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 HostAndPortRange (org.apache.ignite.internal.util.HostAndPortRange)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 InetAddress (java.net.InetAddress)1 ServerSocket (java.net.ServerSocket)1 SQLClientInfoException (java.sql.SQLClientInfoException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 NamingException (javax.naming.NamingException)1