virajjasani commented on code in PR #2426:
URL: https://github.com/apache/phoenix/pull/2426#discussion_r3149597946


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCDefinitionIT.java:
##########
@@ -478,4 +492,74 @@ public void testSelectCDCBadIncludeSpec() throws Exception 
{
       assertTrue(e.getMessage().endsWith("DUMMY"));
     }
   }
+
+  /**
+   * Verifies that UPDATE_CACHE_FREQUENCY supplied to CREATE CDC is persisted 
on the CDC virtual
+   * table in SYSTEM.CATALOG, and that subsequent SELECTs against the CDC 
object do not issue a
+   * getTable RPC for it once the client cache is warm.
+   */
+  @Test
+  public void testCreateCDCWithUpdateCacheFrequency() throws Exception {
+    final long ucfMillis = 300000L;
+    String dataTableName = generateUniqueName();
+    String parentName = dataTableName;
+    String cdcName = generateUniqueName();
+    String fullCdcName = SchemaUtil.getTableName(null, cdcName);
+
+    try (Connection conn = newConnection()) {
+      conn.createStatement().execute("CREATE TABLE " + dataTableName
+        + " (k INTEGER PRIMARY KEY, v INTEGER) " + "UPDATE_CACHE_FREQUENCY=" + 
ucfMillis);
+      if (forView) {
+        String viewName = generateUniqueName();
+        conn.createStatement()
+          .execute("CREATE VIEW " + viewName + " AS SELECT * FROM " + 
dataTableName);
+        parentName = viewName;
+      }
+      createCDC(conn,
+        "CREATE CDC " + cdcName + " ON " + parentName + " 
UPDATE_CACHE_FREQUENCY=" + ucfMillis);
+
+      // Drive at least one row through CDC so cache state is non-trivial. 
Always upsert into
+      // the underlying data table so this works for read-only views too.
+      conn.createStatement().execute("UPSERT INTO " + dataTableName + " VALUES 
(1, 1)");
+      conn.commit();
+
+      // UPDATE_CACHE_FREQUENCY must be persisted on the CDC virtual table row.
+      try (ResultSet rs = conn.createStatement()
+        .executeQuery("SELECT UPDATE_CACHE_FREQUENCY FROM SYSTEM.CATALOG WHERE 
TABLE_NAME = '"
+          + cdcName + "' AND COLUMN_NAME IS NULL AND COLUMN_FAMILY IS NULL")) {
+        assertTrue("CDC row not found in SYSTEM.CATALOG for " + cdcName, 
rs.next());
+        assertEquals("CREATE CDC ... UPDATE_CACHE_FREQUENCY was not persisted 
on the CDC table",
+          ucfMillis, rs.getLong(1));
+      }
+    }
+
+    // with UCF set, repeated SELECTs against the CDC object should not RPC 
for it.
+    ConnectionQueryServices spied =
+      spy(driver.getConnectionQueryServices(getUrl(), 
PropertiesUtil.deepCopy(TEST_PROPERTIES)));
+    Properties cprops = new Properties();
+    cprops.putAll(PhoenixEmbeddedDriver.DEFAULT_PROPS.asMap());
+    String selectSql = "SELECT /*+ CDC_INCLUDE(PRE, POST) */ * FROM " + 
fullCdcName + " LIMIT 1";
+
+    try (Connection conn = spied.connect(getUrl(), cprops)) {
+      // Warm the client metadata cache.
+      try (PreparedStatement ps = conn.prepareStatement(selectSql);
+        ResultSet rs = ps.executeQuery()) {
+        while (rs.next()) {
+        }
+      }
+      reset(spied);
+
+      // Second query - everything should be served from the client metadata 
cache.
+      try (PreparedStatement ps = conn.prepareStatement(selectSql);
+        ResultSet rs = ps.executeQuery()) {
+        while (rs.next()) {
+        }
+      }
+
+      String cdcSchema = SchemaUtil.getSchemaNameFromFullName(fullCdcName);
+      String cdcTableNameOnly = 
SchemaUtil.getTableNameFromFullName(fullCdcName);
+      verify(spied, times(0)).getTable((PName) any(), 
eq(PVarchar.INSTANCE.toBytes(cdcSchema)),
+        eq(PVarchar.INSTANCE.toBytes(cdcTableNameOnly)), anyLong(), anyLong());

Review Comment:
   How about we also verify getTable() is called once if `CREATE CDC` does not 
contain UCF?



-- 
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]

Reply via email to