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.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
31 import java.io.FileInputStream;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.List;
36 import java.util.Properties;
37 import javax.persistence.EntityManager;
38 import javax.persistence.EntityManagerFactory;
39 import javax.persistence.EntityTransaction;
40 import javax.persistence.Persistence;
41 import org.apache.commons.lang3.time.DateUtils;
42 import org.junit.AfterClass;
43 import org.junit.Before;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.onap.policy.common.im.AdministrativeStateException;
47 import org.onap.policy.common.im.IntegrityMonitor;
48 import org.onap.policy.common.im.IntegrityMonitorException;
49 import org.onap.policy.common.im.MonitorTime;
50 import org.onap.policy.common.im.StandbyStatusException;
51 import org.onap.policy.common.im.StateManagement;
52 import org.onap.policy.common.utils.time.CurrentTime;
53 import org.onap.policy.common.utils.time.PseudoTimer;
54 import org.onap.policy.common.utils.time.TestTimeMulti;
55 import org.onap.policy.drools.core.PolicySessionFeatureApi;
56 import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
57 import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
58 import org.powermock.reflect.Whitebox;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
63 * All JUnits are designed to run in the local development environment
64 * where they have write privileges and can execute time-sensitive
68 public class StandbyStateManagementTest {
69 private static final Logger logger = LoggerFactory.getLogger(StandbyStateManagementTest.class);
71 private static final String MONITOR_FIELD_NAME = "instance";
72 private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
75 * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
76 * at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
77 * to ensure that we wait for the DesignationWaiter to do its job, before
78 * checking the results. Add a few seconds for safety
81 private static final long SLEEP_TIME = 10000;
84 * DroolsPdpsElectionHandler runs every 1 seconds, so a 6 second sleep should be
85 * plenty to ensure it has time to re-promote this PDP.
88 private static final long ELECTION_WAIT_SLEEP_TIME = 6000;
91 * Sleep a few seconds after each test to allow interrupt (shutdown) recovery.
94 private static final long INTERRUPT_RECOVERY_TIME = 5000;
96 private static EntityManagerFactory emfx;
97 private static EntityManagerFactory emfd;
98 private static EntityManager emx;
99 private static EntityManager emd;
100 private static EntityTransaction et;
102 private static final String CONFIG_DIR = "src/test/resources";
104 private static CurrentTime saveTime;
105 private static Factory saveFactory;
107 private TestTimeMulti testTime;
110 * This cannot be shared by tests, as each integrity monitor may manipulate it by
111 * adding its own property values.
113 private Properties activeStandbyProperties;
116 * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
122 * @throws Exception exception
125 public static void setUpClass() throws Exception {
127 String userDir = System.getProperty("user.dir");
128 logger.debug("setUpClass: userDir={}", userDir);
129 System.setProperty("com.sun.management.jmxremote.port", "9980");
130 System.setProperty("com.sun.management.jmxremote.authenticate","false");
132 saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
133 saveFactory = Factory.getInstance();
135 resetInstanceObjects();
137 //Create the data access for xacml db
138 Properties smProps = loadStateManagementProperties();
140 emfx = Persistence.createEntityManagerFactory("junitXacmlPU", smProps);
142 // Create an entity manager to use the DB
143 emx = emfx.createEntityManager();
145 //Create the data access for drools db
146 Properties asbProps = loadActiveStandbyProperties();
148 emfd = Persistence.createEntityManagerFactory("junitDroolsPU", asbProps);
150 // Create an entity manager to use the DB
151 emd = emfd.createEntityManager();
155 * Restores the system state.
157 * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
160 public static void tearDownClass() throws IntegrityMonitorException {
161 resetInstanceObjects();
163 Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
164 Factory.setInstance(saveFactory);
176 * @throws Exception exception
179 public void setUp() throws Exception {
180 resetInstanceObjects();
187 * All threads use the test time object for sleeping. As a result, we don't have
188 * to wait more than an instant for them to complete their work, thus we'll use
189 * a very small REAL wait time in the constructor.
191 testTime = new TestTimeMulti(5);
192 Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
194 Factory factory = mock(Factory.class);
195 when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
196 Factory.setInstance(factory);
198 activeStandbyProperties = loadActiveStandbyProperties();
201 private static void resetInstanceObjects() throws IntegrityMonitorException {
202 IntegrityMonitor.setUnitTesting(true);
203 IntegrityMonitor.deleteInstance();
204 IntegrityMonitor.setUnitTesting(false);
206 Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
211 * Clean up the xacml database.
214 public void cleanXacmlDb() {
215 et = emx.getTransaction();
218 // Make sure we leave the DB clean
219 emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
220 emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
221 emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
227 * Clean up the drools db.
229 public void cleanDroolsDb() {
230 et = emd.getTransaction();
233 // Make sure we leave the DB clean
234 emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
240 * Test the standby state change notifier.
242 * @throws Exception exception
245 public void testPmStandbyStateChangeNotifier() throws Exception {
246 logger.debug("\n\ntestPmStandbyStateChangeNotifier: Entering\n\n");
248 logger.debug("testPmStandbyStateChangeNotifier: Reading activeStandbyProperties");
250 String resourceName = "testPMS";
251 activeStandbyProperties.setProperty("resource.name", resourceName);
252 ActiveStandbyProperties.initProperties(activeStandbyProperties);
254 logger.debug("testPmStandbyStateChangeNotifier: Getting StateManagement instance");
256 StateManagement sm = new StateManagement(emfx, resourceName);
258 //Create an instance of the Observer
259 PmStandbyStateChangeNotifier pmNotifier = new PmStandbyStateChangeNotifier();
261 //Register the PmStandbyStateChangeNotifier Observer
262 sm.addObserver(pmNotifier);
264 //At this point the standbystatus = 'null'
266 assertEquals(StateManagement.NULL_VALUE, pmNotifier.getPreviousStandbyStatus());
269 assertEquals(StateManagement.NULL_VALUE, pmNotifier.getPreviousStandbyStatus());
271 //Adding standbystatus=hotstandby
273 System.out.println(pmNotifier.getPreviousStandbyStatus());
274 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
275 pmNotifier.getPreviousStandbyStatus());
277 //Now making standbystatus=coldstandby
279 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
280 pmNotifier.getPreviousStandbyStatus());
282 //standbystatus = hotstandby
284 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
285 pmNotifier.getPreviousStandbyStatus());
287 //standbystatus = providingservice
289 //The previousStandbyStatus is not updated until after the delay activation expires
290 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
291 pmNotifier.getPreviousStandbyStatus());
293 //Sleep long enough for the delayActivationTimer to run
295 assertEquals(StateManagement.PROVIDING_SERVICE, pmNotifier.getPreviousStandbyStatus());
297 //standbystatus = providingservice
299 assertEquals(StateManagement.PROVIDING_SERVICE, pmNotifier.getPreviousStandbyStatus());
301 //standbystatus = coldstandby
303 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
304 pmNotifier.getPreviousStandbyStatus());
306 //standbystatus = hotstandby
308 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
309 pmNotifier.getPreviousStandbyStatus());
311 //standbystatus = hotstandby
313 assertEquals(PmStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY,
314 pmNotifier.getPreviousStandbyStatus());
318 * Test sanitize designated list.
320 * @throws Exception exception
323 public void testSanitizeDesignatedList() throws Exception {
325 logger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n");
327 // Get a DroolsPdpsConnector
329 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
331 // Create 4 pdpd all not designated
333 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
334 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
335 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
336 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
338 List<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
339 listOfDesignated.add(pdp1);
340 listOfDesignated.add(pdp2);
341 listOfDesignated.add(pdp3);
342 listOfDesignated.add(pdp4);
344 // Now we want to create a StateManagementFeature and initialize it. It will be
345 // discovered by the ActiveStandbyFeature when the election handler initializes.
347 StateManagementFeatureApi stateManagementFeature = null;
348 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
349 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
350 stateManagementFeature = feature;
351 logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}",
352 stateManagementFeature.getResourceName());
355 assertNotNull(stateManagementFeature);
358 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
360 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
362 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = {}\n\n",listOfDesignated.size());
364 assertEquals(4, listOfDesignated.size());
366 // Now make 2 designated
368 pdp1.setDesignated(true);
369 pdp2.setDesignated(true);
371 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
373 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = {}\n\n",
374 listOfDesignated.size());
376 assertEquals(2, listOfDesignated.size());
377 assertTrue(listOfDesignated.contains(pdp1));
378 assertTrue(listOfDesignated.contains(pdp2));
381 // Now all are designated. But, we have to add back the previously non-designated nodes
383 pdp3.setDesignated(true);
384 pdp4.setDesignated(true);
385 listOfDesignated.add(pdp3);
386 listOfDesignated.add(pdp4);
388 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
390 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = {}\n\n",
391 listOfDesignated.size());
393 assertEquals(4, listOfDesignated.size());
398 * Test Compute most recent primary.
400 * @throws Exception exception
403 public void testComputeMostRecentPrimary() throws Exception {
405 logger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
407 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
410 // Create 4 pdpd all not designated
413 long designatedDateMs = testTime.getMillis();
414 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
415 pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
417 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
419 pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
421 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
422 pdp3.setDesignatedDate(new Date(designatedDateMs - 1));
424 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
426 pdp4.setDesignatedDate(new Date(designatedDateMs));
428 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
429 listOfAllPdps.add(pdp1);
430 listOfAllPdps.add(pdp2);
431 listOfAllPdps.add(pdp3);
432 listOfAllPdps.add(pdp4);
435 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
436 listOfDesignated.add(pdp1);
437 listOfDesignated.add(pdp2);
438 listOfDesignated.add(pdp3);
439 listOfDesignated.add(pdp4);
441 // Because the way we sanitize the listOfDesignated, it will always contain all hot standby
442 // or all designated members.
444 // Now we want to create a StateManagementFeature and initialize it. It will be
445 // discovered by the ActiveStandbyFeature when the election handler initializes.
447 StateManagementFeatureApi stateManagementFeature = null;
448 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
449 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
450 stateManagementFeature = feature;
451 logger.debug("testComputeMostRecentPrimary stateManagementFeature.getResourceName(): {}",
452 stateManagementFeature.getResourceName());
455 assertNotNull(stateManagementFeature);
457 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
459 DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(
460 listOfAllPdps, listOfDesignated);
462 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
463 mostRecentPrimary.getPdpId());
466 // If all of the pdps are included in the listOfDesignated and none are designated, it will choose
467 // the one which has the most recent designated date.
470 assertEquals("pdp4", mostRecentPrimary.getPdpId());
473 // Now let's designate all of those on the listOfDesignated. It will choose the first one designated
476 pdp1.setDesignated(true);
477 pdp2.setDesignated(true);
478 pdp3.setDesignated(true);
479 pdp4.setDesignated(true);
481 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
483 logger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, "
484 + "mostRecentPrimary.getPdpId() = {}\n\n",
485 mostRecentPrimary.getPdpId());
488 // If all of the pdps are included in the listOfDesignated and all are designated, it will choose
489 // the one which was designated first
492 assertEquals("pdp2", mostRecentPrimary.getPdpId());
495 // Now we will designate only 2 and put just them in the listOfDesignated. The algorithm will now
496 // look for the most recently designated pdp which is not currently designated.
499 pdp3.setDesignated(false);
500 pdp4.setDesignated(false);
502 listOfDesignated.remove(pdp3);
503 listOfDesignated.remove(pdp4);
505 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
507 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n",
508 mostRecentPrimary.getPdpId());
510 assertEquals("pdp4", mostRecentPrimary.getPdpId());
514 // Now we will have none designated and put two of them in the listOfDesignated. The algorithm will now
515 // look for the most recently designated pdp regardless of whether it is currently marked as designated.
518 pdp1.setDesignated(false);
519 pdp2.setDesignated(false);
521 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
523 logger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = {}\n\n",
524 mostRecentPrimary.getPdpId());
526 assertEquals("pdp4", mostRecentPrimary.getPdpId());
529 // If we have only one pdp on in the listOfDesignated,
530 // the most recently designated pdp will be chosen, regardless
531 // of its designation status
534 listOfDesignated.remove(pdp1);
536 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
538 logger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = {}\n\n",
539 mostRecentPrimary.getPdpId());
541 assertEquals("pdp4", mostRecentPrimary.getPdpId());
544 // Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp.
547 listOfDesignated.remove(pdp2);
549 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
551 logger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = {}\n\n",
552 mostRecentPrimary.getPdpId());
554 assertEquals("pdp4", mostRecentPrimary.getPdpId());
559 * Test compute designated PDP.
561 * @throws Exception exception
564 public void testComputeDesignatedPdp() throws Exception {
566 logger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
568 final DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfd);
571 // Create 4 pdpd all not designated. Two on site1. Two on site2
574 long designatedDateMs = testTime.getMillis();
575 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
576 pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
577 pdp1.setSite("site1");
579 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
580 pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
581 pdp2.setSite("site1");
584 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
585 pdp3.setDesignatedDate(new Date(designatedDateMs - 4));
586 pdp3.setSite("site2");
588 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
590 pdp4.setDesignatedDate(new Date(designatedDateMs));
591 pdp4.setSite("site2");
593 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
594 listOfAllPdps.add(pdp1);
595 listOfAllPdps.add(pdp2);
596 listOfAllPdps.add(pdp3);
597 listOfAllPdps.add(pdp4);
600 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
603 // We will first test an empty listOfDesignated. As we know from the previous JUnit,
604 // the pdp with the most designated date will be chosen for mostRecentPrimary
606 // Now we want to create a StateManagementFeature and initialize it. It will be
607 // discovered by the ActiveStandbyFeature when the election handler initializes.
609 StateManagementFeatureApi stateManagementFeature = null;
610 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
611 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
612 stateManagementFeature = feature;
613 logger.debug("testComputeDesignatedPdp stateManagementFeature.getResourceName(): {}",
614 stateManagementFeature.getResourceName());
617 assertNotNull(stateManagementFeature);
620 DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
622 DroolsPdp mostRecentPrimary = pdp4;
624 DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
627 // The designatedPdp should be null
629 assertNull(designatedPdp);
632 // Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary
634 listOfDesignated.add(pdp2);
636 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
639 // Now the designatedPdp should be the one and only selection in the listOfDesignated
642 assertEquals(designatedPdp.getPdpId(), pdp2.getPdpId());
645 // Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary
648 listOfDesignated.add(pdp1);
650 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
653 // The designatedPdp should now be the one with the lowest lexiographic score - pdp1
656 assertEquals(designatedPdp.getPdpId(), pdp1.getPdpId());
659 // Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary
662 listOfDesignated.remove(pdp1);
663 listOfDesignated.add(pdp3);
665 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
668 // The designatedPdp should now be the one on the same site as the mostRecentPrimary
671 assertEquals(designatedPdp.getPdpId(), pdp3.getPdpId());
677 * @throws Exception exception
680 public void testColdStandby() throws Exception {
682 logger.debug("\n\ntestColdStandby: Entering\n\n");
684 final String thisPdpId = activeStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
686 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
688 logger.debug("testColdStandby: Inserting PDP={} as designated", thisPdpId);
689 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
691 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
692 logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
693 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
694 assertTrue(droolsPdpEntity.isDesignated());
697 * When the Standby Status changes (from providingservice) to hotstandby
698 * or coldstandby,the Active/Standby selection algorithm must stand down
699 * if thePDP-D is currently the lead/active node and allow another PDP-D
702 * It must also call lock on all engines in the engine management.
707 * Yes, this is kludgy, but we have a chicken and egg problem here: we
708 * need a StateManagement object to invoke the
709 * deleteAllStateManagementEntities method.
711 logger.debug("testColdStandby: Instantiating stateManagement object");
713 StateManagement sm = new StateManagement(emfx, "dummy");
714 sm.deleteAllStateManagementEntities();
716 // Now we want to create a StateManagementFeature and initialize it. It will be
717 // discovered by the ActiveStandbyFeature when the election handler initializes.
719 StateManagementFeatureApi smf = null;
720 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
721 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
723 logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", smf.getResourceName());
728 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
729 // that has been created.
730 ActiveStandbyFeatureApi activeStandbyFeature = null;
731 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
732 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
733 activeStandbyFeature = feature;
734 logger.debug("testColdStandby activeStandbyFeature.getResourceName(): {}",
735 activeStandbyFeature.getResourceName());
738 assertNotNull(activeStandbyFeature);
740 // Artificially putting a PDP into service is really a two step process, 1)
741 // inserting it as designated and 2) promoting it so that its standbyStatus
742 // is providing service.
744 logger.debug("testColdStandby: Runner started; Sleeping "
745 + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP= {}",
747 sleep(INTERRUPT_RECOVERY_TIME);
749 logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
752 String standbyStatus = sm.getStandbyStatus(thisPdpId);
753 logger.debug("testColdStandby: Before locking, PDP= {} has standbyStatus= {}",
754 thisPdpId, standbyStatus);
756 logger.debug("testColdStandby: Locking smf");
759 sleep(INTERRUPT_RECOVERY_TIME);
761 // Verify that the PDP is no longer designated.
763 droolsPdpEntity = conn.getPdp(thisPdpId);
764 logger.debug("testColdStandby: After lock sm.lock() invoked, "
765 + "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId);
766 assertFalse(droolsPdpEntity.isDesignated());
768 logger.debug("\n\ntestColdStandby: Exiting\n\n");
771 // Tests hot standby when there is only one PDP.
774 * Test hot standby 1.
776 * @throws Exception exception
779 public void testHotStandby1() throws Exception {
781 logger.debug("\n\ntestHotStandby1: Entering\n\n");
783 final String thisPdpId = activeStandbyProperties
784 .getProperty(ActiveStandbyProperties.NODE_NAME);
786 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
789 * Insert this PDP as not designated. Initial standby state will be
790 * either null or cold standby. Demoting should transit state to
794 logger.debug("testHotStandby1: Inserting PDP={} as not designated", thisPdpId);
795 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
796 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
798 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
799 logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}",
800 thisPdpId, droolsPdpEntity.isDesignated());
801 assertFalse(droolsPdpEntity.isDesignated());
803 logger.debug("testHotStandby1: Instantiating stateManagement object");
804 StateManagement sm = new StateManagement(emfx, "dummy");
805 sm.deleteAllStateManagementEntities();
808 // Now we want to create a StateManagementFeature and initialize it. It will be
809 // discovered by the ActiveStandbyFeature when the election handler initializes.
811 StateManagementFeatureApi smf = null;
812 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
813 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
815 logger.debug("testHotStandby1 stateManagementFeature.getResourceName(): {}", smf.getResourceName());
820 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
821 // that has been created.
822 ActiveStandbyFeatureApi activeStandbyFeature = null;
823 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
824 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
825 activeStandbyFeature = feature;
826 logger.debug("testHotStandby1 activeStandbyFeature.getResourceName(): {}",
827 activeStandbyFeature.getResourceName());
830 assertNotNull(activeStandbyFeature);
833 logger.debug("testHotStandby1: Demoting PDP={}", thisPdpId);
834 // demoting should cause state to transit to hotstandby
838 logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
839 + "time to check droolspdpentity table", SLEEP_TIME);
843 // Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
845 droolsPdpEntity = conn.getPdp(thisPdpId);
846 logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} "
847 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
848 assertTrue(droolsPdpEntity.isDesignated());
849 String standbyStatus = smf.getStandbyStatus(thisPdpId);
850 logger.debug("testHotStandby1: After demotion, PDP= {} "
851 + "has standbyStatus= {}", thisPdpId, standbyStatus);
852 assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
854 logger.debug("testHotStandby1: Stopping policyManagementRunner");
856 logger.debug("\n\ntestHotStandby1: Exiting\n\n");
860 * Tests hot standby when two PDPs are involved.
864 * Test hot standby 2.
866 * @throws Exception exception
869 public void testHotStandby2() throws Exception {
871 logger.info("\n\ntestHotStandby2: Entering\n\n");
873 final String thisPdpId = activeStandbyProperties
874 .getProperty(ActiveStandbyProperties.NODE_NAME);
876 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
879 // Insert a PDP that's designated but not current.
881 String activePdpId = "pdp2";
882 logger.info("testHotStandby2: Inserting PDP={} as stale, designated PDP", activePdpId);
883 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
884 DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
886 DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
887 logger.info("testHotStandby2: After insertion, PDP= {}, which is "
888 + "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated());
889 assertTrue(droolsPdpEntity.isDesignated());
892 * Promote the designated PDP.
894 * We have a chicken and egg problem here: we need a StateManagement
895 * object to invoke the deleteAllStateManagementEntities method.
899 logger.info("testHotStandby2: Promoting PDP={}", activePdpId);
900 StateManagement sm = new StateManagement(emfx, "dummy");
901 sm.deleteAllStateManagementEntities();
904 sm = new StateManagement(emfx, activePdpId);//pdp2
906 // Artificially putting a PDP into service is really a two step process, 1)
907 // inserting it as designated and 2) promoting it so that its standbyStatus
908 // is providing service.
911 * Insert this PDP as not designated. Initial standby state will be
912 * either null or cold standby. Demoting should transit state to
917 logger.info("testHotStandby2: Inserting PDP= {} as not designated", thisPdpId);
918 pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
920 droolsPdpEntity = conn.getPdp(thisPdpId);
921 logger.info("testHotStandby2: After insertion, PDP={} "
922 + "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated());
923 assertFalse(droolsPdpEntity.isDesignated());
926 // Now we want to create a StateManagementFeature and initialize it. It will be
927 // discovered by the ActiveStandbyFeature when the election handler initializes.
929 StateManagementFeatureApi sm2 = null;
930 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
931 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
933 logger.debug("testHotStandby2 stateManagementFeature.getResourceName(): {}", sm2.getResourceName());
938 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
939 // that has been created.
940 ActiveStandbyFeatureApi activeStandbyFeature = null;
941 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
942 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
943 activeStandbyFeature = feature;
944 logger.debug("testHotStandby2 activeStandbyFeature.getResourceName(): {}",
945 activeStandbyFeature.getResourceName());
948 assertNotNull(activeStandbyFeature);
950 logger.info("testHotStandby2: Runner started; Sleeping {} "
951 + "ms before promoting/demoting", INTERRUPT_RECOVERY_TIME);
952 sleep(INTERRUPT_RECOVERY_TIME);
954 logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
955 //At this point, the newly created pdp will have set the state to disabled/failed/cold standby
956 //because it is stale. So, it cannot be promoted. We need to call sm.enableNotFailed() so we
957 //can promote it and demote the other pdp - else the other pdp will just spring back to providingservice
958 sm.enableNotFailed();//pdp2
960 String standbyStatus = sm.getStandbyStatus(activePdpId);
961 logger.info("testHotStandby2: After promoting, PDP= {} has standbyStatus= {}", activePdpId, standbyStatus);
963 // demoting PDP should ensure that state transits to hotstandby
964 logger.info("testHotStandby2: Runner started; demoting PDP= {}", thisPdpId);
966 standbyStatus = sm.getStandbyStatus(thisPdpId);
967 logger.info("testHotStandby2: After demoting, PDP={} has standbyStatus= {}",thisPdpId , standbyStatus);
969 logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
970 + "time to check droolspdpentity table", SLEEP_TIME);
974 * Verify that this PDP, demoted to HOT_STANDBY, is now
975 * re-designated and providing service.
978 droolsPdpEntity = conn.getPdp(thisPdpId);
979 logger.info("testHotStandby2: After demoting PDP={}"
981 + " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId);
982 assertTrue(droolsPdpEntity.isDesignated());
983 standbyStatus = sm2.getStandbyStatus(thisPdpId);
984 logger.info("testHotStandby2: After demoting PDP={}"
985 + ", PDP={} has standbyStatus= {}",
986 activePdpId, thisPdpId, standbyStatus);
987 assertTrue(standbyStatus != null
988 && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
990 logger.info("testHotStandby2: Stopping policyManagementRunner");
992 logger.info("\n\ntestHotStandby2: Exiting\n\n");
996 * 1) Inserts and designates this PDP, then verifies that startTransaction
999 * 2) Demotes PDP, and verifies that because there is only one PDP, it will
1000 * be immediately re-promoted, thus allowing startTransaction to be
1003 * 3) Locks PDP and verifies that startTransaction results in
1004 * AdministrativeStateException.
1006 * 4) Unlocks PDP and verifies that startTransaction results in
1007 * StandbyStatusException.
1009 * 5) Promotes PDP and verifies that startTransaction is once again
1016 * @throws Exception exception
1019 public void testLocking1() throws Exception {
1020 logger.debug("testLocking1: Entry");
1022 final String thisPdpId = activeStandbyProperties
1023 .getProperty(ActiveStandbyProperties.NODE_NAME);
1025 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
1028 * Insert this PDP as designated. Initial standby state will be
1029 * either null or cold standby.
1032 logger.debug("testLocking1: Inserting PDP= {} as designated", thisPdpId);
1033 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
1034 conn.insertPdp(pdp);
1035 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1036 logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
1037 thisPdpId, droolsPdpEntity.isDesignated());
1038 assertTrue(droolsPdpEntity.isDesignated());
1040 logger.debug("testLocking1: Instantiating stateManagement object");
1041 StateManagement smDummy = new StateManagement(emfx, "dummy");
1042 smDummy.deleteAllStateManagementEntities();
1044 // Now we want to create a StateManagementFeature and initialize it. It will be
1045 // discovered by the ActiveStandbyFeature when the election handler initializes.
1047 StateManagementFeatureApi sm = null;
1048 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
1049 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1051 logger.debug("testLocking1 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1056 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1057 // that has been created.
1058 ActiveStandbyFeatureApi activeStandbyFeature = null;
1059 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
1060 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1061 activeStandbyFeature = feature;
1062 logger.debug("testLocking1 activeStandbyFeature.getResourceName(): {}",
1063 activeStandbyFeature.getResourceName());
1066 assertNotNull(activeStandbyFeature);
1068 logger.debug("testLocking1: Runner started; Sleeping "
1069 + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP={}",
1071 sleep(INTERRUPT_RECOVERY_TIME);
1073 logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
1076 logger.debug("testLocking1: Sleeping {} ms, to allow time for "
1077 + "policy-management.Main class to come up, designated= {}",
1078 SLEEP_TIME, conn.getPdp(thisPdpId).isDesignated());
1081 logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
1082 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1085 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1087 droolsPdpIntegrityMonitor.startTransaction();
1088 droolsPdpIntegrityMonitor.endTransaction();
1089 logger.debug("testLocking1: As expected, transaction successful");
1090 } catch (AdministrativeStateException e) {
1091 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1093 } catch (StandbyStatusException e) {
1094 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1096 } catch (Exception e) {
1097 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1101 // demoting should cause state to transit to hotstandby, followed by re-promotion,
1102 // since there is only one PDP.
1103 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1106 logger.debug("testLocking1: sleeping" + ELECTION_WAIT_SLEEP_TIME
1107 + " to allow election handler to re-promote PDP={}", thisPdpId);
1108 sleep(ELECTION_WAIT_SLEEP_TIME);
1110 logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
1111 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1113 droolsPdpIntegrityMonitor.startTransaction();
1114 droolsPdpIntegrityMonitor.endTransaction();
1115 logger.debug("testLocking1: As expected, transaction successful");
1116 } catch (AdministrativeStateException e) {
1117 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1119 } catch (StandbyStatusException e) {
1120 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1122 } catch (Exception e) {
1123 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1127 // locking should cause state to transit to cold standby
1128 logger.debug("testLocking1: locking PDP={}", thisPdpId);
1131 // Just to avoid any race conditions, sleep a little after locking
1132 logger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
1135 logger.debug("testLocking1: Invoking startTransaction on locked PDP= {}"
1136 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1138 droolsPdpIntegrityMonitor.startTransaction();
1139 logger.error("testLocking1: startTransaction unexpectedly successful");
1141 } catch (AdministrativeStateException e) {
1142 logger.debug("testLocking1: As expected, caught AdministrativeStateException, ", e);
1143 } catch (StandbyStatusException e) {
1144 logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1146 } catch (Exception e) {
1147 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1150 droolsPdpIntegrityMonitor.endTransaction();
1153 // unlocking should cause state to transit to hot standby and then providing service
1154 logger.debug("testLocking1: unlocking PDP={}", thisPdpId);
1157 // Just to avoid any race conditions, sleep a little after locking
1158 logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
1159 sleep(ELECTION_WAIT_SLEEP_TIME);
1161 logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
1164 + conn.getPdp(thisPdpId).isDesignated());
1166 droolsPdpIntegrityMonitor.startTransaction();
1167 logger.error("testLocking1: startTransaction successful as expected");
1168 } catch (AdministrativeStateException e) {
1169 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1171 } catch (StandbyStatusException e) {
1172 logger.debug("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1174 } catch (Exception e) {
1175 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1178 droolsPdpIntegrityMonitor.endTransaction();
1181 // demoting should cause state to transit to hot standby
1182 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1185 logger.debug("testLocking1: Invoking startTransaction on demoted PDP={}"
1186 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1188 droolsPdpIntegrityMonitor.startTransaction();
1189 droolsPdpIntegrityMonitor.endTransaction();
1190 logger.debug("testLocking1: Unexpectedly, transaction successful");
1192 } catch (AdministrativeStateException e) {
1193 logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1195 } catch (StandbyStatusException e) {
1196 logger.error("testLocking1: As expected caught StandbyStatusException, ", e);
1197 } catch (Exception e) {
1198 logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1202 logger.debug("\n\ntestLocking1: Exiting\n\n");
1207 * 1) Inserts and designates this PDP, then verifies that startTransaction
1210 * 2) Inserts another PDP in hotstandby.
1212 * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
1213 * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
1219 * @throws Exception exception
1222 public void testLocking2() throws Exception {
1224 logger.debug("\n\ntestLocking2: Entering\n\n");
1226 final String thisPdpId = activeStandbyProperties
1227 .getProperty(ActiveStandbyProperties.NODE_NAME);
1229 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfd);
1232 * Insert this PDP as designated. Initial standby state will be
1233 * either null or cold standby. Demoting should transit state to
1237 logger.debug("testLocking2: Inserting PDP= {} as designated", thisPdpId);
1238 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, testTime.getDate());
1239 conn.insertPdp(pdp);
1240 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1241 logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
1242 thisPdpId, droolsPdpEntity.isDesignated());
1243 assertTrue(droolsPdpEntity.isDesignated());
1245 logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId);
1246 StateManagement smDummy = new StateManagement(emfx, "dummy");
1247 smDummy.deleteAllStateManagementEntities();
1249 // Now we want to create a StateManagementFeature and initialize it. It will be
1250 // discovered by the ActiveStandbyFeature when the election handler initializes.
1252 StateManagementFeatureApi sm = null;
1253 for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
1254 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1256 logger.debug("testLocking2 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1261 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1262 // that has been created.
1263 ActiveStandbyFeatureApi activeStandbyFeature = null;
1264 for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
1265 ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
1266 activeStandbyFeature = feature;
1267 logger.debug("testLocking2 activeStandbyFeature.getResourceName(): {}",
1268 activeStandbyFeature.getResourceName());
1271 assertNotNull(activeStandbyFeature);
1274 * Insert another PDP as not designated. Initial standby state will be
1275 * either null or cold standby. Demoting should transit state to
1279 String standbyPdpId = "pdp2";
1280 logger.debug("testLocking2: Inserting PDP= {} as not designated", standbyPdpId);
1281 Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
1282 pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
1283 conn.insertPdp(pdp);
1284 droolsPdpEntity = conn.getPdp(standbyPdpId);
1285 logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}",
1286 standbyPdpId, droolsPdpEntity.isDesignated());
1287 assertFalse(droolsPdpEntity.isDesignated());
1289 logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId);
1290 final StateManagement sm2 = new StateManagement(emfx, standbyPdpId);
1292 logger.debug("testLocking2: Runner started; Sleeping {} ms "
1293 + "before promoting/demoting", INTERRUPT_RECOVERY_TIME);
1294 sleep(INTERRUPT_RECOVERY_TIME);
1296 logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
1299 // demoting PDP should ensure that state transits to hotstandby
1300 logger.debug("testLocking2: Demoting PDP={}", standbyPdpId);
1303 logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", SLEEP_TIME);
1306 logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
1307 + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1309 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1312 droolsPdpIntegrityMonitor.startTransaction();
1313 droolsPdpIntegrityMonitor.endTransaction();
1314 logger.debug("testLocking2: As expected, transaction successful");
1315 } catch (AdministrativeStateException e) {
1316 logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1318 } catch (StandbyStatusException e) {
1319 logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1321 } catch (Exception e) {
1322 logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1326 // demoting should cause state to transit to hotstandby followed by re-promotion.
1327 logger.debug("testLocking2: demoting PDP={}", thisPdpId);
1330 logger.debug("testLocking2: sleeping {}"
1331 + " to allow election handler to re-promote PDP={}", ELECTION_WAIT_SLEEP_TIME, thisPdpId);
1332 sleep(ELECTION_WAIT_SLEEP_TIME);
1334 logger.debug("testLocking2: Waking up and invoking startTransaction "
1335 + "on re-promoted PDP= {}, designated= {}",
1336 thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1338 droolsPdpIntegrityMonitor.startTransaction();
1339 droolsPdpIntegrityMonitor.endTransaction();
1340 logger.debug("testLocking2: As expected, transaction successful");
1341 } catch (AdministrativeStateException e) {
1342 logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1344 } catch (StandbyStatusException e) {
1345 logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1347 } catch (Exception e) {
1348 logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1352 logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId);
1353 assertFalse(conn.getPdp(standbyPdpId).isDesignated());
1355 logger.debug("\n\ntestLocking2: Exiting\n\n");
1358 private static Properties loadStateManagementProperties() throws IOException {
1359 try (FileInputStream input = new FileInputStream(CONFIG_DIR + "/feature-state-management.properties")) {
1360 Properties props = new Properties();
1366 private static Properties loadActiveStandbyProperties() throws IOException {
1367 try (FileInputStream input =
1368 new FileInputStream(CONFIG_DIR + "/feature-active-standby-management.properties")) {
1369 Properties props = new Properties();
1375 private void sleep(long sleepms) throws InterruptedException {
1376 testTime.waitFor(sleepms);