aboutsummaryrefslogtreecommitdiffstats
path: root/context/context-test-utils
diff options
context:
space:
mode:
Diffstat (limited to 'context/context-test-utils')
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java2
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java351
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java2
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java2
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java13
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java24
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java11
-rw-r--r--context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ZooKeeperServerServiceProvider.java30
8 files changed, 230 insertions, 205 deletions
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java
index 0d2528791..50f968997 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java
@@ -54,7 +54,7 @@ public class ContextAlbumUpdate {
* @throws IOException the IO exception
* @throws ApexException the apex exception
*/
- public void testContextAlbumUpdate() throws IOException, ApexException {
+ public void testContextAlbumUpdate() throws ApexException {
LOGGER.debug("Running TestContextAlbumUpdate test . . .");
final AxArtifactKey distributorKey = new AxArtifactKey(APEX_DISTRIBUTOR, VERSION);
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java
index 17c98a12d..8c4f40a5a 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java
@@ -133,218 +133,211 @@ public class ContextInstantiation {
final Distributor contextDistributor = getDistributor();
- try {
+ final ContextAlbum policyContextAlbum = contextDistributor
+ .createContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION));
+
+ assertNotNull(policyContextAlbum);
+ policyContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
+
+ final Date testDate = new Date();
+
+ final TestContextDateTzItem tci9 = getTestContextDateTzItem(testDate);
+ final TestContextDateLocaleItem tciA = getTestContextDateLocaleItem(testDate);
+
+ final TestPolicyContextItem policyContext = getTestPolicyContextItem(policyContextAlbum, testDate);
+
+ final Map<String, Object> valueMap0 = new HashMap<>();
+ valueMap0.put(TEST_POLICY_CONTEXT_ITEM, policyContext);
+
+ policyContextAlbum.putAll(valueMap0);
+
+ final TestPolicyContextItem contextItem = (TestPolicyContextItem) policyContextAlbum
+ .get(TEST_POLICY_CONTEXT_ITEM);
+ assertEquals(STRING_VAL, contextItem.getTestPolicyContextItem000().getStringValue());
+
+ assertEquals(LONG_VAL, contextItem.getTestPolicyContextItem001().getLongValue());
+ assertDouble(contextItem.getTestPolicyContextItem002().getDoubleValue(), PI_VAL);
+ assertTrue(contextItem.getTestPolicyContextItem003().getFlag());
+ assertEquals(contextItem.getTestPolicyContextItem004().getLongValue(), testDate.getTime());
+ assertEquals(TEST_HASH_MAP, contextItem.getTestPolicyContextItem005().getMapValue());
+
+ final TestGlobalContextItem globalContext = getTestGlobalContextItem(contextDistributor, testDate, tci9,
+ tciA);
+
+ final Map<String, Object> valueMap1 = new HashMap<>();
+ valueMap1.put(GLOBAL_CONTEXT_KEY, globalContext);
+
+ final ContextAlbum globalContextAlbum = getContextAlbum(contextDistributor);
+
+ globalContextAlbum.putAll(valueMap1);
- final ContextAlbum policyContextAlbum = contextDistributor
- .createContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION));
+ final TestGlobalContextItem globalContextItem = (TestGlobalContextItem) globalContextAlbum
+ .get(GLOBAL_CONTEXT_KEY);
- assertNotNull(policyContextAlbum);
- policyContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
+ assertFalse(globalContextItem.getTestGlobalContextItem000().getFlag());
- final Date testDate = new Date();
+ assertEquals(BYTE_VAL, globalContextItem.getTestGlobalContextItem001().getByteValue());
- final TestContextDateTzItem tci9 = getTestContextDateTzItem(testDate);
- final TestContextDateLocaleItem tciA = getTestContextDateLocaleItem(testDate);
+ assertEquals(INT_VAL, globalContextItem.getTestGlobalContextItem002().getIntValue());
+ assertEquals(LONG_VAL, globalContextItem.getTestGlobalContextItem003().getLongValue());
+ assertFloat(FLOAT_VAL, globalContextItem.getTestGlobalContextItem004().getFloatValue());
- final TestPolicyContextItem policyContext = getTestPolicyContextItem(policyContextAlbum, testDate);
+ assertDouble(PI_VAL, globalContextItem.getTestGlobalContextItem005().getDoubleValue());
+ assertEquals(STRING_GLOBAL_VAL, globalContextItem.getTestGlobalContextItem006().getStringValue());
- final Map<String, Object> valueMap0 = new HashMap<>();
- valueMap0.put(TEST_POLICY_CONTEXT_ITEM, policyContext);
+ assertEquals((Long) testDate.getTime(), globalContextItem.getTestGlobalContextItem007().getLongValue());
+ assertEquals(testDate, globalContextItem.getTestGlobalContextItem008().getDateValue());
+ assertEquals(tci9.getDateValue().getTime(),
+ globalContextItem.getTestGlobalContextItem009().getDateValue().getTime());
- policyContextAlbum.putAll(valueMap0);
+ assertEquals(tciA.getDateValue().getTime(),
+ globalContextItem.getTestGlobalContextItem00A().getDateValue().getTime());
- final TestPolicyContextItem contextItem = (TestPolicyContextItem) policyContextAlbum
- .get(TEST_POLICY_CONTEXT_ITEM);
- assertEquals(STRING_VAL, contextItem.getTestPolicyContextItem000().getStringValue());
+ assertEquals(TEST_TREE_SET, globalContextItem.getTestGlobalContextItem00B().getSetValue());
+ assertEquals(TEST_HASH_MAP, globalContextItem.getTestGlobalContextItem00C().getMapValue());
- assertEquals(LONG_VAL, contextItem.getTestPolicyContextItem001().getLongValue());
- assertDouble(contextItem.getTestPolicyContextItem002().getDoubleValue(), PI_VAL);
- assertTrue(contextItem.getTestPolicyContextItem003().getFlag());
- assertEquals(contextItem.getTestPolicyContextItem004().getLongValue(), testDate.getTime());
- assertEquals(TEST_HASH_MAP, contextItem.getTestPolicyContextItem005().getMapValue());
+ final AxContextModel externalContextModel = TestContextAlbumFactory.createExternalContextModel();
- final TestGlobalContextItem globalContext = getTestGlobalContextItem(contextDistributor, testDate, tci9,
- tciA);
+ final TestContextDateTzItem tci9A = new TestContextDateTzItem(tci9);
+ final TestContextDateLocaleItem tciAa = new TestContextDateLocaleItem(tciA);
+ final TestExternalContextItem externalContext = getTestExternalContextItem(testDate, tci9A, tciAa);
- final Map<String, Object> valueMap1 = new HashMap<>();
- valueMap1.put(GLOBAL_CONTEXT_KEY, globalContext);
+ final Map<String, Object> valueMap2 = new HashMap<>();
+ valueMap2.put(EXTERNAL_CONTEXT, externalContext);
- final ContextAlbum globalContextAlbum = getContextAlbum(contextDistributor);
+ contextDistributor.clear();
+ contextDistributor.init(new AxArtifactKey("ClearedandInittedDistributor", VERSION));
+ contextDistributor.registerModel(externalContextModel);
- globalContextAlbum.putAll(valueMap1);
+ final AxArtifactKey axContextAlbumKey = new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION);
+ final ContextAlbum externalContextAlbum = contextDistributor.createContextAlbum(axContextAlbumKey);
+ assertNotNull(externalContextAlbum);
+ externalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
- final TestGlobalContextItem globalContextItem = (TestGlobalContextItem) globalContextAlbum
- .get(GLOBAL_CONTEXT_KEY);
+ externalContextAlbum.putAll(valueMap2);
+ externalContextAlbum.getAlbumDefinition().setWritable(false);
- assertFalse(globalContextItem.getTestGlobalContextItem000().getFlag());
+ TestExternalContextItem externalContextItem = (TestExternalContextItem) externalContextAlbum
+ .get(EXTERNAL_CONTEXT);
- assertEquals(BYTE_VAL, globalContextItem.getTestGlobalContextItem001().getByteValue());
+ assertFalse(externalContextItem.getTestExternalContextItem000().getFlag());
+ assertEquals(BYTE_VAL, externalContextItem.getTestExternalContextItem001().getByteValue());
+ assertEquals(INT_VAL, externalContextItem.getTestExternalContextItem002().getIntValue());
- assertEquals(INT_VAL, globalContextItem.getTestGlobalContextItem002().getIntValue());
- assertEquals(LONG_VAL, globalContextItem.getTestGlobalContextItem003().getLongValue());
- assertFloat(FLOAT_VAL, globalContextItem.getTestGlobalContextItem004().getFloatValue());
+ assertFloat(LONG_VAL, externalContextItem.getTestExternalContextItem003().getLongValue());
+ assertFloat(FLOAT_VAL, externalContextItem.getTestExternalContextItem004().getFloatValue());
- assertDouble(PI_VAL, globalContextItem.getTestGlobalContextItem005().getDoubleValue());
- assertEquals(STRING_GLOBAL_VAL, globalContextItem.getTestGlobalContextItem006().getStringValue());
+ assertDouble(PI_VAL, externalContextItem.getTestExternalContextItem005().getDoubleValue());
+ assertEquals(STRING_EXT_VAL, externalContextItem.getTestExternalContextItem006().getStringValue());
+ assertEquals((Long) testDate.getTime(), externalContextItem.getTestExternalContextItem007().getLongValue());
+ assertEquals(testDate, externalContextItem.getTestExternalContextItem008().getDateValue());
+ assertEquals(tci9A.getDateValue().getTime(),
+ externalContextItem.getTestExternalContextItem009().getDateValue().getTime());
- assertEquals((Long) testDate.getTime(), globalContextItem.getTestGlobalContextItem007().getLongValue());
- assertEquals(testDate, globalContextItem.getTestGlobalContextItem008().getDateValue());
- assertEquals(tci9.getDateValue().getTime(),
- globalContextItem.getTestGlobalContextItem009().getDateValue().getTime());
+ assertEquals(tciAa.getDateValue().getTime(),
+ externalContextItem.getTestExternalContextItem00A().getDateValue().getTime());
+ assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
+ assertEquals(TEST_HASH_MAP, externalContextItem.getTestExternalContextItem00C().getMapValue());
- assertEquals(tciA.getDateValue().getTime(),
- globalContextItem.getTestGlobalContextItem00A().getDateValue().getTime());
+ final Collection<Object> mapValues = externalContextAlbum.values();
+ assertTrue(externalContextAlbum.values().containsAll(mapValues));
+
+ // Check that clearing does not work
+ try {
+ externalContextAlbum.clear();
+ fail(EXCEPTION_MESSAGE);
+ } catch (final ContextRuntimeException e) {
+ assertEquals("album \"ExternalContextAlbum:0.0.1\" clear() not allowed on read only albums",
+ e.getMessage());
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
+ }
+
+ assertEquals(1, externalContextAlbum.size());
+
+ assertContextAlbumContains(externalContext, externalContextAlbum);
+
+ final Set<Entry<String, Object>> entrySet = externalContextAlbum.entrySet();
+ assertEquals(1, entrySet.size());
+
+ try {
+ externalContextAlbum.get(null);
+ } catch (final ContextRuntimeException e) {
+ assertEquals("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for get()",
+ e.getMessage());
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
+ }
- assertEquals(TEST_TREE_SET, globalContextItem.getTestGlobalContextItem00B().getSetValue());
- assertEquals(TEST_HASH_MAP, globalContextItem.getTestGlobalContextItem00C().getMapValue());
+ final Object aObject = externalContextAlbum.get(EXTERNAL_CONTEXT);
+ assertEquals(aObject, externalContext);
- final AxContextModel externalContextModel = TestContextAlbumFactory.createExternalContextModel();
+ // put null keys should fail, throws a runtime exception
+ try {
+ externalContextAlbum.put(null, null);
+ } catch (final ContextRuntimeException e) {
+ assertEquals("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for put()",
+ e.getMessage());
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
+ }
- final TestContextDateTzItem tci9A = new TestContextDateTzItem(tci9);
- final TestContextDateLocaleItem tciAa = new TestContextDateLocaleItem(tciA);
- final TestExternalContextItem externalContext = getTestExternalContextItem(testDate, tci9A, tciAa);
+ try {
+ externalContextAlbum.put("TestExternalContextItem00A", null);
+ } catch (final ContextRuntimeException e) {
+ assertEquals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItem00A\" for put()", e.getMessage());
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
+ }
+ assertEquals(tciAa, externalContextItem.getTestExternalContextItem00A());
- final Map<String, Object> valueMap2 = new HashMap<>();
- valueMap2.put(EXTERNAL_CONTEXT, externalContext);
+ // Should return the hash set
+ assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
- contextDistributor.clear();
- contextDistributor.init(new AxArtifactKey("ClearedandInittedDistributor", VERSION));
- contextDistributor.registerModel(externalContextModel);
+ assertTrue(externalContextAlbum.values().containsAll(mapValues));
- final AxArtifactKey axContextAlbumKey = new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION);
- final ContextAlbum externalContextAlbum = contextDistributor.createContextAlbum(axContextAlbumKey);
- assertNotNull(externalContextAlbum);
- externalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
+ // Set the write flag back as it should be
+ externalContextAlbum.getAlbumDefinition().setWritable(true);
- externalContextAlbum.putAll(valueMap2);
- externalContextAlbum.getAlbumDefinition().setWritable(false);
+ // Put should return the previous contextItem
+ final TestExternalContextItem externalContextOther = new TestExternalContextItem();
+ externalContextOther.setTestExternalContextItem002(new TestContextIntItem());
+ externalContextOther.getTestExternalContextItem002().setIntValue(INT_VAL_2);
- TestExternalContextItem externalContextItem = (TestExternalContextItem) externalContextAlbum
- .get(EXTERNAL_CONTEXT);
+ assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther).equals(externalContext));
+ externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
+ assertEquals(INT_VAL_2, externalContextItem.getTestExternalContextItem002().getIntValue());
+ assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext).equals(externalContextOther));
+ externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
+ assertEquals(INT_VAL_3, externalContextItem.getTestExternalContextItem002().getIntValue());
- assertFalse(externalContextItem.getTestExternalContextItem000().getFlag());
- assertEquals(BYTE_VAL, externalContextItem.getTestExternalContextItem001().getByteValue());
- assertEquals(INT_VAL, externalContextItem.getTestExternalContextItem002().getIntValue());
+ try {
+ externalContextAlbum.put("TestExternalContextItem00A", null);
+ } catch (final ContextRuntimeException e) {
+ assert (e.getMessage().equals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItem00A\" for put()"));
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
+ }
+ assertTrue(externalContextAlbum.get(EXTERNAL_CONTEXT).equals(externalContext));
- assertFloat(LONG_VAL, externalContextItem.getTestExternalContextItem003().getLongValue());
- assertFloat(FLOAT_VAL, externalContextItem.getTestExternalContextItem004().getFloatValue());
+ try {
+ externalContextAlbum.put("TestExternalContextItemFFF", null);
+ } catch (final ContextRuntimeException e) {
+ assert (e.getMessage().equals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItemFFF\" for put()"));
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
+ }
+ assertEquals(1, externalContextAlbum.size());
- assertDouble(PI_VAL, externalContextItem.getTestExternalContextItem005().getDoubleValue());
- assertEquals(STRING_EXT_VAL, externalContextItem.getTestExternalContextItem006().getStringValue());
- assertEquals((Long) testDate.getTime(), externalContextItem.getTestExternalContextItem007().getLongValue());
- assertEquals(testDate, externalContextItem.getTestExternalContextItem008().getDateValue());
- assertEquals(tci9A.getDateValue().getTime(),
- externalContextItem.getTestExternalContextItem009().getDateValue().getTime());
-
- assertEquals(tciAa.getDateValue().getTime(),
- externalContextItem.getTestExternalContextItem00A().getDateValue().getTime());
- assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
- assertEquals(TEST_HASH_MAP, externalContextItem.getTestExternalContextItem00C().getMapValue());
-
- final Collection<Object> mapValues = externalContextAlbum.values();
- assertTrue(externalContextAlbum.values().containsAll(mapValues));
-
- // Check that clearing does not work
- try {
- externalContextAlbum.clear();
- fail(EXCEPTION_MESSAGE);
- } catch (final ContextRuntimeException e) {
- assertEquals("album \"ExternalContextAlbum:0.0.1\" clear() not allowed on read only albums",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
-
- assertEquals(1, externalContextAlbum.size());
-
- assertContextAlbumContains(externalContext, externalContextAlbum);
-
- final Set<Entry<String, Object>> entrySet = externalContextAlbum.entrySet();
- assertEquals(1, entrySet.size());
-
- try {
- externalContextAlbum.get(null);
- } catch (final ContextRuntimeException e) {
- assertEquals("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for get()",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
-
- final Object aObject = externalContextAlbum.get(EXTERNAL_CONTEXT);
- assertEquals(aObject, externalContext);
-
- // put null keys should fail, throws a runtime exception
- try {
- externalContextAlbum.put(null, null);
- } catch (final ContextRuntimeException e) {
- assertEquals("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for put()",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
-
- try {
- externalContextAlbum.put("TestExternalContextItem00A", null);
- } catch (final ContextRuntimeException e) {
- assertEquals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItem00A\" for put()", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
- assertEquals(tciAa, externalContextItem.getTestExternalContextItem00A());
-
- // Should return the hash set
- assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
-
- assertTrue(externalContextAlbum.values().containsAll(mapValues));
-
- // Set the write flag back as it should be
- externalContextAlbum.getAlbumDefinition().setWritable(true);
-
- // Put should return the previous contextItem
- final TestExternalContextItem externalContextOther = new TestExternalContextItem();
- externalContextOther.setTestExternalContextItem002(new TestContextIntItem());
- externalContextOther.getTestExternalContextItem002().setIntValue(INT_VAL_2);
-
- assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther).equals(externalContext));
- externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
- assertEquals(INT_VAL_2, externalContextItem.getTestExternalContextItem002().getIntValue());
- assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext).equals(externalContextOther));
- externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
- assertEquals(INT_VAL_3, externalContextItem.getTestExternalContextItem002().getIntValue());
-
- try {
- externalContextAlbum.put("TestExternalContextItem00A", null);
- } catch (final ContextRuntimeException e) {
- assert (e.getMessage().equals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItem00A\" for put()"));
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
- assertTrue(externalContextAlbum.get(EXTERNAL_CONTEXT).equals(externalContext));
-
- try {
- externalContextAlbum.put("TestExternalContextItemFFF", null);
- } catch (final ContextRuntimeException e) {
- assert (e.getMessage().equals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItemFFF\" for put()"));
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
- assertEquals(1, externalContextAlbum.size());
-
- try {
- externalContextAlbum.put("TestExternalContextItemFFF", null);
- } catch (final ContextRuntimeException e) {
- assertEquals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItemFFF\" for put()", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
- assertEquals(1, externalContextAlbum.size());
-
- // Should ignore remove
- externalContextAlbum.remove("TestExternalContextItem017");
- assertEquals(1, externalContextAlbum.size());
- assertEquals(1, externalContextAlbum.values().size());
- assertTrue(externalContextAlbum.values().containsAll(mapValues));
- } catch (final Exception exception) {
- LOGGER.error("Unexpected Error:", exception);
- throw exception;
- } finally {
- contextDistributor.clear();
+ try {
+ externalContextAlbum.put("TestExternalContextItemFFF", null);
+ } catch (final ContextRuntimeException e) {
+ assertEquals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItemFFF\" for put()", e.getMessage());
+ LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
}
+ assertEquals(1, externalContextAlbum.size());
+
+ // Should ignore remove
+ externalContextAlbum.remove("TestExternalContextItem017");
+ assertEquals(1, externalContextAlbum.size());
+ assertEquals(1, externalContextAlbum.values().size());
+ assertTrue(externalContextAlbum.values().containsAll(mapValues));
+ contextDistributor.clear();
}
private void assertContextAlbumContains(final TestExternalContextItem externalContext,
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java
index d6a55effb..65f50d703 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java
@@ -77,7 +77,7 @@ public class ContextUpdate {
* @throws IOException the IO exception
* @throws ApexException the apex exception
*/
- public void testContextUpdate() throws IOException, ApexException {
+ public void testContextUpdate() throws ApexException {
LOGGER.debug("Running TestContextUpdate test . . .");
final Distributor contextDistributor = getDistributor();
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java
index 87ffa3b40..ee0a1072c 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java
@@ -67,7 +67,7 @@ public class ConcurrentContext {
* @throws ApexException the Apex exception occurs in handling Apex
*/
public Map<String, TestContextLongItem> testConcurrentContext()
- throws IOException, ApexException {
+ throws ApexException {
try {
setupAndVerifyContext();
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java
index b8e052947..cd2c2ed1f 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java
@@ -24,6 +24,7 @@ import com.google.gson.Gson;
import java.net.InetAddress;
import java.net.NetworkInterface;
+import java.net.SocketException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -193,7 +194,7 @@ public final class ConcurrentContextJvm {
*
* @throws Exception on configuration errors
*/
- public static void configure() throws Exception {
+ public static void configure() throws ApexException {
System.setProperty("java.net.preferIPv4Stack", "true");
// The JGroups IP address must be set to a real (not loopback) IP address for Infinispan to
// work. IN order to
@@ -204,7 +205,13 @@ public final class ConcurrentContextJvm {
// on a host
final TreeSet<String> ipAddressSet = new TreeSet<>();
- final Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
+ Enumeration<NetworkInterface> nets;
+ try {
+ nets = NetworkInterface.getNetworkInterfaces();
+ } catch (SocketException e) {
+ throw new ApexException("cound not get network interfaces for test", e);
+ }
+
for (final NetworkInterface netint : Collections.list(nets)) {
final Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (final InetAddress inetAddress : Collections.list(inetAddresses)) {
@@ -216,7 +223,7 @@ public final class ConcurrentContextJvm {
}
if (ipAddressSet.isEmpty()) {
- throw new Exception("cound not find real IP address for test");
+ throw new ApexException("cound not find real IP address for test");
}
LOGGER.info("Setting jgroups.tcp.address to: " + ipAddressSet.first());
System.setProperty("jgroups.tcp.address", ipAddressSet.first());
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java
index dca72391a..9e23175fb 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java
@@ -102,19 +102,27 @@ public class ConcurrentContextJvmThread implements Runnable, Closeable {
LOGGER.info(line);
}
- // Wait to get exit value
- try {
- final int exitValue = process.waitFor();
- LOGGER.info("\n\nJVM " + jvm + " finished, exit value is " + exitValue);
- } catch (final InterruptedException e) {
- LOGGER.warn("Thread was interrupted");
- Thread.currentThread().interrupt();
- }
+ waitForExitValue();
+
} catch (final Exception ioException) {
LOGGER.error("Error occured while writing JVM Output for command ", ioException);
}
}
+ /**
+ * Wait for an exit value from the the JVM.
+ */
+ private void waitForExitValue() {
+ // Wait to get exit value
+ try {
+ final int exitValue = process.waitFor();
+ LOGGER.info("\n\nJVM " + jvm + " finished, exit value is " + exitValue);
+ } catch (final InterruptedException e) {
+ LOGGER.warn("Thread was interrupted");
+ Thread.currentThread().interrupt();
+ }
+ }
+
@Override
public void close() {
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java
index 4761bc6f1..ba620d1f4 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java
@@ -65,6 +65,11 @@ public class Constants {
private static final AxArtifactKey[] USED_ARTIFACT_STACK_ARRAY = new AxArtifactKey[] {KEY, KEY2, KEY3};
/**
+ * Instantiates a new constants.
+ */
+ private Constants() {}
+
+ /**
* Gets the ax artifact key array.
*
* @return the ax artifact key array
@@ -72,10 +77,4 @@ public class Constants {
public static final AxArtifactKey[] getAxArtifactKeyArray() {
return USED_ARTIFACT_STACK_ARRAY;
}
-
- /**
- * Instantiates a new constants.
- */
- private Constants() {}
-
}
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ZooKeeperServerServiceProvider.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ZooKeeperServerServiceProvider.java
index 301e8cc61..1c28388ad 100644
--- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ZooKeeperServerServiceProvider.java
+++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ZooKeeperServerServiceProvider.java
@@ -26,7 +26,7 @@ import java.net.InetSocketAddress;
import org.apache.zookeeper.server.NIOServerCnxnFactory;
import org.apache.zookeeper.server.ZooKeeperServer;
-
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -68,12 +68,30 @@ public class ZooKeeperServerServiceProvider {
* @throws IOException the IO exception occurs while setting up Zookeeper server
* @throws InterruptedException the interrupted exception occurs while setting up Zookeeper server
*/
- public void startZookeeperServer() throws IOException, InterruptedException {
+ public void startZookeeperServer() throws ApexException {
LOGGER.info("Starting up ZooKeeperServer using address: {} and port: {}", addr.getAddress(), addr.getPort());
- final ZooKeeperServer server = new ZooKeeperServer(zookeeperDirectory, zookeeperDirectory, 5000);
- zookeeperFactory = new NIOServerCnxnFactory();
- zookeeperFactory.configure(addr, 100);
- zookeeperFactory.startup(server);
+
+ ZooKeeperServer server;
+ try {
+ server = new ZooKeeperServer(zookeeperDirectory, zookeeperDirectory, 5000);
+ zookeeperFactory = new NIOServerCnxnFactory();
+ zookeeperFactory.configure(addr, 100);
+ }
+ catch (IOException ioe) {
+ String message = "exception on starting Zookeeper server";
+ LOGGER.warn(message, ioe);
+ throw new ApexException(message, ioe);
+ }
+
+ try {
+ zookeeperFactory.startup(server);
+ }
+ catch (InterruptedException | IOException ie) {
+ String message = "Zookeeper server start failed";
+ LOGGER.warn(message, ie);
+ throw new ApexException(message, ie);
+ }
+
}
/**