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