virajjasani commented on a change in pull request #1261:
URL: https://github.com/apache/phoenix/pull/1261#discussion_r671419973
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
##########
@@ -670,5 +669,144 @@ public void testColumnQualifierForUpsertedValues() throws
Exception {
assertTrue(next.containsColumn(Bytes.toBytes("CF2"),
PInteger.INSTANCE.toBytes(3)));
}
}
-
+
+ @Test
+ public void testUpsertValueWithDiffSequenceAndConnections() throws
Exception {
+ String tableName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.setAutoCommit(true);
+ PreparedStatement createTableStatement =
conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS " +
+ "%s (SERVICE VARCHAR NOT NULL, SEQUENCE_NUMBER BIGINT NOT
NULL , " +
+ "CONSTRAINT PK PRIMARY KEY (SERVICE, SEQUENCE_NUMBER))
MULTI_TENANT = TRUE", tableName));
+ createTableStatement.execute();
+ }
+
+ testGlobalSequenceUpsertWithTenantConnection(tableName);
+ testGlobalSequenceUpsertWithGlobalConnection(tableName);
+ testTenantSequenceUpsertWithSameTenantConnection(tableName);
+ testTenantSequenceUpsertWithDifferentTenantConnection(tableName);
+ testTenantSequenceUpsertWithGlobalConnection(tableName);
+
+ }
+
+ private void testTenantSequenceUpsertWithGlobalConnection(String
tableName) throws Exception {
+ String sequenceName = generateUniqueSequenceName();
+
+ try (Connection conn = getTenantConnection("PHOENIX")) {
+ conn.setAutoCommit(true);
+ PreparedStatement createSequenceStatement =
conn.prepareStatement(String.format("CREATE SEQUENCE " +
+ "IF NOT EXISTS %s", sequenceName));
+ createSequenceStatement.execute();
+ }
+
+ try (Connection tenantConn = DriverManager.getConnection(getUrl())) {
+ tenantConn.setAutoCommit(true);
+ Statement executeUpdateStatement = tenantConn.createStatement();
+ try {
+ executeUpdateStatement.execute(String.format("UPSERT INTO %s (
SERVICE, SEQUENCE_NUMBER) VALUES " +
+ "( 'PHOENIX', NEXT VALUE FOR %s)", tableName,
sequenceName));
+ } catch (SequenceNotFoundException e) {
+ assertTrue(true);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+ }
+
+ private void testTenantSequenceUpsertWithDifferentTenantConnection(String
tableName) throws Exception {
+ String sequenceName = generateUniqueSequenceName();
+
+ try (Connection conn = getTenantConnection("PHOENIX")) {
+ conn.setAutoCommit(true);
+ PreparedStatement createSequenceStatement =
conn.prepareStatement(String.format("CREATE SEQUENCE " +
+ "IF NOT EXISTS %s", sequenceName));
+ createSequenceStatement.execute();
+ }
+
+ try (Connection tenantConn = getTenantConnection("HBASE")) {
+ tenantConn.setAutoCommit(true);
+
+ Statement executeUpdateStatement = tenantConn.createStatement();
+ try {
+ executeUpdateStatement.execute(String.format("UPSERT INTO %s (
SEQUENCE_NUMBER) VALUES " +
+ "( NEXT VALUE FOR %s)", tableName, sequenceName));
Review comment:
same as above, good to add `fail()` here
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
##########
@@ -670,5 +669,144 @@ public void testColumnQualifierForUpsertedValues() throws
Exception {
assertTrue(next.containsColumn(Bytes.toBytes("CF2"),
PInteger.INSTANCE.toBytes(3)));
}
}
-
+
+ @Test
+ public void testUpsertValueWithDiffSequenceAndConnections() throws
Exception {
+ String tableName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.setAutoCommit(true);
+ PreparedStatement createTableStatement =
conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS " +
+ "%s (SERVICE VARCHAR NOT NULL, SEQUENCE_NUMBER BIGINT NOT
NULL , " +
+ "CONSTRAINT PK PRIMARY KEY (SERVICE, SEQUENCE_NUMBER))
MULTI_TENANT = TRUE", tableName));
+ createTableStatement.execute();
+ }
+
+ testGlobalSequenceUpsertWithTenantConnection(tableName);
+ testGlobalSequenceUpsertWithGlobalConnection(tableName);
+ testTenantSequenceUpsertWithSameTenantConnection(tableName);
+ testTenantSequenceUpsertWithDifferentTenantConnection(tableName);
+ testTenantSequenceUpsertWithGlobalConnection(tableName);
+
+ }
+
+ private void testTenantSequenceUpsertWithGlobalConnection(String
tableName) throws Exception {
+ String sequenceName = generateUniqueSequenceName();
+
+ try (Connection conn = getTenantConnection("PHOENIX")) {
+ conn.setAutoCommit(true);
+ PreparedStatement createSequenceStatement =
conn.prepareStatement(String.format("CREATE SEQUENCE " +
+ "IF NOT EXISTS %s", sequenceName));
+ createSequenceStatement.execute();
+ }
+
+ try (Connection tenantConn = DriverManager.getConnection(getUrl())) {
+ tenantConn.setAutoCommit(true);
+ Statement executeUpdateStatement = tenantConn.createStatement();
+ try {
+ executeUpdateStatement.execute(String.format("UPSERT INTO %s (
SERVICE, SEQUENCE_NUMBER) VALUES " +
+ "( 'PHOENIX', NEXT VALUE FOR %s)", tableName,
sequenceName));
Review comment:
Adding `fail()` here would mean we will make sure above Upsert never
succeeds.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]