diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-08-30 09:37:29 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-08-31 19:23:41 +0100 |
commit | f32508381ce0b555fc14978cbaa458aa4e2d91c5 (patch) | |
tree | 1cab66e5372b6467f288ae1351ce836e4eba2d03 /testsuites/integration/integration-uservice-test/src | |
parent | 052038c7a7e0b385462b3b653b7d06094d472df3 (diff) |
Use parameter service in apex
Switch parameter handling in apex to use
the ONAP PF common parameter service
Change-Id: Id318d19c726b18b1a69c630fa81ca7d695355e9c
Issue-ID: POLICY-954
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'testsuites/integration/integration-uservice-test/src')
7 files changed, 86 insertions, 44 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/KafkaEventProducer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/KafkaEventProducer.java index 639b450df..c243b8b07 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/KafkaEventProducer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/KafkaEventProducer.java @@ -40,14 +40,12 @@ public class KafkaEventProducer implements Runnable { private final long eventInterval; private long eventsSentCount = 0; - private Producer<String, String> producer; - private final Thread producerThread; private boolean sendEventsFlag = false; private boolean stopFlag = false; public KafkaEventProducer(final String topic, final String kafkaServerAddress, final int eventCount, - final boolean xmlEvents, final long eventInterval) { + final boolean xmlEvents, final long eventInterval) { this.topic = topic; this.kafkaServerAddress = kafkaServerAddress; this.eventCount = eventCount; @@ -70,13 +68,13 @@ public class KafkaEventProducer implements Runnable { kafkaProducerProperties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); kafkaProducerProperties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); - producer = new KafkaProducer<String, String>(kafkaProducerProperties); + final Producer<String, String> producer = new KafkaProducer<String, String>(kafkaProducerProperties); while (producerThread.isAlive() && !stopFlag) { ThreadUtilities.sleep(50); if (sendEventsFlag) { - sendEventsToTopic(); + sendEventsToTopic(producer); sendEventsFlag = false; } } @@ -88,13 +86,13 @@ public class KafkaEventProducer implements Runnable { sendEventsFlag = true; } - private void sendEventsToTopic() { + private void sendEventsToTopic(final Producer<String, String> producer) { System.out.println(KafkaEventProducer.class.getCanonicalName() + ": sending events to Kafka server at " - + kafkaServerAddress + ", event count " + eventCount + ", xmlEvents " + xmlEvents); + + kafkaServerAddress + ", event count " + eventCount + ", xmlEvents " + xmlEvents); for (int i = 0; i < eventCount; i++) { System.out.println(KafkaEventProducer.class.getCanonicalName() + ": waiting " + eventInterval - + " milliseconds before sending next event"); + + " milliseconds before sending next event"); ThreadUtilities.sleep(eventInterval); String eventString = null; @@ -159,8 +157,8 @@ public class KafkaEventProducer implements Runnable { return; } - final KafkaEventProducer producer = - new KafkaEventProducer(args[0], args[1], eventCount, xmlEvents, eventInterval); + final KafkaEventProducer producer = new KafkaEventProducer(args[0], args[1], eventCount, xmlEvents, + eventInterval); producer.sendEvents(); producer.shutdown(); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java index d624d66bf..9aa9ac931 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java @@ -26,6 +26,16 @@ import java.io.IOException; import java.nio.file.Files; import java.util.Properties; +import kafka.admin.AdminUtils; +import kafka.admin.RackAwareMode; +import kafka.server.BrokerState; +import kafka.server.KafkaConfig; +import kafka.server.KafkaServer; +import kafka.utils.TestUtils; +import kafka.utils.ZKStringSerializer$; +import kafka.utils.ZkUtils; +import kafka.zk.EmbeddedZookeeper; + import org.I0Itec.zkclient.ZkClient; import org.apache.kafka.common.utils.MockTime; import org.apache.kafka.common.utils.Time; @@ -37,14 +47,6 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.service.engine.main.ApexMain; -import kafka.admin.AdminUtils; -import kafka.admin.RackAwareMode; -import kafka.server.KafkaConfig; -import kafka.server.KafkaServer; -import kafka.utils.TestUtils; -import kafka.utils.ZKStringSerializer$; -import kafka.utils.ZkUtils; -import kafka.zk.EmbeddedZookeeper; public class TestKafka2Kafka { // The method of starting an embedded Kafka server used in this example is based on the method @@ -84,11 +86,13 @@ public class TestKafka2Kafka { final KafkaConfig config = new KafkaConfig(brokerProps); final Time mock = new MockTime(); kafkaServer = TestUtils.createServer(config, mock); - + kafkaServer.startup(); + // create topics AdminUtils.createTopic(zkUtils, "apex-in-0", 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$); AdminUtils.createTopic(zkUtils, "apex-in-1", 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$); AdminUtils.createTopic(zkUtils, "apex-out", 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$); + } @AfterClass @@ -120,12 +124,13 @@ public class TestKafka2Kafka { throws MessagingException, ApexException { final KafkaEventSubscriber subscriber = new KafkaEventSubscriber("apex-out-" + topicSuffix, "localhost:" + BROKERPORT); - final KafkaEventProducer producer = new KafkaEventProducer("apex-in-" + topicSuffix, "localhost:" + BROKERPORT, - EVENT_COUNT, xmlEvents, EVENT_INTERVAL); final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(3000); + final KafkaEventProducer producer = new KafkaEventProducer("apex-in-" + topicSuffix, "localhost:" + BROKERPORT, + EVENT_COUNT, xmlEvents, EVENT_INTERVAL); + producer.sendEvents(); final long testStartTime = System.currentTimeMillis(); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestFile2REST.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestFile2REST.java index d304eb9d0..dd3f15ab6 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestFile2REST.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestFile2REST.java @@ -140,7 +140,7 @@ public class TestFile2REST { System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains(" no URL has been set for event sending on REST client")); + assertTrue(outString.contains(" no URL has been set for event sending on REST client")); } @Test diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestREST2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestREST2File.java index f8898a7c5..922e03217 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestREST2File.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restclient/TestREST2File.java @@ -123,7 +123,7 @@ public class TestREST2File { System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains(" no URL has been set for event sending on REST client")); + assertTrue(outString.contains(" no URL has been set for event sending on REST client")); } @Test diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java index b0bcac439..15928b3c7 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java @@ -201,7 +201,7 @@ public class TestRESTServer { System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains(" host and port are specified only in standalone mode")); + assertTrue(outString.contains(" host is specified only in standalone mode")); } @Test @@ -220,7 +220,7 @@ public class TestRESTServer { System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains(" host and port are specified only in standalone mode")); + assertTrue(outString.contains(" port is specified only in standalone mode")); } @Test @@ -300,7 +300,7 @@ public class TestRESTServer { System.setErr(stderr); assertTrue(outString.contains( - "event output for peered mode \"SYNCHRONOUS\": peer \"FirstConsumer\" for event handler \"FirstProducer\" does not exist or is not defined as being synchronous")); + "peer \"FirstConsumer for peered mode SYNCHRONOUS does not exist or is not defined with the same peered mode")); } @Test diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/context/EventAlbumContextTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/context/EventAlbumContextTest.java index bcdcd571f..d68576d16 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/context/EventAlbumContextTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/context/EventAlbumContextTest.java @@ -33,9 +33,9 @@ import org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.common.utils.resources.ResourceUtils; public class EventAlbumContextTest { diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/engdep/EngDepMessagingTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/engdep/EngDepMessagingTest.java index adc416dca..451b4c76a 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/engdep/EngDepMessagingTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/engdep/EngDepMessagingTest.java @@ -33,6 +33,10 @@ import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.core.deployment.BatchDeployer; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; @@ -42,6 +46,7 @@ import org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; +import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -58,13 +63,55 @@ public class EngDepMessagingTest { private static final long MAX_START_WAIT = 10000; // 10 sec - /** - * Sets the up. - * - * @throws Exception the exception - */ + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineServiceParameters engineServiceParameters; + @Before - public void setUp() throws Exception {} + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineServiceParameters = new EngineServiceParameters(); + engineServiceParameters.setName("EngDepMessagingTest"); + engineServiceParameters.setVersion("0.0.1"); + engineServiceParameters.setDeploymentPort(58820); + engineServiceParameters.setInstanceCount(3); + engineServiceParameters.setId(100); + engineServiceParameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MVELExecutorParameters()); + + ParameterService.register(engineServiceParameters); + ParameterService.register(engineServiceParameters.getEngineParameters()); + } + + @After + public void afterTest() { + ParameterService.deregister(engineServiceParameters); + ParameterService.deregister(engineServiceParameters.getEngineParameters()); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } /** * Test EngDep messaging. @@ -79,15 +126,7 @@ public class EngDepMessagingTest { ModelService.clear(); - final EngineServiceParameters parameters = new EngineServiceParameters(); - parameters.setName("EngDepMessagingTest"); - parameters.setVersion("0.0.1"); - parameters.setDeploymentPort(58820); - parameters.setInstanceCount(3); - parameters.setId(100); - parameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MVELExecutorParameters()); - - final EngineTestServer server = new EngineTestServer(parameters); + final EngineTestServer server = new EngineTestServer(engineServiceParameters); assertNotNull(server); final Thread serverThread = new Thread(server); @@ -135,7 +174,7 @@ public class EngDepMessagingTest { } ThreadUtilities.sleep(500); - assertEquals(server.getTotalActionEventsReceived(), 2); + assertEquals(2, server.getTotalActionEventsReceived()); deployer1.init(); deployer1.stopEngines(); @@ -160,7 +199,7 @@ public class EngDepMessagingTest { } ThreadUtilities.sleep(500); - assertEquals(server.getTotalActionEventsReceived(), 4); + assertEquals(4, server.getTotalActionEventsReceived()); deployer2.init(); deployer2.stopEngines(); |