zstan commented on code in PR #12452:
URL: https://github.com/apache/ignite/pull/12452#discussion_r3145054033


##########
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/ComplexPrimaryKeyUnwrapSelfTest.java:
##########
@@ -152,75 +257,173 @@ public void testSimplePkWithAffinityKey() {
      */
     @Test
     public void testWrappedPk() {
+        checkWrappedPk(false);
+    }
+
+    /**
+     * Test using PK indexes for wrapped primary key on existsing cache.
+     */
+    @Test
+    public void testWrappedPkExistingCache() {
+        checkWrappedPk(true);
+    }
+
+    /** */
+    private void checkWrappedPk(boolean existingCache) {
         String tblName = createTableName();
 
+        if (existingCache)
+            node().createCache(tblName);
+
         executeSql("CREATE TABLE " + tblName + " (id int, name varchar, age 
int, company varchar, city varchar, " +
-            "primary key (id)) WITH \"wrap_key=true\"");
+            "primary key (id)) WITH \"wrap_key=true" +
+            (existingCache ? ",CACHE_NAME=" + tblName : "") + "\"");
 
-        checkUsingIndexes(tblName, "1", 1);
+        // For the new cache unwrapped key field is used as affinity key, but 
for the existing cache
+        // affinity key can't be changed, so we can't prune partitions for 
query on ID field.
+        checkUsingIndexes(tblName, "1", existingCache ? 2 : 1);
     }
 
     /**
      * Test single column PK without wrapping calculate correct inline size.
      */
     @Test
     public void testInlineSizeNoWrap() {
-        executeSql("DROP TABLE IF EXISTS TABLE1");
-        executeSql("CREATE TABLE IF NOT EXISTS TABLE1 ( " +
+        checkInlineSizeNoWrap(false);
+    }
+
+    /**
+     * Test single column PK without wrapping calculate correct inline size on 
existing cache.
+     */
+    @Test
+    public void testInlineSizeNoWrapExistingCache() {
+        checkInlineSizeNoWrap(true);
+    }
+
+    /** */
+    private void checkInlineSizeNoWrap(boolean existingCache) {
+        String tblName = createTableName();
+
+        if (existingCache)
+            node().createCache(tblName);
+
+        executeSql("CREATE TABLE IF NOT EXISTS " + tblName + "( " +
             "  id varchar(15), " +
             "  col varchar(100), " +
-            "  PRIMARY KEY(id) ) ");
-        assertEquals(18, executeSql(
-            "select INLINE_SIZE from SYS.INDEXES where TABLE_NAME = 'TABLE1' 
and IS_PK = true").get(0).get(0));
+            "  PRIMARY KEY(id) ) " +
+            (existingCache ? "WITH \"CACHE_NAME=" + tblName + "\"" : "")
+        );
+        assertEquals(18, pkInlineSize(tblName));
     }
 
     /**
      * Test single column PK with wrapping calculate correct inline size.
      */
     @Test
     public void testInlineSizeWrap() {
-        executeSql("DROP TABLE IF EXISTS TABLE1");
-        executeSql("CREATE TABLE IF NOT EXISTS TABLE1 ( " +
+        checkInlineSizeWrap(false);
+    }
+
+    /**
+     * Test single column PK with wrapping calculate correct inline size on 
existing cache.
+     */
+    @Test
+    public void testInlineSizeWrapExistingCache() {
+        checkInlineSizeWrap(true);
+    }
+
+    /** */
+    private void checkInlineSizeWrap(boolean existingCache) {
+        String tblName = createTableName();
+
+        if (existingCache)
+            node().createCache(tblName);
+
+        executeSql("CREATE TABLE IF NOT EXISTS " + tblName + "( " +
             "  id varchar(15), " +
             "  col varchar(100), " +
-            "  PRIMARY KEY(id) )  WITH \"wrap_key=true\"");
-        assertEquals(18, executeSql(
-            "select INLINE_SIZE from SYS.INDEXES where TABLE_NAME = 'TABLE1' 
and IS_PK = true").get(0).get(0));
+            "  PRIMARY KEY(id) )  " +
+            "  WITH \"wrap_key=true" + (existingCache ? ",CACHE_NAME=" + 
tblName : "") + "\"");
+        assertEquals(18, pkInlineSize(tblName));
     }
 
     /**
      * Test two column PK with wrapping calculate correct inline size.
      */
     @Test
     public void testInlineSizeWrap2() {
-        executeSql("DROP TABLE IF EXISTS TABLE1");
-        executeSql("CREATE TABLE IF NOT EXISTS TABLE1 ( " +
+        checkInlineSizeWrap2(false);
+    }
+
+    /**
+     * Test two column PK with wrapping calculate correct inline size on 
existing cache.
+     */
+    @Test
+    public void testInlineSizeWrap2ExistingCache() {
+        checkInlineSizeWrap2(true);
+    }
+
+    /** */
+    private void checkInlineSizeWrap2(boolean existingCache) {
+        String tblName = createTableName();
+
+        if (existingCache)
+            node().createCache(tblName);
+
+        executeSql("CREATE TABLE IF NOT EXISTS " + tblName + "( " +
             "  id varchar(15), " +
             "  id2 uuid, " +
             "  col varchar(100), " +
-            "  PRIMARY KEY(id, id2) )  WITH \"wrap_key=true\"");
-        assertEquals(35, executeSql(
-            "select INLINE_SIZE from SYS.INDEXES where TABLE_NAME = 'TABLE1' 
and IS_PK = true").get(0).get(0));
+            "  PRIMARY KEY(id, id2) ) " +
+            "  WITH \"wrap_key=true" + (existingCache ? ",CACHE_NAME=" + 
tblName : "") + "\"");
+        assertEquals(35, pkInlineSize(tblName));
+    }
+
+    /** */
+    private int pkInlineSize(String tblName) {
+        return (int)executeSql("select INLINE_SIZE from SYS.INDEXES " +
+            "where TABLE_NAME = '" + tblName + "' and IS_PK = 
true").get(0).get(0);
     }
 
     /**
      * Check using PK indexes for few cases.
      *
      * @param tblName Name of table which should be checked to using PK 
indexes.
-     * @param expResCnt Expceted result count.
+     * @param expResCnt Expected result count.
      */
     private void checkUsingIndexes(String tblName, String idVal, int 
expResCnt) {
+        checkUsingIndexes(node(), tblName, idVal, expResCnt);
+    }
+
+    /**
+     * Check using PK indexes for few cases.
+     *
+     * @param node Ignite node.
+     * @param tblName Name of table which should be checked to using PK 
indexes.
+     * @param expResCnt Expected result count.
+     */
+    private void checkUsingIndexes(IgniteEx node, String tblName, String 
idVal, int expResCnt) {
+        IgniteInternalFuture<?> rebuildFut = indexRebuildFuture(node, 
CU.cacheId(tblName));
+
+        try {
+            if (rebuildFut != null)
+                rebuildFut.get();

Review Comment:
   probably with some timeout ?



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