summaryrefslogtreecommitdiffstats
path: root/feature-server-pool/src/test/java/org/onap/policy
diff options
context:
space:
mode:
Diffstat (limited to 'feature-server-pool/src/test/java/org/onap/policy')
-rw-r--r--feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java69
-rw-r--r--feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/Adapter.java50
-rw-r--r--feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/SimDmaap.java32
3 files changed, 76 insertions, 75 deletions
diff --git a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java
index bac13f18..70dc2114 100644
--- a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java
+++ b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java
@@ -27,27 +27,21 @@ import java.nio.file.Paths;
import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-
import org.kie.api.runtime.KieSession;
-
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
-
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.core.PolicySession;
import org.onap.policy.drools.core.PolicySessionFeatureApiConstants;
-
import org.onap.policy.drools.serverpooltest.Adapter;
import org.onap.policy.drools.serverpooltest.BucketWrapper;
import org.onap.policy.drools.serverpooltest.ServerWrapper;
import org.onap.policy.drools.serverpooltest.TargetLockWrapper;
-
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.util.KieUtils;
import org.onap.policy.drools.utils.PropertyUtil;
import org.powermock.reflect.Whitebox;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,10 +51,11 @@ import org.slf4j.LoggerFactory;
*/
public class AdapterImpl extends Adapter {
private static Logger logger = LoggerFactory.getLogger(AdapterImpl.class);
-
- // Each 'AdapterImpl' instance has it's own class object, making it a
- // singleton. There is only a single 'Adapter' class object, and all
- // 'AdapterImpl' classes are derived from it.
+ /*
+ * Each 'AdapterImpl' instance has it's own class object, making it a
+ * singleton. There is only a single 'Adapter' class object, and all
+ * 'AdapterImpl' classes are derived from it.
+ */
private static AdapterImpl adapter = null;
// this is the adapter index
@@ -94,29 +89,30 @@ public class AdapterImpl extends Adapter {
PolicyEngineConstants.getManager().configure(new Properties());
PolicyEngineConstants.getManager().start();
-
- // Note that this method does basically what
- // 'FeatureServerPool.afterStart(PolicyEngine)' does, but allows us to
- // specify different properties for each of the 6 simulated hosts
+ /*
+ * Note that this method does basically what
+ * 'FeatureServerPool.afterStart(PolicyEngine)' does, but allows us to
+ * specify different properties for each of the 6 simulated hosts
+ */
logger.info("{}: Running: AdapterImpl.init({}), class hash code = {}",
this, index, AdapterImpl.class.hashCode());
-
- Properties prop = new Properties();
- prop.setProperty("server.pool.discovery.servers", "127.0.63.250");
- prop.setProperty("server.pool.discovery.topic", "DISCOVERY-TOPIC");
- prop.setProperty("server.pool.server.ipAddress", "127.0.63." + index);
- prop.setProperty("server.pool.server.port", "20000");
-
- prop.setProperty("keyword.path", "requestID,CommonHeader.RequestID,key");
-
- prop.setProperty("keyword.org.onap.policy.m2.base.Transaction.lookup",
- "getRequestID()");
- prop.setProperty("keyword.org.onap.policy.controlloop.ControlLoopEvent.lookup", "requestID");
- prop.setProperty("keyword.org.onap.policy.drools.serverpool.TargetLock.lookup", "getOwnerKey()");
- prop.setProperty("keyword.java.lang.String.lookup", "toString()");
- prop.setProperty("keyword.org.onap.policy.drools.serverpooltest.TestDroolsObject.lookup",
- "getKey()");
- prop.setProperty("keyword.org.onap.policy.drools.serverpooltest.Test1$KeywordWrapper.lookup", "key");
+ final String propertyFile = "src/test/resources/feature-server-pool-test.properties";
+ Properties prop = PropertyUtil.getProperties(propertyFile);
+ if (System.getProperty("os.name").toLowerCase().indexOf("mac") < 0) {
+ // Window, Unix
+ String[] ipComponent = prop.getProperty("server.pool.server.ipAddress").split("[.]");
+ String serverIP = ipComponent[0] + "." + ipComponent[1] + "." + ipComponent[2] + "."
+ + (Integer.parseInt(ipComponent[3]) + index);
+ prop.setProperty("server.pool.server.ipAddress", serverIP);
+ } else {
+ // Mac, use localhost and different ports
+ String port = Integer.toString(Integer.parseInt(
+ prop.getProperty("server.pool.server.port")) + index);
+ prop.setProperty("server.pool.server.port", port);
+ }
+ logger.info("server={}, serverIP={}, port={}", index,
+ prop.getProperty("server.pool.server.ipAddress"),
+ prop.getProperty("server.pool.server.port"));
TargetLock.startup();
Server.startup(prop);
@@ -181,8 +177,6 @@ public class AdapterImpl extends Adapter {
while (bucket.getOwner() == null) {
Thread.sleep(Math.min(endTime - System.currentTimeMillis(), 100L));
}
- //await().atMost(endTime - System.currentTimeMillis(),
- //TimeUnit.MILLISECONDS).until(() -> bucket.getOwner() != null);
}
} catch (IllegalArgumentException e) {
// 'Thread.sleep()' was passed a negative time-out value --
@@ -253,10 +247,11 @@ public class AdapterImpl extends Adapter {
@Override
public String createController() {
Properties properties;
-
- // set the thread class loader to be the same as the one associated
- // with the 'AdapterImpl' instance, so it will be inherited by any
- // new threads created (the Drools session thread, in particular)
+ /*
+ * set the thread class loader to be the same as the one associated
+ * with the 'AdapterImpl' instance, so it will be inherited by any
+ * new threads created (the Drools session thread, in particular)
+ */
ClassLoader saveClassLoader =
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(AdapterImpl.class.getClassLoader());
diff --git a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/Adapter.java b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/Adapter.java
index 03b970b5..d5d836b4 100644
--- a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/Adapter.java
+++ b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/Adapter.java
@@ -23,21 +23,16 @@ package org.onap.policy.drools.serverpooltest;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamClass;
import java.io.PrintStream;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue;
-
import org.kie.api.runtime.KieSession;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.serverpool.Util;
+import org.onap.policy.drools.utils.PropertyUtil;
/**
* This is a common base class for 6 'AdapterImpl' instances, all running
@@ -53,11 +48,12 @@ import org.onap.policy.drools.serverpool.Util;
public abstract class Adapter {
// 'true' indicates that initialization is still needed
private static boolean initNeeded = true;
-
- // Each 'Adapter' instance is implemented by 'AdapterImpl', but loaded
- // with a different class loader that provides each with a different copy
- // of the set of classes with packages in the list below (see references to
- // 'BlockingClassLoader').
+ /*
+ * Each 'Adapter' instance is implemented by 'AdapterImpl', but loaded
+ * with a different class loader that provides each with a different copy
+ * of the set of classes with packages in the list below (see references to
+ * 'BlockingClassLoader').
+ */
public static Adapter[] adapters = new Adapter[6];
/**
@@ -76,8 +72,11 @@ public abstract class Adapter {
}
}, "DMAAP Simulator").start();
- // wait 1 second to allow time for the port 3904 listener
- assertTrue(NetworkUtil.isTcpPortOpen(SimDmaap.HOSTNAME, 3904, 50, 1000));
+ // wait 200 millisecond to allow time for the port 3904 listener
+ final String propertyFile = "src/test/resources/feature-server-pool-test.properties";
+ Properties prop = PropertyUtil.getProperties(propertyFile);
+ assertTrue(NetworkUtil.isTcpPortOpen(prop.getProperty("server.pool.discovery.servers"),
+ Integer.parseInt(prop.getProperty("server.pool.discovery.port")), 250, 200));
// build 'BlockingClassLoader'
BlockingClassLoader bcl = new BlockingClassLoader(
@@ -113,18 +112,21 @@ public abstract class Adapter {
}
try {
for (int i = 0 ; i < adapters.length ; i += 1) {
- // Build a new 'ClassLoader' for this adapter. The
- // 'ClassLoader' hierarchy is:
- //
- // AdapterClassLoader(one copy per Adapter) ->
- // BlockingClassLoader ->
- // base ClassLoader (with the complete URL list)
+ /*
+ * Build a new 'ClassLoader' for this adapter. The
+ * 'ClassLoader' hierarchy is:
+ *
+ * AdapterClassLoader(one copy per Adapter) ->
+ * BlockingClassLoader ->
+ * base ClassLoader (with the complete URL list)
+ */
ClassLoader classLoader =
new AdapterClassLoader(i, urls, bcl);
-
- // set the current thread class loader, which should be
- // inherited by any child threads created during
- // the initialization of the adapter
+ /*
+ * set the current thread class loader, which should be
+ * inherited by any child threads created during
+ * the initialization of the adapter
+ */
Thread.currentThread().setContextClassLoader(classLoader);
// now, build the adapter -- it is not just a new instance,
diff --git a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/SimDmaap.java b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/SimDmaap.java
index 74fef07f..8513c1f0 100644
--- a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/SimDmaap.java
+++ b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpooltest/SimDmaap.java
@@ -21,6 +21,7 @@
package org.onap.policy.drools.serverpooltest;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
@@ -39,7 +40,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-
+import org.onap.policy.drools.utils.PropertyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,7 +51,6 @@ import org.slf4j.LoggerFactory;
@Path("/")
public class SimDmaap {
private static Logger logger = LoggerFactory.getLogger(SimDmaap.class);
- public static final String HOSTNAME = "127.0.63.250";
// miscellaneous Jetty/Servlet parameters
private static ServletContextHandler context;
@@ -73,8 +73,10 @@ public class SimDmaap {
connector = new ServerConnector(jettyServer);
connector.setName("simdmaap");
connector.setReuseAddress(true);
- connector.setPort(3904);
- connector.setHost("127.0.63.250");
+ final String propertyFile = "src/test/resources/feature-server-pool-test.properties";
+ Properties prop = PropertyUtil.getProperties(propertyFile);
+ connector.setPort(Integer.parseInt(prop.getProperty("server.pool.discovery.port")));
+ connector.setHost(prop.getProperty("server.pool.discovery.servers"));
jettyServer.addConnector(connector);
jettyServer.setHandler(context);
@@ -166,11 +168,12 @@ public class SimDmaap {
int messageCount = 0;
while (cur < end) {
- // The body of the message may consist of multiple JSON messages,
- // each preceded by 3 integers separated by '.'. The second one
- // is the length, in bytes (the third seems to be some kind of
- // channel identifier).
-
+ /*
+ * The body of the message may consist of multiple JSON messages,
+ * each preceded by 3 integers separated by '.'. The second one
+ * is the length, in bytes (the third seems to be some kind of
+ * channel identifier).
+ */
int leftBrace = data.indexOf('{', cur);
if (leftBrace < 0) {
// no more messages
@@ -182,11 +185,12 @@ public class SimDmaap {
// determine length of message, and advance current position
int length = Integer.valueOf(prefix[1]);
cur = leftBrace + length;
-
- // extract message, and update count -- each double quote
- // has a '\' character placed before it, so the overall
- // message can be placed in double quotes, and parsed as
- // a literal string
+ /*
+ * extract message, and update count -- each double quote
+ * has a '\' character placed before it, so the overall
+ * message can be placed in double quotes, and parsed as
+ * a literal string
+ */
String message = data.substring(leftBrace, cur)
.replace("\\", "\\\\").replace("\"", "\\\"")
.replace("\n", "\\n");