summaryrefslogtreecommitdiffstats
path: root/feature-test-transaction
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-09-25 21:49:31 -0500
committerJorge Hernandez <jh1730@att.com>2017-09-25 22:15:54 -0500
commit0360eed8a9ed1a6f83f88971fc4fc5ab2e9a81b2 (patch)
tree94643743ca86428918fd10ab6e6a7ccf749a8bd1 /feature-test-transaction
parente66b47fd3bef54a055b081e6d8be86ebda3505c2 (diff)
junits fixes
I found multiple issues from latest junit submissions when I built in my local that I tried to fix. 1. feature-test-transaction - prone to race conditions as we have experienced in some jenkins builds. There is an assert that checks if the thread is alive that monitors a policy controller kiesession sanity. The thread is very short-lived as it will exit right away since it detects that the underlying "drools session" does not have an attached rules artifact (brainless). Removed that check to fix the race condition. 2. With the increment of junits in the PolicyEngine.manager for multiple packages, it seems that the static instance is reused across junits (which surprised me), so configuration files that are not supposed to be read in junits for a package are read, and for example the lock state could propagate across junits. I tried to clean all that up to make sure that each junit deals with what is has created and state does not propagate to other junits. 3. feature-active-standy-management had a missing "junit" dependency. I generated the effective pom, and indeed did not show, some junits failed to compile in the test phase. Adding the test dependency fixed the problem. As a note, the feature-active-standy-management junits, take over 20 minutes to run. This time is excessive (see below): logs$ head -1 debug.log 2017-09-25 21:24:21.630 [main] DEBUG o.o.p.d.c.t.StandbyStateManagementTest.setUpClass(111) - setUpClass: userDir=/media/sf_jh1730/dev/open/LF/git/master/policy/drools-pdp/feature-active-standby-management logs$ tail -1 debug.log 2017-09-25 21:46:29.801 [Timer-46] DEBUG o.o.p.d.a.DroolsPdpsElectionHandler.run(919) - TimerUpdateClass.run.exit Change-Id: Ie3167e5f784f35f98fa08997e624c51f976b6501 Issue-ID: POLICY-109 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'feature-test-transaction')
-rw-r--r--feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java10
-rw-r--r--feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java24
2 files changed, 17 insertions, 17 deletions
diff --git a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java
index e5cff243..a23f2a46 100644
--- a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java
+++ b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java
@@ -42,8 +42,18 @@ public interface TestTransaction {
public static final TestTransaction manager = new TTImpl();
+ /**
+ * register a controller for monitoring test transactions
+ *
+ * @param controller policy controller
+ */
public void register(PolicyController controller);
+ /**
+ * unregisters a controller for monitoring test transactions
+ *
+ * @param controller policy controller
+ */
public void unregister(PolicyController controller);
}
diff --git a/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java b/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java
index 6c60c5ac..5dd630e1 100644
--- a/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java
+++ b/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java
@@ -74,37 +74,25 @@ public class TestTransactionTest {
}
@Test
- public void registerUnregisterTest() {
+ public void registerUnregisterTest() throws InterruptedException {
final Properties controllerProperties = new Properties();
controllerProperties.put(PolicyProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
final PolicyController controller =
PolicyEngine.manager.createPolicyController(TEST_CONTROLLER_NAME, controllerProperties);
+ assertNotNull(PolicyController.factory.get(TEST_CONTROLLER_NAME));
+ logger.info(controller.toString());
+
Thread ttThread = null;
TestTransaction.manager.register(controller);
assertNotNull(TestTransaction.manager);
/*
- * If the controller was successfully registered it will have a thread created.
- */
- ttThread = this.getThread("tt-controller-task-" + TEST_CONTROLLER_NAME);
- assertNotNull(ttThread);
-
- /*
* Unregistering the controller should terminate its TestTransaction thread if it hasn't already
* been terminated
*/
TestTransaction.manager.unregister(controller);
- /*
- * Put this thread to sleep so the TestTransaction thread has enough time to terminate before we
- * check.
- */
- try {
- Thread.sleep(2000);
- } catch (final InterruptedException e) {
-
- }
ttThread = this.getThread("tt-controller-task-" + TEST_CONTROLLER_NAME);
assertEquals(null, ttThread);
@@ -114,7 +102,9 @@ public class TestTransactionTest {
/*
* Returns thread object based on String name
*/
- public Thread getThread(String threadName) {
+ public Thread getThread(String threadName) throws InterruptedException {
+ // give a chance to the transaction thread to be spawned/destroyed
+ Thread.sleep(5000L);
final Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (final Thread thread : threadSet) {