use of org.apache.ignite.IgniteJdbcThinDriver in project ignite by apache.
the class JmxExporterSpiTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
String host = ignite.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = ignite.configuration().getLocalHost();
int port = ignite.configuration().getClientConnectorConfiguration().getPort();
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
TabularDataSupport conns = systemView(CLI_CONN_VIEW);
Consumer<CompositeData> checkThin = c -> {
assertEquals("THIN", c.get("type"));
assertTrue(c.get("localAddress").toString().endsWith(Integer.toString(port)));
assertEquals(c.get("version"), ProtocolVersion.LATEST_VER.toString());
};
Consumer<CompositeData> checkJdbc = c -> {
assertEquals("JDBC", c.get("type"));
assertTrue(c.get("localAddress").toString().endsWith(Integer.toString(port)));
assertEquals(c.get("version"), JdbcConnectionContext.CURRENT_VER.asString());
};
CompositeData c0 = conns.get(new Object[] { 0 });
CompositeData c1 = conns.get(new Object[] { 1 });
if (c0.get("type").equals("JDBC")) {
checkJdbc.accept(c0);
checkThin.accept(c1);
} else {
checkJdbc.accept(c1);
checkThin.accept(c0);
}
assertEquals(2, conns.size());
}
}
boolean res = GridTestUtils.waitForCondition(() -> systemView(CLI_CONN_VIEW).isEmpty(), 5_000);
assertTrue(res);
}
use of org.apache.ignite.IgniteJdbcThinDriver in project ignite by apache.
the class SystemViewCommandTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
String host = ignite0.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = ignite0.configuration().getLocalHost();
int port = ignite0.configuration().getClientConnectorConfiguration().getPort();
try (IgniteClient ignored1 = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port));
Connection ignored2 = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
assertEquals(2, systemView(ignite0, CLI_CONN_VIEW).size());
}
}
use of org.apache.ignite.IgniteJdbcThinDriver in project ignite by apache.
the class SystemViewSelfTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
try (IgniteEx g0 = startGrid(0)) {
String host = g0.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = g0.configuration().getLocalHost();
int port = g0.configuration().getClientConnectorConfiguration().getPort();
SystemView<ClientConnectionView> conns = g0.context().systemView().view(CLI_CONN_VIEW);
try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
assertEquals(1, conns.size());
ClientConnectionView cliConn = conns.iterator().next();
assertEquals("THIN", cliConn.type());
assertEquals(cliConn.localAddress().getHostName(), cliConn.remoteAddress().getHostName());
assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), cliConn.localAddress().getPort());
assertEquals(cliConn.version(), ProtocolVersion.LATEST_VER.toString());
try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
assertEquals(2, conns.size());
assertEquals(1, F.size(jdbcConnectionsIterator(conns)));
ClientConnectionView jdbcConn = jdbcConnectionsIterator(conns).next();
assertEquals("JDBC", jdbcConn.type());
assertEquals(jdbcConn.localAddress().getHostName(), jdbcConn.remoteAddress().getHostName());
assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), jdbcConn.localAddress().getPort());
assertEquals(jdbcConn.version(), JdbcConnectionContext.CURRENT_VER.asString());
}
}
boolean res = GridTestUtils.waitForCondition(() -> conns.size() == 0, 5_000);
assertTrue(res);
}
}
use of org.apache.ignite.IgniteJdbcThinDriver in project ignite by apache.
the class JdbcThinPreparedStatementLeakTest method test.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("StatementWithEmptyBody")
@Test
public void test() throws Exception {
try (Connection conn = new IgniteJdbcThinDriver().connect(URL, new Properties())) {
for (int i = 0; i < 50000; ++i) {
try (PreparedStatement st = conn.prepareStatement("select 1")) {
ResultSet rs = st.executeQuery();
while (rs.next()) {
// No-op.
}
rs.close();
}
}
Set stmts = U.field(conn, "stmts");
assertEquals(0, stmts.size());
}
}
use of org.apache.ignite.IgniteJdbcThinDriver in project ignite by apache.
the class SqlViewExporterSpiTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
String host = ignite0.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = ignite0.configuration().getLocalHost();
int port = ignite0.configuration().getClientConnectorConfiguration().getPort();
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
List<List<?>> conns = execute(ignite0, "SELECT * FROM SYS.CLIENT_CONNECTIONS");
assertEquals(2, conns.size());
}
}
}
Aggregations