summaryrefslogtreecommitdiffstats
path: root/policy-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'policy-core/src')
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java12
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java10
2 files changed, 21 insertions, 1 deletions
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
index 49ff7bb8..389d5b37 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
@@ -190,6 +190,16 @@ public class PolicySession
}
/**
+ * Unset this 'PolicySession' instance as the one associated with the
+ * currently-running thread.
+ */
+ public void removePolicySession() {
+ if (policySess.get() == this) {
+ policySess.remove();
+ }
+ }
+
+ /**
* Get current session.
*
* @return the 'PolicySession' instance associated with the current thread
@@ -498,6 +508,8 @@ public class PolicySession
logger.error("startThread error in kieSession1.fireUntilHalt", e);
}
}
+
+ session.removePolicySession();
logger.info("fireUntilHalt() returned");
}
}
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java
index 63c71608..3b882195 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java
@@ -102,7 +102,7 @@ public class PolicySessionTest {
}
@Test
- public void testSetPolicySession_testGetCurrentSession() {
+ public void testSetPolicySession_testGetCurrentSession_testRemovePolicySession() {
PolicySession sess2 = new PolicySession(MY_NAME + "-b", container, kie);
session.setPolicySession();
@@ -110,6 +110,14 @@ public class PolicySessionTest {
sess2.setPolicySession();
assertEquals(sess2, PolicySession.getCurrentSession());
+
+ // remove a different session - should be unchanged
+ session.removePolicySession();
+ assertEquals(sess2, PolicySession.getCurrentSession());
+
+ // remove the session
+ sess2.removePolicySession();
+ assertNull(PolicySession.getCurrentSession());
}
@Test