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.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.Date;
33 import java.util.List;
34 import java.util.Properties;
35 import javax.persistence.EntityManager;
36 import javax.persistence.EntityManagerFactory;
37 import javax.persistence.EntityTransaction;
38 import javax.persistence.Persistence;
39 import org.apache.commons.lang3.time.DateUtils;
40 import org.junit.AfterClass;
41 import org.junit.Before;
42 import org.junit.BeforeClass;
43 import org.junit.Test;
44 import org.onap.policy.common.im.AdministrativeStateException;
45 import org.onap.policy.common.im.IntegrityMonitor;
46 import org.onap.policy.common.im.IntegrityMonitorException;
47 import org.onap.policy.common.im.MonitorTime;
48 import org.onap.policy.common.im.StandbyStatusException;
49 import org.onap.policy.common.im.StateManagement;
50 import org.onap.policy.common.utils.time.CurrentTime;
51 import org.onap.policy.common.utils.time.PseudoTimer;
52 import org.onap.policy.common.utils.time.TestTimeMulti;
53 import org.onap.policy.drools.core.PolicySessionFeatureApi;
54 import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
55 import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
56 import org.powermock.reflect.Whitebox;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
61 * All JUnits are designed to run in the local development environment
62 * where they have write privileges and can execute time-sensitive
66 public class StandbyStateManagementTest {
67 private static final Logger logger = LoggerFactory.getLogger(StandbyStateManagementTest.class);
69 private static final String MONITOR_FIELD_NAME = "instance";
70 private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
73 * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
74 * at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
75 * to ensure that we wait for the DesignationWaiter to do its job, before
76 * checking the results. Add a few seconds for safety
79 private static final long SLEEP_TIME = 10000;
82 * DroolsPdpsElectionHandler runs every 1 seconds, so a 6 second sleep should be
83 * plenty to ensure it has time to re-promote this PDP.
86 private static final long ELECTION_WAIT_SLEEP_TIME = 6000;
89 * Sleep a few seconds after each test to allow interrupt (shutdown) recovery.
92 private static final long INTERRUPT_RECOVERY_TIME = 5000;
94 private static EntityManagerFactory emfx;
95 private static EntityManagerFactory emfd;
96 private static EntityManager emx;
97 private static EntityManager emd;
98 private static EntityTransaction et;
100 private static final String CONFIG_DIR = "src/test/resources";
102 private static CurrentTime saveTime;
103 private static Factory saveFactory;
105 private TestTimeMulti testTime;
108 * This cannot be shared by tests, as each integrity monitor may manipulate it by
109 * adding its own property values.
111 private Properties activeStandbyProperties;
114 * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
120 * @throws Exception exception
123 public static void setUpClass() throws Exception {
125 String userDir = System.getProperty("user.dir");
126 logger.debug("setUpClass: userDir={}", userDir);
127 System.setProperty("com.sun.management.jmxremote.port", "9980");
128 System.setProperty("com.sun.management.jmxremote.authenticate","false");
130 saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
131 saveFactory = Factory.getInstance();
133 resetInstanceObjects();
135 //Create the data access for xacml db
136 Properties smProps = loadStateManagementProperties();
138 emfx = Persistence.createEntityManagerFactory("junitXacmlPU", smProps);
140 // Create an entity manager to use the DB
141 emx = emfx.createEntityManager();
143 //Create the data access for drools db
144 Properties asbProps = loadActiveStandbyProperties();
146 emfd = Persistence.createEntityManagerFactory("junitDroolsPU", asbProps);
148 // Create an entity manager to use the DB
149 emd = emfd.createEntityManager();
153 * Restores the system state.
155 * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
158 public static void tearDownClass() throws IntegrityMonitorException {
159 resetInstanceObjects();
161 Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
162 Factory.setInstance(saveFactory);
174 * @throws Exception exception
177 public void setUp() throws Exception {
178 resetInstanceObjects();
185 * All threads use the test time object for sleeping. As a result, we don't have
186 * to wait more than an instant for them to complete their work, thus we'll use
187 * a very small REAL wait time in the constructor.
189 testTime = new TestTimeMulti(5);
190 Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
192 Factory factory = mock(Factory.class);
193 when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
194 Factory.setInstance(factory);
196 activeStandbyProperties = loadActiveStandbyProperties();
199 private static void resetInstanceObjects() throws IntegrityMonitorException {
200 IntegrityMonitor.setUnitTesting(true);
201 IntegrityMonitor.deleteInstance();
202 IntegrityMonitor.setUnitTesting(false);
204 Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
209 * Clean up the xacml database.
212 public void cleanXacmlDb() {
213 et = emx.getTransaction();
216 // Make sure we leave the DB clean
217 emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
218 emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
219 emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
225 * Clean up the drools db.
227 public void cleanDroolsDb() {
228 et = emd.getTransaction();
231 // Make sure we leave the DB clean
232 emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
238 * Test the standby state change notifier.
240 * @throws Exception exception
243 public void testPmStandbyStateChangeNotifier() throws Exception {
244 logger.debug("\n\ntestPmStandbyStateChangeNotifier: Entering\n\n");
246 logger.debug("testPmStandbyStateChangeNotifier: Reading activeStandbyProperties");
248 String resourceName = "testPMS";
249 activeStandbyProperties.setProperty("resource.name", resourceName);
250 ActiveStandbyProperties.initProperties(activeStandbyProperties);
252 logger.debug("testPmStandbyStateChangeNotifier: Getting StateManagement instance");
254 StateManagement sm = new StateManagement(emfx, resourceName);
256 //Create an instance of the Observer
257 PmStandbyStateChangeNotifier pmNotifier = new PmStandbyStateChangeNotifier();
259 //Register the PmStandbyStateChangeNotifier Observer
260 sm.addObserver(pmNotifier);
262 //At this point the standbystatus = 'null'
264 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.NULL_VALUE));
267 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.NULL_VALUE));
269 //Adding standbystatus=hotstandby
271 System.out.println(pmNotifier.getPreviousStandbyStatus());
272 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
273 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
275 //Now making standbystatus=coldstandby
277 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
278 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
280 //standbystatus = hotstandby
282 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
283 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
285 //standbystatus = providingservice
287 //The previousStandbyStatus is not updated until after the delay activation expires
288 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
289 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
291 //Sleep long enough for the delayActivationTimer to run
293 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
295 //standbystatus = providingservice
297 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
299 //standbystatus = coldstandby
301 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
302 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
304 //standbystatus = hotstandby
306 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
307 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
309 //standbystatus = hotstandby
311 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(
312 PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
316 * Test sanitize designated list.
318 * @throws Exception exception
321 public void testSanitizeDesignatedList() throws Exception {
323 logger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n");
325 // Get a DroolsPdpsConnector
327 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
329 // Create 4 pdpd all not designated
331 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
332 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
333 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
334 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
336 List<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
337 listOfDesignated.add(pdp1);
338 listOfDesignated.add(pdp2);
339 listOfDesignated.add(pdp3);
340 listOfDesignated.add(pdp4);
342 // Now we want to create a StateManagementFeature and initialize it. It will be
343 // discovered by the ActiveStandbyFeature when the election handler initializes.
345 StateManagementFeatureApi stateManagementFeature = null;
346 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
347 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
348 stateManagementFeature = feature;
349 logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}",
350 stateManagementFeature.getResourceName());
353 assertNotNull(stateManagementFeature);
356 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
358 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
360 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = {}\n\n",listOfDesignated.size());
362 assertTrue(listOfDesignated.size() == 4);
364 // Now make 2 designated
366 pdp1.setDesignated(true);
367 pdp2.setDesignated(true);
369 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
371 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = {}\n\n",
372 listOfDesignated.size());
374 assertTrue(listOfDesignated.size() == 2);
375 assertTrue(listOfDesignated.contains(pdp1));
376 assertTrue(listOfDesignated.contains(pdp2));
379 // Now all are designated. But, we have to add back the previously non-designated nodes
381 pdp3.setDesignated(true);
382 pdp4.setDesignated(true);
383 listOfDesignated.add(pdp3);
384 listOfDesignated.add(pdp4);
386 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
388 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = {}\n\n",
389 listOfDesignated.size());
391 assertTrue(listOfDesignated.size() == 4);
396 * Test Compute most recent primary.
398 * @throws Exception exception
401 public void testComputeMostRecentPrimary() throws Exception {
403 logger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
405 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
408 // Create 4 pdpd all not designated
411 long designatedDateMs = testTime.getMillis();
412 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
413 pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
415 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
417 pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
419 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
420 pdp3.setDesignatedDate(new Date(designatedDateMs - 1));
422 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
424 pdp4.setDesignatedDate(new Date(designatedDateMs));
426 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
427 listOfAllPdps.add(pdp1);
428 listOfAllPdps.add(pdp2);
429 listOfAllPdps.add(pdp3);
430 listOfAllPdps.add(pdp4);
433 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
434 listOfDesignated.add(pdp1);
435 listOfDesignated.add(pdp2);
436 listOfDesignated.add(pdp3);
437 listOfDesignated.add(pdp4);
439 // Because the way we sanitize the listOfDesignated, it will always contain all hot standby
440 // or all designated members.
442 // Now we want to create a StateManagementFeature and initialize it. It will be
443 // discovered by the ActiveStandbyFeature when the election handler initializes.
445 StateManagementFeatureApi stateManagementFeature = null;
446 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
447 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
448 stateManagementFeature = feature;
449 logger.debug("testComputeMostRecentPrimary stateManagementFeature.getResourceName(): {}",
450 stateManagementFeature.getResourceName());
453 assertNotNull(stateManagementFeature);
455 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
457 DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(
458 listOfAllPdps, listOfDesignated);
460 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
461 mostRecentPrimary.getPdpId());
464 // If all of the pdps are included in the listOfDesignated and none are designated, it will choose
465 // the one which has the most recent designated date.
468 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
471 // Now let's designate all of those on the listOfDesignated. It will choose the first one designated
474 pdp1.setDesignated(true);
475 pdp2.setDesignated(true);
476 pdp3.setDesignated(true);
477 pdp4.setDesignated(true);
479 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
481 logger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, "
482 + "mostRecentPrimary.getPdpId() = {}\n\n",
483 mostRecentPrimary.getPdpId());
486 // If all of the pdps are included in the listOfDesignated and all are designated, it will choose
487 // the one which was designated first
490 assertTrue(mostRecentPrimary.getPdpId().equals("pdp2"));
493 // Now we will designate only 2 and put just them in the listOfDesignated. The algorithm will now
494 // look for the most recently designated pdp which is not currently designated.
497 pdp3.setDesignated(false);
498 pdp4.setDesignated(false);
500 listOfDesignated.remove(pdp3);
501 listOfDesignated.remove(pdp4);
503 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
505 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
506 mostRecentPrimary.getPdpId());
508 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
512 // Now we will have none designated and put two of them in the listOfDesignated. The algorithm will now
513 // look for the most recently designated pdp regardless of whether it is currently marked as designated.
516 pdp1.setDesignated(false);
517 pdp2.setDesignated(false);
519 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
521 logger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = {}\n\n",
522 mostRecentPrimary.getPdpId());
524 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
527 // If we have only one pdp on in the listOfDesignated,
528 // the most recently designated pdp will be chosen, regardless
529 // of its designation status
532 listOfDesignated.remove(pdp1);
534 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
536 logger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = {}\n\n",
537 mostRecentPrimary.getPdpId());
539 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
542 // Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp.
545 listOfDesignated.remove(pdp2);
547 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
549 logger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = {}\n\n",
550 mostRecentPrimary.getPdpId());
552 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
557 * Test compute designated PDP.
559 * @throws Exception exception
562 public void testComputeDesignatedPdp() throws Exception {
564 logger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
566 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
569 // Create 4 pdpd all not designated. Two on site1. Two on site2
572 long designatedDateMs = testTime.getMillis();
573 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
574 pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
575 pdp1.setSite("site1");
577 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
578 pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
579 pdp2.setSite("site1");
582 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
583 pdp3.setDesignatedDate(new Date(designatedDateMs - 4));
584 pdp3.setSite("site2");
586 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
588 pdp4.setDesignatedDate(new Date(designatedDateMs));
589 pdp4.setSite("site2");
591 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
592 listOfAllPdps.add(pdp1);
593 listOfAllPdps.add(pdp2);
594 listOfAllPdps.add(pdp3);
595 listOfAllPdps.add(pdp4);
598 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
601 // We will first test an empty listOfDesignated. As we know from the previous JUnit,
602 // the pdp with the most designated date will be chosen for mostRecentPrimary
604 // Now we want to create a StateManagementFeature and initialize it. It will be
605 // discovered by the ActiveStandbyFeature when the election handler initializes.
607 StateManagementFeatureApi stateManagementFeature = null;
608 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
609 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
610 stateManagementFeature = feature;
611 logger.debug("testComputeDesignatedPdp stateManagementFeature.getResourceName(): {}",
612 stateManagementFeature.getResourceName());
615 assertNotNull(stateManagementFeature);
618 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
620 DroolsPdp mostRecentPrimary = pdp4;
622 DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
625 // The designatedPdp should be null
627 assertTrue(designatedPdp == null);
630 // Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary
632 listOfDesignated.add(pdp2);
634 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
637 // Now the designatedPdp should be the one and only selection in the listOfDesignated
640 assertTrue(designatedPdp.getPdpId().equals(pdp2.getPdpId()));
643 // Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary
646 listOfDesignated.add(pdp1);
648 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
651 // The designatedPdp should now be the one with the lowest lexiographic score - pdp1
654 assertTrue(designatedPdp.getPdpId().equals(pdp1.getPdpId()));
657 // Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary
660 listOfDesignated.remove(pdp1);
661 listOfDesignated.add(pdp3);
663 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
666 // The designatedPdp should now be the one on the same site as the mostRecentPrimary
669 assertTrue(designatedPdp.getPdpId().equals(pdp3.getPdpId()));
675 * @throws Exception exception
678 public void testColdStandby() throws Exception {
680 logger.debug("\n\ntestColdStandby: Entering\n\n");
682 final String thisPdpId = activeStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
684 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
686 logger.debug("testColdStandby: Inserting PDP={} as designated", thisPdpId);
687 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
689 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
690 logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
691 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
692 assertTrue(droolsPdpEntity.isDesignated());
695 * When the Standby Status changes (from providingservice) to hotstandby
696 * or coldstandby,the Active/Standby selection algorithm must stand down
697 * if thePDP-D is currently the lead/active node and allow another PDP-D
700 * It must also call lock on all engines in the engine management.
705 * Yes, this is kludgy, but we have a chicken and egg problem here: we
706 * need a StateManagement object to invoke the
707 * deleteAllStateManagementEntities method.
709 logger.debug("testColdStandby: Instantiating stateManagement object");
711 StateManagement sm = new StateManagement(emfx, "dummy");
712 sm.deleteAllStateManagementEntities();
714 // Now we want to create a StateManagementFeature and initialize it. It will be
715 // discovered by the ActiveStandbyFeature when the election handler initializes.
717 StateManagementFeatureApi smf = null;
718 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
719 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
721 logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", smf.getResourceName());
726 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
727 // that has been created.
728 ActiveStandbyFeatureApi activeStandbyFeature = null;
729 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
730 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
731 activeStandbyFeature = feature;
732 logger.debug("testColdStandby activeStandbyFeature.getResourceName(): {}",
733 activeStandbyFeature.getResourceName());
736 assertNotNull(activeStandbyFeature);
738 // Artificially putting a PDP into service is really a two step process, 1)
739 // inserting it as designated and 2) promoting it so that its standbyStatus
740 // is providing service.
742 logger.debug("testColdStandby: Runner started; Sleeping "
743 + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP= {}",
745 sleep(INTERRUPT_RECOVERY_TIME);
747 logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
750 String standbyStatus = sm.getStandbyStatus(thisPdpId);
751 logger.debug("testColdStandby: Before locking, PDP= {} has standbyStatus= {}",
752 thisPdpId, standbyStatus);
754 logger.debug("testColdStandby: Locking smf");
757 sleep(INTERRUPT_RECOVERY_TIME);
759 // Verify that the PDP is no longer designated.
761 droolsPdpEntity = conn.getPdp(thisPdpId);
762 logger.debug("testColdStandby: After lock sm.lock() invoked, "
763 + "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId);
764 assertFalse(droolsPdpEntity.isDesignated());
766 logger.debug("\n\ntestColdStandby: Exiting\n\n");
769 // Tests hot standby when there is only one PDP.
772 * Test hot standby 1.
774 * @throws Exception exception
777 public void testHotStandby1() throws Exception {
779 logger.debug("\n\ntestHotStandby1: Entering\n\n");
781 final String thisPdpId = activeStandbyProperties
782 .getProperty(ActiveStandbyProperties.NODE_NAME);
784 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
787 * Insert this PDP as not designated. Initial standby state will be
788 * either null or cold standby. Demoting should transit state to
792 logger.debug("testHotStandby1: Inserting PDP={} as not designated", thisPdpId);
793 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
794 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
796 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
797 logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}",
798 thisPdpId, droolsPdpEntity.isDesignated());
799 assertFalse(droolsPdpEntity.isDesignated());
801 logger.debug("testHotStandby1: Instantiating stateManagement object");
802 StateManagement sm = new StateManagement(emfx, "dummy");
803 sm.deleteAllStateManagementEntities();
806 // Now we want to create a StateManagementFeature and initialize it. It will be
807 // discovered by the ActiveStandbyFeature when the election handler initializes.
809 StateManagementFeatureApi smf = null;
810 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
811 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
813 logger.debug("testHotStandby1 stateManagementFeature.getResourceName(): {}", smf.getResourceName());
818 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
819 // that has been created.
820 ActiveStandbyFeatureApi activeStandbyFeature = null;
821 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
822 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
823 activeStandbyFeature = feature;
824 logger.debug("testHotStandby1 activeStandbyFeature.getResourceName(): {}",
825 activeStandbyFeature.getResourceName());
828 assertNotNull(activeStandbyFeature);
831 logger.debug("testHotStandby1: Demoting PDP={}", thisPdpId);
832 // demoting should cause state to transit to hotstandby
836 logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
837 + "time to check droolspdpentity table", SLEEP_TIME);
841 // Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
843 droolsPdpEntity = conn.getPdp(thisPdpId);
844 logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} "
845 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
846 assertTrue(droolsPdpEntity.isDesignated());
847 String standbyStatus = smf.getStandbyStatus(thisPdpId);
848 logger.debug("testHotStandby1: After demotion, PDP= {} "
849 + "has standbyStatus= {}", thisPdpId, standbyStatus);
850 assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
852 logger.debug("testHotStandby1: Stopping policyManagementRunner");
854 logger.debug("\n\ntestHotStandby1: Exiting\n\n");
858 * Tests hot standby when two PDPs are involved.
862 * Test hot standby 2.
864 * @throws Exception exception
867 public void testHotStandby2() throws Exception {
869 logger.info("\n\ntestHotStandby2: Entering\n\n");
871 final String thisPdpId = activeStandbyProperties
872 .getProperty(ActiveStandbyProperties.NODE_NAME);
874 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
877 // Insert a PDP that's designated but not current.
879 String activePdpId = "pdp2";
880 logger.info("testHotStandby2: Inserting PDP={} as stale, designated PDP", activePdpId);
881 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
882 DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
884 DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
885 logger.info("testHotStandby2: After insertion, PDP= {}, which is "
886 + "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated());
887 assertTrue(droolsPdpEntity.isDesignated());
890 * Promote the designated PDP.
892 * We have a chicken and egg problem here: we need a StateManagement
893 * object to invoke the deleteAllStateManagementEntities method.
897 logger.info("testHotStandby2: Promoting PDP={}", activePdpId);
898 StateManagement sm = new StateManagement(emfx, "dummy");
899 sm.deleteAllStateManagementEntities();
902 sm = new StateManagement(emfx, activePdpId);//pdp2
904 // Artificially putting a PDP into service is really a two step process, 1)
905 // inserting it as designated and 2) promoting it so that its standbyStatus
906 // is providing service.
909 * Insert this PDP as not designated. Initial standby state will be
910 * either null or cold standby. Demoting should transit state to
915 logger.info("testHotStandby2: Inserting PDP= {} as not designated", thisPdpId);
916 pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
918 droolsPdpEntity = conn.getPdp(thisPdpId);
919 logger.info("testHotStandby2: After insertion, PDP={} "
920 + "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated());
921 assertFalse(droolsPdpEntity.isDesignated());
924 // Now we want to create a StateManagementFeature and initialize it. It will be
925 // discovered by the ActiveStandbyFeature when the election handler initializes.
927 StateManagementFeatureApi sm2 = null;
928 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
929 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
931 logger.debug("testHotStandby2 stateManagementFeature.getResourceName(): {}", sm2.getResourceName());
936 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
937 // that has been created.
938 ActiveStandbyFeatureApi activeStandbyFeature = null;
939 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
940 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
941 activeStandbyFeature = feature;
942 logger.debug("testHotStandby2 activeStandbyFeature.getResourceName(): {}",
943 activeStandbyFeature.getResourceName());
946 assertNotNull(activeStandbyFeature);
948 logger.info("testHotStandby2: Runner started; Sleeping {} "
949 + "ms before promoting/demoting", INTERRUPT_RECOVERY_TIME);
950 sleep(INTERRUPT_RECOVERY_TIME);
952 logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
953 //At this point, the newly created pdp will have set the state to disabled/failed/cold standby
954 //because it is stale. So, it cannot be promoted. We need to call sm.enableNotFailed() so we
955 //can promote it and demote the other pdp - else the other pdp will just spring back to providingservice
956 sm.enableNotFailed();//pdp2
958 String standbyStatus = sm.getStandbyStatus(activePdpId);
959 logger.info("testHotStandby2: After promoting, PDP= {} has standbyStatus= {}", activePdpId, standbyStatus);
961 // demoting PDP should ensure that state transits to hotstandby
962 logger.info("testHotStandby2: Runner started; demoting PDP= {}", thisPdpId);
964 standbyStatus = sm.getStandbyStatus(thisPdpId);
965 logger.info("testHotStandby2: After demoting, PDP={} has standbyStatus= {}",thisPdpId , standbyStatus);
967 logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
968 + "time to check droolspdpentity table", SLEEP_TIME);
972 * Verify that this PDP, demoted to HOT_STANDBY, is now
973 * re-designated and providing service.
976 droolsPdpEntity = conn.getPdp(thisPdpId);
977 logger.info("testHotStandby2: After demoting PDP={}"
979 + " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId);
980 assertTrue(droolsPdpEntity.isDesignated());
981 standbyStatus = sm2.getStandbyStatus(thisPdpId);
982 logger.info("testHotStandby2: After demoting PDP={}"
983 + ", PDP={} has standbyStatus= {}",
984 activePdpId, thisPdpId, standbyStatus);
985 assertTrue(standbyStatus != null
986 && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
988 logger.info("testHotStandby2: Stopping policyManagementRunner");
990 logger.info("\n\ntestHotStandby2: Exiting\n\n");
994 * 1) Inserts and designates this PDP, then verifies that startTransaction
997 * 2) Demotes PDP, and verifies that because there is only one PDP, it will
998 * be immediately re-promoted, thus allowing startTransaction to be
1001 * 3) Locks PDP and verifies that startTransaction results in
1002 * AdministrativeStateException.
1004 * 4) Unlocks PDP and verifies that startTransaction results in
1005 * StandbyStatusException.
1007 * 5) Promotes PDP and verifies that startTransaction is once again
1014 * @throws Exception exception
1017 public void testLocking1() throws Exception {
1018 logger.debug("testLocking1: Entry");
1020 final String thisPdpId = activeStandbyProperties
1021 .getProperty(ActiveStandbyProperties.NODE_NAME);
1023 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
1026 * Insert this PDP as designated. Initial standby state will be
1027 * either null or cold standby.
1030 logger.debug("testLocking1: Inserting PDP= {} as designated", thisPdpId);
1031 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
1032 conn.insertPdp(pdp);
1033 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1034 logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
1035 thisPdpId, droolsPdpEntity.isDesignated());
1036 assertTrue(droolsPdpEntity.isDesignated());
1038 logger.debug("testLocking1: Instantiating stateManagement object");
1039 StateManagement smDummy = new StateManagement(emfx, "dummy");
1040 smDummy.deleteAllStateManagementEntities();
1042 // Now we want to create a StateManagementFeature and initialize it. It will be
1043 // discovered by the ActiveStandbyFeature when the election handler initializes.
1045 StateManagementFeatureApi sm = null;
1046 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
1047 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1049 logger.debug("testLocking1 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1054 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1055 // that has been created.
1056 ActiveStandbyFeatureApi activeStandbyFeature = null;
1057 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
1058 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1059 activeStandbyFeature = feature;
1060 logger.debug("testLocking1 activeStandbyFeature.getResourceName(): {}",
1061 activeStandbyFeature.getResourceName());
1064 assertNotNull(activeStandbyFeature);
1066 logger.debug("testLocking1: Runner started; Sleeping "
1067 + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP={}",
1069 sleep(INTERRUPT_RECOVERY_TIME);
1071 logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
1074 logger.debug("testLocking1: Sleeping {} ms, to allow time for "
1075 + "policy-management.Main class to come up, designated= {}",
1076 SLEEP_TIME, conn.getPdp(thisPdpId).isDesignated());
1079 logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
1080 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1083 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1085 droolsPdpIntegrityMonitor.startTransaction();
1086 droolsPdpIntegrityMonitor.endTransaction();
1087 logger.debug("testLocking1: As expected, transaction successful");
1088 } catch (AdministrativeStateException e) {
1089 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1091 } catch (StandbyStatusException e) {
1092 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1094 } catch (Exception e) {
1095 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1099 // demoting should cause state to transit to hotstandby, followed by re-promotion,
1100 // since there is only one PDP.
1101 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1104 logger.debug("testLocking1: sleeping" + ELECTION_WAIT_SLEEP_TIME
1105 + " to allow election handler to re-promote PDP={}", thisPdpId);
1106 sleep(ELECTION_WAIT_SLEEP_TIME);
1108 logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
1109 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1111 droolsPdpIntegrityMonitor.startTransaction();
1112 droolsPdpIntegrityMonitor.endTransaction();
1113 logger.debug("testLocking1: As expected, transaction successful");
1114 } catch (AdministrativeStateException e) {
1115 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1117 } catch (StandbyStatusException e) {
1118 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1120 } catch (Exception e) {
1121 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1125 // locking should cause state to transit to cold standby
1126 logger.debug("testLocking1: locking PDP={}", thisPdpId);
1129 // Just to avoid any race conditions, sleep a little after locking
1130 logger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
1133 logger.debug("testLocking1: Invoking startTransaction on locked PDP= {}"
1134 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1136 droolsPdpIntegrityMonitor.startTransaction();
1137 logger.error("testLocking1: startTransaction unexpectedly successful");
1139 } catch (AdministrativeStateException e) {
1140 logger.debug("testLocking1: As expected, caught AdministrativeStateException, ", e);
1141 } catch (StandbyStatusException e) {
1142 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1144 } catch (Exception e) {
1145 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1148 droolsPdpIntegrityMonitor.endTransaction();
1151 // unlocking should cause state to transit to hot standby and then providing service
1152 logger.debug("testLocking1: unlocking PDP={}", thisPdpId);
1155 // Just to avoid any race conditions, sleep a little after locking
1156 logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
1157 sleep(ELECTION_WAIT_SLEEP_TIME);
1159 logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
1162 + conn.getPdp(thisPdpId).isDesignated());
1164 droolsPdpIntegrityMonitor.startTransaction();
1165 logger.error("testLocking1: startTransaction successful as expected");
1166 } catch (AdministrativeStateException e) {
1167 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1169 } catch (StandbyStatusException e) {
1170 logger.debug("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1172 } catch (Exception e) {
1173 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1176 droolsPdpIntegrityMonitor.endTransaction();
1179 // demoting should cause state to transit to hot standby
1180 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1183 logger.debug("testLocking1: Invoking startTransaction on demoted PDP={}"
1184 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1186 droolsPdpIntegrityMonitor.startTransaction();
1187 droolsPdpIntegrityMonitor.endTransaction();
1188 logger.debug("testLocking1: Unexpectedly, transaction successful");
1190 } catch (AdministrativeStateException e) {
1191 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1193 } catch (StandbyStatusException e) {
1194 logger.error("testLocking1: As expected caught StandbyStatusException, ", e);
1195 } catch (Exception e) {
1196 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1200 logger.debug("\n\ntestLocking1: Exiting\n\n");
1205 * 1) Inserts and designates this PDP, then verifies that startTransaction
1208 * 2) Inserts another PDP in hotstandby.
1210 * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
1211 * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
1217 * @throws Exception exception
1220 public void testLocking2() throws Exception {
1222 logger.debug("\n\ntestLocking2: Entering\n\n");
1224 final String thisPdpId = activeStandbyProperties
1225 .getProperty(ActiveStandbyProperties.NODE_NAME);
1227 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
1230 * Insert this PDP as designated. Initial standby state will be
1231 * either null or cold standby. Demoting should transit state to
1235 logger.debug("testLocking2: Inserting PDP= {} as designated", thisPdpId);
1236 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, testTime.getDate());
1237 conn.insertPdp(pdp);
1238 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1239 logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
1240 thisPdpId, droolsPdpEntity.isDesignated());
1241 assertTrue(droolsPdpEntity.isDesignated());
1243 logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId);
1244 StateManagement smDummy = new StateManagement(emfx, "dummy");
1245 smDummy.deleteAllStateManagementEntities();
1247 // Now we want to create a StateManagementFeature and initialize it. It will be
1248 // discovered by the ActiveStandbyFeature when the election handler initializes.
1250 StateManagementFeatureApi sm = null;
1251 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
1252 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1254 logger.debug("testLocking2 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1259 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1260 // that has been created.
1261 ActiveStandbyFeatureApi activeStandbyFeature = null;
1262 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
1263 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1264 activeStandbyFeature = feature;
1265 logger.debug("testLocking2 activeStandbyFeature.getResourceName(): {}",
1266 activeStandbyFeature.getResourceName());
1269 assertNotNull(activeStandbyFeature);
1272 * Insert another PDP as not designated. Initial standby state will be
1273 * either null or cold standby. Demoting should transit state to
1277 String standbyPdpId = "pdp2";
1278 logger.debug("testLocking2: Inserting PDP= {} as not designated", standbyPdpId);
1279 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
1280 pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
1281 conn.insertPdp(pdp);
1282 droolsPdpEntity = conn.getPdp(standbyPdpId);
1283 logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}",
1284 standbyPdpId, droolsPdpEntity.isDesignated());
1285 assertFalse(droolsPdpEntity.isDesignated());
1287 logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId);
1288 final StateManagement sm2 = new StateManagement(emfx, standbyPdpId);
1290 logger.debug("testLocking2: Runner started; Sleeping {} ms "
1291 + "before promoting/demoting", INTERRUPT_RECOVERY_TIME);
1292 sleep(INTERRUPT_RECOVERY_TIME);
1294 logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
1297 // demoting PDP should ensure that state transits to hotstandby
1298 logger.debug("testLocking2: Demoting PDP={}", standbyPdpId);
1301 logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", SLEEP_TIME);
1304 logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
1305 + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1307 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1310 droolsPdpIntegrityMonitor.startTransaction();
1311 droolsPdpIntegrityMonitor.endTransaction();
1312 logger.debug("testLocking2: As expected, transaction successful");
1313 } catch (AdministrativeStateException e) {
1314 logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1316 } catch (StandbyStatusException e) {
1317 logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1319 } catch (Exception e) {
1320 logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1324 // demoting should cause state to transit to hotstandby followed by re-promotion.
1325 logger.debug("testLocking2: demoting PDP={}", thisPdpId);
1328 logger.debug("testLocking2: sleeping {}"
1329 + " to allow election handler to re-promote PDP={}", ELECTION_WAIT_SLEEP_TIME, thisPdpId);
1330 sleep(ELECTION_WAIT_SLEEP_TIME);
1332 logger.debug("testLocking2: Waking up and invoking startTransaction "
1333 + "on re-promoted PDP= {}, designated= {}",
1334 thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1336 droolsPdpIntegrityMonitor.startTransaction();
1337 droolsPdpIntegrityMonitor.endTransaction();
1338 logger.debug("testLocking2: As expected, transaction successful");
1339 } catch (AdministrativeStateException e) {
1340 logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1342 } catch (StandbyStatusException e) {
1343 logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1345 } catch (Exception e) {
1346 logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1350 logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId);
1351 assertFalse(conn.getPdp(standbyPdpId).isDesignated());
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);