diff options
author | Magnusen, Drew (dm741q) <dm741q@att.com> | 2017-11-29 14:01:06 -0600 |
---|---|---|
committer | Magnusen, Drew (dm741q) <dm741q@att.com> | 2017-11-30 09:06:16 -0600 |
commit | f2c75918e425d62d0332da4685cae3518a50d4bb (patch) | |
tree | e733b7210f466f5df700c6285a13454b780ff04a /feature-test-transaction/src/main/java/org/onap | |
parent | ea23f6a4ae6ea590e18c0bce18c2a7a4fecf968a (diff) |
Refactored code to reduce technical debt.
Major changes in this commit include the refactoring of the run method in
TestTransaction.java to reduce the amount of technical debt identified by
sonar. Other small changes were also made.
Issue-ID: POLICY-467
Change-Id: I2522f690de58e3c6f4cc894e6dea47277404d745
Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
Diffstat (limited to 'feature-test-transaction/src/main/java/org/onap')
2 files changed, 40 insertions, 33 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 a23f2a46..5e209faa 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 @@ -64,7 +64,7 @@ public interface TestTransaction { */ class TTImpl implements TestTransaction { - final protected Map<String, TTControllerTask> controllers = new HashMap<>(); + protected final Map<String, TTControllerTask> controllers = new HashMap<>(); @Override public synchronized void register(PolicyController controller) { @@ -158,34 +158,7 @@ class TTControllerTask implements Runnable { while (this.controller.isAlive() && !this.controller.isLocked() && drools.isBrained() && this.alive) { - for (final String session : sessions) { - final List<Object> facts = this.controller.getDrools().factQuery(session, - TestTransaction.TT_FPC, TestTransaction.TT_COUNTER, false); - if (facts == null || facts.size() != 1) { - /* - * unexpected something wrong here, can't expect to recover note this exception is - * caught right below at the exit of run() - */ - logger.error( - "Controller: {}, with rules artifact: (group) {}, (artifact) {}, (version) {} - FPC query failed after EventObject insertion! ", - this.controller.getName(), this.controller.getDrools().getGroupId(), - this.controller.getDrools().getArtifactId(), - this.controller.getDrools().getVersion()); - break; - } - logger.debug("Facts: {}", facts); - - final long fpc = (Long) facts.get(0); - if (fpc != fpcs.get(session)) - logger.info("Controller: {} , session {} - Forward progress successful: {} -> {}", - this.controller.getName(), session, fpcs.get(session), fpc); - else - logger.error("Controller: {}, session {} - Forward progress failure: {}", - this.controller.getName(), session, fpc); - - fpcs.put(session, fpc); - drools.getContainer().insert(session, new EventObject(TestTransaction.TT_UUID)); - } + injectTxIntoSessions(sessions, fpcs, drools); if (!this.alive) return; @@ -208,7 +181,41 @@ class TTControllerTask implements Runnable { this.alive = false; } } + + private void injectTxIntoSessions(List<String> sessions, HashMap<String, Long> fpcs, DroolsController drools) { + for (final String session : sessions) { + final List<Object> facts = this.controller.getDrools().factQuery(session, + TestTransaction.TT_FPC, TestTransaction.TT_COUNTER, false); + if (facts == null || facts.size() != 1) { + /* + * unexpected something wrong here, can't expect to recover note this exception is + * caught right below at the exit of run() + */ + logger.error( + "Controller: {}, with rules artifact: (group) {}, (artifact) {}, (version) {} - FPC query failed after EventObject insertion! ", + this.controller.getName(), this.controller.getDrools().getGroupId(), + this.controller.getDrools().getArtifactId(), + this.controller.getDrools().getVersion()); + break; + } + logger.debug("Facts: {}", facts); + + final long fpc = (Long) facts.get(0); + if (fpc != fpcs.get(session)) + logger.info("Controller: {} , session {} - Forward progress successful: {} -> {}", + this.controller.getName(), session, fpcs.get(session), fpc); + else + logger.error("Controller: {}, session {} - Forward progress failure: {}", + this.controller.getName(), session, fpc); + + fpcs.put(session, fpc); + drools.getContainer().insert(session, new EventObject(TestTransaction.TT_UUID)); + } + + } + + @Override public String toString() { final StringBuilder builder = new StringBuilder(); diff --git a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java index 72c54969..e78668ab 100644 --- a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java +++ b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java @@ -33,7 +33,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { // get an instance of logger private static final Logger logger = LoggerFactory.getLogger(TestTransactionFeature.class); - + @Override public boolean afterStart(PolicyController controller){ @@ -49,7 +49,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean afterLock(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " LOCKED"); + logger.info("controller {} locked", controller.getName()); TestTransaction.manager.unregister(controller); return false; @@ -57,7 +57,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean afterUnlock(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " UNLOCKED"); + logger.info("controller {} unlocked", controller.getName()); if (controller.isAlive() && !controller.isLocked() && @@ -69,7 +69,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean beforeStop(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " ABOUT TO STOP"); + logger.info("controller {} stopping", controller.getName()); TestTransaction.manager.unregister(controller); |