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);
}
}
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);
}
}
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"));
}
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());
}
}
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());
}
}
}
Aggregations