876cd99a485497b202e4aac128469e73fe97ce83
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * feature-active-standby-management
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.drools.controller.test;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.Properties;
30
31 import javax.persistence.EntityManager;
32 import javax.persistence.EntityManagerFactory;
33 import javax.persistence.EntityTransaction;
34 import javax.persistence.Persistence;
35
36 import org.apache.commons.lang3.time.DateUtils;
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.Before;
40 import org.junit.BeforeClass;
41 import org.junit.Ignore;
42 import org.junit.Test;
43 import org.onap.policy.common.im.AdministrativeStateException;
44 import org.onap.policy.common.im.IntegrityMonitor;
45 import org.onap.policy.common.im.StandbyStatusException;
46 import org.onap.policy.common.im.StateManagement;
47 import org.onap.policy.drools.activestandby.ActiveStandbyFeatureAPI;
48 import org.onap.policy.drools.activestandby.ActiveStandbyProperties;
49 import org.onap.policy.drools.activestandby.DroolsPdp;
50 import org.onap.policy.drools.activestandby.DroolsPdpEntity;
51 import org.onap.policy.drools.activestandby.DroolsPdpImpl;
52 import org.onap.policy.drools.activestandby.DroolsPdpsConnector;
53 import org.onap.policy.drools.activestandby.DroolsPdpsElectionHandler;
54 import org.onap.policy.drools.activestandby.JpaDroolsPdpsConnector;
55 import org.onap.policy.drools.activestandby.PMStandbyStateChangeNotifier;
56 import org.onap.policy.drools.core.PolicySessionFeatureAPI;
57 import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
60
61 /*
62  * All JUnits are designed to run in the local development environment
63  * where they have write privileges and can execute time-sensitive
64  * tasks.
65  * 
66  * These tests can be run as JUnits, but there is some issue with running them
67  * as part of a "mvn install" build.  Also, they take a very long time to run
68  * due to many real time breaks.  Consequently, they are marked as @Ignore and
69  * only run from the desktop.
70  */ 
71  
72 public class StandbyStateManagementTest {
73         private static final Logger  logger = LoggerFactory.getLogger(StandbyStateManagementTest.class);
74         /*
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
79          */ 
80          
81         long sleepTime = 10000;
82         
83         /*
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.
86          */
87          
88         long electionWaitSleepTime = 6000;
89         
90         /*
91          * Sleep 1 seconds after each test to allow interrupt (shutdown) recovery.
92          */
93          
94         long interruptRecoveryTime = 5000;
95         
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;
101         
102         private final String configDir = "src/test/resources";
103
104         /*
105          * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
106          */
107          
108         @BeforeClass
109         public static void setUpClass() throws Exception {
110                 
111                 String userDir = System.getProperty("user.dir");
112                 logger.debug("setUpClass: userDir={}", userDir);
113                 System.setProperty("com.sun.management.jmxremote.port", "9980");
114                 System.setProperty("com.sun.management.jmxremote.authenticate","false");
115                                 
116         }
117
118         @AfterClass
119         public static void tearDownClass() throws Exception {
120         }
121
122         @Before
123         public void setUp() throws Exception {
124                 //Create teh data access for xaml db
125                 Properties stateManagementProperties = new Properties();
126                 stateManagementProperties.load(new FileInputStream(new File(
127                                 "src/test/resources/feature-state-management.properties")));
128
129                 emfx = Persistence.createEntityManagerFactory("junitXacmlPU", stateManagementProperties);
130
131                 // Create an entity manager to use the DB
132                 emx = emfx.createEntityManager();
133                 
134                 //Create the data access for drools db
135                 Properties activeStandbyProperties = new Properties();
136                 activeStandbyProperties.load(new FileInputStream(new File(
137                                 "src/test/resources/feature-active-standby-management.properties")));
138
139                 emfd = Persistence.createEntityManagerFactory("junitDroolsPU", activeStandbyProperties);
140
141                 // Create an entity manager to use the DB
142                 emd = emfd.createEntityManager();
143         }
144
145         @After
146         public void tearDown() throws Exception {
147                                 
148         }
149         
150         public void cleanXacmlDb(){
151                 et = emx.getTransaction();
152                 
153                 et.begin();
154                 // Make sure we leave the DB clean
155                 emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
156                 emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
157                 emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
158                 emx.flush();
159                 et.commit();
160         }
161         
162         public void cleanDroolsDb(){
163                 et = emd.getTransaction();
164                 
165                 et.begin();
166                 // Make sure we leave the DB clean
167                 emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
168                 emd.flush();
169                 et.commit();
170         }
171         
172         /*
173          * These JUnit tests must be run one at a time in an eclipse environment 
174          * by right-clicking StandbyStateManagementTest and selecting 
175          * "Run As" -> "JUnit Test". 
176          * 
177          * They will run successfully when you run all of them under runAllTests(), 
178          * however, you will get all sorts of non-fatal errors in the log and on the 
179          * console that result from overlapping threads that are not terminated at the 
180          * end of each test. The problem is that the JUnit environment does not terminate 
181          * all the test threads between tests. This is true even if you break each JUnit
182          * into a separate file. Consequently, all the tests would have to be refactored 
183          * so all test object initializations are coordinated.  In other words, you 
184          * retrieve the ActiveStandbyFeature instance and other class instances only once 
185          * at the beginning of the JUnits and then reuse them throughout the tests. 
186          * Initialization of the state of the objects is pretty straight forward as it
187          * just amounts to manipulating the entries in StateManagementEntity and 
188          * DroolsPdpEntity tables. However, some thought needs to be given to how to
189          * "pause" the processing in ActiveStandbyFeature class.  I think we could "pause"
190          * it by calling globalInit() which will, I think, restart it. So long as it
191          * does not create a new instance, it will force it to go through an initialization
192          * cycle which includes a "pause" at the beginning of proecessing.  We just must
193          * be sure it does not create another instance - which may mean we need to add
194          * a factory interface instead of calling the constructor directly.
195          */
196
197         
198         //@Ignore
199         @Test
200         public void runAllTests() throws Exception {
201                 testColdStandby();
202                 testHotStandby1();
203                 testHotStandby2();
204                 testLocking1();
205                 testLocking2(); 
206                 testPMStandbyStateChangeNotifier();
207                 testSanitizeDesignatedList();
208                 testComputeMostRecentPrimary();
209                 testComputeDesignatedPdp();
210         }
211         
212         //@Ignore
213         //@Test
214         public void testPMStandbyStateChangeNotifier() throws Exception {
215                 logger.debug("\n\ntestPMStandbyStateChangeNotifier: Entering\n\n");
216                 cleanXacmlDb();
217                 
218                 logger.debug("testPMStandbyStateChangeNotifier: Reading activeStandbyProperties");
219                 
220                 Properties activeStandbyProperties = new Properties();
221                 activeStandbyProperties.load(new FileInputStream(new File(
222                                 configDir + "/feature-active-standby-management.properties")));
223                 ActiveStandbyProperties.initProperties(activeStandbyProperties);
224                 String thisPdpId = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
225                 
226                 logger.debug("testPMStandbyStateChangeNotifier: Getting StateManagementFeatureAPI");
227
228                 StateManagementFeatureAPI sm = null;
229                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
230                 {
231                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
232                         sm = feature;
233                         logger.debug("testPMStandbyStateChangeNotifier stateManagementFeature.getResourceName(): {}", sm.getResourceName());
234                         break;
235                 }
236                 if(sm == null){
237                         logger.error("testPMStandbyStateChangeNotifier failed to initialize.  "
238                                         + "Unable to get instance of StateManagementFeatureAPI "
239                                         + "with resourceID: {}", thisPdpId);
240                         logger.debug("testPMStandbyStateChangeNotifier failed to initialize.  "
241                                         + "Unable to get instance of StateManagementFeatureAPI "
242                                         + "with resourceID: {}", thisPdpId);
243                 }
244
245                 //Create an instance of the Observer
246                 PMStandbyStateChangeNotifier pmNotifier = new PMStandbyStateChangeNotifier();
247
248                 //Register the PMStandbyStateChangeNotifier Observer
249                 sm.addObserver(pmNotifier);
250         
251                 //At this point the standbystatus = 'null'
252                 sm.lock();
253                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.NULL_VALUE));
254
255                 sm.unlock();
256                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.NULL_VALUE));
257
258                 //Adding standbystatus=hotstandby
259                 sm.demote();
260                 System.out.println(pmNotifier.getPreviousStandbyStatus());
261                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
262
263                 //Now making standbystatus=coldstandby
264                 sm.lock();
265                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
266
267                 //standbystatus = hotstandby
268                 sm.unlock();
269                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
270
271                 //standbystatus = providingservice
272                 sm.promote();
273                 //The previousStandbyStatus is not updated until after the delay activation expires
274                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
275
276                 //Sleep long enough for the delayActivationTimer to run
277                 Thread.sleep(5000);
278                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
279
280                 //standbystatus = providingservice
281                 sm.promote();
282                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
283                 
284                 //standbystatus = coldstandby
285                 sm.lock();
286                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
287
288                 //standbystatus = hotstandby
289                 sm.unlock();
290                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
291
292                 //standbystatus = hotstandby
293                 sm.demote();
294                 assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
295         }
296
297         //@Ignore
298         //@Test
299         public void testSanitizeDesignatedList() throws Exception {
300
301                 logger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n");
302                 
303                 // Get a DroolsPdpsConnector
304                 
305                 logger.debug("testSanitizeDesignatedList: Reading activeStandbyProperties");
306                 Properties activeStandbyProperties = new Properties();
307                 activeStandbyProperties.load(new FileInputStream(new File(
308                                 configDir + "/feature-active-standby-management.properties")));
309                 String thisPdpId = activeStandbyProperties
310                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
311
312                 logger.debug("testSanitizeDesignatedList: Creating emfDrools");
313                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
314                                 "junitDroolsPU", activeStandbyProperties);
315                 
316                 DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools);
317                 
318                 // Create 4 pdpd all not designated
319                 
320                 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
321                 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
322                 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
323                 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
324                 
325                 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
326                 listOfDesignated.add(pdp1);
327                 listOfDesignated.add(pdp2);
328                 listOfDesignated.add(pdp3);
329                 listOfDesignated.add(pdp4);
330                 
331                 // Now we want to create a StateManagementFeature and initialize it.  It will be
332                 // discovered by the ActiveStandbyFeature when the election handler initializes.
333
334                 StateManagementFeatureAPI stateManagementFeature = null;
335                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
336                 {
337                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
338                         stateManagementFeature = feature;
339                         logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", stateManagementFeature.getResourceName());
340                         break;
341                 }
342                 if(stateManagementFeature == null){
343                         logger.error("testColdStandby failed to initialize.  "
344                                         + "Unable to get instance of StateManagementFeatureAPI "
345                                         + "with resourceID: {}", thisPdpId);
346                         logger.debug("testColdStandby failed to initialize.  "
347                                         + "Unable to get instance of StateManagementFeatureAPI "
348                                         + "with resourceID: {}", thisPdpId);
349                 }
350                 
351                 
352                 DroolsPdpsElectionHandler droolsPdpsElectionHandler =  new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
353                 
354                 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
355                 
356                 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = {}\n\n",listOfDesignated.size());
357                 
358                 assertTrue(listOfDesignated.size()==4);
359                 
360                 // Now make 2 designated
361                  
362                 pdp1.setDesignated(true);
363                 pdp2.setDesignated(true);
364                 
365                 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
366                 
367                 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = {}\n\n", listOfDesignated.size());
368                 
369                 assertTrue(listOfDesignated.size()==2);
370                 assertTrue(listOfDesignated.contains(pdp1));
371                 assertTrue(listOfDesignated.contains(pdp2));
372                 
373                 
374                 // Now all are designated.  But, we have to add back the previously non-designated nodes
375                  
376                 pdp3.setDesignated(true);
377                 pdp4.setDesignated(true);
378                 listOfDesignated.add(pdp3);
379                 listOfDesignated.add(pdp4);
380                 
381                 listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
382                 
383                 logger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = {}\n\n", listOfDesignated.size());
384                 
385                 assertTrue(listOfDesignated.size()==4);
386                 
387         }
388
389
390         //@Ignore
391         //@Test
392         public void testComputeMostRecentPrimary() throws Exception {
393
394                 logger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
395                 
396                 logger.debug("testComputeMostRecentPrimary: Reading activeStandbyProperties");
397                 Properties activeStandbyProperties = new Properties();
398                 activeStandbyProperties.load(new FileInputStream(new File(
399                                 configDir + "/feature-active-standby-management.properties")));
400                 String thisPdpId = activeStandbyProperties
401                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
402
403                 logger.debug("testComputeMostRecentPrimary: Creating emfDrools");
404                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
405                                 "junitDroolsPU", activeStandbyProperties);
406                 
407                 DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools);
408                 
409                 
410                 // Create 4 pdpd all not designated
411                  
412                  
413                 long designatedDateMS = new Date().getTime();
414                 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
415                 pdp1.setDesignatedDate(new Date(designatedDateMS - 2));
416                 
417                 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
418                 //oldest
419                 pdp2.setDesignatedDate(new Date(designatedDateMS - 3));
420                 
421                 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
422                 pdp3.setDesignatedDate(new Date(designatedDateMS - 1));
423
424                 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
425                 //most recent
426                 pdp4.setDesignatedDate(new Date(designatedDateMS));
427                 
428                 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
429                 listOfAllPdps.add(pdp1);
430                 listOfAllPdps.add(pdp2);
431                 listOfAllPdps.add(pdp3);
432                 listOfAllPdps.add(pdp4);
433                                 
434                 
435                 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
436                 listOfDesignated.add(pdp1);
437                 listOfDesignated.add(pdp2);
438                 listOfDesignated.add(pdp3);
439                 listOfDesignated.add(pdp4);
440                 
441                 // Because the way we sanitize the listOfDesignated, it will always contain all hot standby 
442                 // or all designated members.
443                  
444                 // Now we want to create a StateManagementFeature and initialize it.  It will be
445                 // discovered by the ActiveStandbyFeature when the election handler initializes.
446
447                 StateManagementFeatureAPI stateManagementFeature = null;
448                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
449                 {
450                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
451                         stateManagementFeature = feature;
452                         logger.debug("testComputeMostRecentPrimary stateManagementFeature.getResourceName(): {}", stateManagementFeature.getResourceName());
453                         break;
454                 }
455                 if(stateManagementFeature == null){
456                         logger.error("testComputeMostRecentPrimary failed to initialize.  "
457                                         + "Unable to get instance of StateManagementFeatureAPI "
458                                         + "with resourceID: {}", thisPdpId);
459                         logger.debug("testComputeMostRecentPrimary failed to initialize.  "
460                                         + "Unable to get instance of StateManagementFeatureAPI "
461                                         + "with resourceID: {}", thisPdpId);
462                 }
463                 
464                 DroolsPdpsElectionHandler droolsPdpsElectionHandler =  new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
465         
466                 DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
467                 
468                 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n", mostRecentPrimary.getPdpId());
469                 
470                 
471                 // If all of the pdps are included in the listOfDesignated and none are designated, it will choose 
472                 // the one which has the most recent designated date.
473                  
474                  
475                 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
476                 
477                 
478                 // Now let's designate all of those on the listOfDesignated.  It will choose the first one designated
479                  
480                  
481                 pdp1.setDesignated(true);
482                 pdp2.setDesignated(true);
483                 pdp3.setDesignated(true);
484                 pdp4.setDesignated(true);
485                 
486                 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
487                 
488                 logger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, mostRecentPrimary.getPdpId() = {}\n\n", mostRecentPrimary.getPdpId());
489                 
490                 
491                 // If all of the pdps are included in the listOfDesignated and all are designated, it will choose 
492                 // the one which was designated first
493                  
494                  
495                 assertTrue(mostRecentPrimary.getPdpId().equals("pdp2"));
496                 
497                 
498                 // Now we will designate only 2 and put just them in the listOfDesignated.  The algorithm will now
499                 // look for the most recently designated pdp which is not currently designated.
500                  
501                  
502                 pdp3.setDesignated(false);
503                 pdp4.setDesignated(false);
504                 
505                 listOfDesignated.remove(pdp3);
506                 listOfDesignated.remove(pdp4);
507                 
508                 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
509                 
510                 logger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = {}\n\n", mostRecentPrimary.getPdpId());
511                 
512                 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
513                 
514                 
515                 
516                 // Now we will have none designated and put two of them in the listOfDesignated.  The algorithm will now
517                 // look for the most recently designated pdp regardless of whether it is currently marked as designated.
518                  
519                  
520                 pdp1.setDesignated(false);
521                 pdp2.setDesignated(false);
522                 
523                 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
524                 
525                 logger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = {}\n\n", mostRecentPrimary.getPdpId());
526                 
527                 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
528                 
529                 
530                 // If we have only one pdp on in the listOfDesignated, the most recently designated pdp will be chosen, regardless
531                 // of its designation status
532                  
533                  
534                 listOfDesignated.remove(pdp1);
535                 
536                 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
537                 
538                 logger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = {}\n\n", mostRecentPrimary.getPdpId());
539                 
540                 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
541                 
542                 
543                 // Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp.
544                  
545                  
546                 listOfDesignated.remove(pdp2);
547
548                 mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
549                 
550                 logger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = {}\n\n", mostRecentPrimary.getPdpId());
551                 
552                 assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
553                 
554         }
555
556         //@Ignore
557         //@Test
558         public void testComputeDesignatedPdp() throws Exception{
559                 
560                 logger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
561                 
562                 logger.debug("testComputeDesignatedPdp: Reading activeStandbyProperties");
563                 Properties activeStandbyProperties = new Properties();
564                 activeStandbyProperties.load(new FileInputStream(new File(
565                                 configDir + "/feature-active-standby-management.properties")));
566                 String thisPdpId = activeStandbyProperties
567                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
568                  
569
570                 logger.debug("testComputeDesignatedPdp: Creating emfDrools");
571                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
572                                 "junitDroolsPU", activeStandbyProperties);
573                 
574                 DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools);
575                 
576                 
577                 // Create 4 pdpd all not designated.  Two on site1. Two on site2
578                  
579                  
580                 long designatedDateMS = new Date().getTime();
581                 DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
582                 pdp1.setDesignatedDate(new Date(designatedDateMS - 2));
583                 pdp1.setSiteName("site1");
584                 
585                 DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
586                 pdp2.setDesignatedDate(new Date(designatedDateMS - 3));
587                 pdp2.setSiteName("site1");
588
589                 //oldest                
590                 DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
591                 pdp3.setDesignatedDate(new Date(designatedDateMS - 4));
592                 pdp3.setSiteName("site2");
593                 
594                 DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
595                 //most recent
596                 pdp4.setDesignatedDate(new Date(designatedDateMS));
597                 pdp4.setSiteName("site2");
598                 
599                 ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
600                 listOfAllPdps.add(pdp1);
601                 listOfAllPdps.add(pdp2);
602                 listOfAllPdps.add(pdp3);
603                 listOfAllPdps.add(pdp4);
604                                 
605                 
606                 ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
607                 
608                 
609                 // We will first test an empty listOfDesignated. As we know from the previous JUnit,
610                 // the pdp with the most designated date will be chosen for mostRecentPrimary
611                 
612                 // Now we want to create a StateManagementFeature and initialize it.  It will be
613                 // discovered by the ActiveStandbyFeature when the election handler initializes.
614
615                 StateManagementFeatureAPI stateManagementFeature = null;
616                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
617                 {
618                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
619                         stateManagementFeature = feature;
620                         logger.debug("testComputeDesignatedPdp stateManagementFeature.getResourceName(): {}", stateManagementFeature.getResourceName());
621                         break;
622                 }
623                 if(stateManagementFeature == null){
624                         logger.error("testComputeDesignatedPdp failed to initialize.  "
625                                         + "Unable to get instance of StateManagementFeatureAPI "
626                                         + "with resourceID: {}", thisPdpId);
627                         logger.debug("testComputeDesignatedPdp failed to initialize.  "
628                                         + "Unable to get instance of StateManagementFeatureAPI "
629                                         + "with resourceID: {}", thisPdpId);
630                 }
631                 
632         
633                 DroolsPdpsElectionHandler droolsPdpsElectionHandler =  new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
634                 
635                 DroolsPdp mostRecentPrimary = pdp4;
636         
637                 DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
638                 
639                 
640                 // The designatedPdp should be null
641                  
642                 assertTrue(designatedPdp==null);
643                 
644                 
645                 // Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary
646                  
647                 listOfDesignated.add(pdp2);
648                 
649                 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
650                 
651                 
652                 // Now the designatedPdp should be the one and only selection in the listOfDesignated
653                  
654                  
655                 assertTrue(designatedPdp.getPdpId().equals(pdp2.getPdpId()));
656                 
657                 
658                 // Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary
659                  
660                  
661                 listOfDesignated.add(pdp1);
662                 
663                 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
664                 
665                 
666                 // The designatedPdp should now be the one with the lowest lexiographic score - pdp1
667                  
668                  
669                 assertTrue(designatedPdp.getPdpId().equals(pdp1.getPdpId()));
670                 
671                 
672                 // Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary
673                  
674                  
675                 listOfDesignated.remove(pdp1);
676                 listOfDesignated.add(pdp3);
677                 
678                 designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
679                 
680                 
681                 // The designatedPdp should now be the one on the same site as the mostRecentPrimary
682                  
683                  
684                 assertTrue(designatedPdp.getPdpId().equals(pdp3.getPdpId()));
685         }
686         
687         //@Ignore
688         //@Test
689         public void testColdStandby() throws Exception {
690
691                 logger.debug("\n\ntestColdStandby: Entering\n\n");
692                 cleanXacmlDb();
693                 cleanDroolsDb();
694
695                 logger.debug("testColdStandby: Reading stateManagementProperties");
696                 Properties stateManagementProperties = new Properties();
697                 stateManagementProperties.load(new FileInputStream(new File(
698                                 configDir + "/feature-state-management.properties")));
699                 
700                 logger.debug("testColdStandby: Creating emfXacml");
701                 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
702                                 "junitXacmlPU", stateManagementProperties);
703                 
704                 logger.debug("testColdStandby: Reading activeStandbyProperties");
705                 Properties activeStandbyProperties = new Properties();
706                 activeStandbyProperties.load(new FileInputStream(new File(
707                                 configDir + "/feature-active-standby-management.properties")));
708                 String thisPdpId = activeStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
709
710                 logger.debug("testColdStandby: Creating emfDrools");
711                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
712                                 "junitDroolsPU", activeStandbyProperties);
713                 
714                 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
715                 
716                 logger.debug("testColdStandby: Cleaning up tables");
717                 conn.deleteAllPdps();
718         
719                 logger.debug("testColdStandby: Inserting PDP={} as designated", thisPdpId);
720                 DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
721                 conn.insertPdp(pdp);
722                 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
723                 logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
724                                 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
725                 assertTrue(droolsPdpEntity.isDesignated() == true);
726
727                 /*
728                  * When the Standby Status changes (from providingservice) to hotstandby
729                  * or coldstandby,the Active/Standby selection algorithm must stand down
730                  * if thePDP-D is currently the lead/active node and allow another PDP-D
731                  * to take over.
732                  * 
733                  * It must also call lock on all engines in the engine management.
734                  */
735                 
736                 
737                 /*
738                  * Yes, this is kludgy, but we have a chicken and egg problem here: we
739                  * need a StateManagement object to invoke the
740                  * deleteAllStateManagementEntities method.
741                  */
742                 logger.debug("testColdStandby: Instantiating stateManagement object");
743                 
744                 StateManagement sm = new StateManagement(emfXacml, "dummy");
745                 sm.deleteAllStateManagementEntities();
746                         
747                 // Now we want to create a StateManagementFeature and initialize it.  It will be
748                 // discovered by the ActiveStandbyFeature when the election handler initializes.
749
750                 StateManagementFeatureAPI smf = null;
751                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
752                 {
753                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
754                         smf = feature;
755                         logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", smf.getResourceName());
756                         break;
757                 }
758                 if(smf == null){
759                         logger.error("testColdStandby failed to initialize.  "
760                                         + "Unable to get instance of StateManagementFeatureAPI "
761                                         + "with resourceID: {}", thisPdpId);
762                         logger.debug("testColdStandby failed to initialize.  "
763                                         + "Unable to get instance of StateManagementFeatureAPI "
764                                         + "with resourceID: {}", thisPdpId);
765                 }
766                 
767                 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
768                 // that has been created.
769                 ActiveStandbyFeatureAPI activeStandbyFeature = null;
770                 for (ActiveStandbyFeatureAPI feature : ActiveStandbyFeatureAPI.impl.getList())
771                 {
772                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
773                         activeStandbyFeature = feature;
774                         logger.debug("testColdStandby activeStandbyFeature.getResourceName(): {}", activeStandbyFeature.getResourceName());
775                         break;
776                 }
777                 if(activeStandbyFeature == null){
778                         logger.error("testColdStandby failed to initialize.  "
779                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
780                                         + "with resourceID:{}", thisPdpId);
781                         logger.debug("testColdStandby failed to initialize.  "
782                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
783                                         + "with resourceID:{}", thisPdpId);
784                 }
785
786                 // Artificially putting a PDP into service is really a two step process, 1)
787                 // inserting it as designated and 2) promoting it so that its standbyStatus
788                 // is providing service.
789                 
790                 logger.debug("testColdStandby: Runner started; Sleeping "
791                                 + interruptRecoveryTime + "ms before promoting PDP= {}",
792                                 thisPdpId);
793                 Thread.sleep(interruptRecoveryTime);
794
795                 logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
796                 smf.promote();          
797                 
798                 String standbyStatus = sm.getStandbyStatus(thisPdpId);
799                 logger.debug("testColdStandby: Before locking, PDP= {}  has standbyStatus= {}",
800                                  thisPdpId, standbyStatus);
801                 
802                 logger.debug("testColdStandby: Locking smf");
803                 smf.lock();
804                 
805                 Thread.sleep(interruptRecoveryTime);
806                 
807                 // Verify that the PDP is no longer designated.
808                  
809                 droolsPdpEntity = conn.getPdp(thisPdpId);
810                 logger.debug("testColdStandby: After lock sm.lock() invoked, "
811                                 + "DESIGNATED= {} for PDP={}", droolsPdpEntity.isDesignated(), thisPdpId);
812                 assertTrue(droolsPdpEntity.isDesignated() == false);
813                 
814                 logger.debug("\n\ntestColdStandby: Exiting\n\n");
815                 Thread.sleep(interruptRecoveryTime);
816
817         }
818
819         // Tests hot standby when there is only one PDP.
820          
821         //@Ignore
822         //@Test
823         public void testHotStandby1() throws Exception {
824         
825                 logger.debug("\n\ntestHotStandby1: Entering\n\n");
826                 cleanXacmlDb();
827                 cleanDroolsDb();
828                 
829                 logger.debug("testHotStandby1: Reading stateManagementProperties");
830                 Properties stateManagementProperties = new Properties();
831                 stateManagementProperties.load(new FileInputStream(new File(
832                                 configDir + "/feature-state-management.properties")));
833
834                 logger.debug("testHotStandby1: Creating emfXacml");
835                 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
836                                 "junitXacmlPU", stateManagementProperties);
837                 
838                 logger.debug("testHotStandby1: Reading activeStandbyProperties");
839                 Properties activeStandbyProperties = new Properties();
840                 activeStandbyProperties.load(new FileInputStream(new File(
841                                 configDir + "/feature-active-standby-management.properties")));
842                 String thisPdpId = activeStandbyProperties
843                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
844
845                 logger.debug("testHotStandby1: Creating emfDrools");
846                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
847                                 "junitDroolsPU", activeStandbyProperties);
848                 
849                 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
850                 
851                 logger.debug("testHotStandby1: Cleaning up tables");
852                 conn.deleteAllPdps();
853                                         
854                 /*
855                  * Insert this PDP as not designated.  Initial standby state will be 
856                  * either null or cold standby.   Demoting should transit state to
857                  * hot standby.
858                  */
859                  
860                 logger.debug("testHotStandby1: Inserting PDP={} as not designated", thisPdpId);
861                 Date yesterday = DateUtils.addDays(new Date(), -1);
862                 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
863                 conn.insertPdp(pdp);
864                 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
865                 logger.debug("testHotStandby1: After insertion, PDP={} has DESIGNATED={}",
866                                 thisPdpId, droolsPdpEntity.isDesignated());
867                 assertTrue(droolsPdpEntity.isDesignated() == false);
868                 
869                 logger.debug("testHotStandby1: Instantiating stateManagement object");
870                 StateManagement sm = new StateManagement(emfXacml, "dummy");
871                 sm.deleteAllStateManagementEntities();
872                 
873                 
874                 // Now we want to create a StateManagementFeature and initialize it.  It will be
875                 // discovered by the ActiveStandbyFeature when the election handler initializes.
876
877                 StateManagementFeatureAPI smf = null;
878                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
879                 {
880                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
881                         smf = feature;
882                         logger.debug("testHotStandby1 stateManagementFeature.getResourceName(): {}", smf.getResourceName());
883                         break;
884                 }
885                 if(smf == null){
886                         logger.error("testHotStandby1 failed to initialize.  "
887                                         + "Unable to get instance of StateManagementFeatureAPI "
888                                         + "with resourceID: {}", thisPdpId);
889                         logger.debug("testHotStandby1 failed to initialize.  "
890                                         + "Unable to get instance of StateManagementFeatureAPI "
891                                         + "with resourceID: {}", thisPdpId);
892                 }
893                 
894                 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
895                 // that has been created.
896                 ActiveStandbyFeatureAPI activeStandbyFeature = null;
897                 for (ActiveStandbyFeatureAPI feature : ActiveStandbyFeatureAPI.impl.getList())
898                 {
899                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
900                         activeStandbyFeature = feature;
901                         logger.debug("testHotStandby1 activeStandbyFeature.getResourceName(): {}", activeStandbyFeature.getResourceName());
902                         break;
903                 }
904                 if(activeStandbyFeature == null){
905                         logger.error("testHotStandby1 failed to initialize.  "
906                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
907                                         + "with resourceID: {}", thisPdpId);
908                         logger.debug("testHotStandby1 failed to initialize.  "
909                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
910                                         + "with resourceID: {}", thisPdpId);
911                 }
912                 
913
914                 logger.debug("testHotStandby1: Demoting PDP={}", thisPdpId);
915                 // demoting should cause state to transit to hotstandby
916                 smf.demote();
917                 
918                                 
919                 logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
920                                 + "time to check droolspdpentity table", sleepTime);
921                 Thread.sleep(sleepTime);
922                 
923                 
924                 // Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
925                  
926                 droolsPdpEntity = conn.getPdp(thisPdpId);
927                 logger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED= {} "
928                                 + "for PDP= {}", droolsPdpEntity.isDesignated(), thisPdpId);
929                 assertTrue(droolsPdpEntity.isDesignated() == true);
930                 String standbyStatus = smf.getStandbyStatus(thisPdpId);
931                 logger.debug("testHotStandby1: After demotion, PDP= {} "
932                                 + "has standbyStatus= {}", thisPdpId, standbyStatus);
933                 assertTrue(standbyStatus != null  &&  standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
934                                 
935                 logger.debug("testHotStandby1: Stopping policyManagementRunner");
936                 //policyManagementRunner.stopRunner();          
937         
938                 logger.debug("\n\ntestHotStandby1: Exiting\n\n");
939                 Thread.sleep(interruptRecoveryTime);
940
941         }
942
943         /*
944          * Tests hot standby when two PDPs are involved.
945          */
946                  
947         //@Ignore
948         //@Test
949         public void testHotStandby2() throws Exception {
950
951                 logger.info("\n\ntestHotStandby2: Entering\n\n");
952                 cleanXacmlDb();
953                 cleanDroolsDb();
954                 
955                 logger.info("testHotStandby2: Reading stateManagementProperties");
956                 Properties stateManagementProperties = new Properties();
957                 stateManagementProperties.load(new FileInputStream(new File(
958                                 configDir + "/feature-state-management.properties")));
959                 
960                 logger.info("testHotStandby2: Creating emfXacml");
961                 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
962                                 "junitXacmlPU", stateManagementProperties);
963                 
964                 logger.info("testHotStandby2: Reading activeStandbyProperties");
965                 Properties activeStandbyProperties = new Properties();
966                 activeStandbyProperties.load(new FileInputStream(new File(
967                                 configDir + "/feature-active-standby-management.properties")));
968                 String thisPdpId = activeStandbyProperties
969                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
970
971                 logger.info("testHotStandby2: Creating emfDrools");
972                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
973                                 "junitDroolsPU", activeStandbyProperties);
974                 
975                 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
976                 
977                 logger.info("testHotStandby2: Cleaning up tables");
978                 conn.deleteAllPdps();
979                 
980                 
981                 // Insert a PDP that's designated but not current.
982                  
983                 String activePdpId = "pdp2";
984                 logger.info("testHotStandby2: Inserting PDP={} as stale, designated PDP", activePdpId);
985                 Date yesterday = DateUtils.addDays(new Date(), -1);
986                 DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
987                 conn.insertPdp(pdp);
988                 DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
989                 logger.info("testHotStandby2: After insertion, PDP= {}, which is "
990                                 + "not current, has DESIGNATED= {}", activePdpId, droolsPdpEntity.isDesignated());
991                 assertTrue(droolsPdpEntity.isDesignated() == true);
992                 
993                 /*
994                  * Promote the designated PDP.
995                  * 
996                  * We have a chicken and egg problem here: we need a StateManagement
997                  * object to invoke the deleteAllStateManagementEntities method.
998                  */
999                  
1000                  
1001                 logger.info("testHotStandby2: Promoting PDP={}", activePdpId);
1002                 StateManagement sm = new StateManagement(emfXacml, "dummy");
1003                 sm.deleteAllStateManagementEntities();
1004                 
1005                 
1006                 sm = new StateManagement(emfXacml, activePdpId);//pdp2
1007                 
1008                 // Artificially putting a PDP into service is really a two step process, 1)
1009                 // inserting it as designated and 2) promoting it so that its standbyStatus
1010                 // is providing service.
1011                                 
1012                 /*
1013                  * Insert this PDP as not designated.  Initial standby state will be 
1014                  * either null or cold standby.   Demoting should transit state to
1015                  * hot standby.
1016                  */
1017                  
1018                  
1019                 logger.info("testHotStandby2: Inserting PDP= {} as not designated", thisPdpId);
1020                 pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
1021                 conn.insertPdp(pdp);
1022                 droolsPdpEntity = conn.getPdp(thisPdpId);
1023                 logger.info("testHotStandby2: After insertion, PDP={} "
1024                                 + "has DESIGNATED= {}", thisPdpId, droolsPdpEntity.isDesignated());
1025                 assertTrue(droolsPdpEntity.isDesignated() == false);
1026                 
1027                 
1028                 // Now we want to create a StateManagementFeature and initialize it.  It will be
1029                 // discovered by the ActiveStandbyFeature when the election handler initializes.
1030
1031                 StateManagementFeatureAPI sm2 = null;
1032                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
1033                 {
1034                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
1035                         sm2 = feature;
1036                         logger.debug("testHotStandby2 stateManagementFeature.getResourceName(): {}", sm2.getResourceName());
1037                         break;
1038                 }
1039                 if(sm2 == null){
1040                         logger.error("testHotStandby2 failed to initialize.  "
1041                                         + "Unable to get instance of StateManagementFeatureAPI "
1042                                         + "with resourceID: {}", thisPdpId);
1043                         logger.debug("testHotStandby2 failed to initialize.  "
1044                                         + "Unable to get instance of StateManagementFeatureAPI "
1045                                         + "with resourceID: {}", thisPdpId);
1046                 }
1047                 
1048                 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1049                 // that has been created.
1050                 ActiveStandbyFeatureAPI activeStandbyFeature = null;
1051                 for (ActiveStandbyFeatureAPI feature : ActiveStandbyFeatureAPI.impl.getList())
1052                 {
1053                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
1054                         activeStandbyFeature = feature;
1055                         logger.debug("testHotStandby2 activeStandbyFeature.getResourceName(): {}", activeStandbyFeature.getResourceName());
1056                         break;
1057                 }
1058                 if(activeStandbyFeature == null){
1059                         logger.error("testHotStandby2 failed to initialize.  "
1060                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
1061                                         + "with resourceID: {}", thisPdpId);
1062                         logger.debug("testHotStandby2 failed to initialize.  "
1063                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
1064                                         + "with resourceID: {}", thisPdpId);
1065                 }
1066                 
1067                 logger.info("testHotStandby2: Runner started; Sleeping {} "
1068                                 + "ms before promoting/demoting", interruptRecoveryTime);
1069                 Thread.sleep(interruptRecoveryTime);
1070
1071                 logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
1072                 //At this point, the newly created pdp will have set the state to disabled/failed/cold standby
1073                 //because it is stale. So, it cannot be promoted.  We need to call sm.enableNotFailed() so we
1074                 //can promote it and demote the other pdp - else the other pdp will just spring back to providingservice
1075                 sm.enableNotFailed();//pdp2
1076                 sm.promote();
1077                 String standbyStatus = sm.getStandbyStatus(activePdpId);
1078                 logger.info("testHotStandby2: After promoting, PDP= {} has standbyStatus= {}", activePdpId, standbyStatus);
1079                 
1080                 // demoting PDP should ensure that state transits to hotstandby
1081                 logger.info("testHotStandby2: Runner started; demoting PDP= {}", thisPdpId);
1082                 sm2.demote();//pdp1
1083                 standbyStatus = sm.getStandbyStatus(thisPdpId);
1084                 logger.info("testHotStandby2: After demoting, PDP={} has standbyStatus= {}",thisPdpId , standbyStatus);
1085                 
1086                 logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
1087                                 + "time to check droolspdpentity table", sleepTime);
1088                 Thread.sleep(sleepTime);
1089                 
1090                 /*
1091                  * Verify that this PDP, demoted to HOT_STANDBY, is now
1092                  * re-designated and providing service.
1093                  */
1094                  
1095                 droolsPdpEntity = conn.getPdp(thisPdpId);
1096                 logger.info("testHotStandby2: After demoting PDP={}"
1097                                 + ", DESIGNATED= {}"
1098                                 + " for PDP= {}", activePdpId, droolsPdpEntity.isDesignated(), thisPdpId);
1099                 assertTrue(droolsPdpEntity.isDesignated() == true);
1100                 standbyStatus = sm2.getStandbyStatus(thisPdpId);
1101                 logger.info("testHotStandby2: After demoting PDP={}"
1102                                 + ", PDP={} has standbyStatus= {}",
1103                                 activePdpId, thisPdpId, standbyStatus);
1104                 assertTrue(standbyStatus != null
1105                                 && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
1106                                 
1107                 logger.info("testHotStandby2: Stopping policyManagementRunner");
1108                 //policyManagementRunner.stopRunner();          
1109
1110                 logger.info("\n\ntestHotStandby2: Exiting\n\n");
1111                 Thread.sleep(interruptRecoveryTime);
1112
1113         }
1114         
1115          /*                     
1116          * 1) Inserts and designates this PDP, then verifies that startTransaction
1117          * is successful.
1118          * 
1119          * 2) Demotes PDP, and verifies that because there is only one PDP, it will
1120          * be immediately re-promoted, thus allowing startTransaction to be
1121          * successful.
1122          * 
1123          * 3) Locks PDP and verifies that startTransaction results in
1124          * AdministrativeStateException.
1125          * 
1126          * 4) Unlocks PDP and verifies that startTransaction results in
1127          * StandbyStatusException.
1128          * 
1129          * 5) Promotes PDP and verifies that startTransaction is once again
1130          * successful.
1131          */
1132          
1133         //@Ignore
1134         //@Test
1135         public void testLocking1() throws Exception {
1136                 logger.debug("testLocking1: Entry");
1137                 cleanXacmlDb();
1138                 cleanDroolsDb();                
1139                 
1140                 logger.debug("testLocking1: Reading stateManagementProperties");
1141                 Properties stateManagementProperties = new Properties();
1142                 stateManagementProperties.load(new FileInputStream(new File(
1143                                 configDir + "/feature-state-management.properties")));
1144
1145                 logger.debug("testLocking1: Creating emfXacml");
1146                 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
1147                                 "junitXacmlPU", stateManagementProperties);
1148                 
1149                 logger.debug("testLocking1: Reading activeStandbyProperties");
1150                 Properties activeStandbyProperties = new Properties();
1151                 activeStandbyProperties.load(new FileInputStream(new File(
1152                                 configDir + "/feature-active-standby-management.properties")));
1153                 String thisPdpId = activeStandbyProperties
1154                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
1155
1156                 logger.debug("testLocking1: Creating emfDrools");
1157                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
1158                                 "junitDroolsPU", activeStandbyProperties);
1159                 
1160                 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
1161                 
1162                 logger.debug("testLocking1: Cleaning up tables");
1163                 conn.deleteAllPdps();
1164                 
1165                 /*
1166                  * Insert this PDP as designated.  Initial standby state will be 
1167                  * either null or cold standby.
1168                  */   
1169                  
1170                 logger.debug("testLocking1: Inserting PDP= {} as designated", thisPdpId);
1171                 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
1172                 conn.insertPdp(pdp);
1173                 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1174                 logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
1175                                  thisPdpId, droolsPdpEntity.isDesignated());
1176                 assertTrue(droolsPdpEntity.isDesignated() == true);
1177                 
1178                 logger.debug("testLocking1: Instantiating stateManagement object");
1179                 StateManagement smDummy = new StateManagement(emfXacml, "dummy");
1180                 smDummy.deleteAllStateManagementEntities();
1181                 
1182                 // Now we want to create a StateManagementFeature and initialize it.  It will be
1183                 // discovered by the ActiveStandbyFeature when the election handler initializes.
1184
1185                 StateManagementFeatureAPI sm = null;
1186                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
1187                 {
1188                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
1189                         sm = feature;
1190                         logger.debug("testLocking1 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1191                         break;
1192                 }
1193                 if(sm == null){
1194                         logger.error("testLocking1 failed to initialize.  "
1195                                         + "Unable to get instance of StateManagementFeatureAPI "
1196                                         + "with resourceID: {}", thisPdpId);
1197                         logger.debug("testLocking1 failed to initialize.  "
1198                                         + "Unable to get instance of StateManagementFeatureAPI "
1199                                         + "with resourceID: {}", thisPdpId);
1200                 }
1201                 
1202                 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1203                 // that has been created.
1204                 ActiveStandbyFeatureAPI activeStandbyFeature = null;
1205                 for (ActiveStandbyFeatureAPI feature : ActiveStandbyFeatureAPI.impl.getList())
1206                 {
1207                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
1208                         activeStandbyFeature = feature;
1209                         logger.debug("testLocking1 activeStandbyFeature.getResourceName(): {}", activeStandbyFeature.getResourceName());
1210                         break;
1211                 }
1212                 if(activeStandbyFeature == null){
1213                         logger.error("testLocking1 failed to initialize.  "
1214                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
1215                                         + "with resourceID: {}", thisPdpId);
1216                         logger.debug("testLocking1 failed to initialize.  "
1217                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
1218                                         + "with resourceID: {}", thisPdpId);
1219                 }
1220                 
1221                 logger.debug("testLocking1: Runner started; Sleeping "
1222                                 + interruptRecoveryTime + "ms before promoting PDP={}",
1223                                 thisPdpId);
1224                 Thread.sleep(interruptRecoveryTime);
1225
1226                 logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
1227                 sm.promote();
1228
1229                 logger.debug("testLocking1: Sleeping {} ms, to allow time for "
1230                                 + "policy-management.Main class to come up, designated= {}", 
1231                                  sleepTime, conn.getPdp(thisPdpId).isDesignated());
1232                 Thread.sleep(sleepTime);
1233                 
1234                 logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
1235                                 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1236
1237
1238                 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1239                 try {
1240                         droolsPdpIntegrityMonitor.startTransaction();
1241                         droolsPdpIntegrityMonitor.endTransaction();
1242                         logger.debug("testLocking1: As expected, transaction successful");
1243                 } catch (AdministrativeStateException e) {
1244                         logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1245                         assertTrue(false);
1246                 } catch (StandbyStatusException e) {
1247                         logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1248                         assertTrue(false);
1249                 } catch (Exception e) {
1250                         logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1251                         assertTrue(false);
1252                 }
1253                 
1254                 // demoting should cause state to transit to hotstandby, followed by re-promotion,
1255                 // since there is only one PDP.
1256                 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1257                 sm.demote();
1258                 
1259                 logger.debug("testLocking1: sleeping" + electionWaitSleepTime
1260                                 + " to allow election handler to re-promote PDP={}", thisPdpId);
1261                 Thread.sleep(electionWaitSleepTime);
1262                                                                 
1263                 logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
1264                                 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1265                 try {
1266                         droolsPdpIntegrityMonitor.startTransaction();
1267                         droolsPdpIntegrityMonitor.endTransaction();
1268                         logger.debug("testLocking1: As expected, transaction successful");
1269                 } catch (AdministrativeStateException e) {
1270                         logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1271                         assertTrue(false);
1272                 } catch (StandbyStatusException e) {
1273                         logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1274                         assertTrue(false);
1275                 } catch (Exception e) {
1276                         logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1277                         assertTrue(false);
1278                 }
1279                 
1280                 // locking should cause state to transit to cold standby
1281                 logger.debug("testLocking1: locking PDP={}", thisPdpId);
1282                 sm.lock();
1283                 
1284                 // Just to avoid any race conditions, sleep a little after locking
1285                 logger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
1286                 Thread.sleep(100);
1287                 
1288                 logger.debug("testLocking1: Invoking startTransaction on locked PDP= {}"
1289                                 + ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1290                 try {
1291                         droolsPdpIntegrityMonitor.startTransaction();
1292                         logger.error("testLocking1: startTransaction unexpectedly successful");
1293                         assertTrue(false);
1294                 } catch (AdministrativeStateException e) {
1295                         logger.debug("testLocking1: As expected, caught AdministrativeStateException, ", e);
1296                 } catch (StandbyStatusException e) {
1297                         logger.error("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1298                         assertTrue(false);
1299                 } catch (Exception e) {
1300                         logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1301                         assertTrue(false);
1302                 } finally {
1303                         droolsPdpIntegrityMonitor.endTransaction();
1304                 }               
1305                 
1306                 // unlocking should cause state to transit to hot standby and then providing service
1307                 logger.debug("testLocking1: unlocking PDP={}", thisPdpId);
1308                 sm.unlock();
1309                 
1310                 // Just to avoid any race conditions, sleep a little after locking
1311                 logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
1312                 Thread.sleep(electionWaitSleepTime);
1313                 
1314                 logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
1315                                 + thisPdpId
1316                                 + ", designated="
1317                                 + conn.getPdp(thisPdpId).isDesignated());
1318                 try {
1319                         droolsPdpIntegrityMonitor.startTransaction();
1320                         logger.error("testLocking1: startTransaction successful as expected");
1321                 } catch (AdministrativeStateException e) {
1322                         logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1323                         assertTrue(false);
1324                 } catch (StandbyStatusException e) {
1325                         logger.debug("testLocking1: Unexpectedly caught StandbyStatusException, ", e);
1326                         assertTrue(false);
1327                 } catch (Exception e) {
1328                         logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1329                         assertTrue(false);
1330                 } finally {
1331                         droolsPdpIntegrityMonitor.endTransaction();
1332                 }
1333                 
1334                 // demoting should cause state to transit to hot standby
1335                 logger.debug("testLocking1: demoting PDP={}", thisPdpId);
1336                 sm.demote();
1337                 
1338                 // Just to avoid any race conditions, sleep a little after promoting
1339                 logger.debug("testLocking1: Sleeping a few millis after demoting, to avoid race condition");
1340                 Thread.sleep(100);
1341                 
1342                 logger.debug("testLocking1: Invoking startTransaction on demoted PDP={}"
1343                                 + ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1344                 try {
1345                         droolsPdpIntegrityMonitor.startTransaction();
1346                         droolsPdpIntegrityMonitor.endTransaction();
1347                         logger.debug("testLocking1: Unexpectedly, transaction successful");
1348                         assertTrue(false);
1349                 } catch (AdministrativeStateException e) {
1350                         logger.error("testLocking1: Unexpectedly caught AdministrativeStateException, ", e);
1351                         assertTrue(false);
1352                 } catch (StandbyStatusException e) {
1353                         logger.error("testLocking1: As expected caught StandbyStatusException, ", e);
1354                 } catch (Exception e) {
1355                         logger.error("testLocking1: Unexpectedly caught Exception, ", e);
1356                         assertTrue(false);
1357                 }
1358                 
1359                 logger.debug("\n\ntestLocking1: Exiting\n\n");
1360                 Thread.sleep(interruptRecoveryTime);
1361
1362         }
1363         
1364         
1365         /*
1366          * 1) Inserts and designates this PDP, then verifies that startTransaction
1367          * is successful.
1368          * 
1369          * 2) Inserts another PDP in hotstandby.
1370          * 
1371          * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
1372          * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
1373          */
1374          
1375         //@Ignore
1376         //@Test
1377         public void testLocking2() throws Exception {
1378
1379                 logger.debug("\n\ntestLocking2: Entering\n\n");
1380                 cleanXacmlDb();
1381                 cleanDroolsDb();                
1382                 
1383                 logger.debug("testLocking2: Reading stateManagementProperties");
1384                 Properties stateManagementProperties = new Properties();
1385                 stateManagementProperties.load(new FileInputStream(new File(
1386                                 configDir + "/feature-state-management.properties")));
1387
1388                 logger.debug("testLocking2: Creating emfXacml");
1389                 EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
1390                                 "junitXacmlPU", stateManagementProperties);
1391                 
1392                 logger.debug("testLocking2: Reading activeStandbyProperties");
1393                 Properties activeStandbyProperties = new Properties();
1394                 activeStandbyProperties.load(new FileInputStream(new File(
1395                                 configDir + "/feature-active-standby-management.properties")));
1396                 String thisPdpId = activeStandbyProperties
1397                                 .getProperty(ActiveStandbyProperties.NODE_NAME);
1398
1399                 logger.debug("testLocking2: Creating emfDrools");
1400                 EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
1401                                 "junitDroolsPU", activeStandbyProperties);
1402                 
1403                 DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
1404                 
1405                 logger.debug("testLocking2: Cleaning up tables");
1406                 conn.deleteAllPdps();
1407                 
1408                 /*
1409                  * Insert this PDP as designated.  Initial standby state will be 
1410                  * either null or cold standby.   Demoting should transit state to
1411                  * hot standby.
1412                  */
1413                  
1414                 logger.debug("testLocking2: Inserting PDP= {} as designated", thisPdpId);
1415                 DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, new Date());
1416                 conn.insertPdp(pdp);
1417                 DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
1418                 logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
1419                                 thisPdpId, droolsPdpEntity.isDesignated());
1420                 assertTrue(droolsPdpEntity.isDesignated() == true);
1421                 
1422                 logger.debug("testLocking2: Instantiating stateManagement object and promoting PDP={}", thisPdpId);
1423                 StateManagement smDummy = new StateManagement(emfXacml, "dummy");
1424                 smDummy.deleteAllStateManagementEntities();
1425                 
1426                 // Now we want to create a StateManagementFeature and initialize it.  It will be
1427                 // discovered by the ActiveStandbyFeature when the election handler initializes.
1428
1429                 StateManagementFeatureAPI sm = null;
1430                 for (StateManagementFeatureAPI feature : StateManagementFeatureAPI.impl.getList())
1431                 {
1432                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
1433                         sm = feature;
1434                         logger.debug("testLocking2 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
1435                         break;
1436                 }
1437                 if(sm == null){
1438                         logger.error("testLocking2 failed to initialize.  "
1439                                         + "Unable to get instance of StateManagementFeatureAPI "
1440                                         + "with resourceID: {}", thisPdpId);
1441                         logger.debug("testLocking2 failed to initialize.  "
1442                                         + "Unable to get instance of StateManagementFeatureAPI "
1443                                         + "with resourceID: {}", thisPdpId);
1444                 }
1445                 
1446                 // Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
1447                 // that has been created.
1448                 ActiveStandbyFeatureAPI activeStandbyFeature = null;
1449                 for (ActiveStandbyFeatureAPI feature : ActiveStandbyFeatureAPI.impl.getList())
1450                 {
1451                         ((PolicySessionFeatureAPI) feature).globalInit(null, configDir);
1452                         activeStandbyFeature = feature;
1453                         logger.debug("testLocking2 activeStandbyFeature.getResourceName(): {}", activeStandbyFeature.getResourceName());
1454                         break;
1455                 }
1456                 if(activeStandbyFeature == null){
1457                         logger.error("testLocking2 failed to initialize.  "
1458                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
1459                                         + "with resourceID: {}", thisPdpId);
1460                         logger.debug("testLocking2 failed to initialize.  "
1461                                         + "Unable to get instance of ActiveStandbyFeatureAPI "
1462                                         + "with resourceID: {}", thisPdpId);
1463                 }
1464                 
1465                 /*
1466                  * Insert another PDP as not designated.  Initial standby state will be 
1467                  * either null or cold standby.   Demoting should transit state to
1468                  * hot standby.
1469                  */
1470                  
1471                 String standbyPdpId = "pdp2";
1472                 logger.debug("testLocking2: Inserting PDP= {} as not designated", standbyPdpId);
1473                 Date yesterday = DateUtils.addDays(new Date(), -1);
1474                 pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
1475                 conn.insertPdp(pdp);
1476                 droolsPdpEntity = conn.getPdp(standbyPdpId);
1477                 logger.debug("testLocking2: After insertion, PDP={} has DESIGNATED= {}", 
1478                                  standbyPdpId, droolsPdpEntity.isDesignated());
1479                 assertTrue(droolsPdpEntity.isDesignated() == false);
1480                 
1481                 logger.debug("testLocking2: Demoting PDP= {}", standbyPdpId);
1482                 StateManagement sm2 = new StateManagement(emfXacml, standbyPdpId);
1483                                 
1484                 logger.debug("testLocking2: Runner started; Sleeping {} ms "
1485                                 + "before promoting/demoting", interruptRecoveryTime);
1486                 Thread.sleep(interruptRecoveryTime);
1487
1488                 logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
1489                 sm.promote();
1490
1491                 // demoting PDP should ensure that state transits to hotstandby
1492                 logger.debug("testLocking2: Demoting PDP={}", standbyPdpId);
1493                 sm2.demote();
1494                 
1495                 logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", sleepTime);
1496                 Thread.sleep(sleepTime);
1497                 
1498                 logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
1499                                 + ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1500
1501                 IntegrityMonitor droolsPdpIntegrityMonitor = IntegrityMonitor.getInstance();
1502
1503                 try {
1504                         droolsPdpIntegrityMonitor.startTransaction();
1505                         droolsPdpIntegrityMonitor.endTransaction();
1506                         logger.debug("testLocking2: As expected, transaction successful");
1507                 } catch (AdministrativeStateException e) {
1508                         logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1509                         assertTrue(false);
1510                 } catch (StandbyStatusException e) {
1511                         logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1512                         assertTrue(false);
1513                 } catch (Exception e) {
1514                         logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1515                         assertTrue(false);
1516                 }
1517                 
1518                 // demoting should cause state to transit to hotstandby followed by re-promotion.
1519                 logger.debug("testLocking2: demoting PDP={}", thisPdpId);
1520                 sm.demote();
1521                 
1522                 logger.debug("testLocking2: sleeping {}"
1523                                 + " to allow election handler to re-promote PDP={}", electionWaitSleepTime, thisPdpId);
1524                 Thread.sleep(electionWaitSleepTime);
1525                 
1526                 logger.debug("testLocking2: Waking up and invoking startTransaction "
1527                                 + "on re-promoted PDP= {}, designated= {}",
1528                                  thisPdpId, conn.getPdp(thisPdpId).isDesignated());
1529                 try {
1530                         droolsPdpIntegrityMonitor.startTransaction();
1531                         droolsPdpIntegrityMonitor.endTransaction();
1532                         logger.debug("testLocking2: As expected, transaction successful");
1533                 } catch (AdministrativeStateException e) {
1534                         logger.error("testLocking2: Unexpectedly caught AdministrativeStateException, ", e);
1535                         assertTrue(false);
1536                 } catch (StandbyStatusException e) {
1537                         logger.error("testLocking2: Unexpectedly caught StandbyStatusException, ", e);
1538                         assertTrue(false);
1539                 } catch (Exception e) {
1540                         logger.error("testLocking2: Unexpectedly caught Exception, ", e);
1541                         assertTrue(false);
1542                 }
1543                 
1544                 logger.debug("testLocking2: Verifying designated status for PDP= {}", standbyPdpId);
1545                 boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated();
1546                 assertTrue(standbyPdpDesignated == false);
1547
1548                 logger.debug("\n\ntestLocking2: Exiting\n\n");
1549                 Thread.sleep(interruptRecoveryTime);
1550         }
1551 }