2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.drools.controller.test;
23 import static org.junit.Assert.assertTrue;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.util.Date;
30 import java.util.Properties;
32 import javax.persistence.EntityManager;
33 import javax.persistence.EntityManagerFactory;
34 import javax.persistence.EntityTransaction;
35 import javax.persistence.Persistence;
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.Before;
40 import org.junit.BeforeClass;
41 import org.junit.Ignore;
42 import org.junit.Test;
44 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
45 import org.openecomp.policy.common.im.AdministrativeStateException;
46 import org.openecomp.policy.common.im.IntegrityMonitor;
47 import org.openecomp.policy.common.im.StandbyStatusException;
48 import org.openecomp.policy.common.im.StateManagement;
49 import org.openecomp.policy.drools.core.DroolsPDPIntegrityMonitor;
50 import org.openecomp.policy.drools.core.IntegrityMonitorProperties;
51 import org.openecomp.policy.drools.core.PolicyContainer;
52 import org.openecomp.policy.drools.im.PMStandbyStateChangeNotifier;
53 import org.openecomp.policy.drools.persistence.DroolsPdp;
54 import org.openecomp.policy.drools.persistence.DroolsPdpEntity;
55 import org.openecomp.policy.drools.persistence.DroolsPdpImpl;
56 import org.openecomp.policy.drools.persistence.DroolsPdpsConnector;
57 import org.openecomp.policy.drools.persistence.JpaDroolsPdpsConnector;
58 import org.openecomp.policy.drools.persistence.DroolsPersistenceProperties;
59 import org.openecomp.policy.drools.persistence.XacmlPersistenceProperties;
60 import org.openecomp.policy.drools.system.Main;
61 import org.openecomp.policy.drools.system.PolicyEngine;
63 import org.apache.commons.lang3.time.DateUtils;
66 * Cloned from StandbyStateManagement.java in support of US673632.
67 * See MultiSite_v1-10.ppt, slide 38
69 public class ResiliencyTestCases {
72 * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every ten seconds, starting
73 * at ten seconds after the minute boundary (e.g. 13:05:10). So, an 80 second sleep should be
74 * sufficient to ensure that we wait for the DesignationWaiter to do its job, before
75 * checking the results.
77 long sleepTime = 80000;
80 * DroolsPdpsElectionHandler runs every ten seconds, so a 15 second sleep should be
81 * plenty to ensure it has time to re-promote this PDP.
83 long electionWaitSleepTime = 15000;
86 * Sleep 5 seconds after each test to allow interrupt (shutdown) recovery.
88 long interruptRecoveryTime = 5000;
91 * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
94 public static void setUpClass() throws Exception {
96 String userDir = System.getProperty("user.dir");
97 PolicyLogger.debug("setUpClass: userDir=" + userDir);
98 System.setProperty("com.sun.management.jmxremote.port", "9980");
99 System.setProperty("com.sun.management.jmxremote.authenticate","false");
101 // Make sure path to config directory is set correctly in PolicyContainer.main
102 // Also make sure we ignore HTTP server failures resulting from port conflicts.
103 PolicyContainer.isUnitTesting = true;
108 public static void tearDownClass() throws Exception {
112 public void setUp() throws Exception {
116 public void tearDown() throws Exception {
120 public void cleanDroolsDB() throws Exception{
121 PolicyLogger.debug("\n\ncleanDroolsDB: Entering\n\n");
123 PolicyLogger.debug("cleanDroolsDB: Reading droolsPersistenceProperties");
124 Properties droolsPersistenceProperties = new Properties();
125 droolsPersistenceProperties.load(new FileInputStream(new File(
126 "src/test/server/config/droolsPersistence.properties")));
128 PolicyLogger.debug("cleanDroolsDB: Creating emfDrools");
129 EntityManagerFactory emf = Persistence.createEntityManagerFactory(
130 "junitDroolsPU", droolsPersistenceProperties);
132 PolicyLogger.debug("cleanDroolsDB: Cleaning up tables");
134 EntityManager em = emf.createEntityManager();
135 EntityTransaction et = em.getTransaction();
138 // Make sure the DB is clean
139 PolicyLogger.debug("cleanDroolsDB: clean DroolsPdpEntity");
140 em.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
141 PolicyLogger.debug("cleanDroolsDB: clean DroolsSessionEntity");
142 em.createQuery("DELETE FROM DroolsSessionEntity").executeUpdate();
145 PolicyLogger.debug("cleanDroolsDB: after flush");
149 PolicyLogger.debug("\n\ncleanDroolsDB: Exiting\n\n");
152 public void cleanXacmlDB() throws Exception {
153 PolicyLogger.debug("\n\ncleanXacmlDB: Entering\n\n");
155 PolicyLogger.debug("cleanXacmlDB: Reading IntegrityMonitorProperties");
157 PolicyLogger.debug("cleanXacmlDB: Reading xacmlPersistenceProperties");
158 Properties xacmlPersistenceProperties = new Properties();
159 xacmlPersistenceProperties.load(new FileInputStream(new File(
160 "src/test/server/config/xacmlPersistence.properties")));
162 PolicyLogger.debug("cleanXacmlDB: Creating emf");
163 EntityManagerFactory emf = Persistence.createEntityManagerFactory(
164 "junitXacmlPU", xacmlPersistenceProperties);
166 EntityManager em = emf.createEntityManager();
167 EntityTransaction et = em.getTransaction();
170 // Make sure the DB is clean
171 PolicyLogger.debug("cleanXacmlDB: clean StateManagementEntity");
172 em.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
173 PolicyLogger.debug("cleanXacmlDB: clean ResourceRegistrationEntity");
174 em.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
175 PolicyLogger.debug("cleanXacmlDB: clean ForwardProgressEntity");
176 em.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
179 PolicyLogger.debug("cleandXacmlDB: after flush");
183 PolicyLogger.debug("\n\ncleanXacmlDB: Exiting\n\n");
189 public void singleNodeTests() throws Exception{
191 snNewInstallBadDepData();
192 /*snRecoveryFromBadDepData();
201 public void twoNodeTests() throws Exception{
204 tnUnlockColdStandby();
211 public void twoSitesTwoNodesPerSiteTests() throws Exception{
215 tstnFailActiveSite2();
216 tstnRecoverFailedSite2();
225 public void snNewInstall() throws Exception{
226 PolicyLogger.debug("\n\nsnNewInstall: Entry\n\n");
230 //*******************************************
232 PolicyLogger.debug("snNewInstall: Reading IntegrityMonitorProperties");
233 Properties integrityMonitorProperties = new Properties();
234 integrityMonitorProperties.load(new FileInputStream(new File(
235 "src/test/server/config/IntegrityMonitor.properties")));
236 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
237 String thisPdpId = IntegrityMonitorProperties
238 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
240 PolicyLogger.debug("snNewInstall: Reading xacmlPersistenceProperties");
241 Properties xacmlPersistenceProperties = new Properties();
242 xacmlPersistenceProperties.load(new FileInputStream(new File(
243 "src/test/server/config/xacmlPersistence.properties")));
244 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
246 PolicyLogger.debug("snNewInstall: Creating emfXacml");
247 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
248 "junitXacmlPU", xacmlPersistenceProperties);
250 PolicyLogger.debug("snNewInstall: Reading droolsPersistenceProperties");
251 Properties droolsPersistenceProperties = new Properties();
252 droolsPersistenceProperties.load(new FileInputStream(new File(
253 "src/test/server/config/droolsPersistence.properties")));
254 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
256 PolicyLogger.debug("snNewInstall: Creating emfDrools");
257 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
258 "junitDroolsPU", droolsPersistenceProperties);
260 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
262 PolicyLogger.debug("snNewInstall: Inserting PDP=" + thisPdpId + " as designated");
263 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
265 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
266 PolicyLogger.debug("snNewInstall: After insertion, DESIGNATED="
267 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
268 assertTrue(droolsPdpEntity.isDesignated() == true);
271 * When the Standby Status changes (from providingservice) to hotstandby
272 * or coldstandby,the Active/Standby selection algorithm must stand down
273 * if thePDP-D is currently the lead/active node and allow another PDP-D
276 * It must also call lock on all engines in the engine management.
279 PolicyLogger.debug("snNewInstall: Instantiating stateManagement object");
280 StateManagement sm = new StateManagement(emfXacml, thisPdpId);
281 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
282 sm.addObserver(pmStandbyStateChangeNotifier);
284 // Artificially putting a PDP into service is really a two step process, 1)
285 // inserting it as designated and 2) promoting it so that its standbyStatus
286 // is providing service.
288 PolicyLogger.debug("snNewInstall: Running policy-management.Main class");
289 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
290 policyManagementRunner.start();
292 PolicyLogger.debug("snNewInstall: Runner started; Sleeping "
293 + interruptRecoveryTime + "ms before promoting PDP="
295 Thread.sleep(interruptRecoveryTime);
297 PolicyLogger.debug("snNewInstall: Promoting PDP=" + thisPdpId);
300 String standbyStatus = sm.getStandbyStatus(thisPdpId);
301 PolicyLogger.debug("snNewInstall: Before locking, PDP=" + thisPdpId + " has standbyStatus="
304 PolicyLogger.debug("snNewInstall: Locking sm");
307 Thread.sleep(interruptRecoveryTime);
309 * Verify that the PDP is no longer designated.
311 droolsPdpEntity = conn.getPdp(thisPdpId);
312 PolicyLogger.debug("snNewInstall: After lock sm.lock() invoked, DESIGNATED="
313 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
314 assertTrue(droolsPdpEntity.isDesignated() == false);
316 PolicyLogger.debug("snNewInstall: Stopping policyManagementRunner");
317 policyManagementRunner.stopRunner();
319 PolicyLogger.debug("\n\nsnNewInstall: Exiting\n\n");
320 Thread.sleep(interruptRecoveryTime);
322 //********************************************
324 PolicyLogger.debug("\n\nsnNewInstall: Exit\n\n");
327 public void snNewInstallBadDepData() throws Exception{
328 PolicyLogger.debug("\n\nsnNewInstallBadDepData: Entry\n\n");
332 //*******************************************
334 PolicyLogger.debug("snNewInstallBadDepData: Reading IntegrityMonitor_BadDependencyData.properties");
335 Properties integrityMonitorProperties = new Properties();
336 integrityMonitorProperties.load(new FileInputStream(new File(
337 "src/test/server/config/IntegrityMonitor_BadDependencyData.properties")));
338 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
339 String thisPdpId = IntegrityMonitorProperties
340 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
342 PolicyLogger.debug("snNewInstallBadDepData: Reading xacmlPersistenceProperties");
343 Properties xacmlPersistenceProperties = new Properties();
344 xacmlPersistenceProperties.load(new FileInputStream(new File(
345 "src/test/server/config/xacmlPersistence.properties")));
346 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
348 PolicyLogger.debug("snNewInstallBadDepData: Creating emfXacml");
349 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
350 "junitXacmlPU", xacmlPersistenceProperties);
352 PolicyLogger.debug("snNewInstallBadDepData: Reading droolsPersistenceProperties");
353 Properties droolsPersistenceProperties = new Properties();
354 droolsPersistenceProperties.load(new FileInputStream(new File(
355 "src/test/server/config/droolsPersistence.properties")));
356 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
358 PolicyLogger.debug("snNewInstallBadDepData: Creating emfDrools");
359 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
360 "junitDroolsPU", droolsPersistenceProperties);
362 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
364 PolicyLogger.debug("snNewInstallBadDepData: Inserting PDP=" + thisPdpId + " as designated");
365 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
367 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
370 ("\n\nsnNewInstallBadDepData: After insertion, DESIGNATED="
371 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId + "\n\n********************");
372 assertTrue(droolsPdpEntity.isDesignated() == true);
375 * When the Standby Status changes (from providingservice) to hotstandby
376 * or coldstandby,the Active/Standby selection algorithm must stand down
377 * if thePDP-D is currently the lead/active node and allow another PDP-D
380 PolicyLogger.debug("snNewInstall: Instantiating stateManagement object");
381 StateManagement sm = new StateManagement(emfXacml, thisPdpId);
382 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
383 sm.addObserver(pmStandbyStateChangeNotifier);
385 // Artificially putting a PDP into service is really a two step process, 1)
386 // inserting it as designated and 2) promoting it so that its standbyStatus
387 // is providing service.
389 PolicyLogger.debug("snNewInstall: Running policy-management.Main class");
390 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
391 policyManagementRunner.start();
393 PolicyLogger.debug("snNewInstall: Runner started; Sleeping "
394 + interruptRecoveryTime + "ms before promoting PDP="
396 Thread.sleep(interruptRecoveryTime);
398 PolicyLogger.debug("snNewInstall: Promoting PDP=" + thisPdpId);
401 String standbyStatus = sm.getStandbyStatus(thisPdpId);
402 PolicyLogger.debug("snNewInstall: Before locking, PDP=" + thisPdpId + " has standbyStatus="
406 * Verify that the PDP is no longer designated.
408 droolsPdpEntity = conn.getPdp(thisPdpId);
409 PolicyLogger.debug("snNewInstall: After lock sm.lock() invoked, DESIGNATED="
410 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
411 assertTrue(droolsPdpEntity.isDesignated() == false);
413 PolicyLogger.debug("snNewInstall: Stopping policyManagementRunner");
414 policyManagementRunner.stopRunner();
416 PolicyLogger.debug("\n\nsnNewInstall: Exiting\n\n");
417 Thread.sleep(interruptRecoveryTime);
419 //********************************************
421 PolicyLogger.debug("\n\nsnNewInstallBadDepData: Exit\n\n");
424 public void snRecoveryFromBadDepData() throws Exception{
428 public void snLock() throws Exception {
432 public void snLockRestart() throws Exception {
436 public void snUnlock() throws Exception {
440 public void snUnlockRestart() throws Exception {
447 public void tnNewInstall() throws Exception {
451 public void tnLockActive() throws Exception {
455 public void tnUnlockColdStandby() throws Exception {
459 public void tnFailActive() throws Exception {
463 public void tnRecoverFailed() throws Exception {
468 * Two Sites, Two Nodes Each Site tests
471 public void tstnNewInstall() throws Exception {
475 public void tstnLock1Site1() throws Exception {
479 public void tstnLock2Site1() throws Exception {
483 public void tstnFailActiveSite2() throws Exception {
487 public void tstnRecoverFailedSite2() throws Exception {
491 public void tstnUnlockSite1() throws Exception {
495 public void tstnFailSite2() throws Exception {
502 public void testColdStandby() throws Exception {
504 PolicyLogger.debug("\n\ntestColdStandby: Entering\n\n");
506 PolicyLogger.debug("testColdStandby: Reading IntegrityMonitorProperties");
507 Properties integrityMonitorProperties = new Properties();
508 integrityMonitorProperties.load(new FileInputStream(new File(
509 "src/test/server/config/IntegrityMonitor.properties")));
510 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
511 String thisPdpId = IntegrityMonitorProperties
512 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
514 PolicyLogger.debug("testColdStandby: Reading xacmlPersistenceProperties");
515 Properties xacmlPersistenceProperties = new Properties();
516 xacmlPersistenceProperties.load(new FileInputStream(new File(
517 "src/test/server/config/xacmlPersistence.properties")));
518 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
520 PolicyLogger.debug("testColdStandby: Creating emfXacml");
521 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
522 "junitXacmlPU", xacmlPersistenceProperties);
524 PolicyLogger.debug("testColdStandby: Reading droolsPersistenceProperties");
525 Properties droolsPersistenceProperties = new Properties();
526 droolsPersistenceProperties.load(new FileInputStream(new File(
527 "src/test/server/config/droolsPersistence.properties")));
528 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
530 PolicyLogger.debug("testColdStandby: Creating emfDrools");
531 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
532 "junitDroolsPU", droolsPersistenceProperties);
534 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
536 PolicyLogger.debug("testColdStandby: Cleaning up tables");
537 conn.deleteAllSessions();
538 conn.deleteAllPdps();
540 PolicyLogger.debug("testColdStandby: Inserting PDP=" + thisPdpId + " as designated");
541 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
543 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
544 PolicyLogger.debug("testColdStandby: After insertion, DESIGNATED="
545 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
546 assertTrue(droolsPdpEntity.isDesignated() == true);
549 * When the Standby Status changes (from providingservice) to hotstandby
550 * or coldstandby,the Active/Standby selection algorithm must stand down
551 * if thePDP-D is currently the lead/active node and allow another PDP-D
554 * It must also call lock on all engines in the engine management.
556 * Yes, this is kludgy, but we have a chicken and egg problem here: we
557 * need a StateManagement object to invoke the
558 * deleteAllStateManagementEntities method.
560 PolicyLogger.debug("testColdStandby: Instantiating stateManagement object");
561 StateManagement sm = new StateManagement(emfXacml, "dummy");
562 sm.deleteAllStateManagementEntities();
563 sm = new StateManagement(emfXacml, thisPdpId);
564 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
565 sm.addObserver(pmStandbyStateChangeNotifier);
567 // Artificially putting a PDP into service is really a two step process, 1)
568 // inserting it as designated and 2) promoting it so that its standbyStatus
569 // is providing service.
571 PolicyLogger.debug("testColdStandby: Running policy-management.Main class");
572 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
573 policyManagementRunner.start();
575 PolicyLogger.debug("testColdStandby: Runner started; Sleeping "
576 + interruptRecoveryTime + "ms before promoting PDP="
578 Thread.sleep(interruptRecoveryTime);
580 PolicyLogger.debug("testColdStandby: Promoting PDP=" + thisPdpId);
583 String standbyStatus = sm.getStandbyStatus(thisPdpId);
584 PolicyLogger.debug("testColdStandby: Before locking, PDP=" + thisPdpId + " has standbyStatus="
587 PolicyLogger.debug("testColdStandby: Locking sm");
590 Thread.sleep(interruptRecoveryTime);
592 * Verify that the PDP is no longer designated.
594 droolsPdpEntity = conn.getPdp(thisPdpId);
595 PolicyLogger.debug("testColdStandby: After lock sm.lock() invoked, DESIGNATED="
596 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
597 assertTrue(droolsPdpEntity.isDesignated() == false);
599 PolicyLogger.debug("testColdStandby: Stopping policyManagementRunner");
600 policyManagementRunner.stopRunner();
602 PolicyLogger.debug("\n\ntestColdStandby: Exiting\n\n");
603 Thread.sleep(interruptRecoveryTime);
608 * Tests hot standby when there is only one PDP.
612 public void testHotStandby1() throws Exception {
614 PolicyLogger.debug("\n\ntestHotStandby1: Entering\n\n");
616 PolicyLogger.debug("testHotStandby1: Reading IntegrityMonitorProperties");
617 Properties integrityMonitorProperties = new Properties();
618 integrityMonitorProperties.load(new FileInputStream(new File(
619 "src/test/server/config/IntegrityMonitor.properties")));
620 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
621 String thisPdpId = IntegrityMonitorProperties
622 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
624 PolicyLogger.debug("testHotStandby1: Reading xacmlPersistenceProperties");
625 Properties xacmlPersistenceProperties = new Properties();
626 xacmlPersistenceProperties.load(new FileInputStream(new File(
627 "src/test/server/config/xacmlPersistence.properties")));
628 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
630 PolicyLogger.debug("testHotStandby1: Creating emfXacml");
631 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
632 "junitXacmlPU", xacmlPersistenceProperties);
634 PolicyLogger.debug("testHotStandby1: Reading droolsPersistenceProperties");
635 Properties droolsPersistenceProperties = new Properties();
636 droolsPersistenceProperties.load(new FileInputStream(new File(
637 "src/test/server/config/droolsPersistence.properties")));
638 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
640 PolicyLogger.debug("testHotStandby1: Creating emfDrools");
641 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
642 "junitDroolsPU", droolsPersistenceProperties);
644 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
646 PolicyLogger.debug("testHotStandby1: Cleaning up tables");
647 conn.deleteAllSessions();
648 conn.deleteAllPdps();
651 * Insert this PDP as not designated. Initial standby state will be
652 * either null or cold standby. Demoting should transit state to
655 PolicyLogger.debug("testHotStandby1: Inserting PDP=" + thisPdpId + " as not designated");
656 Date yesterday = DateUtils.addDays(new Date(), -1);
657 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
659 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
660 PolicyLogger.debug("testHotStandby1: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
661 + droolsPdpEntity.isDesignated());
662 assertTrue(droolsPdpEntity.isDesignated() == false);
664 PolicyLogger.debug("testHotStandby1: Instantiating stateManagement object");
665 StateManagement sm = new StateManagement(emfXacml, "dummy");
666 sm.deleteAllStateManagementEntities();
667 sm = new StateManagement(emfXacml, thisPdpId);
668 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
669 sm.addObserver(pmStandbyStateChangeNotifier);
671 PolicyLogger.debug("testHotStandby1: Demoting PDP=" + thisPdpId);
672 // demoting should cause state to transit to hotstandby
675 PolicyLogger.debug("testHotStandby1: Running policy-management.Main class");
676 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
677 policyManagementRunner.start();
679 PolicyLogger.debug("testHotStandby1: Sleeping "
681 + "ms, to allow JpaDroolsPdpsConnector time to check droolspdpentity table");
682 Thread.sleep(sleepTime);
685 * Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
687 droolsPdpEntity = conn.getPdp(thisPdpId);
688 PolicyLogger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED="
689 + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
690 assertTrue(droolsPdpEntity.isDesignated() == true);
691 String standbyStatus = sm.getStandbyStatus(thisPdpId);
692 PolicyLogger.debug("testHotStandby1: After demotion, PDP=" + thisPdpId + " has standbyStatus="
694 assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
696 PolicyLogger.debug("testHotStandby1: Stopping policyManagementRunner");
697 policyManagementRunner.stopRunner();
699 PolicyLogger.debug("\n\ntestHotStandby1: Exiting\n\n");
700 Thread.sleep(interruptRecoveryTime);
705 * Tests hot standby when two PDPs are involved.
709 public void testHotStandby2() throws Exception {
711 PolicyLogger.debug("\n\ntestHotStandby2: Entering\n\n");
713 PolicyLogger.debug("testHotStandby2: Reading IntegrityMonitorProperties");
714 Properties integrityMonitorProperties = new Properties();
715 integrityMonitorProperties.load(new FileInputStream(new File(
716 "src/test/server/config/IntegrityMonitor.properties")));
717 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
718 String thisPdpId = IntegrityMonitorProperties
719 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
721 PolicyLogger.debug("testHotStandby2: Reading xacmlPersistenceProperties");
722 Properties xacmlPersistenceProperties = new Properties();
723 xacmlPersistenceProperties.load(new FileInputStream(new File(
724 "src/test/server/config/xacmlPersistence.properties")));
725 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
727 PolicyLogger.debug("testHotStandby2: Creating emfXacml");
728 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
729 "junitXacmlPU", xacmlPersistenceProperties);
731 PolicyLogger.debug("testHotStandby2: Reading droolsPersistenceProperties");
732 Properties droolsPersistenceProperties = new Properties();
733 droolsPersistenceProperties.load(new FileInputStream(new File(
734 "src/test/server/config/droolsPersistence.properties")));
735 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
737 PolicyLogger.debug("testHotStandby2: Creating emfDrools");
738 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
739 "junitDroolsPU", droolsPersistenceProperties);
741 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
743 PolicyLogger.debug("testHotStandby2: Cleaning up tables");
744 conn.deleteAllSessions();
745 conn.deleteAllPdps();
748 * Insert a PDP that's designated but not current.
750 String activePdpId = "pdp2";
751 PolicyLogger.debug("testHotStandby2: Inserting PDP=" + activePdpId + " as stale, designated PDP");
752 Date yesterday = DateUtils.addDays(new Date(), -1);
753 DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
755 DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
756 PolicyLogger.debug("testHotStandby2: After insertion, PDP=" + activePdpId + ", which is not current, has DESIGNATED="
757 + droolsPdpEntity.isDesignated());
758 assertTrue(droolsPdpEntity.isDesignated() == true);
761 * Promote the designated PDP.
763 * We have a chicken and egg problem here: we need a StateManagement
764 * object to invoke the deleteAllStateManagementEntities method.
766 PolicyLogger.debug("testHotStandy2: Promoting PDP=" + activePdpId);
767 StateManagement sm = new StateManagement(emfXacml, "dummy");
768 sm.deleteAllStateManagementEntities();
769 sm = new StateManagement(emfXacml, activePdpId);
770 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
771 sm.addObserver(pmStandbyStateChangeNotifier);
773 // Artificially putting a PDP into service is really a two step process, 1)
774 // inserting it as designated and 2) promoting it so that its standbyStatus
775 // is providing service.
778 * Insert this PDP as not designated. Initial standby state will be
779 * either null or cold standby. Demoting should transit state to
782 PolicyLogger.debug("testHotStandby2: Inserting PDP=" + thisPdpId + " as not designated");
783 pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
785 droolsPdpEntity = conn.getPdp(thisPdpId);
786 PolicyLogger.debug("testHotStandby2: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
787 + droolsPdpEntity.isDesignated());
788 assertTrue(droolsPdpEntity.isDesignated() == false);
790 PolicyLogger.debug("testHotStandby2: Demoting PDP=" + thisPdpId);
791 StateManagement sm2 = new StateManagement(emfXacml, thisPdpId);
792 sm2.addObserver(pmStandbyStateChangeNotifier);
794 PolicyLogger.debug("testHotStandby2: Running policy-management.Main class");
795 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
796 policyManagementRunner.start();
798 PolicyLogger.debug("testHotStandby2: Runner started; Sleeping "
799 + interruptRecoveryTime + "ms before promoting/demoting");
800 Thread.sleep(interruptRecoveryTime);
802 PolicyLogger.debug("testHotStandby2: Runner started; promoting PDP=" + activePdpId);
804 String standbyStatus = sm.getStandbyStatus(activePdpId);
805 PolicyLogger.debug("testHotStandby2: After promoting, PDP=" + activePdpId + " has standbyStatus="
808 // demoting PDP should ensure that state transits to hotstandby
809 PolicyLogger.debug("testHotStandby2: Runner started; demoting PDP=" + thisPdpId);
811 standbyStatus = sm.getStandbyStatus(thisPdpId);
812 PolicyLogger.debug("testHotStandby2: After demoting, PDP=" + thisPdpId + " has standbyStatus="
815 PolicyLogger.debug("testHotStandby2: Sleeping "
817 + "ms, to allow JpaDroolsPdpsConnector time to check droolspdpentity table");
818 Thread.sleep(sleepTime);
821 * Verify that this PDP, demoted to HOT_STANDBY, is now
822 * re-designated and providing service.
824 droolsPdpEntity = conn.getPdp(thisPdpId);
825 PolicyLogger.debug("testHotStandby2: After demoting PDP=" + activePdpId
826 + ", DESIGNATED=" + droolsPdpEntity.isDesignated()
827 + " for PDP=" + thisPdpId);
828 assertTrue(droolsPdpEntity.isDesignated() == true);
829 standbyStatus = sm2.getStandbyStatus(thisPdpId);
830 PolicyLogger.debug("testHotStandby2: After demoting PDP=" + activePdpId
831 + ", PDP=" + thisPdpId + " has standbyStatus=" + standbyStatus);
832 assertTrue(standbyStatus != null
833 && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
835 PolicyLogger.debug("testHotStandby2: Stopping policyManagementRunner");
836 policyManagementRunner.stopRunner();
838 PolicyLogger.debug("\n\ntestHotStandby2: Exiting\n\n");
839 Thread.sleep(interruptRecoveryTime);
844 * 1) Inserts and designates this PDP, then verifies that startTransaction
847 * 2) Demotes PDP, and verifies that because there is only one PDP, it will
848 * be immediately re-promoted, thus allowing startTransaction to be
851 * 3) Locks PDP and verifies that startTransaction results in
852 * AdministrativeStateException.
854 * 4) Unlocks PDP and verifies that startTransaction results in
855 * StandbyStatusException.
857 * 5) Promotes PDP and verifies that startTransaction is once again
862 public void testLocking1() throws Exception {
864 PolicyLogger.debug("testLocking1: Reading IntegrityMonitorProperties");
865 Properties integrityMonitorProperties = new Properties();
866 integrityMonitorProperties.load(new FileInputStream(new File(
867 "src/test/server/config/IntegrityMonitor.properties")));
868 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
869 String thisPdpId = IntegrityMonitorProperties
870 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
872 PolicyLogger.debug("testLocking1: Reading xacmlPersistenceProperties");
873 Properties xacmlPersistenceProperties = new Properties();
874 xacmlPersistenceProperties.load(new FileInputStream(new File(
875 "src/test/server/config/xacmlPersistence.properties")));
876 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
878 PolicyLogger.debug("testLocking1: Creating emfXacml");
879 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
880 "junitXacmlPU", xacmlPersistenceProperties);
882 PolicyLogger.debug("testLocking1: Reading droolsPersistenceProperties");
883 Properties droolsPersistenceProperties = new Properties();
884 droolsPersistenceProperties.load(new FileInputStream(new File(
885 "src/test/server/config/droolsPersistence.properties")));
886 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
888 PolicyLogger.debug("testLocking1: Creating emfDrools");
889 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
890 "junitDroolsPU", droolsPersistenceProperties);
892 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
894 PolicyLogger.debug("testLocking1: Cleaning up tables");
895 conn.deleteAllSessions();
896 conn.deleteAllPdps();
899 * Insert this PDP as designated. Initial standby state will be
900 * either null or cold standby.
902 PolicyLogger.debug("testLocking1: Inserting PDP=" + thisPdpId + " as designated");
903 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
905 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
906 PolicyLogger.debug("testLocking1: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
907 + droolsPdpEntity.isDesignated());
908 assertTrue(droolsPdpEntity.isDesignated() == true);
910 PolicyLogger.debug("testLocking1: Instantiating stateManagement object");
911 StateManagement sm = new StateManagement(emfXacml, "dummy");
912 sm.deleteAllStateManagementEntities();
913 sm = new StateManagement(emfXacml, thisPdpId);
914 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
915 sm.addObserver(pmStandbyStateChangeNotifier);
917 PolicyLogger.debug("testLocking1: Running policy-management.Main class, designated="
918 + conn.getPdp(thisPdpId).isDesignated());
919 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
920 policyManagementRunner.start();
922 PolicyLogger.debug("testLocking1: Runner started; Sleeping "
923 + interruptRecoveryTime + "ms before promoting PDP="
925 Thread.sleep(interruptRecoveryTime);
927 PolicyLogger.debug("testLocking1: Promoting PDP=" + thisPdpId);
930 PolicyLogger.debug("testLocking1: Sleeping "
932 + "ms, to allow time for policy-management.Main class to come up, designated="
933 + conn.getPdp(thisPdpId).isDesignated());
934 Thread.sleep(sleepTime);
936 PolicyLogger.debug("testLocking1: Waking up and invoking startTransaction on active PDP="
939 + conn.getPdp(thisPdpId).isDesignated());
940 DroolsPDPIntegrityMonitor droolsPdpIntegrityMonitor = (DroolsPDPIntegrityMonitor) IntegrityMonitor
943 droolsPdpIntegrityMonitor.startTransaction();
944 droolsPdpIntegrityMonitor.endTransaction();
945 PolicyLogger.debug("testLocking1: As expected, transaction successful");
946 } catch (AdministrativeStateException e) {
947 PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
949 } catch (StandbyStatusException e) {
950 PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
952 } catch (Exception e) {
953 PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
957 // demoting should cause state to transit to hotstandby, followed by re-promotion,
958 // since there is only one PDP.
959 PolicyLogger.debug("testLocking1: demoting PDP=" + thisPdpId);
960 sm = droolsPdpIntegrityMonitor.getStateManager();
963 PolicyLogger.debug("testLocking1: sleeping" + electionWaitSleepTime
964 + " to allow election handler to re-promote PDP=" + thisPdpId);
965 Thread.sleep(electionWaitSleepTime);
967 PolicyLogger.debug("testLocking1: Invoking startTransaction on re-promoted PDP="
970 + conn.getPdp(thisPdpId).isDesignated());
972 droolsPdpIntegrityMonitor.startTransaction();
973 droolsPdpIntegrityMonitor.endTransaction();
974 PolicyLogger.debug("testLocking1: As expected, transaction successful");
975 } catch (AdministrativeStateException e) {
976 PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
978 } catch (StandbyStatusException e) {
979 PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
981 } catch (Exception e) {
982 PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
986 // locking should cause state to transit to cold standby
987 PolicyLogger.debug("testLocking1: locking PDP=" + thisPdpId);
990 // Just to avoid any race conditions, sleep a little after locking
991 PolicyLogger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
994 PolicyLogger.debug("testLocking1: Invoking startTransaction on locked PDP="
997 + conn.getPdp(thisPdpId).isDesignated());
999 droolsPdpIntegrityMonitor.startTransaction();
1000 PolicyLogger.error("testLocking1: startTransaction unexpectedly successful");
1002 } catch (AdministrativeStateException e) {
1003 PolicyLogger.debug("testLocking1: As expected, caught AdministrativeStateException, message=" + e.getMessage());
1004 } catch (StandbyStatusException e) {
1005 PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
1007 } catch (Exception e) {
1008 PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
1011 droolsPdpIntegrityMonitor.endTransaction();
1014 // unlocking should cause state to transit to hot standby
1015 PolicyLogger.debug("testLocking1: unlocking PDP=" + thisPdpId);
1018 // Just to avoid any race conditions, sleep a little after locking
1019 PolicyLogger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
1022 PolicyLogger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
1025 + conn.getPdp(thisPdpId).isDesignated());
1027 droolsPdpIntegrityMonitor.startTransaction();
1028 PolicyLogger.error("testLocking1: startTransaction unexpectedly successful");
1030 } catch (AdministrativeStateException e) {
1031 PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
1033 } catch (StandbyStatusException e) {
1034 PolicyLogger.debug("testLocking1: As expected, caught StandbyStatusException, message=" + e.getMessage());
1035 } catch (Exception e) {
1036 PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
1039 droolsPdpIntegrityMonitor.endTransaction();
1042 // promoting should cause state to transit to providing service
1043 PolicyLogger.debug("testLocking1: promoting PDP=" + thisPdpId);
1046 // Just to avoid any race conditions, sleep a little after promoting
1047 PolicyLogger.debug("testLocking1: Sleeping a few millis after promoting, to avoid race condition");
1050 PolicyLogger.debug("testLocking1: Invoking startTransaction on promoted PDP="
1053 + conn.getPdp(thisPdpId).isDesignated());
1055 droolsPdpIntegrityMonitor.startTransaction();
1056 droolsPdpIntegrityMonitor.endTransaction();
1057 PolicyLogger.debug("testLocking1: As expected, transaction successful");
1058 } catch (AdministrativeStateException e) {
1059 PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
1061 } catch (StandbyStatusException e) {
1062 PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
1064 } catch (Exception e) {
1065 PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
1069 PolicyLogger.debug("testLocking1: Stopping policyManagementRunner");
1070 policyManagementRunner.stopRunner();
1072 PolicyLogger.debug("\n\ntestLocking1: Exiting\n\n");
1073 Thread.sleep(interruptRecoveryTime);
1078 * 1) Inserts and designates this PDP, then verifies that startTransaction
1081 * 2) Inserts another PDP in hotstandby.
1083 * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
1084 * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
1088 public void testLocking2() throws Exception {
1090 PolicyLogger.debug("\n\ntestLocking2: Entering\n\n");
1092 PolicyLogger.debug("testLocking2: Reading IntegrityMonitorProperties");
1093 Properties integrityMonitorProperties = new Properties();
1094 integrityMonitorProperties.load(new FileInputStream(new File(
1095 "src/test/server/config/IntegrityMonitor.properties")));
1096 IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
1097 String thisPdpId = IntegrityMonitorProperties
1098 .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
1100 PolicyLogger.debug("testLocking2: Reading xacmlPersistenceProperties");
1101 Properties xacmlPersistenceProperties = new Properties();
1102 xacmlPersistenceProperties.load(new FileInputStream(new File(
1103 "src/test/server/config/xacmlPersistence.properties")));
1104 XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
1106 PolicyLogger.debug("testLocking2: Creating emfXacml");
1107 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
1108 "junitXacmlPU", xacmlPersistenceProperties);
1110 PolicyLogger.debug("testLocking2: Reading droolsPersistenceProperties");
1111 Properties droolsPersistenceProperties = new Properties();
1112 droolsPersistenceProperties.load(new FileInputStream(new File(
1113 "src/test/server/config/droolsPersistence.properties")));
1114 DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
1116 PolicyLogger.debug("testLocking2: Creating emfDrools");
1117 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
1118 "junitDroolsPU", droolsPersistenceProperties);
1120 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
1122 PolicyLogger.debug("testLocking2: Cleaning up tables");
1123 conn.deleteAllSessions();
1124 conn.deleteAllPdps();
1127 * Insert this PDP as designated. Initial standby state will be
1128 * either null or cold standby. Demoting should transit state to
1131 PolicyLogger.debug("testLocking2: Inserting PDP=" + thisPdpId + " as designated");
1132 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, new Date());
1133 conn.insertPdp(pdp);
1134 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1135 PolicyLogger.debug("testLocking2: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
1136 + droolsPdpEntity.isDesignated());
1137 assertTrue(droolsPdpEntity.isDesignated() == true);
1139 PolicyLogger.debug("testLocking2: Instantiating stateManagement object and promoting PDP=" + thisPdpId);
1140 StateManagement sm = new StateManagement(emfXacml, "dummy");
1141 sm.deleteAllStateManagementEntities();
1142 sm = new StateManagement(emfXacml, thisPdpId);
1143 PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
1144 sm.addObserver(pmStandbyStateChangeNotifier);
1147 * Insert another PDP as not designated. Initial standby state will be
1148 * either null or cold standby. Demoting should transit state to
1151 String standbyPdpId = "pdp2";
1152 PolicyLogger.debug("testLocking2: Inserting PDP=" + standbyPdpId + " as not designated");
1153 Date yesterday = DateUtils.addDays(new Date(), -1);
1154 pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
1155 conn.insertPdp(pdp);
1156 droolsPdpEntity = conn.getPdp(standbyPdpId);
1157 PolicyLogger.debug("testLocking2: After insertion, PDP=" + standbyPdpId + " has DESIGNATED="
1158 + droolsPdpEntity.isDesignated());
1159 assertTrue(droolsPdpEntity.isDesignated() == false);
1161 PolicyLogger.debug("testLocking2: Demoting PDP=" + standbyPdpId);
1162 StateManagement sm2 = new StateManagement(emfXacml, standbyPdpId);
1163 sm2.addObserver(pmStandbyStateChangeNotifier);
1165 PolicyLogger.debug("testLocking2: Running policy-management.Main class");
1166 PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
1167 policyManagementRunner.start();
1169 PolicyLogger.debug("testLocking2: Runner started; Sleeping "
1170 + interruptRecoveryTime + "ms before promoting/demoting");
1171 Thread.sleep(interruptRecoveryTime);
1173 PolicyLogger.debug("testLocking2: Promoting PDP=" + thisPdpId);
1176 // demoting PDP should ensure that state transits to hotstandby
1177 PolicyLogger.debug("testLocking2: Demoting PDP=" + standbyPdpId);
1180 PolicyLogger.debug("testLocking2: Sleeping "
1182 + "ms, to allow time for policy-management.Main class to come up");
1183 Thread.sleep(sleepTime);
1185 PolicyLogger.debug("testLocking2: Waking up and invoking startTransaction on active PDP="
1188 + conn.getPdp(thisPdpId).isDesignated());
1189 DroolsPDPIntegrityMonitor droolsPdpIntegrityMonitor = (DroolsPDPIntegrityMonitor) IntegrityMonitor
1192 droolsPdpIntegrityMonitor.startTransaction();
1193 droolsPdpIntegrityMonitor.endTransaction();
1194 PolicyLogger.debug("testLocking2: As expected, transaction successful");
1195 } catch (AdministrativeStateException e) {
1196 PolicyLogger.error("testLocking2: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
1198 } catch (StandbyStatusException e) {
1199 PolicyLogger.error("testLocking2: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
1201 } catch (Exception e) {
1202 PolicyLogger.error("testLocking2: Unexpectedly caught Exception, message=" + e.getMessage());
1206 // demoting should cause state to transit to hotstandby followed by re-promotion.
1207 PolicyLogger.debug("testLocking2: demoting PDP=" + thisPdpId);
1208 sm = droolsPdpIntegrityMonitor.getStateManager();
1211 PolicyLogger.debug("testLocking2: sleeping" + electionWaitSleepTime
1212 + " to allow election handler to re-promote PDP=" + thisPdpId);
1213 Thread.sleep(electionWaitSleepTime);
1215 PolicyLogger.debug("testLocking2: Waking up and invoking startTransaction on re-promoted PDP="
1216 + thisPdpId + ", designated="
1217 + conn.getPdp(thisPdpId).isDesignated());
1219 droolsPdpIntegrityMonitor.startTransaction();
1220 droolsPdpIntegrityMonitor.endTransaction();
1221 PolicyLogger.debug("testLocking2: As expected, transaction successful");
1222 } catch (AdministrativeStateException e) {
1223 PolicyLogger.error("testLocking2: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
1225 } catch (StandbyStatusException e) {
1226 PolicyLogger.error("testLocking2: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
1228 } catch (Exception e) {
1229 PolicyLogger.error("testLocking2: Unexpectedly caught Exception, message=" + e.getMessage());
1233 PolicyLogger.debug("testLocking2: Verifying designated status for PDP="
1235 boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated();
1236 assertTrue(standbyPdpDesignated == false);
1238 PolicyLogger.debug("testLocking2: Stopping policyManagementRunner");
1239 policyManagementRunner.stopRunner();
1241 PolicyLogger.debug("\n\ntestLocking2: Exiting\n\n");
1242 Thread.sleep(interruptRecoveryTime);
1246 private class PolicyManagementRunner extends Thread {
1249 PolicyLogger.debug("PolicyManagementRunner.run: Entering");
1250 String args[] = { "src/main/server/config" };
1253 } catch (Exception e) {
1255 .debug("PolicyManagementRunner.run: Exception thrown from Main.main(), message="
1258 PolicyLogger.debug("PolicyManagementRunner.run: Exiting");
1261 public void stopRunner() {
1262 PolicyEngine.manager.shutdown();