private ResultSet executeAndGetResultSet(String query) throws Exception { Statement stmt = loggedConn.createStatement(); stmt.execute(query); return stmt.getResultSet(); }
private ResultSet upsertRows(String query) throws SQLException { Statement stmt = loggedConn.createStatement(); ResultSet rs = stmt.executeQuery(query); assertTrue(rs instanceof LoggingPhoenixResultSet); int rowsRetrievedCounter = 0; while (rs.next()) { rowsRetrievedCounter++; } rs.close(); assertTrue(rowsRetrievedCounter == NUM_ROWS); return rs; }
loggedConn.createStatement().executeUpdate(upsertSelect); loggedConn.createStatement().execute(query); assertTrue("Read metrics found for " + tableName1, mutationReadMetricsMap.size() == 0); loggedConn.createStatement().execute(upsertSelect);
@Test public void testPhoenixMetricsLoggedOnClose() throws Exception { // run SELECT to verify read metrics are logged String query = "SELECT * FROM " + tableName1; ResultSet rs = upsertRows(query); verifyQueryLevelMetricsLogging(query, rs); // run UPSERT SELECT to verify mutation metrics are logged String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " + tableName1; loggedConn.createStatement().executeUpdate(upsertSelect); // Autocommit is turned off by default // Hence mutation metrics are not expected during connection close loggedConn.close(); assertTrue("Mutation write metrics are not logged for " + tableName2, mutationWriteMetricsMap.size() == 0); assertTrue("Mutation read metrics for not found for " + tableName1, mutationReadMetricsMap.get(tableName1).size() > 0); assertReadMetricsForMutatingSql(tableName1, 1, mutationReadMetricsMap); clearAllTestMetricMaps(); loggedConn.close(); assertTrue("Mutation write metrics are not logged again.", mutationWriteMetricsMap.size() == 0); assertTrue("Mutation read metrics are not logged again.", mutationReadMetricsMap.size() == 0); }
loggedConn.createStatement().executeUpdate(upsertSelect);