/** * @param qry SQL query. * @throws SQLException In case of failure. */ private void runJdbcQuery(String qry) throws SQLException { try (Connection conn = GridTestUtils.connect(queryNode(), null); Statement stmt = conn.createStatement()) { stmt.execute(qry); } }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); IgniteEx ign = startGrid(0); conn = GridTestUtils.connect(ign, null); }
/** * Test metrics for JDBC in case not fully resultset is not fully read. * * @throws Exception In case of error. */ @Test public void testJdbcSelectNotFullyFetchedQueryHistory() throws Exception { String qry = "select * from A.String"; try (Connection conn = GridTestUtils.connect(queryNode(), null); Statement stmt = conn.createStatement()) { stmt.setFetchSize(1); ResultSet rs = stmt.executeQuery(qry); assertTrue(rs.next()); checkMetrics(0, 0, 0, 0, true); } }
/** * Test metrics for JDBC in case of DDL and DML * * @throws Exception In case of error. */ @Test public void testJdbcQueryHistoryForDmlAndDdl() throws Exception { List<String> cmds = Arrays.asList( "create table TST(id int PRIMARY KEY, name varchar)", "insert into TST(id) values(1)", "commit" ); try (Connection conn = GridTestUtils.connect(queryNode(), null); Statement stmt = conn.createStatement()) { for (String cmd : cmds) stmt.execute(cmd); } checkSeriesCommand(cmds); }
/** * Test metrics for failed SQL queries. */ @Test public void testJdbcQueryHistoryFailed() { try (Connection conn = GridTestUtils.connect(queryNode(), null); Statement stmt = conn.createStatement()) { stmt.executeQuery("select * from A.String where A.fail()=1"); fail("Query should be failed."); } catch (Exception ignore) { //No-Op } checkMetrics(1, 0, 1, 1, true); }
/** * Check tracking running queries for stream batching. * * @throws Exception in case of failure. */ @Test public void testJdbcStreamBatchUpdate() throws Exception { try (Connection conn = GridTestUtils.connect(ignite, null); Statement stmt = conn.createStatement()) { conn.setSchema("\"default\""); newBarrier(1); final int BATCH_SIZE = 10; stmt.executeUpdate("SET STREAMING ON BATCH_SIZE " + BATCH_SIZE); newBarrier(2); for (int i = 0; i < BATCH_SIZE; i++) stmt.addBatch("insert into Integer (_key, _val) values (" + i + "," + i + ")"); for (int i = 0; i < BATCH_SIZE; i++) { assertWaitingOnBarrier(); awaitTimeouted(); assertWaitingOnBarrier(); Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1); assertEquals(1, runningQueries.size()); awaitTimeouted(); } } }
/** * Check tracking running queries for stream COPY command. * * @throws SQLException If failed. */ @Test public void testCopyCommand() throws Exception { try (Connection conn = GridTestUtils.connect(ignite, null); Statement stmt = conn.createStatement()) { conn.setSchema("\"default\""); newBarrier(1); stmt.execute("CREATE TABLE Person(id integer primary key, age integer, firstName varchar, lastname varchar)"); String path = Objects.requireNonNull(resolveIgnitePath("/modules/clients/src/test/resources/bulkload1.csv")) .getAbsolutePath(); newBarrier(2); String sql = "copy from '" + path + "'" + " into Person" + " (_key, age, firstName, lastName)" + " format csv charset 'ascii'"; IgniteInternalFuture<Integer> fut = GridTestUtils.runAsync(() -> stmt.executeUpdate(sql)); assertWaitingOnBarrier(); List<GridRunningQueryInfo> runningQueries = (List<GridRunningQueryInfo>)ignite.context().query().runningQueries(-1); assertEquals(1, runningQueries.size()); assertEquals(sql, runningQueries.get(0).query()); awaitTimeouted(); fut.get(TIMEOUT_IN_MS); } }
try (Connection conn = GridTestUtils.connect(ignite, null); Statement stmt = conn.createStatement()) { IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(() -> stmt.execute(sql));
/** * Check tracking running queries for batches. * * @throws Exception Exception in case of failure. */ @Test public void testJdbcBatchDML() throws Exception { newBarrier(2); try (Connection conn = GridTestUtils.connect(ignite, null); Statement stmt = conn.createStatement()) { conn.setSchema("\"default\""); final int BATCH_SIZE = 10; int key = 0; for (int i = 0; i < BATCH_SIZE; i++) { while (ignite.affinity(DEFAULT_CACHE_NAME).isPrimary(ignite.localNode(), key)) key++; stmt.addBatch("insert into Integer (_key, _val) values (" + key + "," + key + ")"); key++; } IgniteInternalFuture<int[]> fut = GridTestUtils.runAsync(stmt::executeBatch); for (int i = 0; i < BATCH_SIZE; i++) { assertWaitingOnBarrier(); Collection<GridRunningQueryInfo> runningQueries = ignite.context().query().runningQueries(-1); assertEquals(1, runningQueries.size()); awaitTimeouted(); assertWaitingOnBarrier(); awaitTimeouted(); } fut.get(TIMEOUT_IN_MS); } }