tkhurana commented on code in PR #2026:
URL: https://github.com/apache/phoenix/pull/2026#discussion_r1862733543
##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java:
##########
@@ -443,4 +445,108 @@ public void testOrphanViewDetection() throws Exception {
}
}
+ /**
+ * Test {@link ViewUtil#getViewIndexIds(PhoenixConnection, String,
boolean)} for a table which is not view index and ensure it throws {@link
IllegalArgumentException}
+ * @throws IOException
+ * @throws SQLException
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void testGetViewIndexIdsForNonViewIndexTable() throws IOException,
SQLException {
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ ViewUtil.getViewIndexIds(conn.unwrap(PhoenixConnection.class),
"TEST_TABLE", true);
+ }
+ }
+
+ /**
+ * Test {@link ViewUtil#getViewIndexIds(PhoenixConnection, String,
boolean)} for a table with non-null schema
+ * @throws SQLException
+ * @throws IOException
+ */
+ @Test
+ public void testGetViewIndexIdsWithSchema() throws SQLException,
IOException {
+ testGetViewIndexIds(true);
+ }
+
+ /**
+ * Test {@link ViewUtil#getViewIndexIds(PhoenixConnection, String,
boolean)} for a table without schema
+ * @throws SQLException
+ * @throws IOException
+ */
+ @Test
+ public void testGetViewIndexIdsWithoutSchema() throws SQLException,
IOException {
+ testGetViewIndexIds(false);
+ }
+
+ /**
+ * Helper method to test {@link
ViewUtil#getViewIndexIds(PhoenixConnection, String, boolean)} method
+ * 1. Create a multi-tenant table
+ * 2. Create 2 global views (globalViewName1 & globalViewName2) and 5
global view indexes (2 on globalViewName1 & 3 on globalViewName2)
+ * 3. Create 2 tenant views (tenantViewName1 & tenantViewName2) and 3
tenant view indexes (1 on tenantViewName1 & 2 on tenantViewName2)
+ * 4. Get view index ids EXCLUDING tenant view indexes and ensure the
count is 5 (5 global view indexes)
+ * 5. Get view index ids INCLUDING tenant view indexes and ensure the
count is 8 (5 global view index + 3 tenant view indexes)
+ * @param includeSchema - if schema needs to be added while creating the
table
+ * @throws IOException
+ * @throws SQLException
+ */
+ private void testGetViewIndexIds(boolean includeSchema) throws
IOException, SQLException {
+ final String schemaPrefix = (includeSchema ? (generateUniqueName() +
".") : "");
+ final String tableName = schemaPrefix + generateUniqueName();
+ final String globalViewName1 = schemaPrefix + generateUniqueName();
+ final String globalViewName2 = schemaPrefix + generateUniqueName();
Review Comment:
`SchemaUtil#getTableName` API is generally used. It works with null schema
name.
--
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]