Search in sources :

Example 11 with JdbcThinTcpIo

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

the class JdbcThinDataSourceSelfTest method testSqlHints.

/**
 * @throws Exception If failed.
 */
@Test
public void testSqlHints() throws Exception {
    IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertFalse(io.connectionProperties().isAutoCloseServerCursor());
            assertFalse(io.connectionProperties().isCollocated());
            assertFalse(io.connectionProperties().isEnforceJoinOrder());
            assertFalse(io.connectionProperties().isLazy());
            assertFalse(io.connectionProperties().isDistributedJoins());
            assertFalse(io.connectionProperties().isReplicatedOnly());
        }
    }
    ids.setAutoCloseServerCursor(true);
    ids.setCollocated(true);
    ids.setEnforceJoinOrder(true);
    ids.setLazy(true);
    ids.setDistributedJoins(true);
    ids.setReplicatedOnly(true);
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertTrue(io.connectionProperties().isAutoCloseServerCursor());
            assertTrue(io.connectionProperties().isCollocated());
            assertTrue(io.connectionProperties().isEnforceJoinOrder());
            assertTrue(io.connectionProperties().isLazy());
            assertTrue(io.connectionProperties().isDistributedJoins());
            assertTrue(io.connectionProperties().isReplicatedOnly());
        }
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) Test(org.junit.Test)

Example 12 with JdbcThinTcpIo

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

the class JdbcThinDataSourceSelfTest method testSocketBuffers.

/**
 * @throws Exception If failed.
 */
@Test
public void testSocketBuffers() throws Exception {
    final IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    ids.setSocketReceiveBuffer(111);
    ids.setSocketSendBuffer(111);
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(111, io.connectionProperties().getSocketReceiveBuffer());
            assertEquals(111, io.connectionProperties().getSocketSendBuffer());
        }
    }
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ids.setSocketReceiveBuffer(-1);
            ids.getConnection();
            return null;
        }
    }, SQLException.class, "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]");
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ids.setSocketReceiveBuffer(1024);
            ids.setSocketSendBuffer(-1);
            ids.getConnection();
            return null;
        }
    }, SQLException.class, "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]");
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 13 with JdbcThinTcpIo

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

the class JdbcThinTcpIoTest method testHostWithValidAddress.

/**
 * Test connection to host with accessible address.
 *
 * @throws Exception If failed.
 */
@Test
public void testHostWithValidAddress() throws Exception {
    startGrids(1);
    JdbcThinTcpIo jdbcThinTcpIo = null;
    try {
        jdbcThinTcpIo = new JdbcThinTcpIo(new ConnectionPropertiesImpl(), new InetSocketAddress("127.0.0.1", 10800), null, 500);
    } finally {
        if (jdbcThinTcpIo != null)
            jdbcThinTcpIo.close();
    }
    stopGrid(0);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionPropertiesImpl(org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 14 with JdbcThinTcpIo

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

the class JdbcThinConnectionMultipleAddressesTest method stop.

/**
 * @param conn Connection.
 * @param all If {@code true} all nodes will be stopped.
 */
private void stop(Connection conn, boolean all) {
    if (all)
        stopAllGrids();
    else {
        JdbcThinTcpIo io = GridTestUtils.getFieldValue(conn, "cliIo");
        int idx = GridTestUtils.getFieldValue(io, "srvIdx");
        stopGrid(idx);
    }
}
Also used : JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo)

Example 15 with JdbcThinTcpIo

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

the class JdbcThinTcpIoTest method testHostWithManyAddresses.

/**
 * Test connection to host which has inaccessible A-records.
 *
 * @throws SQLException On connection error or reject.
 * @throws IOException On IO error in handshake.
 */
public void testHostWithManyAddresses() throws SQLException, IOException, InterruptedException {
    CountDownLatch connectionAccepted = new CountDownLatch(1);
    try (ServerSocket sock = createServerSocket(connectionAccepted)) {
        String[] addrs = { INACCESSIBLE_ADDRESSES[0], "127.0.0.1", INACCESSIBLE_ADDRESSES[1] };
        JdbcThinTcpIo jdbcThinTcpIo = createTcpIo(addrs, sock.getLocalPort());
        try {
            jdbcThinTcpIo.start(500);
            // Check connection
            assertTrue(connectionAccepted.await(1000, TimeUnit.MILLISECONDS));
        } finally {
            jdbcThinTcpIo.close();
        }
    }
}
Also used : ServerSocket(java.net.ServerSocket) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) CountDownLatch(java.util.concurrent.CountDownLatch)

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