xtern commented on code in PR #2982:
URL: https://github.com/apache/ignite-3/pull/2982#discussion_r1445714590


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/mapping/MappingServiceImplTest.java:
##########
@@ -134,6 +164,66 @@ public void lateServiceInitializationOnNodeJoin() {
         assertThat(mappingService.map(PLAN), willSucceedFast());
     }
 
+    @Test
+    public void testCacheInvalidationOnTopologyChange() {
+        String localNodeName = "NODE";
+        List<String> nodeNames = List.of(localNodeName, "NODE1");
+
+        // Initialize mapping service.
+        MappingServiceImpl mappingService = 
createMappingService(localNodeName, nodeNames);
+        mappingService.onNodeJoined(Mockito.mock(LogicalNode.class),
+                new LogicalTopologySnapshot(1, 
logicalNodes(nodeNames.toArray(new String[0]))));
+
+        List<MappedFragment> tableOnlyMapping = 
await(mappingService.map(PLAN));
+        List<MappedFragment> sysViewMapping = 
await(mappingService.map(PLAN_WITH_SYSTEM_VIEW));
+
+        assertSame(tableOnlyMapping, await(mappingService.map(PLAN)));
+        assertSame(sysViewMapping, 
await(mappingService.map(PLAN_WITH_SYSTEM_VIEW)));
+
+        mappingService.onNodeLeft(Mockito.mock(LogicalNode.class),
+                new LogicalTopologySnapshot(2, logicalNodes("NODE")));
+        // Plan with tables only must not be invalidated.
+        assertSame(tableOnlyMapping, await(mappingService.map(PLAN)));
+        // Plan with system views must be invalidated.
+        assertNotSame(sysViewMapping, 
await(mappingService.map(PLAN_WITH_SYSTEM_VIEW)));
+    }
+
+    @Test
+    public void testCacheInvalidationOnPrimaryExpiration() {
+        String localNodeName = "NODE";
+        List<String> nodeNames = List.of(localNodeName, "NODE1");
+
+        Function<String, PrimaryReplicaEventParameters> prepareEvtParams = 
(name) -> {
+            CatalogService catalogService = 
cluster.node("N1").catalogService();
+            Catalog catalog = 
catalogService.catalog(catalogService.latestCatalogVersion());
+
+            Optional<Integer> tblId = catalog.tables().stream()
+                    .filter(desc -> name.equals(desc.name()))
+                    .findFirst()
+                    .map(CatalogObjectDescriptor::id);
+
+            assertTrue(tblId.isPresent());
+
+            return new PrimaryReplicaEventParameters(
+                    0, new TablePartitionId(tblId.get(), 0), "test", 
HybridTimestamp.MIN_VALUE);
+        };
+
+        // Initialize mapping service.
+        MappingServiceImpl mappingService = 
createMappingService(localNodeName, nodeNames);
+        mappingService.onNodeJoined(Mockito.mock(LogicalNode.class),
+                new LogicalTopologySnapshot(1, 
logicalNodes(nodeNames.toArray(new String[0]))));
+
+        List<MappedFragment> mappedFragments = 
await(mappingService.map(PLAN_WITH_SYSTEM_VIEW));
+
+        // Simulate expiration of the primary replica for non-mapped table - 
the cache entry should not be invalidated.
+        
await(mappingService.onPrimaryReplicaExpired(prepareEvtParams.apply("T2")));
+        assertSame(mappedFragments, 
await(mappingService.map(PLAN_WITH_SYSTEM_VIEW)));
+
+        // Simulate expiration of the primary replica for mapped table - the 
cache entry should be invalidated.
+        
await(mappingService.onPrimaryReplicaExpired(prepareEvtParams.apply("T1")));
+        assertNotSame(mappedFragments, 
await(mappingService.map(PLAN_WITH_SYSTEM_VIEW)));
+    }
+

Review Comment:
   Thanks, added additional checks to verify `ExecutionTargetProvider` calls.



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