This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch 4.x in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push: new 1bafe9b PHOENIX-6543 de-flake AuditLoggingIT 1bafe9b is described below commit 1bafe9b2807f91d6c48a8bf5dbb91fdf1494a43a Author: Istvan Toth <st...@apache.org> AuthorDate: Tue Sep 14 10:56:37 2021 +0200 PHOENIX-6543 de-flake AuditLoggingIT --- .../org/apache/phoenix/end2end/AuditLoggingIT.java | 169 ++++++++++++--------- 1 file changed, 101 insertions(+), 68 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AuditLoggingIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AuditLoggingIT.java index e83ff90..4458306 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AuditLoggingIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AuditLoggingIT.java @@ -49,6 +49,7 @@ public class AuditLoggingIT extends ParallelStatsDisabledIT { stmt.executeQuery(selectQuery); conn.commit(); + Thread.sleep(4000); ResultSet rs = stmt.executeQuery(getLogsQuery); assertFalse(rs.next()); } finally { @@ -65,27 +66,37 @@ public class AuditLoggingIT extends ParallelStatsDisabledIT { String getLogsQuery = "select * from SYSTEM.LOG WHERE TABLE_NAME='TEST2' order by start_time"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(QueryServices.LOG_LEVEL, LogLevel.TRACE.name()); - Connection conn = DriverManager.getConnection(getUrl(), props); - conn.setAutoCommit(true); - try { - conn.createStatement().execute(createqQery); - conn.createStatement().execute(upsertQuery); - ResultSet rs = conn.createStatement().executeQuery(selectQuery); + try (Connection conn = DriverManager.getConnection(getUrl(), props); + Statement stmt = conn.createStatement(); + ){ + conn.setAutoCommit(true); + stmt.execute(createqQery); + stmt.execute(upsertQuery); + ResultSet rs = stmt.executeQuery(selectQuery); assertTrue(rs.next()); assertFalse(rs.next()); rs.close(); - ResultSet rs2 = conn.createStatement().executeQuery(getLogsQuery); - assertTrue(rs2.next()); - assertEquals(rs2.getString(7), selectQuery); - assertFalse(rs2.next()); - } finally { - conn.close(); + int retryCount=10; + while (true) { + try { + ResultSet rs2 = stmt.executeQuery(getLogsQuery); + assertTrue(rs2.next()); + assertEquals(rs2.getString(7), selectQuery); + assertFalse(rs2.next()); + break; + } catch (AssertionError e) { + if(retryCount-- <= 0) { + throw e; + } + Thread.sleep(4000); + } + } } } @Test - public void testLoggingDMLAandDDL() throws Exception { + public void testLoggingDMLAndDDL() throws Exception { String createqQery = "create table test3 (mykey integer not null primary key," + " mycolumn varchar)"; String upsertQuery = "upsert into test3 values (1,'Hello')"; @@ -93,31 +104,41 @@ public class AuditLoggingIT extends ParallelStatsDisabledIT { String getLogsQuery = "select * from SYSTEM.LOG WHERE TABLE_NAME='TEST3' order by start_time"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(QueryServices.AUDIT_LOG_LEVEL, LogLevel.INFO.name()); - Connection conn = DriverManager.getConnection(getUrl(), props); - conn.setAutoCommit(true); - try { - conn.createStatement().execute(createqQery); - conn.createStatement().execute(upsertQuery); + try (Connection conn = DriverManager.getConnection(getUrl(), props); + Statement stmt = conn.createStatement(); + ){ + conn.setAutoCommit(true); + + stmt.execute(createqQery); + stmt.execute(upsertQuery); ResultSet rs = conn.createStatement().executeQuery(selectQuery); assertTrue(rs.next()); assertFalse(rs.next()); rs.close(); - ResultSet rs2 = conn.createStatement().executeQuery(getLogsQuery); - assertTrue(rs2.next()); - assertEquals(rs2.getString(7), createqQery); - assertTrue(rs2.next()); - assertEquals(rs2.getString(7), upsertQuery); - - assertFalse(rs2.next()); - } finally { - conn.close(); + int retryCount=10; + while (true) { + try { + ResultSet rs2 = stmt.executeQuery(getLogsQuery); + assertTrue(rs2.next()); + assertEquals(rs2.getString(7), createqQery); + assertTrue(rs2.next()); + assertEquals(rs2.getString(7), upsertQuery); + assertFalse(rs2.next()); + break; + } catch (AssertionError e) { + if(retryCount-- <= 0) { + throw e; + } + Thread.sleep(4000); + } + } } } @Test public void testLoggingDMLAandDDLandSelect() throws Exception { - String createqQery = "create table test4 (mykey integer not null primary key," + + String createqQuery = "create table test4 (mykey integer not null primary key," + " mycolumn varchar)"; String upsertQuery = "upsert into test4 values (1,'Hello')"; String selectQuery = "select * from test4"; @@ -125,29 +146,36 @@ public class AuditLoggingIT extends ParallelStatsDisabledIT { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(QueryServices.AUDIT_LOG_LEVEL, LogLevel.INFO.name()); props.setProperty(QueryServices.LOG_LEVEL, LogLevel.TRACE.name()); - Connection conn = DriverManager.getConnection(getUrl(), props); - conn.setAutoCommit(true); - try { - Statement stat = conn.createStatement(); - stat.execute(createqQery); - stat.execute(upsertQuery); - ResultSet rs = stat.executeQuery(selectQuery); + try (Connection conn = DriverManager.getConnection(getUrl(), props); + Statement stmt = conn.createStatement(); + ){ + conn.setAutoCommit(true); + stmt.execute(createqQuery); + stmt.execute(upsertQuery); + ResultSet rs = stmt.executeQuery(selectQuery); assertTrue(rs.next()); assertFalse(rs.next()); rs.close(); - ResultSet rs2 = conn.createStatement().executeQuery(getLogsQuery); - assertTrue(rs2.next()); - assertEquals(rs2.getString(7), createqQery); - assertTrue(rs2.next()); - assertEquals(rs2.getString(7), upsertQuery); - assertTrue(rs2.next()); - assertEquals(rs2.getString(7), selectQuery); - - assertFalse(rs2.next()); - - } finally { - conn.close(); + int retryCount=10; + while (true) { + try { + ResultSet rs2 = conn.createStatement().executeQuery(getLogsQuery); + assertTrue(rs2.next()); + assertEquals(rs2.getString(7), createqQuery); + assertTrue(rs2.next()); + assertEquals(rs2.getString(7), upsertQuery); + assertTrue(rs2.next()); + assertEquals(rs2.getString(7), selectQuery); + assertFalse(rs2.next()); + break; + } catch (AssertionError e) { + if(retryCount-- <= 0) { + throw e; + } + Thread.sleep(4000); + } + } } } @@ -161,41 +189,46 @@ public class AuditLoggingIT extends ParallelStatsDisabledIT { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(QueryServices.AUDIT_LOG_LEVEL, LogLevel.INFO.name()); props.setProperty(QueryServices.LOG_LEVEL, LogLevel.TRACE.name()); - Connection conn = DriverManager.getConnection(getUrl(), props); - conn.setAutoCommit(true); - try { - Statement stat = conn.createStatement(); - stat.execute(createqQery); - + try (Connection conn = DriverManager.getConnection(getUrl(), props); + Statement stmt = conn.createStatement(); + PreparedStatement p = conn.prepareStatement(upsertQuery); + ){ + conn.setAutoCommit(true); + stmt.execute(createqQery); - PreparedStatement p = conn.prepareStatement(upsertQuery); p.setInt(1, 1); p.setString(2, "foo"); - p.execute(); p.setInt(1, 2); p.setString(2, "bar"); - p.execute(); - ResultSet rs = stat.executeQuery(selectQuery); + ResultSet rs = stmt.executeQuery(selectQuery); assertTrue(rs.next()); assertTrue(rs.next()); assertFalse(rs.next()); rs.close(); - ResultSet rs2 = conn.createStatement().executeQuery(getLogsQuery); - assertTrue(rs2.next()); - assertTrue(rs2.next()); - assertEquals("1,foo", rs2.getString(13)); - assertTrue(rs2.next()); - assertEquals( "2,bar", rs2.getString(13)); - assertTrue(rs2.next()); - assertFalse(rs2.next()); - - } finally { - conn.close(); + int retryCount=10; + while (true) { + try { + ResultSet rs2 = conn.createStatement().executeQuery(getLogsQuery); + assertTrue(rs2.next()); + assertTrue(rs2.next()); + assertEquals("1,foo", rs2.getString(13)); + assertTrue(rs2.next()); + assertEquals( "2,bar", rs2.getString(13)); + assertTrue(rs2.next()); + assertFalse(rs2.next()); + break; + } catch (AssertionError e) { + if(retryCount-- <= 0) { + throw e; + } + Thread.sleep(4000); + } + } } }