Search in sources :

Example 21 with JdbcThinTcpIo

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

the class JdbcThinConnectionSelfTest 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>) getFieldValue(conn0, JdbcThinConnection.class, "ios")).values() : Collections.singleton(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)

Example 22 with JdbcThinTcpIo

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

the class JdbcThinConnectionSelfTest method testTcpNoDelay.

/**
 * Test TCP no delay property handling.
 *
 * @throws Exception If failed.
 */
@Test
public void testTcpNoDelay() throws Exception {
    assertInvalid(urlWithPartitionAwarenessProp + "&tcpNoDelay=0", "Invalid property value. [name=tcpNoDelay, val=0, choices=[true, false]]");
    assertInvalid(urlWithPartitionAwarenessProp + "&tcpNoDelay=1", "Invalid property value. [name=tcpNoDelay, val=1, choices=[true, false]]");
    assertInvalid(urlWithPartitionAwarenessProp + "&tcpNoDelay=false1", "Invalid property value. [name=tcpNoDelay, val=false1, choices=[true, false]]");
    assertInvalid(urlWithPartitionAwarenessProp + "&tcpNoDelay=true1", "Invalid property value. [name=tcpNoDelay, val=true1, choices=[true, false]]");
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&tcpNoDelay=true")) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&tcpNoDelay=True")) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&tcpNoDelay=false")) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay());
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&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 23 with JdbcThinTcpIo

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

the class JdbcThinConnectionSelfTest method testInvalidNestedTxModeOnServerSide.

/**
 * Test that attempting to send unexpected name of nested TX mode to server on handshake yields an error.
 * We have to do this without explicit {@link Connection} as long as there's no other way to bypass validation and
 * supply a malformed {@link ConnectionProperties} to {@link JdbcThinTcpIo}.
 */
@Test
public void testInvalidNestedTxModeOnServerSide() {
    ConnectionPropertiesImpl connProps = new ConnectionPropertiesImpl();
    connProps.setAddresses(new HostAndPortRange[] { new HostAndPortRange(LOCALHOST, DFLT_PORT, DFLT_PORT) });
    connProps.nestedTxMode("invalid");
    connProps.setPartitionAwareness(partitionAwareness);
    assertThrows(null, new Callable<Object>() {

        @SuppressWarnings("ResultOfObjectAllocationIgnored")
        @Override
        public Object call() throws Exception {
            new JdbcThinTcpIo(connProps, new InetSocketAddress(LOCALHOST, DFLT_PORT), getBinaryContext(), 0);
            return null;
        }
    }, SQLException.class, "err=Invalid nested transactions handling mode: invalid");
}
Also used : HostAndPortRange(org.apache.ignite.internal.util.HostAndPortRange) InetSocketAddress(java.net.InetSocketAddress) ConnectionPropertiesImpl(org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 24 with JdbcThinTcpIo

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

the class JdbcThinConnectionSelfTest method testSocketBuffers.

/**
 * Test invalid socket buffer sizes.
 *
 * @throws Exception If failed.
 */
@Test
public void testSocketBuffers() throws Exception {
    final int dfltDufSize = 64 * 1024;
    assertInvalid(urlWithPartitionAwarenessProp + "&socketSendBuffer=-1", "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]");
    assertInvalid(urlWithPartitionAwarenessProp + "&socketReceiveBuffer=-1", "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]");
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(dfltDufSize, io.connectionProperties().getSocketSendBuffer());
            assertEquals(dfltDufSize, io.connectionProperties().getSocketReceiveBuffer());
        }
    }
    // 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(urlWithPartitionAwarenessProp + "&socketSendBuffer=1024")) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(1024, io.connectionProperties().getSocketSendBuffer());
            assertEquals(dfltDufSize, io.connectionProperties().getSocketReceiveBuffer());
        }
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&socketReceiveBuffer=1024")) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(dfltDufSize, io.connectionProperties().getSocketSendBuffer());
            assertEquals(1024, io.connectionProperties().getSocketReceiveBuffer());
        }
    }
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&" + "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)

Example 25 with JdbcThinTcpIo

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

the class JdbcThinDataSourceSelfTest method testTcpNoDelay.

/**
 * @throws Exception If failed.
 */
@Test
public void testTcpNoDelay() 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)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    ids.setTcpNoDelay(false);
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay());
    }
}
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)

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