[phoenix] 12/34: PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is set to True.

2019-04-19 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.4
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 1961a97ce1e2a6dff48437872ca738e83968c498
Author: s.kadam 
AuthorDate: Wed Sep 5 17:00:03 2018 -0700

PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is 
set to True.
---
 .../monitoring/PhoenixLoggingMetricsIT.java| 61 --
 .../phoenix/jdbc/LoggingPhoenixConnection.java | 37 +++--
 .../jdbc/LoggingPhoenixPreparedStatement.java  | 25 +++--
 .../phoenix/jdbc/LoggingPhoenixStatement.java  | 28 --
 4 files changed, 125 insertions(+), 26 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
index 5d5524c..483d341 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
@@ -102,7 +102,8 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 public void testPhoenixMetricsLoggedOnCommit() throws Exception {
 // run SELECT to verify read metrics are logged
 String query = "SELECT * FROM " + tableName1;
-verifyQueryLevelMetricsLogging(query);
+ResultSet rs = upsertRows(query);
+verifyQueryLevelMetricsLogging(query, rs);
 
 // run UPSERT SELECT to verify mutation metrics are logged
 String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " 
+ tableName1;
@@ -140,7 +141,9 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 public void testPhoenixMetricsLoggedOnClose() throws Exception {
 // run SELECT to verify read metrics are logged
 String query = "SELECT * FROM " + tableName1;
-verifyQueryLevelMetricsLogging(query);
+
+ResultSet rs = upsertRows(query);
+verifyQueryLevelMetricsLogging(query, rs);
 
 // run UPSERT SELECT to verify mutation metrics are logged
 String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " 
+ tableName1;
@@ -164,13 +167,61 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 mutationReadMetricsMap.size() == 0);
 }
 
+/**
+ * This test is added to verify if metrics are being logged in case
+ * auto commit is set to true.
+ */
+@Test
+public void testPhoenixMetricsLoggedOnAutoCommitTrue() throws Exception {
+loggedConn.setAutoCommit(true);
+
+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);
+
+assertTrue("Mutation write metrics are not logged for " + tableName2,
+mutationWriteMetricsMap.get(tableName2).size()  > 0);
+assertTrue("Mutation read metrics are not found for " + tableName1,
+mutationReadMetricsMap.get(tableName1).size() > 0);
+
+clearAllTestMetricMaps();
+
+loggedConn.createStatement().execute(query);
+assertTrue("Read metrics found for " + tableName1,
+mutationReadMetricsMap.size() == 0);
+loggedConn.createStatement().execute(upsertSelect);
+
+assertTrue("Mutation write metrics are not logged for " + tableName2
++ " in 
createStatement",mutationWriteMetricsMap.get(tableName2).size()  > 0);
+assertTrue("Mutation read metrics are not found for " + tableName1
++ " in 
createStatement",mutationReadMetricsMap.get(tableName1).size() > 0);
+
+clearAllTestMetricMaps();
+
+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);
+assertTrue("Mutation read metrics are not found for " + tableName1
++ " in 
prepareStatement",mutationReadMetricsMap.get(tableName1).size() > 0);
+
+
+}
+
 private ResultSet executeAndGetResultSet(String query) throws Exception {
 Statement stmt = loggedConn.createStatement();
 stmt.execute(query);
 return stmt.getResultSet();
 }
 
-private void verifyQueryLevelMetricsLogging(String query) throws 
SQLException {
+private ResultSet upsertRows(String query) throws SQLException 

[phoenix] 12/34: PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is set to True.

2019-04-19 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit f9ff033ccef034e2164391594cc5649538b22f35
Author: s.kadam 
AuthorDate: Wed Sep 5 17:00:03 2018 -0700

PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is 
set to True.
---
 .../monitoring/PhoenixLoggingMetricsIT.java| 61 --
 .../phoenix/jdbc/LoggingPhoenixConnection.java | 37 +++--
 .../jdbc/LoggingPhoenixPreparedStatement.java  | 25 +++--
 .../phoenix/jdbc/LoggingPhoenixStatement.java  | 28 --
 4 files changed, 125 insertions(+), 26 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
index 5d5524c..483d341 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
@@ -102,7 +102,8 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 public void testPhoenixMetricsLoggedOnCommit() throws Exception {
 // run SELECT to verify read metrics are logged
 String query = "SELECT * FROM " + tableName1;
-verifyQueryLevelMetricsLogging(query);
+ResultSet rs = upsertRows(query);
+verifyQueryLevelMetricsLogging(query, rs);
 
 // run UPSERT SELECT to verify mutation metrics are logged
 String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " 
+ tableName1;
@@ -140,7 +141,9 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 public void testPhoenixMetricsLoggedOnClose() throws Exception {
 // run SELECT to verify read metrics are logged
 String query = "SELECT * FROM " + tableName1;
-verifyQueryLevelMetricsLogging(query);
+
+ResultSet rs = upsertRows(query);
+verifyQueryLevelMetricsLogging(query, rs);
 
 // run UPSERT SELECT to verify mutation metrics are logged
 String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " 
+ tableName1;
@@ -164,13 +167,61 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 mutationReadMetricsMap.size() == 0);
 }
 
+/**
+ * This test is added to verify if metrics are being logged in case
+ * auto commit is set to true.
+ */
+@Test
+public void testPhoenixMetricsLoggedOnAutoCommitTrue() throws Exception {
+loggedConn.setAutoCommit(true);
+
+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);
+
+assertTrue("Mutation write metrics are not logged for " + tableName2,
+mutationWriteMetricsMap.get(tableName2).size()  > 0);
+assertTrue("Mutation read metrics are not found for " + tableName1,
+mutationReadMetricsMap.get(tableName1).size() > 0);
+
+clearAllTestMetricMaps();
+
+loggedConn.createStatement().execute(query);
+assertTrue("Read metrics found for " + tableName1,
+mutationReadMetricsMap.size() == 0);
+loggedConn.createStatement().execute(upsertSelect);
+
+assertTrue("Mutation write metrics are not logged for " + tableName2
++ " in 
createStatement",mutationWriteMetricsMap.get(tableName2).size()  > 0);
+assertTrue("Mutation read metrics are not found for " + tableName1
++ " in 
createStatement",mutationReadMetricsMap.get(tableName1).size() > 0);
+
+clearAllTestMetricMaps();
+
+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);
+assertTrue("Mutation read metrics are not found for " + tableName1
++ " in 
prepareStatement",mutationReadMetricsMap.get(tableName1).size() > 0);
+
+
+}
+
 private ResultSet executeAndGetResultSet(String query) throws Exception {
 Statement stmt = loggedConn.createStatement();
 stmt.execute(query);
 return stmt.getResultSet();
 }
 
-private void verifyQueryLevelMetricsLogging(String query) throws 
SQLException {
+private ResultSet upsertRows(String query) throws SQLException 

[phoenix] 12/34: PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is set to True.

2019-04-19 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 4f7065ae2ed8dac4245dcbe0652b08c2f2c33d84
Author: s.kadam 
AuthorDate: Wed Sep 5 17:00:03 2018 -0700

PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is 
set to True.
---
 .../monitoring/PhoenixLoggingMetricsIT.java| 61 --
 .../phoenix/jdbc/LoggingPhoenixConnection.java | 37 +++--
 .../jdbc/LoggingPhoenixPreparedStatement.java  | 25 +++--
 .../phoenix/jdbc/LoggingPhoenixStatement.java  | 28 --
 4 files changed, 125 insertions(+), 26 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
index 5d5524c..483d341 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixLoggingMetricsIT.java
@@ -102,7 +102,8 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 public void testPhoenixMetricsLoggedOnCommit() throws Exception {
 // run SELECT to verify read metrics are logged
 String query = "SELECT * FROM " + tableName1;
-verifyQueryLevelMetricsLogging(query);
+ResultSet rs = upsertRows(query);
+verifyQueryLevelMetricsLogging(query, rs);
 
 // run UPSERT SELECT to verify mutation metrics are logged
 String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " 
+ tableName1;
@@ -140,7 +141,9 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 public void testPhoenixMetricsLoggedOnClose() throws Exception {
 // run SELECT to verify read metrics are logged
 String query = "SELECT * FROM " + tableName1;
-verifyQueryLevelMetricsLogging(query);
+
+ResultSet rs = upsertRows(query);
+verifyQueryLevelMetricsLogging(query, rs);
 
 // run UPSERT SELECT to verify mutation metrics are logged
 String upsertSelect = "UPSERT INTO " + tableName2 + " SELECT * FROM " 
+ tableName1;
@@ -164,13 +167,61 @@ public class PhoenixLoggingMetricsIT extends 
BasePhoenixMetricsIT {
 mutationReadMetricsMap.size() == 0);
 }
 
+/**
+ * This test is added to verify if metrics are being logged in case
+ * auto commit is set to true.
+ */
+@Test
+public void testPhoenixMetricsLoggedOnAutoCommitTrue() throws Exception {
+loggedConn.setAutoCommit(true);
+
+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);
+
+assertTrue("Mutation write metrics are not logged for " + tableName2,
+mutationWriteMetricsMap.get(tableName2).size()  > 0);
+assertTrue("Mutation read metrics are not found for " + tableName1,
+mutationReadMetricsMap.get(tableName1).size() > 0);
+
+clearAllTestMetricMaps();
+
+loggedConn.createStatement().execute(query);
+assertTrue("Read metrics found for " + tableName1,
+mutationReadMetricsMap.size() == 0);
+loggedConn.createStatement().execute(upsertSelect);
+
+assertTrue("Mutation write metrics are not logged for " + tableName2
++ " in 
createStatement",mutationWriteMetricsMap.get(tableName2).size()  > 0);
+assertTrue("Mutation read metrics are not found for " + tableName1
++ " in 
createStatement",mutationReadMetricsMap.get(tableName1).size() > 0);
+
+clearAllTestMetricMaps();
+
+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);
+assertTrue("Mutation read metrics are not found for " + tableName1
++ " in 
prepareStatement",mutationReadMetricsMap.get(tableName1).size() > 0);
+
+
+}
+
 private ResultSet executeAndGetResultSet(String query) throws Exception {
 Statement stmt = loggedConn.createStatement();
 stmt.execute(query);
 return stmt.getResultSet();
 }
 
-private void verifyQueryLevelMetricsLogging(String query) throws 
SQLException {
+private ResultSet upsertRows(String query) throws SQLException