Search in sources :

Example 16 with JdbcThinTcpIo

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

the class JdbcThinPartitionAwarenessReconnectionAndFailoverSelfTest method testConnectionFailover.

/**
 * Test connection failover:
 * <ol>
 * <li>Check that at the beginning of test {@code INITIAL_NODES_CNT} connections are established.</li>
 * <li>Stop one node, invalidate dead connection (jdbc thin, won't detect that node has gone,
 * until it tries to touch it) and verify, that connections count has decremented. </li>
 * <li>Start, previously stopped node, and check that connections count also restored to initial value.</li>
 * </ol>
 *
 * @throws Exception If failed.
 */
@Test
public void testConnectionFailover() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        Map<UUID, JdbcThinTcpIo> ios = GridTestUtils.getFieldValue(conn, "ios");
        assertConnectionsCount(ios, INITIAL_NODES_CNT);
        assertEquals("Unexpected connections count.", INITIAL_NODES_CNT, ios.size());
        stopGrid(1);
        invalidateConnectionToStoppedNode(conn);
        assertEquals("Unexpected connections count.", INITIAL_NODES_CNT - 1, ios.size());
        startGrid(1);
        assertConnectionsCount(ios, INITIAL_NODES_CNT);
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with JdbcThinTcpIo

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

the class JdbcThinPartitionAwarenessReconnectionAndFailoverSelfTest method testEagerConnectionFailover.

/**
 * Test eager connection failover:
 * <ol>
 * <li>Check that at the beginning of test {@code INITIAL_NODES_CNT} connections are established.</li>
 * <li>Stop all nodes, invalidate dead connections (jdbc thin, won't detect that node has gone,
 * until it tries to touch it) and verify, that connections count equals to zero. </li>
 * <li>Wait for some time, in order for reconnection thread to increase delay between connection attempts,
 * because of reconnection failures.</li>
 * <li>Start, previously stopped nodes, and send simple query immediately. Eager reconnection is expected.
 * <b>NOTE</b>:There's still a chance that connection would be recreated by background thread and not eager
 * process. In order to decrease given possibility we've waited for some time on previous step.</li>
 * <li>Ensure that after some time all connections will be restored.</li>
 * </ol>
 *
 * @throws Exception If failed.
 */
@Test
public void testEagerConnectionFailover() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        Map<UUID, JdbcThinTcpIo> ios = GridTestUtils.getFieldValue(conn, "ios");
        assertConnectionsCount(ios, INITIAL_NODES_CNT);
        for (int i = 0; i < INITIAL_NODES_CNT; i++) {
            stopGrid(i);
            invalidateConnectionToStoppedNode(conn);
        }
        assertEquals("Unexpected connections count.", 0, ios.size());
        doSleep(4 * JdbcThinConnection.RECONNECTION_DELAY);
        for (int i = 0; i < INITIAL_NODES_CNT; i++) startGrid(i);
        conn.createStatement().execute("select 1;");
        assertConnectionsCount(ios, INITIAL_NODES_CNT);
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with JdbcThinTcpIo

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

the class JdbcThinTcpIoTest method testExceptionMessage.

/**
 * Test exception text (should contain inaccessible ip addresses list).
 */
@Test
public void testExceptionMessage() {
    Throwable throwable = GridTestUtils.assertThrows(log, new Callable<Object>() {

        @SuppressWarnings("ResultOfObjectAllocationIgnored")
        @Override
        public Object call() throws Exception {
            new JdbcThinTcpIo(new ConnectionPropertiesImpl(), new InetSocketAddress("123.45.67.89", 10800), null, 500);
            return null;
        }
    }, SQLException.class, "Failed to connect to server [host=123.45.67.89, port=10800]");
    assertEquals(java.net.SocketTimeoutException.class, throwable.getCause().getClass());
    assertTrue(throwable.getCause().getMessage().contains("connect timed out"));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionPropertiesImpl(org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) SQLException(java.sql.SQLException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 19 with JdbcThinTcpIo

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

the class JdbcThinConnectionSelfTest method testAutoCloseServerCursorPropertySemicolon.

/**
 * Test autoCloseServerCursor property handling with semicolon.
 *
 * @throws Exception If failed.
 */
@Test
public void testAutoCloseServerCursorPropertySemicolon() throws Exception {
    String url = urlWithPartitionAwarenessPropSemicolon + ";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(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 20 with JdbcThinTcpIo

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

the class JdbcThinConnectionSelfTest method testSocketBuffersSemicolon.

/**
 * Test invalid socket buffer sizes with semicolon.
 *
 * @throws Exception If failed.
 */
@Test
public void testSocketBuffersSemicolon() throws Exception {
    final int dfltDufSize = 64 * 1024;
    assertInvalid(urlWithPartitionAwarenessPropSemicolon + ";socketSendBuffer=-1", "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]");
    assertInvalid(urlWithPartitionAwarenessPropSemicolon + ";socketReceiveBuffer=-1", "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]");
    // Note that SO_* options are hints, so we check that value is equals to either what we set or to default.
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";socketSendBuffer=1024")) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(1024, io.connectionProperties().getSocketSendBuffer());
            assertEquals(dfltDufSize, io.connectionProperties().getSocketReceiveBuffer());
        }
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";socketReceiveBuffer=1024")) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(dfltDufSize, io.connectionProperties().getSocketSendBuffer());
            assertEquals(1024, io.connectionProperties().getSocketReceiveBuffer());
        }
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";" + "socketSendBuffer=1024;socketReceiveBuffer=2048")) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(1024, io.connectionProperties().getSocketSendBuffer());
            assertEquals(2048, io.connectionProperties().getSocketReceiveBuffer());
        }
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) Savepoint(java.sql.Savepoint) Test(org.junit.Test)

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