mariofusco commented on code in PR #7318:
URL: https://github.com/apache/incubator-kie/pull/7318#discussion_r4717435114


##########
drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/session/SessionsPoolTest.java:
##########
@@ -493,4 +496,113 @@ public void testListenersReset(KieBaseTestConfiguration 
kieBaseTestConfiguration
             ksession.dispose();
         }
     }
+
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void 
testPooledSessionDoesNotRetainTuplesAfterRightDeleteOnExists(KieBaseTestConfiguration
 kieBaseTestConfiguration) throws InterruptedException {
+        String drl =
+                "rule R1 when\n" +
+                "  $s : String()\n" +
+                "  exists Number( intValue == $s.length() )\n" +
+                "then\n" +
+                "end\n";
+
+        final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", 
kieBaseTestConfiguration, drl);
+        final KieContainerSessionsPool pool = 
KieServices.get().newKieContainer(kieModule.getReleaseId()).newKieSessionsPool( 
1 );
+
+        try {
+            WeakReference<Object> leftFact = useAndReleasePooledSession(pool, 
(ksession, blocker) -> ksession.delete(blocker));
+
+            for (int i = 0; i < 20 && leftFact.get() != null; i++) {
+                System.gc();
+                Thread.sleep(50);
+            }
+
+            assertThat(leftFact.get())
+                    .as("a session returned to the pool must not keep the left 
tuple (and its fact) reachable through a BetaMemory context")
+                    .isNull();
+        } finally {
+            pool.shutdown();
+        }
+    }
+
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void 
testPooledSessionDoesNotRetainTuplesAfterRightUpdateOnExists(KieBaseTestConfiguration
 kieBaseTestConfiguration) throws InterruptedException {
+        String drl =
+                "rule R1 when\n" +
+                "  $s : String()\n" +
+                "  exists Number( intValue == $s.length() )\n" +
+                "then\n" +
+                "end\n";
+
+        final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", 
kieBaseTestConfiguration, drl);
+        final KieContainerSessionsPool pool = 
KieServices.get().newKieContainer(kieModule.getReleaseId()).newKieSessionsPool( 
1 );
+
+        try {
+            WeakReference<Object> leftFact = useAndReleasePooledSession(pool, 
(ksession, blocker) -> ksession.update(blocker, ksession.getObject(blocker)));
+
+            for (int i = 0; i < 20 && leftFact.get() != null; i++) {
+                System.gc();
+                Thread.sleep(50);

Review Comment:
   This looks brittle, why is this `sleep` necessary?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to