diff options
author | Ralph Straubs <rs8887@att.com> | 2017-04-21 04:23:55 -0500 |
---|---|---|
committer | Ralph Straubs <rs8887@att.com> | 2017-04-21 05:55:16 -0500 |
commit | 5bd9ff4130799247be3be88fc02f3ce0efd014c0 (patch) | |
tree | 327ed17fae044265b08c419913290e2f9bcddcec /policy-persistence/src/test | |
parent | 8f7e5de17521836a96fa1c771a1651f63216675c (diff) |
Batch submit -- force rebuild
[ECOMPD2TD-1126 1707] Delay the start of the election handler by one
more update interval to allow updatedDate to be set and recoginized by
other nodes.
[ECOMPD2TD-1073 1707] Remove pessimistic locks from DB access to prevent
DB deadlock
[US867397-policy-management-feature-api] Split original FeatureAPI into
three service interfaces.
These are:
- the original FeatureAPI for core
- PolicyControllerFeatureAPI (additional interface methods yet to
come ..)
- PolicyEngineFeatureAPI (additional interface methods yet to come ..)
Additional extensions will be done in the future.
This is to have equivalent functionality with what it is already there.
[US867397-policy-management-feature-api] Split original FeatureAPI into
three service interfaces.
These are:
- the original FeatureAPI for core
- PolicyControllerFeatureAPI (additional interface methods yet to
come ..)
- PolicyEngineFeatureAPI (additional interface methods yet to come ..)
Additional extensions will be done in the future.
This is to have equivalent functionality with what it is already there.
[ECOMPD2TD-1167] Avoid redundant dependencies and remove obsolete sql
scripts
[ECOMPD2TD-848] Fix copied from ATT droolspdp repo -- add timestamp to
metric and audit logs
[ECOMPD2TD-1167] update jetty version to 9.3.14
[ECOMPD2TD-1167] pull in policy-core jar as a dependency of
policy-management, instead of zip file
[ECOMPD2TD-1159] Add property to ignore repository audit errors
The property is called 'repository.audit.ignore.errors' -- it resides in
'IntegrityMonitor.properties', and it defaults to 'true'. When true, any
errors that occur in the repository audit are logged, but not reported
to integrity monitor.
[US867397] additional hooks for policy engine, and support operation
take over by feature bypassing further feature processing
[US867397] additional hooks for policy engine, and support operation
take over by feature bypassing further feature processing
[US867397] fix reverse return javadoc comment
[ECOMPD2TD-1192] Select correct persistent session information
This is a modification to 'DroolsPdpsElectionHandler.DesignatedWaiter'.
When going active, the list of persistent sessions needs to come from
the most recent active DroolsPDP. The most recent active DroolsPDP is
tracked in a local variable 'mostRecentPrimary', and the associated
list of sessions needs to be extracted just prior to going active.
The problem was that the list of sessions was extracted after the
current DroolsPDP was set to 'mostRecentPrimary'.
[ECOMPD2TD-1073 1707] Remove pessimistic locks from DB access to
prevent DB deadlock
[US860546] Add workaround for missing logger in message router
[US860546] add DME2 properties to PolicyProperties
[US860546] add DME2 support, pending unit testing
[US860546] updated unit tests for dmaap/DME2
[US860546] removed System.out.println lines from BusConsumer and
BusPublisher
[US860546] modifications and additions to TopicEndpoint tests
[US860546] remove block to append /events to serviceName in
BusConsumer, BusPublisher
[US860546] removing dmaap unit tests with ATT references
[ECOMPD2TD-1167] Audit release repository by default
[ECOMPD2TD-000] Cherry-pick versioning fixes from 1707.39.1 release
branch
[ECOMPD2TD-000] Fix policy-endpoints cambriaClient version
[US865296] ECOMP Policy Logging Compliance, remove redundant timestamp
from metric and audit log for logging compliance
[US865296] ECOMP Policy Logging Compliance, remove TargetVirtualEntity
from audit log, provide name to un-used column
[US865296] ECOMP Policy Logging Compliance, remove Unused from
AuditLogPattern, leave the column blank means un-used.
[US000000] Cleanup and performance improvements
1) Changed 'OrderedServiceImpl' to ensure that the same service instance
is used in every queue. This gets around the 'ServiceLoader' behavior
that generates a new instance for each interface the service
implements.
2) In 'PolicySession': add adaptive poll times within Drools sessions.
Instead of always polling every 5 seconds, poll frequency increases
when rules fire, and decreases when they don't. At present, the
poll delay ranges from 100 milliseconds to 5 seconds, but at some
point, it would be nice to make this configurable.
3) In 'PolicySession': add tests for 'logger.isDebugEnabled()' in
session listener methods -- this results in a significant amount of
real-time savings under load.
[ECOMPD2TD-1126 1707] Changes to the election handler to deal with
situations (race conditions) which can affect the site choice
[ECOMPD2TD-1126 1707] Clean up of site afinity logic. Minor changes
and a fix of the case where all pdpd are designated or all are
hot standby.
[ECOMPD2TD-1126 1707] Fixed issue with election handler and got all
StandbyStateManagmentTest JUnits working.
[ECOMPD2TD-1126 1707] Hopefully final changes to
DroolsPdpsElectionHandler and StateManagementTest. Also removed the
ResiliencyTestCases since they were redundant.
[ECOMPD2TD-1126 1707] Found a minor bug in the computeMostRecentPrimary
algorithm which I corrected and added a JUnit to confirm.
[ECOMPD2TD-1126 1707] Removed code that was commented out of election
handler to improve reability. Added an explanatory note to
StandbyStateManagementTest.
[US869183] Convert integrity monitor test endpoint to use
HttpServletServer
[US869183] add swagger-maven-plugin, update swagger annotation for
IM test interface
[US860371] Modified existing Dmaap and Ueb code to allow for https
connectivity. HTTP/HTTPS is configurable via controller.properties file
[US860520] Removed extra useHttps() method call from BusConsumer class
where the consumer should be using http. Also, restored pom.xml to
version at time feature branch was created.
[US860520] Removed TopicEndpointTest.java.
Added the ability to configure use of self-signed certificates for
consumer topics. Functionality cannot be added for publisher at
this time.
Removed useHttps parameter field from multiple .builder methods to
allow for greater ability to build source/sink objects without
specifying http vs https connectivity.
Other code cleanup and comments
[US860520] -Deleted sys.out statements used in testing from
BusConsumer/BusPublisher
-Moved setProps method outside of if/else stub in BusConsumer
-Could not add useHttps or selfSignedCerts to toString methods in
BusConsumer
-Move setProperty(contenttype, app/json) call outside of if/else
branch in BusPublisher
-Renamed doesAllowSelfSignedCerts method to is isAllowSelfSignedCerts
and moved to BusTopicBase
-Moved allowSelfSignedCerts member variable to BusTopicBase class.
BusTopicBase is ancestor of
SingleThreadedDmapp*/SingleThreadedUeb*/SingleThreadedBus* classes
therefore, it will be inherited.
-This changed resulted in cascading changes to the subclasses of
BusTopicbase
-Default is now set to disallow self-signed certs
-Added several javadoc param annotations
[US869183 1707] Changes to satisfy dependencies and correct pom syntax
[ECOMPD2TD-1280] move DroolsPDPIntegrityMonitor.RestManager to its
own class
[ECOMPD2TD-1278] Resolve duplicate dependency issues
(cherry-pick from 1707.40.1)
[ECOMPD2TD-1278] revert cambriaClient back to 0.0.1
[ECOMPD2TD-1278] put dmaap version back to 0.2.12
[ECOMPD2TD-1280 1707] Fix Commons-lang3 version and
common-modules version
Conflicts:
policy-endpoints/pom.xml
policy-healthcheck/pom.xml
policy-persistence/pom.xml
pom.xml
Change-Id: I803554bc64c55d2e82a3d6ad9120757f287144fb
Signed-off-by: Ralph Straubs <rs8887@att.com>
Diffstat (limited to 'policy-persistence/src/test')
5 files changed, 478 insertions, 1301 deletions
diff --git a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java b/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java deleted file mode 100644 index f58d304e..00000000 --- a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java +++ /dev/null @@ -1,1267 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * policy-persistence - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.drools.controller.test; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Date; -import java.util.Properties; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.Persistence; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import org.openecomp.policy.common.logging.eelf.PolicyLogger; -import org.openecomp.policy.common.im.AdministrativeStateException; -import org.openecomp.policy.common.im.IntegrityMonitor; -import org.openecomp.policy.common.im.StandbyStatusException; -import org.openecomp.policy.common.im.StateManagement; -import org.openecomp.policy.drools.core.DroolsPDPIntegrityMonitor; -import org.openecomp.policy.drools.core.IntegrityMonitorProperties; -import org.openecomp.policy.drools.core.PolicyContainer; -import org.openecomp.policy.drools.im.PMStandbyStateChangeNotifier; -import org.openecomp.policy.drools.persistence.DroolsPdp; -import org.openecomp.policy.drools.persistence.DroolsPdpEntity; -import org.openecomp.policy.drools.persistence.DroolsPdpImpl; -import org.openecomp.policy.drools.persistence.DroolsPdpsConnector; -import org.openecomp.policy.drools.persistence.JpaDroolsPdpsConnector; -import org.openecomp.policy.drools.persistence.DroolsPersistenceProperties; -import org.openecomp.policy.drools.persistence.XacmlPersistenceProperties; -import org.openecomp.policy.drools.system.Main; -import org.openecomp.policy.drools.system.PolicyEngine; - -import org.apache.commons.lang3.time.DateUtils; - -/* - * Cloned from StandbyStateManagement.java in support of US673632. - * See MultiSite_v1-10.ppt, slide 38 - */ -public class ResiliencyTestCases { - - /* - * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every ten seconds, starting - * at ten seconds after the minute boundary (e.g. 13:05:10). So, an 80 second sleep should be - * sufficient to ensure that we wait for the DesignationWaiter to do its job, before - * checking the results. - */ - long sleepTime = 80000; - - /* - * DroolsPdpsElectionHandler runs every ten seconds, so a 15 second sleep should be - * plenty to ensure it has time to re-promote this PDP. - */ - long electionWaitSleepTime = 15000; - - /* - * Sleep 5 seconds after each test to allow interrupt (shutdown) recovery. - */ - long interruptRecoveryTime = 5000; - - /* - * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing. - */ - @BeforeClass - public static void setUpClass() throws Exception { - - String userDir = System.getProperty("user.dir"); - PolicyLogger.debug("setUpClass: userDir=" + userDir); - System.setProperty("com.sun.management.jmxremote.port", "9980"); - System.setProperty("com.sun.management.jmxremote.authenticate","false"); - - // Make sure path to config directory is set correctly in PolicyContainer.main - // Also make sure we ignore HTTP server failures resulting from port conflicts. - PolicyContainer.isUnitTesting = true; - - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - - } - - public void cleanDroolsDB() throws Exception{ - PolicyLogger.debug("\n\ncleanDroolsDB: Entering\n\n"); - - PolicyLogger.debug("cleanDroolsDB: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - - PolicyLogger.debug("cleanDroolsDB: Creating emfDrools"); - EntityManagerFactory emf = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - PolicyLogger.debug("cleanDroolsDB: Cleaning up tables"); - - EntityManager em = emf.createEntityManager(); - EntityTransaction et = em.getTransaction(); - et.begin(); - - // Make sure the DB is clean - PolicyLogger.debug("cleanDroolsDB: clean DroolsPdpEntity"); - em.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate(); - PolicyLogger.debug("cleanDroolsDB: clean DroolsSessionEntity"); - em.createQuery("DELETE FROM DroolsSessionEntity").executeUpdate(); - - em.flush(); - PolicyLogger.debug("cleanDroolsDB: after flush"); - - et.commit(); - - PolicyLogger.debug("\n\ncleanDroolsDB: Exiting\n\n"); - } - - public void cleanXacmlDB() throws Exception { - PolicyLogger.debug("\n\ncleanXacmlDB: Entering\n\n"); - - PolicyLogger.debug("cleanXacmlDB: Reading IntegrityMonitorProperties"); - - PolicyLogger.debug("cleanXacmlDB: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - - PolicyLogger.debug("cleanXacmlDB: Creating emf"); - EntityManagerFactory emf = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - EntityManager em = emf.createEntityManager(); - EntityTransaction et = em.getTransaction(); - et.begin(); - - // Make sure the DB is clean - PolicyLogger.debug("cleanXacmlDB: clean StateManagementEntity"); - em.createQuery("DELETE FROM StateManagementEntity").executeUpdate(); - PolicyLogger.debug("cleanXacmlDB: clean ResourceRegistrationEntity"); - em.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate(); - PolicyLogger.debug("cleanXacmlDB: clean ForwardProgressEntity"); - em.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate(); - - em.flush(); - PolicyLogger.debug("cleandXacmlDB: after flush"); - - et.commit(); - - PolicyLogger.debug("\n\ncleanXacmlDB: Exiting\n\n"); - - } - - @Ignore - @Test - public void singleNodeTests() throws Exception{ - //snNewInstall(); - snNewInstallBadDepData(); - /*snRecoveryFromBadDepData(); - snLock(); - snLockRestart(); - snUnlock(); - snUnlockRestart();*/ - } - - @Ignore - @Test - public void twoNodeTests() throws Exception{ - tnNewInstall(); - tnLockActive(); - tnUnlockColdStandby(); - tnFailActive(); - tnRecoverFailed(); - } - - @Ignore - @Test - public void twoSitesTwoNodesPerSiteTests() throws Exception{ - tstnNewInstall(); - tstnLock1Site1(); - tstnLock2Site1(); - tstnFailActiveSite2(); - tstnRecoverFailedSite2(); - tstnUnlockSite1(); - tstnFailSite2(); - } - - - /* - * Single Node Tests - */ - public void snNewInstall() throws Exception{ - PolicyLogger.debug("\n\nsnNewInstall: Entry\n\n"); - cleanDroolsDB(); - cleanXacmlDB(); - - //******************************************* - - PolicyLogger.debug("snNewInstall: Reading IntegrityMonitorProperties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("snNewInstall: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("snNewInstall: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("snNewInstall: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("snNewInstall: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("snNewInstall: Inserting PDP=" + thisPdpId + " as designated"); - DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date()); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("snNewInstall: After insertion, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); - - /* - * When the Standby Status changes (from providingservice) to hotstandby - * or coldstandby,the Active/Standby selection algorithm must stand down - * if thePDP-D is currently the lead/active node and allow another PDP-D - * to take over. - * - * It must also call lock on all engines in the engine management. - * - */ - PolicyLogger.debug("snNewInstall: Instantiating stateManagement object"); - StateManagement sm = new StateManagement(emfXacml, thisPdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - // Artificially putting a PDP into service is really a two step process, 1) - // inserting it as designated and 2) promoting it so that its standbyStatus - // is providing service. - - PolicyLogger.debug("snNewInstall: Running policy-management.Main class"); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("snNewInstall: Runner started; Sleeping " - + interruptRecoveryTime + "ms before promoting PDP=" - + thisPdpId); - Thread.sleep(interruptRecoveryTime); - - PolicyLogger.debug("snNewInstall: Promoting PDP=" + thisPdpId); - sm.promote(); - - String standbyStatus = sm.getStandbyStatus(thisPdpId); - PolicyLogger.debug("snNewInstall: Before locking, PDP=" + thisPdpId + " has standbyStatus=" - + standbyStatus); - - PolicyLogger.debug("snNewInstall: Locking sm"); - sm.lock(); - - Thread.sleep(interruptRecoveryTime); - /* - * Verify that the PDP is no longer designated. - */ - droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("snNewInstall: After lock sm.lock() invoked, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == false); - - PolicyLogger.debug("snNewInstall: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\nsnNewInstall: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - //******************************************** - - PolicyLogger.debug("\n\nsnNewInstall: Exit\n\n"); - } - - public void snNewInstallBadDepData() throws Exception{ - PolicyLogger.debug("\n\nsnNewInstallBadDepData: Entry\n\n"); - cleanDroolsDB(); - cleanXacmlDB(); - - //******************************************* - - PolicyLogger.debug("snNewInstallBadDepData: Reading IntegrityMonitor_BadDependencyData.properties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor_BadDependencyData.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("snNewInstallBadDepData: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("snNewInstallBadDepData: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("snNewInstallBadDepData: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("snNewInstallBadDepData: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("snNewInstallBadDepData: Inserting PDP=" + thisPdpId + " as designated"); - DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date()); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); - //PolicyLogger.debug - System.out.println - ("\n\nsnNewInstallBadDepData: After insertion, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId + "\n\n********************"); - assertTrue(droolsPdpEntity.isDesignated() == true); - - /* - * When the Standby Status changes (from providingservice) to hotstandby - * or coldstandby,the Active/Standby selection algorithm must stand down - * if thePDP-D is currently the lead/active node and allow another PDP-D - * to take over. - */ - PolicyLogger.debug("snNewInstall: Instantiating stateManagement object"); - StateManagement sm = new StateManagement(emfXacml, thisPdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - // Artificially putting a PDP into service is really a two step process, 1) - // inserting it as designated and 2) promoting it so that its standbyStatus - // is providing service. - - PolicyLogger.debug("snNewInstall: Running policy-management.Main class"); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("snNewInstall: Runner started; Sleeping " - + interruptRecoveryTime + "ms before promoting PDP=" - + thisPdpId); - Thread.sleep(interruptRecoveryTime); - - PolicyLogger.debug("snNewInstall: Promoting PDP=" + thisPdpId); - sm.promote(); - - String standbyStatus = sm.getStandbyStatus(thisPdpId); - PolicyLogger.debug("snNewInstall: Before locking, PDP=" + thisPdpId + " has standbyStatus=" - + standbyStatus); - - /* - * Verify that the PDP is no longer designated. - */ - droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("snNewInstall: After lock sm.lock() invoked, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == false); - - PolicyLogger.debug("snNewInstall: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\nsnNewInstall: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - //******************************************** - - PolicyLogger.debug("\n\nsnNewInstallBadDepData: Exit\n\n"); - } - - public void snRecoveryFromBadDepData() throws Exception{ - - } - - public void snLock() throws Exception { - - } - - public void snLockRestart() throws Exception { - - } - - public void snUnlock() throws Exception { - - } - - public void snUnlockRestart() throws Exception { - - } - - /* - * Two Nodes tests - */ - public void tnNewInstall() throws Exception { - - } - - public void tnLockActive() throws Exception { - - } - - public void tnUnlockColdStandby() throws Exception { - - } - - public void tnFailActive() throws Exception { - - } - - public void tnRecoverFailed() throws Exception { - - } - - /* - * Two Sites, Two Nodes Each Site tests - */ - - public void tstnNewInstall() throws Exception { - - } - - public void tstnLock1Site1() throws Exception { - - } - - public void tstnLock2Site1() throws Exception { - - } - - public void tstnFailActiveSite2() throws Exception { - - } - - public void tstnRecoverFailedSite2() throws Exception { - - } - - public void tstnUnlockSite1() throws Exception { - - } - - public void tstnFailSite2() throws Exception { - - } - - - @Ignore - @Test - public void testColdStandby() throws Exception { - - PolicyLogger.debug("\n\ntestColdStandby: Entering\n\n"); - - PolicyLogger.debug("testColdStandby: Reading IntegrityMonitorProperties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("testColdStandby: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("testColdStandby: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("testColdStandby: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("testColdStandby: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("testColdStandby: Cleaning up tables"); - conn.deleteAllSessions(); - conn.deleteAllPdps(); - - PolicyLogger.debug("testColdStandby: Inserting PDP=" + thisPdpId + " as designated"); - DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date()); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testColdStandby: After insertion, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); - - /* - * When the Standby Status changes (from providingservice) to hotstandby - * or coldstandby,the Active/Standby selection algorithm must stand down - * if thePDP-D is currently the lead/active node and allow another PDP-D - * to take over. - * - * It must also call lock on all engines in the engine management. - * - * Yes, this is kludgy, but we have a chicken and egg problem here: we - * need a StateManagement object to invoke the - * deleteAllStateManagementEntities method. - */ - PolicyLogger.debug("testColdStandby: Instantiating stateManagement object"); - StateManagement sm = new StateManagement(emfXacml, "dummy"); - sm.deleteAllStateManagementEntities(); - sm = new StateManagement(emfXacml, thisPdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - // Artificially putting a PDP into service is really a two step process, 1) - // inserting it as designated and 2) promoting it so that its standbyStatus - // is providing service. - - PolicyLogger.debug("testColdStandby: Running policy-management.Main class"); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("testColdStandby: Runner started; Sleeping " - + interruptRecoveryTime + "ms before promoting PDP=" - + thisPdpId); - Thread.sleep(interruptRecoveryTime); - - PolicyLogger.debug("testColdStandby: Promoting PDP=" + thisPdpId); - sm.promote(); - - String standbyStatus = sm.getStandbyStatus(thisPdpId); - PolicyLogger.debug("testColdStandby: Before locking, PDP=" + thisPdpId + " has standbyStatus=" - + standbyStatus); - - PolicyLogger.debug("testColdStandby: Locking sm"); - sm.lock(); - - Thread.sleep(interruptRecoveryTime); - /* - * Verify that the PDP is no longer designated. - */ - droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testColdStandby: After lock sm.lock() invoked, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == false); - - PolicyLogger.debug("testColdStandby: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\ntestColdStandby: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - } - - /* - * Tests hot standby when there is only one PDP. - */ - @Ignore - @Test - public void testHotStandby1() throws Exception { - - PolicyLogger.debug("\n\ntestHotStandby1: Entering\n\n"); - - PolicyLogger.debug("testHotStandby1: Reading IntegrityMonitorProperties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("testHotStandby1: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("testHotStandby1: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("testHotStandby1: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("testHotStandby1: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("testHotStandby1: Cleaning up tables"); - conn.deleteAllSessions(); - conn.deleteAllPdps(); - - /* - * Insert this PDP as not designated. Initial standby state will be - * either null or cold standby. Demoting should transit state to - * hot standby. - */ - PolicyLogger.debug("testHotStandby1: Inserting PDP=" + thisPdpId + " as not designated"); - Date yesterday = DateUtils.addDays(new Date(), -1); - DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testHotStandby1: After insertion, PDP=" + thisPdpId + " has DESIGNATED=" - + droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); - - PolicyLogger.debug("testHotStandby1: Instantiating stateManagement object"); - StateManagement sm = new StateManagement(emfXacml, "dummy"); - sm.deleteAllStateManagementEntities(); - sm = new StateManagement(emfXacml, thisPdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - PolicyLogger.debug("testHotStandby1: Demoting PDP=" + thisPdpId); - // demoting should cause state to transit to hotstandby - sm.demote(); - - PolicyLogger.debug("testHotStandby1: Running policy-management.Main class"); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("testHotStandby1: Sleeping " - + sleepTime - + "ms, to allow JpaDroolsPdpsConnector time to check droolspdpentity table"); - Thread.sleep(sleepTime); - - /* - * Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service. - */ - droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED=" - + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); - String standbyStatus = sm.getStandbyStatus(thisPdpId); - PolicyLogger.debug("testHotStandby1: After demotion, PDP=" + thisPdpId + " has standbyStatus=" - + standbyStatus); - assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE)); - - PolicyLogger.debug("testHotStandby1: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\ntestHotStandby1: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - } - - /* - * Tests hot standby when two PDPs are involved. - */ - @Ignore - @Test - public void testHotStandby2() throws Exception { - - PolicyLogger.debug("\n\ntestHotStandby2: Entering\n\n"); - - PolicyLogger.debug("testHotStandby2: Reading IntegrityMonitorProperties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("testHotStandby2: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("testHotStandby2: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("testHotStandby2: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("testHotStandby2: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("testHotStandby2: Cleaning up tables"); - conn.deleteAllSessions(); - conn.deleteAllPdps(); - - /* - * Insert a PDP that's designated but not current. - */ - String activePdpId = "pdp2"; - PolicyLogger.debug("testHotStandby2: Inserting PDP=" + activePdpId + " as stale, designated PDP"); - Date yesterday = DateUtils.addDays(new Date(), -1); - DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId); - PolicyLogger.debug("testHotStandby2: After insertion, PDP=" + activePdpId + ", which is not current, has DESIGNATED=" - + droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == true); - - /* - * Promote the designated PDP. - * - * We have a chicken and egg problem here: we need a StateManagement - * object to invoke the deleteAllStateManagementEntities method. - */ - PolicyLogger.debug("testHotStandy2: Promoting PDP=" + activePdpId); - StateManagement sm = new StateManagement(emfXacml, "dummy"); - sm.deleteAllStateManagementEntities(); - sm = new StateManagement(emfXacml, activePdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - // Artificially putting a PDP into service is really a two step process, 1) - // inserting it as designated and 2) promoting it so that its standbyStatus - // is providing service. - - /* - * Insert this PDP as not designated. Initial standby state will be - * either null or cold standby. Demoting should transit state to - * hot standby. - */ - PolicyLogger.debug("testHotStandby2: Inserting PDP=" + thisPdpId + " as not designated"); - pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday); - conn.insertPdp(pdp); - droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testHotStandby2: After insertion, PDP=" + thisPdpId + " has DESIGNATED=" - + droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); - - PolicyLogger.debug("testHotStandby2: Demoting PDP=" + thisPdpId); - StateManagement sm2 = new StateManagement(emfXacml, thisPdpId); - sm2.addObserver(pmStandbyStateChangeNotifier); - - PolicyLogger.debug("testHotStandby2: Running policy-management.Main class"); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("testHotStandby2: Runner started; Sleeping " - + interruptRecoveryTime + "ms before promoting/demoting"); - Thread.sleep(interruptRecoveryTime); - - PolicyLogger.debug("testHotStandby2: Runner started; promoting PDP=" + activePdpId); - sm.promote(); - String standbyStatus = sm.getStandbyStatus(activePdpId); - PolicyLogger.debug("testHotStandby2: After promoting, PDP=" + activePdpId + " has standbyStatus=" - + standbyStatus); - - // demoting PDP should ensure that state transits to hotstandby - PolicyLogger.debug("testHotStandby2: Runner started; demoting PDP=" + thisPdpId); - sm2.demote(); - standbyStatus = sm.getStandbyStatus(thisPdpId); - PolicyLogger.debug("testHotStandby2: After demoting, PDP=" + thisPdpId + " has standbyStatus=" - + standbyStatus); - - PolicyLogger.debug("testHotStandby2: Sleeping " - + sleepTime - + "ms, to allow JpaDroolsPdpsConnector time to check droolspdpentity table"); - Thread.sleep(sleepTime); - - /* - * Verify that this PDP, demoted to HOT_STANDBY, is now - * re-designated and providing service. - */ - droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testHotStandby2: After demoting PDP=" + activePdpId - + ", DESIGNATED=" + droolsPdpEntity.isDesignated() - + " for PDP=" + thisPdpId); - assertTrue(droolsPdpEntity.isDesignated() == true); - standbyStatus = sm2.getStandbyStatus(thisPdpId); - PolicyLogger.debug("testHotStandby2: After demoting PDP=" + activePdpId - + ", PDP=" + thisPdpId + " has standbyStatus=" + standbyStatus); - assertTrue(standbyStatus != null - && standbyStatus.equals(StateManagement.PROVIDING_SERVICE)); - - PolicyLogger.debug("testHotStandby2: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\ntestHotStandby2: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - } - - /* - * 1) Inserts and designates this PDP, then verifies that startTransaction - * is successful. - * - * 2) Demotes PDP, and verifies that because there is only one PDP, it will - * be immediately re-promoted, thus allowing startTransaction to be - * successful. - * - * 3) Locks PDP and verifies that startTransaction results in - * AdministrativeStateException. - * - * 4) Unlocks PDP and verifies that startTransaction results in - * StandbyStatusException. - * - * 5) Promotes PDP and verifies that startTransaction is once again - * successful. - */ - @Ignore - @Test - public void testLocking1() throws Exception { - - PolicyLogger.debug("testLocking1: Reading IntegrityMonitorProperties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("testLocking1: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("testLocking1: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("testLocking1: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("testLocking1: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("testLocking1: Cleaning up tables"); - conn.deleteAllSessions(); - conn.deleteAllPdps(); - - /* - * Insert this PDP as designated. Initial standby state will be - * either null or cold standby. - */ - PolicyLogger.debug("testLocking1: Inserting PDP=" + thisPdpId + " as designated"); - DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date()); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testLocking1: After insertion, PDP=" + thisPdpId + " has DESIGNATED=" - + droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == true); - - PolicyLogger.debug("testLocking1: Instantiating stateManagement object"); - StateManagement sm = new StateManagement(emfXacml, "dummy"); - sm.deleteAllStateManagementEntities(); - sm = new StateManagement(emfXacml, thisPdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - PolicyLogger.debug("testLocking1: Running policy-management.Main class, designated=" - + conn.getPdp(thisPdpId).isDesignated()); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("testLocking1: Runner started; Sleeping " - + interruptRecoveryTime + "ms before promoting PDP=" - + thisPdpId); - Thread.sleep(interruptRecoveryTime); - - PolicyLogger.debug("testLocking1: Promoting PDP=" + thisPdpId); - sm.promote(); - - PolicyLogger.debug("testLocking1: Sleeping " - + sleepTime - + "ms, to allow time for policy-management.Main class to come up, designated=" - + conn.getPdp(thisPdpId).isDesignated()); - Thread.sleep(sleepTime); - - PolicyLogger.debug("testLocking1: Waking up and invoking startTransaction on active PDP=" - + thisPdpId - + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - DroolsPDPIntegrityMonitor droolsPdpIntegrityMonitor = (DroolsPDPIntegrityMonitor) IntegrityMonitor - .getInstance(); - try { - droolsPdpIntegrityMonitor.startTransaction(); - droolsPdpIntegrityMonitor.endTransaction(); - PolicyLogger.debug("testLocking1: As expected, transaction successful"); - } catch (AdministrativeStateException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); - assertTrue(false); - } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); - } catch (Exception e) { - PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } - - // demoting should cause state to transit to hotstandby, followed by re-promotion, - // since there is only one PDP. - PolicyLogger.debug("testLocking1: demoting PDP=" + thisPdpId); - sm = droolsPdpIntegrityMonitor.getStateManager(); - sm.demote(); - - PolicyLogger.debug("testLocking1: sleeping" + electionWaitSleepTime - + " to allow election handler to re-promote PDP=" + thisPdpId); - Thread.sleep(electionWaitSleepTime); - - PolicyLogger.debug("testLocking1: Invoking startTransaction on re-promoted PDP=" - + thisPdpId - + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - try { - droolsPdpIntegrityMonitor.startTransaction(); - droolsPdpIntegrityMonitor.endTransaction(); - PolicyLogger.debug("testLocking1: As expected, transaction successful"); - } catch (AdministrativeStateException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); - assertTrue(false); - } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); - } catch (Exception e) { - PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } - - // locking should cause state to transit to cold standby - PolicyLogger.debug("testLocking1: locking PDP=" + thisPdpId); - sm.lock(); - - // Just to avoid any race conditions, sleep a little after locking - PolicyLogger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition"); - Thread.sleep(100); - - PolicyLogger.debug("testLocking1: Invoking startTransaction on locked PDP=" - + thisPdpId - + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - try { - droolsPdpIntegrityMonitor.startTransaction(); - PolicyLogger.error("testLocking1: startTransaction unexpectedly successful"); - assertTrue(false); - } catch (AdministrativeStateException e) { - PolicyLogger.debug("testLocking1: As expected, caught AdministrativeStateException, message=" + e.getMessage()); - } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); - } catch (Exception e) { - PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } finally { - droolsPdpIntegrityMonitor.endTransaction(); - } - - // unlocking should cause state to transit to hot standby - PolicyLogger.debug("testLocking1: unlocking PDP=" + thisPdpId); - sm.unlock(); - - // Just to avoid any race conditions, sleep a little after locking - PolicyLogger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition"); - Thread.sleep(100); - - PolicyLogger.debug("testLocking1: Invoking startTransaction on unlocked PDP=" - + thisPdpId - + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - try { - droolsPdpIntegrityMonitor.startTransaction(); - PolicyLogger.error("testLocking1: startTransaction unexpectedly successful"); - assertTrue(false); - } catch (AdministrativeStateException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); - assertTrue(false); - } catch (StandbyStatusException e) { - PolicyLogger.debug("testLocking1: As expected, caught StandbyStatusException, message=" + e.getMessage()); - } catch (Exception e) { - PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } finally { - droolsPdpIntegrityMonitor.endTransaction(); - } - - // promoting should cause state to transit to providing service - PolicyLogger.debug("testLocking1: promoting PDP=" + thisPdpId); - sm.promote(); - - // Just to avoid any race conditions, sleep a little after promoting - PolicyLogger.debug("testLocking1: Sleeping a few millis after promoting, to avoid race condition"); - Thread.sleep(100); - - PolicyLogger.debug("testLocking1: Invoking startTransaction on promoted PDP=" - + thisPdpId - + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - try { - droolsPdpIntegrityMonitor.startTransaction(); - droolsPdpIntegrityMonitor.endTransaction(); - PolicyLogger.debug("testLocking1: As expected, transaction successful"); - } catch (AdministrativeStateException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); - assertTrue(false); - } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); - } catch (Exception e) { - PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } - - PolicyLogger.debug("testLocking1: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\ntestLocking1: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - } - - /* - * 1) Inserts and designates this PDP, then verifies that startTransaction - * is successful. - * - * 2) Inserts another PDP in hotstandby. - * - * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one - * PDP cannot promote another PDP) and 2) that this PDP is re-promoted. - */ - @Ignore - @Test - public void testLocking2() throws Exception { - - PolicyLogger.debug("\n\ntestLocking2: Entering\n\n"); - - PolicyLogger.debug("testLocking2: Reading IntegrityMonitorProperties"); - Properties integrityMonitorProperties = new Properties(); - integrityMonitorProperties.load(new FileInputStream(new File( - "src/test/server/config/IntegrityMonitor.properties"))); - IntegrityMonitorProperties.initProperties(integrityMonitorProperties); - String thisPdpId = IntegrityMonitorProperties - .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID); - - PolicyLogger.debug("testLocking2: Reading xacmlPersistenceProperties"); - Properties xacmlPersistenceProperties = new Properties(); - xacmlPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/xacmlPersistence.properties"))); - XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties); - - PolicyLogger.debug("testLocking2: Creating emfXacml"); - EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory( - "junitXacmlPU", xacmlPersistenceProperties); - - PolicyLogger.debug("testLocking2: Reading droolsPersistenceProperties"); - Properties droolsPersistenceProperties = new Properties(); - droolsPersistenceProperties.load(new FileInputStream(new File( - "src/test/server/config/droolsPersistence.properties"))); - DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); - - PolicyLogger.debug("testLocking2: Creating emfDrools"); - EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( - "junitDroolsPU", droolsPersistenceProperties); - - DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools); - - PolicyLogger.debug("testLocking2: Cleaning up tables"); - conn.deleteAllSessions(); - conn.deleteAllPdps(); - - /* - * Insert this PDP as designated. Initial standby state will be - * either null or cold standby. Demoting should transit state to - * hot standby. - */ - PolicyLogger.debug("testLocking2: Inserting PDP=" + thisPdpId + " as designated"); - DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, new Date()); - conn.insertPdp(pdp); - DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId); - PolicyLogger.debug("testLocking2: After insertion, PDP=" + thisPdpId + " has DESIGNATED=" - + droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == true); - - PolicyLogger.debug("testLocking2: Instantiating stateManagement object and promoting PDP=" + thisPdpId); - StateManagement sm = new StateManagement(emfXacml, "dummy"); - sm.deleteAllStateManagementEntities(); - sm = new StateManagement(emfXacml, thisPdpId); - PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier(); - sm.addObserver(pmStandbyStateChangeNotifier); - - /* - * Insert another PDP as not designated. Initial standby state will be - * either null or cold standby. Demoting should transit state to - * hot standby. - */ - String standbyPdpId = "pdp2"; - PolicyLogger.debug("testLocking2: Inserting PDP=" + standbyPdpId + " as not designated"); - Date yesterday = DateUtils.addDays(new Date(), -1); - pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday); - conn.insertPdp(pdp); - droolsPdpEntity = conn.getPdp(standbyPdpId); - PolicyLogger.debug("testLocking2: After insertion, PDP=" + standbyPdpId + " has DESIGNATED=" - + droolsPdpEntity.isDesignated()); - assertTrue(droolsPdpEntity.isDesignated() == false); - - PolicyLogger.debug("testLocking2: Demoting PDP=" + standbyPdpId); - StateManagement sm2 = new StateManagement(emfXacml, standbyPdpId); - sm2.addObserver(pmStandbyStateChangeNotifier); - - PolicyLogger.debug("testLocking2: Running policy-management.Main class"); - PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner(); - policyManagementRunner.start(); - - PolicyLogger.debug("testLocking2: Runner started; Sleeping " - + interruptRecoveryTime + "ms before promoting/demoting"); - Thread.sleep(interruptRecoveryTime); - - PolicyLogger.debug("testLocking2: Promoting PDP=" + thisPdpId); - sm.promote(); - - // demoting PDP should ensure that state transits to hotstandby - PolicyLogger.debug("testLocking2: Demoting PDP=" + standbyPdpId); - sm2.demote(); - - PolicyLogger.debug("testLocking2: Sleeping " - + sleepTime - + "ms, to allow time for policy-management.Main class to come up"); - Thread.sleep(sleepTime); - - PolicyLogger.debug("testLocking2: Waking up and invoking startTransaction on active PDP=" - + thisPdpId - + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - DroolsPDPIntegrityMonitor droolsPdpIntegrityMonitor = (DroolsPDPIntegrityMonitor) IntegrityMonitor - .getInstance(); - try { - droolsPdpIntegrityMonitor.startTransaction(); - droolsPdpIntegrityMonitor.endTransaction(); - PolicyLogger.debug("testLocking2: As expected, transaction successful"); - } catch (AdministrativeStateException e) { - PolicyLogger.error("testLocking2: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); - assertTrue(false); - } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking2: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); - } catch (Exception e) { - PolicyLogger.error("testLocking2: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } - - // demoting should cause state to transit to hotstandby followed by re-promotion. - PolicyLogger.debug("testLocking2: demoting PDP=" + thisPdpId); - sm = droolsPdpIntegrityMonitor.getStateManager(); - sm.demote(); - - PolicyLogger.debug("testLocking2: sleeping" + electionWaitSleepTime - + " to allow election handler to re-promote PDP=" + thisPdpId); - Thread.sleep(electionWaitSleepTime); - - PolicyLogger.debug("testLocking2: Waking up and invoking startTransaction on re-promoted PDP=" - + thisPdpId + ", designated=" - + conn.getPdp(thisPdpId).isDesignated()); - try { - droolsPdpIntegrityMonitor.startTransaction(); - droolsPdpIntegrityMonitor.endTransaction(); - PolicyLogger.debug("testLocking2: As expected, transaction successful"); - } catch (AdministrativeStateException e) { - PolicyLogger.error("testLocking2: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); - assertTrue(false); - } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking2: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); - } catch (Exception e) { - PolicyLogger.error("testLocking2: Unexpectedly caught Exception, message=" + e.getMessage()); - assertTrue(false); - } - - PolicyLogger.debug("testLocking2: Verifying designated status for PDP=" - + standbyPdpId); - boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated(); - assertTrue(standbyPdpDesignated == false); - - PolicyLogger.debug("testLocking2: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); - - PolicyLogger.debug("\n\ntestLocking2: Exiting\n\n"); - Thread.sleep(interruptRecoveryTime); - - } - - private class PolicyManagementRunner extends Thread { - - public void run() { - PolicyLogger.debug("PolicyManagementRunner.run: Entering"); - String args[] = { "src/main/server/config" }; - try { - Main.main(args); - } catch (Exception e) { - PolicyLogger - .debug("PolicyManagementRunner.run: Exception thrown from Main.main(), message=" - + e.getMessage()); - } - PolicyLogger.debug("PolicyManagementRunner.run: Exiting"); - } - - public void stopRunner() { - PolicyEngine.manager.shutdown(); - } - - } - -} diff --git a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java b/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java index af649866..7e1d396f 100644 --- a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java +++ b/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java @@ -24,10 +24,16 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.Properties; +import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import org.junit.After; @@ -36,7 +42,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; - import org.openecomp.policy.common.logging.eelf.PolicyLogger; import org.openecomp.policy.common.im.AdministrativeStateException; import org.openecomp.policy.common.im.IntegrityMonitor; @@ -50,17 +55,24 @@ import org.openecomp.policy.drools.persistence.DroolsPdp; import org.openecomp.policy.drools.persistence.DroolsPdpEntity; import org.openecomp.policy.drools.persistence.DroolsPdpImpl; import org.openecomp.policy.drools.persistence.DroolsPdpsConnector; +import org.openecomp.policy.drools.persistence.DroolsPdpsElectionHandler; import org.openecomp.policy.drools.persistence.JpaDroolsPdpsConnector; import org.openecomp.policy.drools.persistence.DroolsPersistenceProperties; import org.openecomp.policy.drools.persistence.XacmlPersistenceProperties; import org.openecomp.policy.drools.system.Main; import org.openecomp.policy.drools.system.PolicyEngine; - import org.apache.commons.lang3.time.DateUtils; /* - * Cloned from StandbyStateManagement.java in support of US673632. - * See MultiSite_v1-10.ppt, slide 38 + * All JUnits are designed to run in the local development environment + * where they have write privileges and can execute time-sensitive + * tasks. + * + * These tests can be run as JUnits, but there is some issue with running them + * as part of a "mvn install" build. Also, they take a very long time to run + * due to many real time breaks. Consequently, they are marked as @Ignore and + * only run from the desktop. + * */ public class StandbyStateManagementTest { @@ -82,6 +94,12 @@ public class StandbyStateManagementTest { * Sleep 5 seconds after each test to allow interrupt (shutdown) recovery. */ long interruptRecoveryTime = 5000; + + private static EntityManagerFactory emfx; + private static EntityManagerFactory emfd; + private static EntityManager emx; + private static EntityManager emd; + private static EntityTransaction et; /* * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing. @@ -106,18 +124,423 @@ public class StandbyStateManagementTest { @Before public void setUp() throws Exception { + //Create teh data access for xaml db + Properties xacmlPersistenceProperties = new Properties(); + xacmlPersistenceProperties.load(new FileInputStream(new File( + "src/test/server/config/xacmlPersistence.properties"))); + + emfx = Persistence.createEntityManagerFactory("junitXacmlPU", xacmlPersistenceProperties); + + // Create an entity manager to use the DB + emx = emfx.createEntityManager(); + + //Create the data access for drools db + Properties droolsPersistenceProperties = new Properties(); + droolsPersistenceProperties.load(new FileInputStream(new File( + "src/test/server/config/droolsPersistence.properties"))); + + emfd = Persistence.createEntityManagerFactory("junitDroolsPU", droolsPersistenceProperties); + + // Create an entity manager to use the DB + emd = emfd.createEntityManager(); } @After public void tearDown() throws Exception { } - + + public void cleanXacmlDb(){ + et = emx.getTransaction(); + + et.begin(); + // Make sure we leave the DB clean + emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate(); + emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate(); + emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate(); + emx.createQuery("DELETE FROM IntegrityAuditEntity").executeUpdate(); + emx.flush(); + et.commit(); + } + + public void cleanDroolsDb(){ + et = emd.getTransaction(); + + et.begin(); + // Make sure we leave the DB clean + emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate(); + emd.createQuery("DELETE FROM DroolsSessionEntity").executeUpdate(); + emd.createQuery("DELETE FROM SessionInfo").executeUpdate(); + emd.createQuery("DELETE FROM WorkItemInfo").executeUpdate(); + emd.createQuery("DELETE FROM IntegrityAuditEntity").executeUpdate(); + emd.flush(); + et.commit(); + } + @Ignore @Test + public void runAllTests() throws Exception { + //testColdStandby(); + //testHotStandby1(); + //testHotStandby2(); + //testLocking1(); + //testLocking2(); + testSanitizeDesignatedList(); + testComputeMostRecentPrimary(); + testComputeDesignatedPdp(); + } + + //@Ignore + //@Test + public void testSanitizeDesignatedList() throws Exception { + + PolicyLogger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n"); + + /* + * Get a DroolsPdpsConnector + */ + PolicyLogger.debug("testSanitizeDesignatedList: Reading droolsPersistenceProperties"); + Properties droolsPersistenceProperties = new Properties(); + droolsPersistenceProperties.load(new FileInputStream(new File( + "src/test/server/config/droolsPersistence.properties"))); + DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); + + PolicyLogger.debug("testSanitizeDesignatedList: Creating emfDrools"); + EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( + "junitDroolsPU", droolsPersistenceProperties); + + DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools); + + /* + * Create 4 pdpd all not designated + */ + DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date()); + DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date()); + DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date()); + DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date()); + + ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>(); + listOfDesignated.add(pdp1); + listOfDesignated.add(pdp2); + listOfDesignated.add(pdp3); + listOfDesignated.add(pdp4); + + DroolsPDPIntegrityMonitor droolsPDPIntegrityMonitor; + try{ + droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.init("src/test/server/config"); + }catch(Exception e){ + //If it already exists, just get it + droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance(); + } + DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1, droolsPDPIntegrityMonitor); + + listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated); + + PolicyLogger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = " + listOfDesignated.size() + "\n\n"); + + assertTrue(listOfDesignated.size()==4); + + /* + * Now make 2 designated + */ + pdp1.setDesignated(true); + pdp2.setDesignated(true); + + listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated); + + PolicyLogger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = " + listOfDesignated.size() + "\n\n"); + + assertTrue(listOfDesignated.size()==2); + assertTrue(listOfDesignated.contains(pdp1)); + assertTrue(listOfDesignated.contains(pdp2)); + + /* + * Now all are designated. But, we have to add back the previously non-designated nodes + */ + pdp3.setDesignated(true); + pdp4.setDesignated(true); + listOfDesignated.add(pdp3); + listOfDesignated.add(pdp4); + + listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated); + + PolicyLogger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = " + listOfDesignated.size() + "\n\n"); + + assertTrue(listOfDesignated.size()==4); + + } + + //@Ignore + //@Test + public void testComputeMostRecentPrimary() throws Exception { + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n"); + + /* + * Get a DroolsPdpsConnector + */ + PolicyLogger.debug("testComputeMostRecentPrimary: Reading droolsPersistenceProperties"); + Properties droolsPersistenceProperties = new Properties(); + droolsPersistenceProperties.load(new FileInputStream(new File( + "src/test/server/config/droolsPersistence.properties"))); + DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); + + PolicyLogger.debug("testComputeMostRecentPrimary: Creating emfDrools"); + EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( + "junitDroolsPU", droolsPersistenceProperties); + + DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools); + + /* + * Create 4 pdpd all not designated + */ + long designatedDateMS = new Date().getTime(); + DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date()); + pdp1.setDesignatedDate(new Date(designatedDateMS - 2)); + + DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date()); + //oldest + pdp2.setDesignatedDate(new Date(designatedDateMS - 3)); + + DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date()); + pdp3.setDesignatedDate(new Date(designatedDateMS - 1)); + + DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date()); + //most recent + pdp4.setDesignatedDate(new Date(designatedDateMS)); + + ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>(); + listOfAllPdps.add(pdp1); + listOfAllPdps.add(pdp2); + listOfAllPdps.add(pdp3); + listOfAllPdps.add(pdp4); + + + ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>(); + listOfDesignated.add(pdp1); + listOfDesignated.add(pdp2); + listOfDesignated.add(pdp3); + listOfDesignated.add(pdp4); + + + /* + * Because the way we sanitize the listOfDesignated, it will always contain all hot standby + * or all designated members. + */ + DroolsPDPIntegrityMonitor droolsPDPIntegrityMonitor; + try{ + droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.init("src/test/server/config"); + }catch(Exception e){ + //If it already exists, just get it + droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance(); + } + DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1, droolsPDPIntegrityMonitor); + + DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated); + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n"); + + /* + * If all of the pdps are included in the listOfDesignated and none are designated, it will choose + * the one which has the most recent designated date. + */ + assertTrue(mostRecentPrimary.getPdpId().equals("pdp4")); + + /* + * Now let's designate all of those on the listOfDesignated. It will choose the first one designated + */ + pdp1.setDesignated(true); + pdp2.setDesignated(true); + pdp3.setDesignated(true); + pdp4.setDesignated(true); + + mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated); + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n"); + + /* + * If all of the pdps are included in the listOfDesignated and all are designated, it will choose + * the one which was designated first + */ + assertTrue(mostRecentPrimary.getPdpId().equals("pdp2")); + + /* + * Now we will designate only 2 and put just them in the listOfDesignated. The algorithm will now + * look for the most recently designated pdp which is not currently designated. + */ + pdp3.setDesignated(false); + pdp4.setDesignated(false); + + listOfDesignated.remove(pdp3); + listOfDesignated.remove(pdp4); + + mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated); + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n"); + + assertTrue(mostRecentPrimary.getPdpId().equals("pdp4")); + + + /* + * Now we will have none designated and put two of them in the listOfDesignated. The algorithm will now + * look for the most recently designated pdp regardless of whether it is currently marked as designated. + */ + pdp1.setDesignated(false); + pdp2.setDesignated(false); + + mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated); + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n"); + + assertTrue(mostRecentPrimary.getPdpId().equals("pdp4")); + + /* + * If we have only one pdp on in the listOfDesignated, the most recently designated pdp will be chosen, regardless + * of its designation status + */ + listOfDesignated.remove(pdp1); + + mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated); + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n"); + + assertTrue(mostRecentPrimary.getPdpId().equals("pdp4")); + + /* + * Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp. + */ + listOfDesignated.remove(pdp2); + + mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated); + + PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n"); + + assertTrue(mostRecentPrimary.getPdpId().equals("pdp4")); + + } + + //@Ignore + //@Test + public void testComputeDesignatedPdp() throws Exception{ + + PolicyLogger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n"); + + /* + * Get a DroolsPdpsConnector + */ + PolicyLogger.debug("testComputeDesignatedPdp: Reading droolsPersistenceProperties"); + Properties droolsPersistenceProperties = new Properties(); + droolsPersistenceProperties.load(new FileInputStream(new File( + "src/test/server/config/droolsPersistence.properties"))); + DroolsPersistenceProperties.initProperties(droolsPersistenceProperties); + + PolicyLogger.debug("testComputeDesignatedPdp: Creating emfDrools"); + EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory( + "junitDroolsPU", droolsPersistenceProperties); + + DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools); + + /* + * Create 4 pdpd all not designated. Two on site1. Two on site2 + */ + long designatedDateMS = new Date().getTime(); + DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date()); + pdp1.setDesignatedDate(new Date(designatedDateMS - 2)); + pdp1.setSiteName("site1"); + + DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date()); + pdp2.setDesignatedDate(new Date(designatedDateMS - 3)); + pdp2.setSiteName("site1"); + + //oldest + DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date()); + pdp3.setDesignatedDate(new Date(designatedDateMS - 4)); + pdp3.setSiteName("site2"); + + DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date()); + //most recent + pdp4.setDesignatedDate(new Date(designatedDateMS)); + pdp4.setSiteName("site2"); + + ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>(); + listOfAllPdps.add(pdp1); + listOfAllPdps.add(pdp2); + listOfAllPdps.add(pdp3); + listOfAllPdps.add(pdp4); + + + ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>(); + + /* + * We will first test an empty listOfDesignated. As we know from the previous JUnit, + * the pdp with the most designated date will be chosen for mostRecentPrimary + */ + + DroolsPDPIntegrityMonitor droolsPDPIntegrityMonitor; + try{ + droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.init("src/test/server/config"); + }catch(Exception e){ + //If it already exists, just get it + droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance(); + } + DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1, droolsPDPIntegrityMonitor); + + DroolsPdp mostRecentPrimary = pdp4; + + DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary); + + /* + * The designatedPdp should be null + */ + assertTrue(designatedPdp==null); + + /* + * Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary + */ + + listOfDesignated.add(pdp2); + + designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary); + + /* + * Now the designatedPdp should be the one and only selection in the listOfDesignated + */ + assertTrue(designatedPdp.getPdpId().equals(pdp2.getPdpId())); + + /* + * Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary + */ + listOfDesignated.add(pdp1); + + designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary); + + /* + * The designatedPdp should now be the one with the lowest lexiographic score - pdp1 + */ + assertTrue(designatedPdp.getPdpId().equals(pdp1.getPdpId())); + + /* + * Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary + */ + listOfDesignated.remove(pdp1); + listOfDesignated.add(pdp3); + + designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary); + + /* + * The designatedPdp should now be the one on the same site as the mostRecentPrimary + */ + assertTrue(designatedPdp.getPdpId().equals(pdp3.getPdpId())); + } + + + //@Ignore + //@Test public void testColdStandby() throws Exception { PolicyLogger.debug("\n\ntestColdStandby: Entering\n\n"); + cleanXacmlDb(); + cleanDroolsDb(); PolicyLogger.debug("testColdStandby: Reading IntegrityMonitorProperties"); Properties integrityMonitorProperties = new Properties(); @@ -213,7 +636,7 @@ public class StandbyStateManagementTest { assertTrue(droolsPdpEntity.isDesignated() == false); PolicyLogger.debug("testColdStandby: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); + //policyManagementRunner.stopRunner(); PolicyLogger.debug("\n\ntestColdStandby: Exiting\n\n"); Thread.sleep(interruptRecoveryTime); @@ -223,11 +646,13 @@ public class StandbyStateManagementTest { /* * Tests hot standby when there is only one PDP. */ - @Ignore - @Test + //@Ignore + //@Test public void testHotStandby1() throws Exception { PolicyLogger.debug("\n\ntestHotStandby1: Entering\n\n"); + cleanXacmlDb(); + cleanDroolsDb(); PolicyLogger.debug("testHotStandby1: Reading IntegrityMonitorProperties"); Properties integrityMonitorProperties = new Properties(); @@ -310,7 +735,7 @@ public class StandbyStateManagementTest { assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE)); PolicyLogger.debug("testHotStandby1: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); + //policyManagementRunner.stopRunner(); PolicyLogger.debug("\n\ntestHotStandby1: Exiting\n\n"); Thread.sleep(interruptRecoveryTime); @@ -320,11 +745,13 @@ public class StandbyStateManagementTest { /* * Tests hot standby when two PDPs are involved. */ - @Ignore - @Test + //@Ignore + //@Test public void testHotStandby2() throws Exception { PolicyLogger.info("\n\ntestHotStandby2: Entering\n\n"); + cleanXacmlDb(); + cleanDroolsDb(); PolicyLogger.info("testHotStandby2: Reading IntegrityMonitorProperties"); Properties integrityMonitorProperties = new Properties(); @@ -453,7 +880,7 @@ public class StandbyStateManagementTest { && standbyStatus.equals(StateManagement.PROVIDING_SERVICE)); PolicyLogger.info("testHotStandby2: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); + //policyManagementRunner.stopRunner(); PolicyLogger.info("\n\ntestHotStandby2: Exiting\n\n"); Thread.sleep(interruptRecoveryTime); @@ -477,10 +904,13 @@ public class StandbyStateManagementTest { * 5) Promotes PDP and verifies that startTransaction is once again * successful. */ - @Ignore - @Test + //@Ignore + //@Test public void testLocking1() throws Exception { - + PolicyLogger.debug("testLocking1: Entry"); + cleanXacmlDb(); + cleanDroolsDb(); + PolicyLogger.debug("testLocking1: Reading IntegrityMonitorProperties"); Properties integrityMonitorProperties = new Properties(); integrityMonitorProperties.load(new FileInputStream(new File( @@ -631,13 +1061,13 @@ public class StandbyStateManagementTest { droolsPdpIntegrityMonitor.endTransaction(); } - // unlocking should cause state to transit to hot standby + // unlocking should cause state to transit to hot standby and then providing service PolicyLogger.debug("testLocking1: unlocking PDP=" + thisPdpId); sm.unlock(); // Just to avoid any race conditions, sleep a little after locking PolicyLogger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition"); - Thread.sleep(100); + Thread.sleep(electionWaitSleepTime); PolicyLogger.debug("testLocking1: Invoking startTransaction on unlocked PDP=" + thisPdpId @@ -645,13 +1075,13 @@ public class StandbyStateManagementTest { + conn.getPdp(thisPdpId).isDesignated()); try { droolsPdpIntegrityMonitor.startTransaction(); - PolicyLogger.error("testLocking1: startTransaction unexpectedly successful"); - assertTrue(false); + PolicyLogger.error("testLocking1: startTransaction successful as expected"); } catch (AdministrativeStateException e) { PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); assertTrue(false); } catch (StandbyStatusException e) { - PolicyLogger.debug("testLocking1: As expected, caught StandbyStatusException, message=" + e.getMessage()); + PolicyLogger.debug("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); + assertTrue(false); } catch (Exception e) { PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); assertTrue(false); @@ -659,35 +1089,35 @@ public class StandbyStateManagementTest { droolsPdpIntegrityMonitor.endTransaction(); } - // promoting should cause state to transit to providing service - PolicyLogger.debug("testLocking1: promoting PDP=" + thisPdpId); - sm.promote(); + // demoting should cause state to transit to providing service + PolicyLogger.debug("testLocking1: demoting PDP=" + thisPdpId); + sm.demote(); // Just to avoid any race conditions, sleep a little after promoting - PolicyLogger.debug("testLocking1: Sleeping a few millis after promoting, to avoid race condition"); + PolicyLogger.debug("testLocking1: Sleeping a few millis after demoting, to avoid race condition"); Thread.sleep(100); - PolicyLogger.debug("testLocking1: Invoking startTransaction on promoted PDP=" + PolicyLogger.debug("testLocking1: Invoking startTransaction on demoted PDP=" + thisPdpId + ", designated=" + conn.getPdp(thisPdpId).isDesignated()); try { droolsPdpIntegrityMonitor.startTransaction(); droolsPdpIntegrityMonitor.endTransaction(); - PolicyLogger.debug("testLocking1: As expected, transaction successful"); + PolicyLogger.debug("testLocking1: Unexpectedly, transaction successful"); + assertTrue(false); } catch (AdministrativeStateException e) { PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage()); assertTrue(false); } catch (StandbyStatusException e) { - PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage()); - assertTrue(false); + PolicyLogger.error("testLocking1: As expected caught StandbyStatusException, message=" + e.getMessage()); } catch (Exception e) { PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage()); assertTrue(false); } PolicyLogger.debug("testLocking1: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); + //policyManagementRunner.stopRunner(); PolicyLogger.debug("\n\ntestLocking1: Exiting\n\n"); Thread.sleep(interruptRecoveryTime); @@ -703,11 +1133,13 @@ public class StandbyStateManagementTest { * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one * PDP cannot promote another PDP) and 2) that this PDP is re-promoted. */ - @Ignore - @Test + //@Ignore + //@Test public void testLocking2() throws Exception { PolicyLogger.debug("\n\ntestLocking2: Entering\n\n"); + cleanXacmlDb(); + cleanDroolsDb(); PolicyLogger.debug("testLocking2: Reading IntegrityMonitorProperties"); Properties integrityMonitorProperties = new Properties(); @@ -856,7 +1288,7 @@ public class StandbyStateManagementTest { assertTrue(standbyPdpDesignated == false); PolicyLogger.debug("testLocking2: Stopping policyManagementRunner"); - policyManagementRunner.stopRunner(); + //policyManagementRunner.stopRunner(); PolicyLogger.debug("\n\ntestLocking2: Exiting\n\n"); Thread.sleep(interruptRecoveryTime); @@ -874,6 +1306,7 @@ public class StandbyStateManagementTest { PolicyLogger .info("PolicyManagementRunner.run: Exception thrown from Main.main(), message=" + e.getMessage()); + return; } PolicyLogger.info("PolicyManagementRunner.run: Exiting"); } diff --git a/policy-persistence/src/test/resources/IntegrityMonitor.properties b/policy-persistence/src/test/resources/IntegrityMonitor.properties index 0ab36286..4e182e02 100644 --- a/policy-persistence/src/test/resources/IntegrityMonitor.properties +++ b/policy-persistence/src/test/resources/IntegrityMonitor.properties @@ -60,8 +60,12 @@ pdp.initialWait=20000 resource.name=pdp1 #resource.name=${{resource_name}} +# Flag to control the execution of the subsystemTest for the Database +db.audit.is.active=false - +# Flag to control the execution of the subsystemTest for the Nexus Maven repository +repository.audit.is.active=false +repository.audit.ignore.errors=true diff --git a/policy-persistence/src/test/resources/META-INF/persistence.xml b/policy-persistence/src/test/resources/META-INF/persistence.xml index 51ec1613..ed8a8cd7 100644 --- a/policy-persistence/src/test/resources/META-INF/persistence.xml +++ b/policy-persistence/src/test/resources/META-INF/persistence.xml @@ -27,7 +27,7 @@ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>org.openecomp.policy.drools.persistence.DroolsPdpEntity</class> <class>org.openecomp.policy.drools.persistence.DroolsSessionEntity</class> - <class>org.openecomp.policy.drools.persistence.LastSiteEntity</class> + <!-- <class>org.openecomp.policy.drools.persistence.LastSiteEntity</class> --> <class>org.drools.persistence.info.SessionInfo</class> <class>org.drools.persistence.info.WorkItemInfo</class> <class>org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity</class> diff --git a/policy-persistence/src/test/server/config/IntegrityMonitor.properties b/policy-persistence/src/test/server/config/IntegrityMonitor.properties index b16beda9..5e7085ca 100644 --- a/policy-persistence/src/test/server/config/IntegrityMonitor.properties +++ b/policy-persistence/src/test/server/config/IntegrityMonitor.properties @@ -60,3 +60,10 @@ resource.name=pdp1 # -1 turns off audit # zero forces audit to run continuously integrity_audit_period_seconds=60 + +# Flag to control the execution of the subsystemTest for the Database +db.audit.is.active=false + +# Flag to control the execution of the subsystemTest for the Nexus Maven repository +repository.audit.is.active=false +repository.audit.ignore.errors=true
\ No newline at end of file |