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