* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.controller.test;
+package org.onap.policy.drools.activestandby;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.util.Date;
import java.util.Properties;
-import java.util.function.Supplier;
+import java.util.concurrent.Callable;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.commons.lang3.time.DateUtils;
-import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.im.IntegrityMonitor;
+import org.onap.policy.common.im.IntegrityMonitorException;
+import org.onap.policy.common.im.MonitorTime;
import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.drools.activestandby.ActiveStandbyFeatureApi;
-import org.onap.policy.drools.activestandby.ActiveStandbyFeatureApiConstants;
-import org.onap.policy.drools.activestandby.ActiveStandbyProperties;
-import org.onap.policy.drools.activestandby.DroolsPdpEntity;
-import org.onap.policy.drools.activestandby.DroolsPdpImpl;
-import org.onap.policy.drools.activestandby.DroolsPdpsConnector;
-import org.onap.policy.drools.activestandby.DroolsPdpsElectionHandler;
-import org.onap.policy.drools.activestandby.JpaDroolsPdpsConnector;
+import org.onap.policy.common.utils.time.CurrentTime;
+import org.onap.policy.common.utils.time.PseudoTimer;
+import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.core.PolicySessionFeatureApi;
import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
+import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AllSeemsWellTest {
private static final Logger logger = LoggerFactory.getLogger(AllSeemsWellTest.class);
+
+ private static final String MONITOR_FIELD_NAME = "instance";
+ private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
+
/*
* Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
* at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
* checking the results. Add a few seconds for safety
*/
- private static int SLEEP_TIME_SEC = 10;
+ private static final int SLEEP_TIME_SEC = 10;
/*
* DroolsPdpsElectionHandler runs every 1 seconds, so it takes 10 seconds for the
* the forward progress counter to go stale which should add an additional 5 sec.
*/
- private static int STALLED_ELECTION_HANDLER_SLEEP_TIME_SEC = 15;
+ private static final int STALLED_ELECTION_HANDLER_SLEEP_TIME_SEC = 15;
/*
* As soon as the election hander successfully runs, it will resume the forward progress.
* then fpc is written every 1 sec and then the fpc is checked every 2 sec, that could
* take a total of 5 sec to recognize the resumption of progress. So, add 1 for safety.
*/
- private static int RESUMED_ELECTION_HANDLER_SLEEP_TIME_SEC = 6;
+ private static final int RESUMED_ELECTION_HANDLER_SLEEP_TIME_SEC = 6;
private static EntityManagerFactory emfx;
private static EntityManagerFactory emfd;
private static EntityManager emd;
private static EntityTransaction et;
- private final String configDir = "src/test/resources/asw";
+ private static final String CONFIG_DIR = "src/test/resources/asw";
+
+ private static CurrentTime saveTime;
+ private static Factory saveFactory;
+
+ private TestTimeMulti testTime;
/*
* See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
logger.debug("setUpClass: userDir={}", userDir);
System.setProperty("com.sun.management.jmxremote.port", "9980");
System.setProperty("com.sun.management.jmxremote.authenticate","false");
- }
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
+ DroolsPdpsElectionHandler.setIsUnitTesting(true);
- /**
- * Setup.
- *
- * @throws Exception exception
- */
- @Before
- public void setUp() throws Exception {
- //Create teh data access for xaml db
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
+ saveFactory = Factory.getInstance();
+
+ resetInstanceObjects();
+
+ //Create the data access for xacml db
+ Properties stateManagementProperties = loadStateManagementProperties();
emfx = Persistence.createEntityManagerFactory("junitXacmlPU", stateManagementProperties);
emx = emfx.createEntityManager();
//Create the data access for drools db
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
emfd = Persistence.createEntityManagerFactory("junitDroolsPU", activeStandbyProperties);
// Create an entity manager to use the DB
emd = emfd.createEntityManager();
+ }
- DroolsPdpsElectionHandler.setIsUnitTesting(true);
+ /**
+ * Restores the system state.
+ *
+ * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
+ */
+ @AfterClass
+ public static void tearDownClass() throws IntegrityMonitorException {
+ resetInstanceObjects();
+
+ Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
+ Factory.setInstance(saveFactory);
+
+ DroolsPdpsElectionHandler.setIsUnitTesting(false);
+
+ emd.close();
+ emfd.close();
+
+ emx.close();
+ emfx.close();
}
- @After
- public void tearDown() throws Exception {
+ /**
+ * Setup.
+ *
+ * @throws Exception exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ resetInstanceObjects();
+
+ // set test time
+ testTime = new TestTimeMulti();
+ Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
+
+ Factory factory = mock(Factory.class);
+ when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
+ Factory.setInstance(factory);
+ }
+
+ private static void resetInstanceObjects() throws IntegrityMonitorException {
+ IntegrityMonitor.setUnitTesting(true);
+ IntegrityMonitor.deleteInstance();
+ IntegrityMonitor.setUnitTesting(false);
+
+ Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
}
cleanXacmlDb();
cleanDroolsDb();
- logger.debug("testAllSeemsWell: Reading stateManagementProperties");
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ Properties stateManagementProperties = loadStateManagementProperties();
logger.debug("testAllSeemsWell: Creating emfXacml");
final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
"junitXacmlPU", stateManagementProperties);
- logger.debug("testAllSeemsWell: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
final String thisPdpId = activeStandbyProperties
.getProperty(ActiveStandbyProperties.NODE_NAME);
*/
logger.debug("testAllSeemsWell: Inserting PDP={} as not designated", thisPdpId);
- Date yesterday = DateUtils.addDays(new Date(), -1);
+ Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
conn.insertPdp(pdp);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
StateManagementFeatureApi stateManagementFeatureApi = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
stateManagementFeatureApi = feature;
logger.debug("testAllSeemsWell stateManagementFeature.getResourceName(): {}",
stateManagementFeatureApi.getResourceName());
break;
}
- if (stateManagementFeatureApi == null) {
- logger.error("testAllSeemsWell failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testAllSeemsWell failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(stateManagementFeatureApi);
+
final StateManagementFeatureApi smf = stateManagementFeatureApi;
// Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
// that has been created.
ActiveStandbyFeatureApi activeStandbyFeature = null;
for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
activeStandbyFeature = feature;
logger.debug("testAllSeemsWell activeStandbyFeature.getResourceName(): {}",
activeStandbyFeature.getResourceName());
break;
}
- if (activeStandbyFeature == null) {
- logger.error("testAllSeemsWell failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testAllSeemsWell failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(activeStandbyFeature);
logger.debug("testAllSeemsWell: Demoting PDP={}", thisPdpId);
}
- private void waitForCondition(Supplier<Boolean> testCondition, int timeoutInSeconds) throws InterruptedException {
- int maxIterations = timeoutInSeconds * 10;
- int iterations = 0;
- while (!testCondition.get() && iterations < maxIterations) {
- iterations++;
- Thread.sleep(100);
+ private static Properties loadStateManagementProperties() throws IOException {
+ try (FileInputStream input = new FileInputStream(CONFIG_DIR + "/feature-state-management.properties")) {
+ Properties props = new Properties();
+ props.load(input);
+ return props;
}
}
+
+ private static Properties loadActiveStandbyProperties() throws IOException {
+ try (FileInputStream input =
+ new FileInputStream(CONFIG_DIR + "/feature-active-standby-management.properties")) {
+ Properties props = new Properties();
+ props.load(input);
+ return props;
+ }
+ }
+
+ private void waitForCondition(Callable<Boolean> testCondition, int timeoutInSeconds) throws InterruptedException {
+ testTime.waitUntil(testCondition);
+ }
}
-/*
+/*-
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.controller.test;
+package org.onap.policy.drools.activestandby;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
-
import org.apache.commons.lang3.time.DateUtils;
-import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.im.AdministrativeStateException;
import org.onap.policy.common.im.IntegrityMonitor;
+import org.onap.policy.common.im.IntegrityMonitorException;
+import org.onap.policy.common.im.MonitorTime;
import org.onap.policy.common.im.StandbyStatusException;
import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.drools.activestandby.ActiveStandbyFeatureApi;
-import org.onap.policy.drools.activestandby.ActiveStandbyFeatureApiConstants;
-import org.onap.policy.drools.activestandby.ActiveStandbyProperties;
-import org.onap.policy.drools.activestandby.DroolsPdp;
-import org.onap.policy.drools.activestandby.DroolsPdpEntity;
-import org.onap.policy.drools.activestandby.DroolsPdpImpl;
-import org.onap.policy.drools.activestandby.DroolsPdpsConnector;
-import org.onap.policy.drools.activestandby.DroolsPdpsElectionHandler;
-import org.onap.policy.drools.activestandby.JpaDroolsPdpsConnector;
-import org.onap.policy.drools.activestandby.PmStandbyStateChangeNotifier;
+import org.onap.policy.common.utils.time.CurrentTime;
+import org.onap.policy.common.utils.time.PseudoTimer;
+import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.core.PolicySessionFeatureApi;
import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
+import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StandbyStateManagementTest {
private static final Logger logger = LoggerFactory.getLogger(StandbyStateManagementTest.class);
+
+ private static final String MONITOR_FIELD_NAME = "instance";
+ private static final String HANDLER_INSTANCE_FIELD = "electionHandler";
+
/*
* Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every 1 seconds, starting
* at the start of the next multiple of pdpUpdateInterval, but with a minimum of 5 sec cushion
* checking the results. Add a few seconds for safety
*/
- long sleepTime = 10000;
+ private static final long SLEEP_TIME = 10000;
/*
* DroolsPdpsElectionHandler runs every 1 seconds, so a 6 second sleep should be
* plenty to ensure it has time to re-promote this PDP.
*/
- long electionWaitSleepTime = 6000;
+ private static final long ELECTION_WAIT_SLEEP_TIME = 6000;
/*
- * Sleep 1 seconds after each test to allow interrupt (shutdown) recovery.
+ * Sleep a few seconds after each test to allow interrupt (shutdown) recovery.
*/
- long interruptRecoveryTime = 5000;
+ private static final long INTERRUPT_RECOVERY_TIME = 5000;
private static EntityManagerFactory emfx;
private static EntityManagerFactory emfd;
private static EntityManager emd;
private static EntityTransaction et;
- private final String configDir = "src/test/resources";
+ private static final String CONFIG_DIR = "src/test/resources";
+
+ private static CurrentTime saveTime;
+ private static Factory saveFactory;
+
+ private TestTimeMulti testTime;
/*
* See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
System.setProperty("com.sun.management.jmxremote.port", "9980");
System.setProperty("com.sun.management.jmxremote.authenticate","false");
- }
+ saveTime = Whitebox.getInternalState(MonitorTime.class, MONITOR_FIELD_NAME);
+ saveFactory = Factory.getInstance();
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
+ resetInstanceObjects();
- /**
- * Setup.
- *
- * @throws Exception exception
- */
- @Before
- public void setUp() throws Exception {
- //Create teh data access for xaml db
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- "src/test/resources/feature-state-management.properties")));
+ //Create the data access for xacml db
+ Properties stateManagementProperties = loadStateManagementProperties();
emfx = Persistence.createEntityManagerFactory("junitXacmlPU", stateManagementProperties);
emx = emfx.createEntityManager();
//Create the data access for drools db
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- "src/test/resources/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
emfd = Persistence.createEntityManagerFactory("junitDroolsPU", activeStandbyProperties);
emd = emfd.createEntityManager();
}
- @After
- public void tearDown() throws Exception {
+ /**
+ * Restores the system state.
+ *
+ * @throws IntegrityMonitorException if the integrity monitor cannot be shut down
+ */
+ @AfterClass
+ public static void tearDownClass() throws IntegrityMonitorException {
+ resetInstanceObjects();
+
+ Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, saveTime);
+ Factory.setInstance(saveFactory);
+
+ emd.close();
+ emfd.close();
+
+ emx.close();
+ emfx.close();
+ }
+
+ /**
+ * Setup.
+ *
+ * @throws Exception exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ resetInstanceObjects();
+
+ // set test time
+ testTime = new TestTimeMulti();
+ Whitebox.setInternalState(MonitorTime.class, MONITOR_FIELD_NAME, testTime);
+
+ Factory factory = mock(Factory.class);
+ when(factory.makeTimer()).thenAnswer(ans -> new PseudoTimer(testTime));
+ Factory.setInstance(factory);
+ }
+
+ private static void resetInstanceObjects() throws IntegrityMonitorException {
+ IntegrityMonitor.setUnitTesting(true);
+ IntegrityMonitor.deleteInstance();
+ IntegrityMonitor.setUnitTesting(false);
+
+ Whitebox.setInternalState(ActiveStandbyFeature.class, HANDLER_INSTANCE_FIELD, (Object) null);
}
logger.debug("testPmStandbyStateChangeNotifier: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
String resourceName = "testPMS";
activeStandbyProperties.setProperty("resource.name", resourceName);
// Get a DroolsPdpsConnector
- logger.debug("testSanitizeDesignatedList: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
- String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
logger.debug("testSanitizeDesignatedList: Creating emfDrools");
EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
// 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());
+ DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
+ DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
+ DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
+ DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
List<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
listOfDesignated.add(pdp1);
StateManagementFeatureApi stateManagementFeature = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
stateManagementFeature = feature;
logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}",
stateManagementFeature.getResourceName());
break;
}
- if (stateManagementFeature == null) {
- logger.error("testColdStandby failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testColdStandby failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(stateManagementFeature);
DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
logger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
- logger.debug("testComputeMostRecentPrimary: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
- String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
logger.debug("testComputeMostRecentPrimary: Creating emfDrools");
EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
// Create 4 pdpd all not designated
- long designatedDateMs = new Date().getTime();
- DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
+ long designatedDateMs = testTime.getMillis();
+ DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
- DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
+ DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
//oldest
pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
- DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
+ DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
pdp3.setDesignatedDate(new Date(designatedDateMs - 1));
- DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
+ DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
//most recent
pdp4.setDesignatedDate(new Date(designatedDateMs));
StateManagementFeatureApi stateManagementFeature = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
stateManagementFeature = feature;
logger.debug("testComputeMostRecentPrimary stateManagementFeature.getResourceName(): {}",
stateManagementFeature.getResourceName());
break;
}
- if (stateManagementFeature == null) {
- logger.error("testComputeMostRecentPrimary failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testComputeMostRecentPrimary failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(stateManagementFeature);
DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
logger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
- logger.debug("testComputeDesignatedPdp: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
- String thisPdpId = activeStandbyProperties
- .getProperty(ActiveStandbyProperties.NODE_NAME);
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
logger.debug("testComputeDesignatedPdp: Creating 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());
+ long designatedDateMs = testTime.getMillis();
+ DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, testTime.getDate());
pdp1.setDesignatedDate(new Date(designatedDateMs - 2));
pdp1.setSite("site1");
- DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
+ DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, testTime.getDate());
pdp2.setDesignatedDate(new Date(designatedDateMs - 3));
pdp2.setSite("site1");
//oldest
- DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
+ DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, testTime.getDate());
pdp3.setDesignatedDate(new Date(designatedDateMs - 4));
pdp3.setSite("site2");
- DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
+ DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, testTime.getDate());
//most recent
pdp4.setDesignatedDate(new Date(designatedDateMs));
pdp4.setSite("site2");
StateManagementFeatureApi stateManagementFeature = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
stateManagementFeature = feature;
logger.debug("testComputeDesignatedPdp stateManagementFeature.getResourceName(): {}",
stateManagementFeature.getResourceName());
break;
}
- if (stateManagementFeature == null) {
- logger.error("testComputeDesignatedPdp failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testComputeDesignatedPdp failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(stateManagementFeature);
DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1);
cleanXacmlDb();
cleanDroolsDb();
- logger.debug("testColdStandby: Reading stateManagementProperties");
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ Properties stateManagementProperties = loadStateManagementProperties();
logger.debug("testColdStandby: Creating emfXacml");
final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
"junitXacmlPU", stateManagementProperties);
- logger.debug("testColdStandby: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
final String thisPdpId = activeStandbyProperties.getProperty(ActiveStandbyProperties.NODE_NAME);
logger.debug("testColdStandby: Creating emfDrools");
conn.deleteAllPdps();
logger.debug("testColdStandby: Inserting PDP={} as designated", thisPdpId);
- DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
+ DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
conn.insertPdp(pdp);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testColdStandby: After insertion, DESIGNATED= {} "
StateManagementFeatureApi smf = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
smf = feature;
logger.debug("testColdStandby stateManagementFeature.getResourceName(): {}", smf.getResourceName());
break;
}
- if (smf == null) {
- logger.error("testColdStandby failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testColdStandby failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(smf);
// Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
// that has been created.
ActiveStandbyFeatureApi activeStandbyFeature = null;
for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
activeStandbyFeature = feature;
logger.debug("testColdStandby activeStandbyFeature.getResourceName(): {}",
activeStandbyFeature.getResourceName());
break;
}
- if (activeStandbyFeature == null) {
- logger.error("testColdStandby failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID:{}", thisPdpId);
- logger.debug("testColdStandby failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID:{}", thisPdpId);
- }
+ assertNotNull(activeStandbyFeature);
// 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.
logger.debug("testColdStandby: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting PDP= {}",
+ + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP= {}",
thisPdpId);
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
smf.promote();
logger.debug("testColdStandby: Locking smf");
smf.lock();
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
// Verify that the PDP is no longer designated.
assertTrue(droolsPdpEntity.isDesignated() == false);
logger.debug("\n\ntestColdStandby: Exiting\n\n");
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
}
cleanXacmlDb();
cleanDroolsDb();
- logger.debug("testHotStandby1: Reading stateManagementProperties");
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ Properties stateManagementProperties = loadStateManagementProperties();
logger.debug("testHotStandby1: Creating emfXacml");
final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
"junitXacmlPU", stateManagementProperties);
- logger.debug("testHotStandby1: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
final String thisPdpId = activeStandbyProperties
.getProperty(ActiveStandbyProperties.NODE_NAME);
*/
logger.debug("testHotStandby1: Inserting PDP={} as not designated", thisPdpId);
- Date yesterday = DateUtils.addDays(new Date(), -1);
+ Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
conn.insertPdp(pdp);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
StateManagementFeatureApi smf = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
smf = feature;
logger.debug("testHotStandby1 stateManagementFeature.getResourceName(): {}", smf.getResourceName());
break;
}
- if (smf == null) {
- logger.error("testHotStandby1 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testHotStandby1 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(smf);
// Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
// that has been created.
ActiveStandbyFeatureApi activeStandbyFeature = null;
for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
activeStandbyFeature = feature;
logger.debug("testHotStandby1 activeStandbyFeature.getResourceName(): {}",
activeStandbyFeature.getResourceName());
break;
}
- if (activeStandbyFeature == null) {
- logger.error("testHotStandby1 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testHotStandby1 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(activeStandbyFeature);
logger.debug("testHotStandby1: Demoting PDP={}", thisPdpId);
logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
- + "time to check droolspdpentity table", sleepTime);
- sleep(sleepTime);
+ + "time to check droolspdpentity table", SLEEP_TIME);
+ sleep(SLEEP_TIME);
// Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
logger.debug("testHotStandby1: Stopping policyManagementRunner");
logger.debug("\n\ntestHotStandby1: Exiting\n\n");
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
}
cleanXacmlDb();
cleanDroolsDb();
- logger.info("testHotStandby2: Reading stateManagementProperties");
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ Properties stateManagementProperties = loadStateManagementProperties();
logger.info("testHotStandby2: Creating emfXacml");
final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
"junitXacmlPU", stateManagementProperties);
- logger.info("testHotStandby2: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
final String thisPdpId = activeStandbyProperties
.getProperty(ActiveStandbyProperties.NODE_NAME);
String activePdpId = "pdp2";
logger.info("testHotStandby2: Inserting PDP={} as stale, designated PDP", activePdpId);
- Date yesterday = DateUtils.addDays(new Date(), -1);
+ Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
conn.insertPdp(pdp);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
StateManagementFeatureApi sm2 = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
sm2 = feature;
logger.debug("testHotStandby2 stateManagementFeature.getResourceName(): {}", sm2.getResourceName());
break;
}
- if (sm2 == null) {
- logger.error("testHotStandby2 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testHotStandby2 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(sm2);
// Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
// that has been created.
ActiveStandbyFeatureApi activeStandbyFeature = null;
for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
activeStandbyFeature = feature;
logger.debug("testHotStandby2 activeStandbyFeature.getResourceName(): {}",
activeStandbyFeature.getResourceName());
break;
}
- if (activeStandbyFeature == null) {
- logger.error("testHotStandby2 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testHotStandby2 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(activeStandbyFeature);
logger.info("testHotStandby2: Runner started; Sleeping {} "
- + "ms before promoting/demoting", interruptRecoveryTime);
- sleep(interruptRecoveryTime);
+ + "ms before promoting/demoting", INTERRUPT_RECOVERY_TIME);
+ sleep(INTERRUPT_RECOVERY_TIME);
logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
//At this point, the newly created pdp will have set the state to disabled/failed/cold standby
logger.info("testHotStandby2: After demoting, PDP={} has standbyStatus= {}",thisPdpId , standbyStatus);
logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
- + "time to check droolspdpentity table", sleepTime);
- sleep(sleepTime);
+ + "time to check droolspdpentity table", SLEEP_TIME);
+ sleep(SLEEP_TIME);
/*
* Verify that this PDP, demoted to HOT_STANDBY, is now
logger.info("testHotStandby2: Stopping policyManagementRunner");
logger.info("\n\ntestHotStandby2: Exiting\n\n");
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
}
cleanXacmlDb();
cleanDroolsDb();
- logger.debug("testLocking1: Reading stateManagementProperties");
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ Properties stateManagementProperties = loadStateManagementProperties();
logger.debug("testLocking1: Creating emfXacml");
final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
"junitXacmlPU", stateManagementProperties);
- logger.debug("testLocking1: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
final String thisPdpId = activeStandbyProperties
.getProperty(ActiveStandbyProperties.NODE_NAME);
*/
logger.debug("testLocking1: Inserting PDP= {} as designated", thisPdpId);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
+ DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, testTime.getDate());
conn.insertPdp(pdp);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testLocking1: After insertion, PDP= {} has DESIGNATED= {}",
StateManagementFeatureApi sm = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
sm = feature;
logger.debug("testLocking1 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
break;
}
- if (sm == null) {
- logger.error("testLocking1 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testLocking1 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(sm);
// Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
// that has been created.
ActiveStandbyFeatureApi activeStandbyFeature = null;
for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
activeStandbyFeature = feature;
logger.debug("testLocking1 activeStandbyFeature.getResourceName(): {}",
activeStandbyFeature.getResourceName());
break;
}
- if (activeStandbyFeature == null) {
- logger.error("testLocking1 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testLocking1 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(activeStandbyFeature);
logger.debug("testLocking1: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting PDP={}",
+ + INTERRUPT_RECOVERY_TIME + "ms before promoting PDP={}",
thisPdpId);
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
sm.promote();
logger.debug("testLocking1: Sleeping {} ms, to allow time for "
+ "policy-management.Main class to come up, designated= {}",
- sleepTime, conn.getPdp(thisPdpId).isDesignated());
- sleep(sleepTime);
+ SLEEP_TIME, conn.getPdp(thisPdpId).isDesignated());
+ sleep(SLEEP_TIME);
logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
+ ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
logger.debug("testLocking1: demoting PDP={}", thisPdpId);
sm.demote();
- logger.debug("testLocking1: sleeping" + electionWaitSleepTime
+ logger.debug("testLocking1: sleeping" + ELECTION_WAIT_SLEEP_TIME
+ " to allow election handler to re-promote PDP={}", thisPdpId);
- sleep(electionWaitSleepTime);
+ sleep(ELECTION_WAIT_SLEEP_TIME);
logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
+ ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
// Just to avoid any race conditions, sleep a little after locking
logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
- sleep(electionWaitSleepTime);
+ sleep(ELECTION_WAIT_SLEEP_TIME);
logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
+ thisPdpId
}
logger.debug("\n\ntestLocking1: Exiting\n\n");
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
}
cleanXacmlDb();
cleanDroolsDb();
- logger.debug("testLocking2: Reading stateManagementProperties");
- Properties stateManagementProperties = new Properties();
- stateManagementProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
+ Properties stateManagementProperties = loadStateManagementProperties();
logger.debug("testLocking2: Creating emfXacml");
final EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
"junitXacmlPU", stateManagementProperties);
- logger.debug("testLocking2: Reading activeStandbyProperties");
- Properties activeStandbyProperties = new Properties();
- activeStandbyProperties.load(new FileInputStream(new File(
- configDir + "/feature-active-standby-management.properties")));
+ Properties activeStandbyProperties = loadActiveStandbyProperties();
final String thisPdpId = activeStandbyProperties
.getProperty(ActiveStandbyProperties.NODE_NAME);
*/
logger.debug("testLocking2: Inserting PDP= {} as designated", thisPdpId);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, new Date());
+ DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, testTime.getDate());
conn.insertPdp(pdp);
DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
logger.debug("testLocking2: After insertion, PDP= {} has DESIGNATED= {}",
StateManagementFeatureApi sm = null;
for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
sm = feature;
logger.debug("testLocking2 stateManagementFeature.getResourceName(): {}", sm.getResourceName());
break;
}
- if (sm == null) {
- logger.error("testLocking2 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testLocking2 failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(sm);
// Create an ActiveStandbyFeature and initialize it. It will discover the StateManagementFeature
// that has been created.
ActiveStandbyFeatureApi activeStandbyFeature = null;
for (ActiveStandbyFeatureApi feature : ActiveStandbyFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
+ ((PolicySessionFeatureApi) feature).globalInit(null, CONFIG_DIR);
activeStandbyFeature = feature;
logger.debug("testLocking2 activeStandbyFeature.getResourceName(): {}",
activeStandbyFeature.getResourceName());
break;
}
- if (activeStandbyFeature == null) {
- logger.error("testLocking2 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- logger.debug("testLocking2 failed to initialize. "
- + "Unable to get instance of ActiveStandbyFeatureAPI "
- + "with resourceID: {}", thisPdpId);
- }
+ assertNotNull(activeStandbyFeature);
/*
* Insert another PDP as not designated. Initial standby state will be
String standbyPdpId = "pdp2";
logger.debug("testLocking2: Inserting PDP= {} as not designated", standbyPdpId);
- Date yesterday = DateUtils.addDays(new Date(), -1);
+ Date yesterday = DateUtils.addDays(testTime.getDate(), -1);
pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
conn.insertPdp(pdp);
droolsPdpEntity = conn.getPdp(standbyPdpId);
final StateManagement sm2 = new StateManagement(emfXacml, standbyPdpId);
logger.debug("testLocking2: Runner started; Sleeping {} ms "
- + "before promoting/demoting", interruptRecoveryTime);
- sleep(interruptRecoveryTime);
+ + "before promoting/demoting", INTERRUPT_RECOVERY_TIME);
+ sleep(INTERRUPT_RECOVERY_TIME);
logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
sm.promote();
logger.debug("testLocking2: Demoting PDP={}", standbyPdpId);
sm2.demote();
- logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", sleepTime);
- sleep(sleepTime);
+ logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", SLEEP_TIME);
+ sleep(SLEEP_TIME);
logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
+ ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
sm.demote();
logger.debug("testLocking2: sleeping {}"
- + " to allow election handler to re-promote PDP={}", electionWaitSleepTime, thisPdpId);
- sleep(electionWaitSleepTime);
+ + " to allow election handler to re-promote PDP={}", ELECTION_WAIT_SLEEP_TIME, thisPdpId);
+ sleep(ELECTION_WAIT_SLEEP_TIME);
logger.debug("testLocking2: Waking up and invoking startTransaction "
+ "on re-promoted PDP= {}, designated= {}",
assertTrue(standbyPdpDesignated == false);
logger.debug("\n\ntestLocking2: Exiting\n\n");
- sleep(interruptRecoveryTime);
+ sleep(INTERRUPT_RECOVERY_TIME);
+ }
+
+ private static Properties loadStateManagementProperties() throws IOException {
+ try (FileInputStream input = new FileInputStream(CONFIG_DIR + "/feature-state-management.properties")) {
+ Properties props = new Properties();
+ props.load(input);
+ return props;
+ }
+ }
+
+ private static Properties loadActiveStandbyProperties() throws IOException {
+ try (FileInputStream input =
+ new FileInputStream(CONFIG_DIR + "/feature-active-standby-management.properties")) {
+ Properties props = new Properties();
+ props.load(input);
+ return props;
+ }
}
private void sleep(long sleepms) throws InterruptedException {
- Thread.sleep(sleepms);
+ testTime.waitFor(sleepms);
}
}