private void loggingAutoCommitHelper() throws SQLException { if(conn.getAutoCommit() && (conn instanceof LoggingPhoenixConnection)) { ((LoggingPhoenixConnection)conn).loggingMetricsHelper(); } }
LoggingPhoenixConnection getLoggingPhoenixConnection(Connection conn) { return new LoggingPhoenixConnection(conn, new PhoenixMetricsLog() { @Override public void logOverAllReadRequestMetrics(
private ResultSet executeAndGetResultSet(String query) throws Exception { Statement stmt = loggedConn.createStatement(); stmt.execute(query); return stmt.getResultSet(); }
loggedConn.setAutoCommit(true); loggedConn.createStatement().executeUpdate(upsertSelect); loggedConn.createStatement().execute(query); assertTrue("Read metrics found for " + tableName1, mutationReadMetricsMap.size() == 0); loggedConn.createStatement().execute(upsertSelect); loggedConn.prepareStatement(query).executeQuery(); assertTrue("Read metrics found for " + tableName1, mutationReadMetricsMap.size() == 0); loggedConn.prepareStatement(upsertSelect).executeUpdate(); assertTrue("Mutation write metrics are not logged for " + tableName2 + " in prepareStatement",mutationWriteMetricsMap.get(tableName2).size() > 0);
loggedConn.createStatement().executeUpdate(upsertSelect); loggedConn.commit(); assertTrue("Mutation write metrics for not found for " + tableName2, mutationWriteMetricsMap.get(tableName2).size() > 0); loggedConn.close(); assertTrue("Mutation write metrics are not logged again.", mutationWriteMetricsMap.size() == 0); loggedConn.close(); assertTrue("Mutation write metrics are not logged again.", mutationWriteMetricsMap.size() == 0);
@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); }
private void loggingAutoCommitHelper() throws SQLException { if(conn.getAutoCommit() && (conn instanceof LoggingPhoenixConnection)) { ((LoggingPhoenixConnection)conn).loggingMetricsHelper(); } } }
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; }
@Override public void close() throws SQLException { try { loggingMetricsHelper(); } finally { super.close(); } }
@Override public void commit() throws SQLException { super.commit(); loggingMetricsHelper(); }
private void loggingAutoCommitHelper() throws SQLException { if(conn.getAutoCommit() && (conn instanceof LoggingPhoenixConnection)) { ((LoggingPhoenixConnection)conn).loggingMetricsHelper(); } }
private void loggingAutoCommitHelper() throws SQLException { if(conn.getAutoCommit() && (conn instanceof LoggingPhoenixConnection)) { ((LoggingPhoenixConnection)conn).loggingMetricsHelper(); } } }
@Override public void commit() throws SQLException { super.commit(); loggingMetricsHelper(); }
@Override public void close() throws SQLException { try { loggingMetricsHelper(); } finally { super.close(); } }