2 * ============LICENSE_START=======================================================
3 * feature-active-standby-management
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.onap.policy.drools.activestandby;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Properties;
34 import javax.persistence.EntityManager;
35 import javax.persistence.EntityManagerFactory;
36 import javax.persistence.EntityTransaction;
37 import javax.persistence.Persistence;
38 import org.apache.commons.lang3.time.DateUtils;
39 import org.junit.AfterClass;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43 import org.onap.policy.common.im.AdministrativeStateException;
44 import org.onap.policy.common.im.IntegrityMonitor;
45 import org.onap.policy.common.im.IntegrityMonitorException;
46 import org.onap.policy.common.im.MonitorTime;
47 import org.onap.policy.common.im.StandbyStatusException;
48 import org.onap.policy.common.im.StateManagement;
49 import org.onap.policy.common.utils.time.CurrentTime;
50 import org.onap.policy.common.utils.time.PseudoTimer;
51 import org.onap.policy.common.utils.time.TestTimeMulti;
52 import org.onap.policy.drools.core.PolicySessionFeatureApi;
53 import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
54 import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
55 import org.powermock.reflect.Whitebox;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
60 * All JUnits are designed to run in the local development environment
61 * where they have write privileges and can execute time-sensitive
65 public class StandbyStateManagementTest {
66 private static final Logger logger = LoggerFactory.getLogger(StandbyStateManagementTest.class);
68 private static final String MONITOR_FIELD_NAME = "instance";
69 private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
72 * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
73 * at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
74 * to ensure that we wait for the DesignationWaiter to do its job, before
75 * checking the results. Add a few seconds for safety
78 private static final long SLEEP_TIME = 10000;
81 * DroolsPdpsElectionHandler runs every 1 seconds, so a 6 second sleep should be
82 * plenty to ensure it has time to re-promote this PDP.
85 private static final long ELECTION_WAIT_SLEEP_TIME = 6000;
88 * Sleep a few seconds after each test to allow interrupt (shutdown) recovery.
91 private static final long INTERRUPT_RECOVERY_TIME = 5000;
93 private static EntityManagerFactory emfx;
94 private static EntityManagerFactory emfd;
95 private static EntityManager emx;
96 private static EntityManager emd;
97 private static EntityTransaction et;
99 private static final String CONFIG_DIR = "src/test/resources";
101 private static CurrentTime saveTime;
102 private static Factory saveFactory;
104 private TestTimeMulti testTime;
107 * This cannot be shared by tests, as each integrity monitor may manipulate it by
108 * adding its own property values.
110 private Properties activeStandbyProperties;
113 * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
119 * @throws Exception exception
122 public static void setUpClass() throws Exception {
124 String userDir = System.getProperty("user.dir");
125 logger.debug("setUpClass: userDir={}", userDir);
126 System.setProperty("com.sun.management.jmxremote.port", "9980");
127 System.setProperty("com.sun.management.jmxremote.authenticate","false");
129 saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
130 saveFactory = Factory.getInstance();
132 resetInstanceObjects();
134 //Create the data access for xacml db
135 Properties smProps = loadStateManagementProperties();
137 emfx = Persistence.createEntityManagerFactory("junitXacmlPU", smProps);
139 // Create an entity manager to use the DB
140 emx = emfx.createEntityManager();
142 //Create the data access for drools db
143 Properties asbProps = loadActiveStandbyProperties();
145 emfd = Persistence.createEntityManagerFactory("junitDroolsPU", asbProps);
147 // Create an entity manager to use the DB
148 emd = emfd.createEntityManager();
152 * Restores the system state.
154 * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
157 public static void tearDownClass() throws IntegrityMonitorException {
158 resetInstanceObjects();
160 Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
161 Factory.setInstance(saveFactory);
173 * @throws Exception exception
176 public void setUp() throws Exception {
177 resetInstanceObjects();
184 * All threads use the test time object for sleeping. As a result, we don't have
185 * to wait more than an instant for them to complete their work, thus we'll use
186 * a very small REAL wait time in the constructor.
188 testTime = new TestTimeMulti(5);
189 Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
191 Factory factory = mock(Factory.class);
192 when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
193 Factory.setInstance(factory);
195 activeStandbyProperties = loadActiveStandbyProperties();
198 private static void resetInstanceObjects() throws IntegrityMonitorException {
199 IntegrityMonitor.setUnitTesting(true);
200 IntegrityMonitor.deleteInstance();
201 IntegrityMonitor.setUnitTesting(false);
203 Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
208 * Clean up the xacml database.
211 public void cleanXacmlDb() {
212 et = emx.getTransaction();
215 // Make sure we leave the DB clean
216 emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
217 emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
218 emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
224 * Clean up the drools db.
226 public void cleanDroolsDb() {
227 et = emd.getTransaction();
230 // Make sure we leave the DB clean
231 emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
237 * Test the standby state change notifier.
239 * @throws Exception exception
242 public void testPmStandbyStateChangeNotifier() throws Exception {
243 logger.debug("\n\ntestPmStandbyStateChangeNotifier: Entering\n\n");
245 logger.debug("testPmStandbyStateChangeNotifier: Reading activeStandbyProperties");
247 String resourceName = "testPMS";
248 activeStandbyProperties.setProperty("resource.name", resourceName);
249 ActiveStandbyProperties.initProperties(activeStandbyProperties);
251 logger.debug("testPmStandbyStateChangeNotifier: Getting StateManagement instance");
253 StateManagement sm = new StateManagement(emfx, resourceName);
255 //Create an instance of the Observer
256 PmStandbyStateChangeNotifier pmNotifier = new PmStandbyStateChangeNotifier();
258 //Register the PmStandbyStateChangeNotifier Observer
259 sm.addObserver(pmNotifier);
261 //At this point the standbystatus = 'null'
263 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.NULL_VALUE));
266 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.NULL_VALUE));
268 //Adding standbystatus=hotstandby
270 System.out.println(pmNotifier.getPreviousStandbyStatus());
271 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
272 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
274 //Now making standbystatus=coldstandby
276 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
277 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
279 //standbystatus = hotstandby
281 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
282 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
284 //standbystatus = providingservice
286 //The previousStandbyStatus is not updated until after the delay activation expires
287 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
288 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
290 //Sleep long enough for the delayActivationTimer to run
292 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
294 //standbystatus = providingservice
296 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
298 //standbystatus = coldstandby
300 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
301 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
303 //standbystatus = hotstandby
305 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
306 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
308 //standbystatus = hotstandby
310 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
311 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
315 * Test sanitize designated list.
317 * @throws Exception exception
320 public void testSanitizeDesignatedList() throws Exception {
322 logger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n");
324 // Get a DroolsPdpsConnector
326 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
328 // Create 4 pdpd all not designated
330 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
331 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
332 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
333 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
335 List<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
336 listOfDesignated.add(pdp1);
337 listOfDesignated.add(pdp2);
338 listOfDesignated.add(pdp3);
339 listOfDesignated.add(pdp4);
341 // Now we want to create a StateManagementFeature and initialize it. It will be
342 // discovered by the ActiveStandbyFeature when the election handler initializes.
344 StateManagementFeatureApi stateManagementFeature = null;
345 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
346 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
347 stateManagementFeature = feature;
348 logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}",
349 stateManagementFeature.getResourceName());
352 assertNotNull(stateManagementFeature);
355 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
357 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
359 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = {}\n\n",listOfDesignated.size());
361 assertTrue(listOfDesignated.size() == 4);
363 // Now make 2 designated
365 pdp1.setDesignated(true);
366 pdp2.setDesignated(true);
368 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
370 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = {}\n\n",
371 listOfDesignated.size());
373 assertTrue(listOfDesignated.size() == 2);
374 assertTrue(listOfDesignated.contains(pdp1));
375 assertTrue(listOfDesignated.contains(pdp2));
378 // Now all are designated. But, we have to add back the previously non-designated nodes
380 pdp3.setDesignated(true);
381 pdp4.setDesignated(true);
382 listOfDesignated.add(pdp3);
383 listOfDesignated.add(pdp4);
385 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
387 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = {}\n\n",
388 listOfDesignated.size());
390 assertTrue(listOfDesignated.size() == 4);
395 * Test Compute most recent primary.
397 * @throws Exception exception
400 public void testComputeMostRecentPrimary() throws Exception {
402 logger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
404 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
407 // Create 4 pdpd all not designated
410 long designatedDateMs = testTime.getMillis();
411 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
412 pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
414 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
416 pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
418 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
419 pdp3.setDesignatedDate(new Date(designatedDateMs - 1));
421 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
423 pdp4.setDesignatedDate(new Date(designatedDateMs));
425 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
426 listOfAllPdps.add(pdp1);
427 listOfAllPdps.add(pdp2);
428 listOfAllPdps.add(pdp3);
429 listOfAllPdps.add(pdp4);
432 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
433 listOfDesignated.add(pdp1);
434 listOfDesignated.add(pdp2);
435 listOfDesignated.add(pdp3);
436 listOfDesignated.add(pdp4);
438 // Because the way we sanitize the listOfDesignated, it will always contain all hot standby
439 // or all designated members.
441 // Now we want to create a StateManagementFeature and initialize it. It will be
442 // discovered by the ActiveStandbyFeature when the election handler initializes.
444 StateManagementFeatureApi stateManagementFeature = null;
445 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
446 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
447 stateManagementFeature = feature;
448 logger.debug("testComputeMostRecentPrimary stateManagementFeature.getResourceName(): {}",
449 stateManagementFeature.getResourceName());
452 assertNotNull(stateManagementFeature);
454 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
456 DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(
457 listOfAllPdps, listOfDesignated);
459 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
460 mostRecentPrimary.getPdpId());
463 // If all of the pdps are included in the listOfDesignated and none are designated, it will choose
464 // the one which has the most recent designated date.
467 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
470 // Now let's designate all of those on the listOfDesignated. It will choose the first one designated
473 pdp1.setDesignated(true);
474 pdp2.setDesignated(true);
475 pdp3.setDesignated(true);
476 pdp4.setDesignated(true);
478 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
480 logger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, "
481 + "mostRecentPrimary.getPdpId() = {}\n\n",
482 mostRecentPrimary.getPdpId());
485 // If all of the pdps are included in the listOfDesignated and all are designated, it will choose
486 // the one which was designated first
489 assertTrue(mostRecentPrimary.getPdpId().equals("pdp2"));
492 // Now we will designate only 2 and put just them in the listOfDesignated. The algorithm will now
493 // look for the most recently designated pdp which is not currently designated.
496 pdp3.setDesignated(false);
497 pdp4.setDesignated(false);
499 listOfDesignated.remove(pdp3);
500 listOfDesignated.remove(pdp4);
502 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
504 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
505 mostRecentPrimary.getPdpId());
507 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
511 // Now we will have none designated and put two of them in the listOfDesignated. The algorithm will now
512 // look for the most recently designated pdp regardless of whether it is currently marked as designated.
515 pdp1.setDesignated(false);
516 pdp2.setDesignated(false);
518 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
520 logger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = {}\n\n",
521 mostRecentPrimary.getPdpId());
523 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
526 // If we have only one pdp on in the listOfDesignated,
527 // the most recently designated pdp will be chosen, regardless
528 // of its designation status
531 listOfDesignated.remove(pdp1);
533 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
535 logger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = {}\n\n",
536 mostRecentPrimary.getPdpId());
538 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
541 // Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp.
544 listOfDesignated.remove(pdp2);
546 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
548 logger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = {}\n\n",
549 mostRecentPrimary.getPdpId());
551 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
556 * Test compute designated PDP.
558 * @throws Exception exception
561 public void testComputeDesignatedPdp() throws Exception {
563 logger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
565 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
568 // Create 4 pdpd all not designated. Two on site1. Two on site2
571 long designatedDateMs = testTime.getMillis();
572 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
573 pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
574 pdp1.setSite("site1");
576 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
577 pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
578 pdp2.setSite("site1");
581 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
582 pdp3.setDesignatedDate(new Date(designatedDateMs - 4));
583 pdp3.setSite("site2");
585 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
587 pdp4.setDesignatedDate(new Date(designatedDateMs));
588 pdp4.setSite("site2");
590 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
591 listOfAllPdps.add(pdp1);
592 listOfAllPdps.add(pdp2);
593 listOfAllPdps.add(pdp3);
594 listOfAllPdps.add(pdp4);
597 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
600 // We will first test an empty listOfDesignated. As we know from the previous JUnit,
601 // the pdp with the most designated date will be chosen for mostRecentPrimary
603 // Now we want to create a StateManagementFeature and initialize it. It will be
604 // discovered by the ActiveStandbyFeature when the election handler initializes.
606 StateManagementFeatureApi stateManagementFeature = null;
607 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
608 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
609 stateManagementFeature = feature;
610 logger.debug("testComputeDesignatedPdp stateManagementFeature.getResourceName(): {}",
611 stateManagementFeature.getResourceName());
614 assertNotNull(stateManagementFeature);
617 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
619 DroolsPdp mostRecentPrimary = pdp4;
621 DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
624 // The designatedPdp should be null
626 assertTrue(designatedPdp == null);
629 // Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary
631 listOfDesignated.add(pdp2);
633 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
636 // Now the designatedPdp should be the one and only selection in the listOfDesignated
639 assertTrue(designatedPdp.getPdpId().equals(pdp2.getPdpId()));
642 // Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary
645 listOfDesignated.add(pdp1);
647 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
650 // The designatedPdp should now be the one with the lowest lexiographic score - pdp1
653 assertTrue(designatedPdp.getPdpId().equals(pdp1.getPdpId()));
656 // Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary
659 listOfDesignated.remove(pdp1);
660 listOfDesignated.add(pdp3);
662 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
665 // The designatedPdp should now be the one on the same site as the mostRecentPrimary
668 assertTrue(designatedPdp.getPdpId().equals(pdp3.getPdpId()));
674 * @throws Exception exception
677 public void testColdStandby() throws Exception {
679 logger.debug("\n\ntestColdStandby: Entering\n\n");
681 final String thisPdpId = activeStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
683 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
685 logger.debug("testColdStandby: Inserting PDP={} as designated", thisPdpId);
686 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
688 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
689 logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
690 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
691 assertTrue(droolsPdpEntity.isDesignated() == true);
694 * When the Standby Status changes (from providingservice) to hotstandby
695 * or coldstandby,the Active/Standby selection algorithm must stand down
696 * if thePDP-D is currently the lead/active node and allow another PDP-D
699 * It must also call lock on all engines in the engine management.
704 * Yes, this is kludgy, but we have a chicken and egg problem here: we
705 * need a StateManagement object to invoke the
706 * deleteAllStateManagementEntities method.
708 logger.debug("testColdStandby: Instantiating stateManagement object");
710 StateManagement sm = new StateManagement(emfx, "dummy");
711 sm.deleteAllStateManagementEntities();
713 // Now we want to create a StateManagementFeature and initialize it. It will be
714 // discovered by the ActiveStandbyFeature when the election handler initializes.
716 StateManagementFeatureApi smf = null;
717 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
718 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
720 logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", smf.getResourceName());
725 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
726 // that has been created.
727 ActiveStandbyFeatureApi activeStandbyFeature = null;
728 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
729 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
730 activeStandbyFeature = feature;
731 logger.debug("testColdStandby activeStandbyFeature.getResourceName(): {}",
732 activeStandbyFeature.getResourceName());
735 assertNotNull(activeStandbyFeature);
737 // Artificially putting a PDP into service is really a two step process, 1)
738 // inserting it as designated and 2) promoting it so that its standbyStatus
739 // is providing service.
741 logger.debug("testColdStandby: Runner started; Sleeping "
742 + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP= {}",
744 sleep(INTERRUPT_RECOVERY_TIME);
746 logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
749 String standbyStatus = sm.getStandbyStatus(thisPdpId);
750 logger.debug("testColdStandby: Before locking, PDP= {} has standbyStatus= {}",
751 thisPdpId, standbyStatus);
753 logger.debug("testColdStandby: Locking smf");
756 sleep(INTERRUPT_RECOVERY_TIME);
758 // Verify that the PDP is no longer designated.
760 droolsPdpEntity = conn.getPdp(thisPdpId);
761 logger.debug("testColdStandby: After lock sm.lock() invoked, "
762 + "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId);
763 assertTrue(droolsPdpEntity.isDesignated() == false);
765 logger.debug("\n\ntestColdStandby: Exiting\n\n");
768 // Tests hot standby when there is only one PDP.
771 * Test hot standby 1.
773 * @throws Exception exception
776 public void testHotStandby1() throws Exception {
778 logger.debug("\n\ntestHotStandby1: Entering\n\n");
780 final String thisPdpId = activeStandbyProperties
781 .getProperty(ActiveStandbyProperties.NODE_NAME);
783 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
786 * Insert this PDP as not designated. Initial standby state will be
787 * either null or cold standby. Demoting should transit state to
791 logger.debug("testHotStandby1: Inserting PDP={} as not designated", thisPdpId);
792 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
793 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
795 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
796 logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}",
797 thisPdpId, droolsPdpEntity.isDesignated());
798 assertTrue(droolsPdpEntity.isDesignated() == false);
800 logger.debug("testHotStandby1: Instantiating stateManagement object");
801 StateManagement sm = new StateManagement(emfx, "dummy");
802 sm.deleteAllStateManagementEntities();
805 // Now we want to create a StateManagementFeature and initialize it. It will be
806 // discovered by the ActiveStandbyFeature when the election handler initializes.
808 StateManagementFeatureApi smf = null;
809 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
810 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
812 logger.debug("testHotStandby1 stateManagementFeature.getResourceName(): {}", smf.getResourceName());
817 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
818 // that has been created.
819 ActiveStandbyFeatureApi activeStandbyFeature = null;
820 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
821 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
822 activeStandbyFeature = feature;
823 logger.debug("testHotStandby1 activeStandbyFeature.getResourceName(): {}",
824 activeStandbyFeature.getResourceName());
827 assertNotNull(activeStandbyFeature);
830 logger.debug("testHotStandby1: Demoting PDP={}", thisPdpId);
831 // demoting should cause state to transit to hotstandby
835 logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
836 + "time to check droolspdpentity table", SLEEP_TIME);
840 // Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
842 droolsPdpEntity = conn.getPdp(thisPdpId);
843 logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} "
844 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
845 assertTrue(droolsPdpEntity.isDesignated() == true);
846 String standbyStatus = smf.getStandbyStatus(thisPdpId);
847 logger.debug("testHotStandby1: After demotion, PDP= {} "
848 + "has standbyStatus= {}", thisPdpId, standbyStatus);
849 assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
851 logger.debug("testHotStandby1: Stopping policyManagementRunner");
853 logger.debug("\n\ntestHotStandby1: Exiting\n\n");
857 * Tests hot standby when two PDPs are involved.
861 * Test hot standby 2.
863 * @throws Exception exception
866 public void testHotStandby2() throws Exception {
868 logger.info("\n\ntestHotStandby2: Entering\n\n");
870 final String thisPdpId = activeStandbyProperties
871 .getProperty(ActiveStandbyProperties.NODE_NAME);
873 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
876 // Insert a PDP that's designated but not current.
878 String activePdpId = "pdp2";
879 logger.info("testHotStandby2: Inserting PDP={} as stale, designated PDP", activePdpId);
880 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
881 DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
883 DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
884 logger.info("testHotStandby2: After insertion, PDP= {}, which is "
885 + "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated());
886 assertTrue(droolsPdpEntity.isDesignated() == true);
889 * Promote the designated PDP.
891 * We have a chicken and egg problem here: we need a StateManagement
892 * object to invoke the deleteAllStateManagementEntities method.
896 logger.info("testHotStandby2: Promoting PDP={}", activePdpId);
897 StateManagement sm = new StateManagement(emfx, "dummy");
898 sm.deleteAllStateManagementEntities();
901 sm = new StateManagement(emfx, activePdpId);//pdp2
903 // Artificially putting a PDP into service is really a two step process, 1)
904 // inserting it as designated and 2) promoting it so that its standbyStatus
905 // is providing service.
908 * Insert this PDP as not designated. Initial standby state will be
909 * either null or cold standby. Demoting should transit state to
914 logger.info("testHotStandby2: Inserting PDP= {} as not designated", thisPdpId);
915 pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
917 droolsPdpEntity = conn.getPdp(thisPdpId);
918 logger.info("testHotStandby2: After insertion, PDP={} "
919 + "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated());
920 assertTrue(droolsPdpEntity.isDesignated() == false);
923 // Now we want to create a StateManagementFeature and initialize it. It will be
924 // discovered by the ActiveStandbyFeature when the election handler initializes.
926 StateManagementFeatureApi sm2 = null;
927 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
928 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
930 logger.debug("testHotStandby2 stateManagementFeature.getResourceName(): {}", sm2.getResourceName());
935 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
936 // that has been created.
937 ActiveStandbyFeatureApi activeStandbyFeature = null;
938 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
939 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
940 activeStandbyFeature = feature;
941 logger.debug("testHotStandby2 activeStandbyFeature.getResourceName(): {}",
942 activeStandbyFeature.getResourceName());
945 assertNotNull(activeStandbyFeature);
947 logger.info("testHotStandby2: Runner started; Sleeping {} "
948 + "ms before promoting/demoting", INTERRUPT_RECOVERY_TIME);
949 sleep(INTERRUPT_RECOVERY_TIME);
951 logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
952 //At this point, the newly created pdp will have set the state to disabled/failed/cold standby
953 //because it is stale. So, it cannot be promoted. We need to call sm.enableNotFailed() so we
954 //can promote it and demote the other pdp - else the other pdp will just spring back to providingservice
955 sm.enableNotFailed();//pdp2
957 String standbyStatus = sm.getStandbyStatus(activePdpId);
958 logger.info("testHotStandby2: After promoting, PDP= {} has standbyStatus= {}", activePdpId, standbyStatus);
960 // demoting PDP should ensure that state transits to hotstandby
961 logger.info("testHotStandby2: Runner started; demoting PDP= {}", thisPdpId);
963 standbyStatus = sm.getStandbyStatus(thisPdpId);
964 logger.info("testHotStandby2: After demoting, PDP={} has standbyStatus= {}",thisPdpId , standbyStatus);
966 logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
967 + "time to check droolspdpentity table", SLEEP_TIME);
971 * Verify that this PDP, demoted to HOT_STANDBY, is now
972 * re-designated and providing service.
975 droolsPdpEntity = conn.getPdp(thisPdpId);
976 logger.info("testHotStandby2: After demoting PDP={}"
978 + " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId);
979 assertTrue(droolsPdpEntity.isDesignated() == true);
980 standbyStatus = sm2.getStandbyStatus(thisPdpId);
981 logger.info("testHotStandby2: After demoting PDP={}"
982 + ", PDP={} has standbyStatus= {}",
983 activePdpId, thisPdpId, standbyStatus);
984 assertTrue(standbyStatus != null
985 && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
987 logger.info("testHotStandby2: Stopping policyManagementRunner");
989 logger.info("\n\ntestHotStandby2: Exiting\n\n");
993 * 1) Inserts and designates this PDP, then verifies that startTransaction
996 * 2) Demotes PDP, and verifies that because there is only one PDP, it will
997 * be immediately re-promoted, thus allowing startTransaction to be
1000 * 3) Locks PDP and verifies that startTransaction results in
1001 * AdministrativeStateException.
1003 * 4) Unlocks PDP and verifies that startTransaction results in
1004 * StandbyStatusException.
1006 * 5) Promotes PDP and verifies that startTransaction is once again
1013 * @throws Exception exception
1016 public void testLocking1() throws Exception {
1017 logger.debug("testLocking1: Entry");
1019 final String thisPdpId = activeStandbyProperties
1020 .getProperty(ActiveStandbyProperties.NODE_NAME);
1022 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
1025 * Insert this PDP as designated. Initial standby state will be
1026 * either null or cold standby.
1029 logger.debug("testLocking1: Inserting PDP= {} as designated", thisPdpId);
1030 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
1031 conn.insertPdp(pdp);
1032 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1033 logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
1034 thisPdpId, droolsPdpEntity.isDesignated());
1035 assertTrue(droolsPdpEntity.isDesignated() == true);
1037 logger.debug("testLocking1: Instantiating stateManagement object");
1038 StateManagement smDummy = new StateManagement(emfx, "dummy");
1039 smDummy.deleteAllStateManagementEntities();
1041 // Now we want to create a StateManagementFeature and initialize it. It will be
1042 // discovered by the ActiveStandbyFeature when the election handler initializes.
1044 StateManagementFeatureApi sm = null;
1045 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
1046 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1048 logger.debug("testLocking1 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1053 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1054 // that has been created.
1055 ActiveStandbyFeatureApi activeStandbyFeature = null;
1056 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
1057 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1058 activeStandbyFeature = feature;
1059 logger.debug("testLocking1 activeStandbyFeature.getResourceName(): {}",
1060 activeStandbyFeature.getResourceName());
1063 assertNotNull(activeStandbyFeature);
1065 logger.debug("testLocking1: Runner started; Sleeping "
1066 + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP={}",
1068 sleep(INTERRUPT_RECOVERY_TIME);
1070 logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
1073 logger.debug("testLocking1: Sleeping {} ms, to allow time for "
1074 + "policy-management.Main class to come up, designated= {}",
1075 SLEEP_TIME, conn.getPdp(thisPdpId).isDesignated());
1078 logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
1079 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1082 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1084 droolsPdpIntegrityMonitor.startTransaction();
1085 droolsPdpIntegrityMonitor.endTransaction();
1086 logger.debug("testLocking1: As expected, transaction successful");
1087 } catch (AdministrativeStateException e) {
1088 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1090 } catch (StandbyStatusException e) {
1091 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1093 } catch (Exception e) {
1094 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1098 // demoting should cause state to transit to hotstandby, followed by re-promotion,
1099 // since there is only one PDP.
1100 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1103 logger.debug("testLocking1: sleeping" + ELECTION_WAIT_SLEEP_TIME
1104 + " to allow election handler to re-promote PDP={}", thisPdpId);
1105 sleep(ELECTION_WAIT_SLEEP_TIME);
1107 logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
1108 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1110 droolsPdpIntegrityMonitor.startTransaction();
1111 droolsPdpIntegrityMonitor.endTransaction();
1112 logger.debug("testLocking1: As expected, transaction successful");
1113 } catch (AdministrativeStateException e) {
1114 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1116 } catch (StandbyStatusException e) {
1117 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1119 } catch (Exception e) {
1120 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1124 // locking should cause state to transit to cold standby
1125 logger.debug("testLocking1: locking PDP={}", thisPdpId);
1128 // Just to avoid any race conditions, sleep a little after locking
1129 logger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
1132 logger.debug("testLocking1: Invoking startTransaction on locked PDP= {}"
1133 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1135 droolsPdpIntegrityMonitor.startTransaction();
1136 logger.error("testLocking1: startTransaction unexpectedly successful");
1138 } catch (AdministrativeStateException e) {
1139 logger.debug("testLocking1: As expected, caught AdministrativeStateException, ", e);
1140 } catch (StandbyStatusException e) {
1141 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1143 } catch (Exception e) {
1144 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1147 droolsPdpIntegrityMonitor.endTransaction();
1150 // unlocking should cause state to transit to hot standby and then providing service
1151 logger.debug("testLocking1: unlocking PDP={}", thisPdpId);
1154 // Just to avoid any race conditions, sleep a little after locking
1155 logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
1156 sleep(ELECTION_WAIT_SLEEP_TIME);
1158 logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
1161 + conn.getPdp(thisPdpId).isDesignated());
1163 droolsPdpIntegrityMonitor.startTransaction();
1164 logger.error("testLocking1: startTransaction successful as expected");
1165 } catch (AdministrativeStateException e) {
1166 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1168 } catch (StandbyStatusException e) {
1169 logger.debug("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1171 } catch (Exception e) {
1172 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1175 droolsPdpIntegrityMonitor.endTransaction();
1178 // demoting should cause state to transit to hot standby
1179 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1182 logger.debug("testLocking1: Invoking startTransaction on demoted PDP={}"
1183 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1185 droolsPdpIntegrityMonitor.startTransaction();
1186 droolsPdpIntegrityMonitor.endTransaction();
1187 logger.debug("testLocking1: Unexpectedly, transaction successful");
1189 } catch (AdministrativeStateException e) {
1190 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1192 } catch (StandbyStatusException e) {
1193 logger.error("testLocking1: As expected caught StandbyStatusException, ", e);
1194 } catch (Exception e) {
1195 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1199 logger.debug("\n\ntestLocking1: Exiting\n\n");
1204 * 1) Inserts and designates this PDP, then verifies that startTransaction
1207 * 2) Inserts another PDP in hotstandby.
1209 * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
1210 * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
1216 * @throws Exception exception
1219 public void testLocking2() throws Exception {
1221 logger.debug("\n\ntestLocking2: Entering\n\n");
1223 final String thisPdpId = activeStandbyProperties
1224 .getProperty(ActiveStandbyProperties.NODE_NAME);
1226 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
1229 * Insert this PDP as designated. Initial standby state will be
1230 * either null or cold standby. Demoting should transit state to
1234 logger.debug("testLocking2: Inserting PDP= {} as designated", thisPdpId);
1235 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, testTime.getDate());
1236 conn.insertPdp(pdp);
1237 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1238 logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
1239 thisPdpId, droolsPdpEntity.isDesignated());
1240 assertTrue(droolsPdpEntity.isDesignated() == true);
1242 logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId);
1243 StateManagement smDummy = new StateManagement(emfx, "dummy");
1244 smDummy.deleteAllStateManagementEntities();
1246 // Now we want to create a StateManagementFeature and initialize it. It will be
1247 // discovered by the ActiveStandbyFeature when the election handler initializes.
1249 StateManagementFeatureApi sm = null;
1250 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
1251 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1253 logger.debug("testLocking2 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1258 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1259 // that has been created.
1260 ActiveStandbyFeatureApi activeStandbyFeature = null;
1261 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
1262 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1263 activeStandbyFeature = feature;
1264 logger.debug("testLocking2 activeStandbyFeature.getResourceName(): {}",
1265 activeStandbyFeature.getResourceName());
1268 assertNotNull(activeStandbyFeature);
1271 * Insert another PDP as not designated. Initial standby state will be
1272 * either null or cold standby. Demoting should transit state to
1276 String standbyPdpId = "pdp2";
1277 logger.debug("testLocking2: Inserting PDP= {} as not designated", standbyPdpId);
1278 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
1279 pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
1280 conn.insertPdp(pdp);
1281 droolsPdpEntity = conn.getPdp(standbyPdpId);
1282 logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}",
1283 standbyPdpId, droolsPdpEntity.isDesignated());
1284 assertTrue(droolsPdpEntity.isDesignated() == false);
1286 logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId);
1287 final StateManagement sm2 = new StateManagement(emfx, standbyPdpId);
1289 logger.debug("testLocking2: Runner started; Sleeping {} ms "
1290 + "before promoting/demoting", INTERRUPT_RECOVERY_TIME);
1291 sleep(INTERRUPT_RECOVERY_TIME);
1293 logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
1296 // demoting PDP should ensure that state transits to hotstandby
1297 logger.debug("testLocking2: Demoting PDP={}", standbyPdpId);
1300 logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", SLEEP_TIME);
1303 logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
1304 + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1306 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1309 droolsPdpIntegrityMonitor.startTransaction();
1310 droolsPdpIntegrityMonitor.endTransaction();
1311 logger.debug("testLocking2: As expected, transaction successful");
1312 } catch (AdministrativeStateException e) {
1313 logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1315 } catch (StandbyStatusException e) {
1316 logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1318 } catch (Exception e) {
1319 logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1323 // demoting should cause state to transit to hotstandby followed by re-promotion.
1324 logger.debug("testLocking2: demoting PDP={}", thisPdpId);
1327 logger.debug("testLocking2: sleeping {}"
1328 + " to allow election handler to re-promote PDP={}", ELECTION_WAIT_SLEEP_TIME, thisPdpId);
1329 sleep(ELECTION_WAIT_SLEEP_TIME);
1331 logger.debug("testLocking2: Waking up and invoking startTransaction "
1332 + "on re-promoted PDP= {}, designated= {}",
1333 thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1335 droolsPdpIntegrityMonitor.startTransaction();
1336 droolsPdpIntegrityMonitor.endTransaction();
1337 logger.debug("testLocking2: As expected, transaction successful");
1338 } catch (AdministrativeStateException e) {
1339 logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1341 } catch (StandbyStatusException e) {
1342 logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1344 } catch (Exception e) {
1345 logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1349 logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId);
1350 boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated();
1351 assertTrue(standbyPdpDesignated == false);
1353 logger.debug("\n\ntestLocking2: Exiting\n\n");
1356 private static Properties loadStateManagementProperties() throws IOException {
1357 try (FileInputStream input = new FileInputStream(CONFIG_DIR + "/feature-state-management.properties")) {
1358 Properties props = new Properties();
1364 private static Properties loadActiveStandbyProperties() throws IOException {
1365 try (FileInputStream input =
1366 new FileInputStream(CONFIG_DIR + "/feature-active-standby-management.properties")) {
1367 Properties props = new Properties();
1373 private void sleep(long sleepms) throws InterruptedException {
1374 testTime.waitFor(sleepms);