diff options
12 files changed, 344 insertions, 89 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java index aa82e1c95..c39be64fc 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Map.Entry; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.engdep.EngDepMessagingService; import org.onap.policy.apex.service.engine.runtime.EngineService; @@ -32,6 +33,7 @@ import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; import org.onap.policy.apex.service.parameters.ApexParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -179,6 +181,10 @@ public class ApexActivator { engineServiceHandler.terminate(); engineServiceHandler = null; } + + // Clear the services + ModelService.clear(); + ParameterService.clear(); } /** diff --git a/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJRuby.json b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJRuby.json new file mode 100644 index 000000000..9d1c891b7 --- /dev/null +++ b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJRuby.json @@ -0,0 +1,45 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "examples/models/SampleDomain/SamplePolicyModelJRUBY.xml", + "engineParameters": { + "executorParameters": { + "JRUBY": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FirstConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/GetEvents" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/PostEvent" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +} diff --git a/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJava.json b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJava.json new file mode 100644 index 000000000..2602390ae --- /dev/null +++ b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJava.json @@ -0,0 +1,45 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "examples/models/SampleDomain/SamplePolicyModelJAVA.xml", + "engineParameters": { + "executorParameters": { + "JAVA": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FirstConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/GetEvents" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/PostEvent" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +} diff --git a/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEvent.json b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJavascript.json index fca96852a..110996e6a 100644 --- a/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEvent.json +++ b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJavascript.json @@ -20,7 +20,7 @@ "carrierTechnology": "RESTCLIENT", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", "parameters": { - "url": "http://localhost:32801/TestRest2REST/apex/event/GetEvent" + "url": "http://localhost:32801/EventGenerator/GetEvents" } }, "eventProtocolParameters": { @@ -34,7 +34,7 @@ "carrierTechnology": "RESTCLIENT", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", "parameters": { - "url": "http://localhost:32801/TestRest2REST/apex/event/PostEvent" + "url": "http://localhost:32801/EventGenerator/PostEvent" } }, "eventProtocolParameters": { diff --git a/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJython.json b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJython.json new file mode 100644 index 000000000..0bd8c35dd --- /dev/null +++ b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventJython.json @@ -0,0 +1,45 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "examples/models/SampleDomain/SamplePolicyModelJYTHON.xml", + "engineParameters": { + "executorParameters": { + "JYTHON": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FirstConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/GetEvents" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/PostEvent" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +} diff --git a/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventMvel.json b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventMvel.json new file mode 100644 index 000000000..b62b93e06 --- /dev/null +++ b/testsuites/integration/integration-common/src/main/resources/examples/config/SampleDomain/REST2RESTJsonEventMvel.json @@ -0,0 +1,45 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "examples/models/SampleDomain/SamplePolicyModelMVEL.xml", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FirstConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/GetEvents" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/EventGenerator/PostEvent" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +} diff --git a/testsuites/integration/integration-uservice-test/pom.xml b/testsuites/integration/integration-uservice-test/pom.xml index 5c595e589..b139f2494 100644 --- a/testsuites/integration/integration-uservice-test/pom.xml +++ b/testsuites/integration/integration-uservice-test/pom.xml @@ -68,6 +68,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId> + <artifactId>plugins-executor-mvel</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution</groupId> <artifactId>plugins-context-distribution-infinispan</artifactId> <version>${project.version}</version> diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java index 5c8eb7eb1..7afef538b 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java @@ -41,9 +41,9 @@ import org.onap.policy.apex.service.engine.main.ApexMain; * The Class TestKafka2Kafka tests Kafka event sending and reception. */ public class TestKafka2Kafka { - private static final long MAX_TEST_LENGTH = 60000; + private static final long MAX_TEST_LENGTH = 300000; - private static final int EVENT_COUNT = 100; + private static final int EVENT_COUNT = 25; private static final int EVENT_INTERVAL = 20; /** @@ -131,7 +131,7 @@ public class TestKafka2Kafka { ThreadUtilities.sleep(EVENT_INTERVAL); } - ThreadUtilities.sleep(1000); + ThreadUtilities.sleep(3000); apexMain.shutdown(); subscriber.shutdown(); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java index 9a9b48bad..69bcf8706 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java @@ -156,8 +156,8 @@ public class TestFile2Rest { Response response = null; // Wait for the required amount of events to be received or for 10 seconds - for (int i = 0; i < 100; i++) { - ThreadUtilities.sleep(100); + for (int i = 0; i < 20; i++) { + ThreadUtilities.sleep(300); response = client.target("http://localhost:32801/TestFile2Rest/apex/event/Stats") .request("application/json").get(); @@ -169,7 +169,7 @@ public class TestFile2Rest { @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); - if ((double) jsonMap.get("PUT") == 100) { + if ((double) jsonMap.get("PUT") == 20) { break; } } diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceModelUpdateTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java index cf930150e..ff6a3a279 100644 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceModelUpdateTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java @@ -18,13 +18,14 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.apex.testsuites.performance.benchmark.engine.runtime; +package org.onap.policy.apex.testsuites.integration.uservice.engine; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Date; import java.util.HashMap; @@ -33,11 +34,22 @@ import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.DistributorParameters; +import org.onap.policy.apex.context.parameters.LockManagerParameters; +import org.onap.policy.apex.context.parameters.PersistorParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameterConstants; +import org.onap.policy.apex.core.engine.EngineParameters; 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.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.event.ApexEventException; @@ -45,9 +57,10 @@ import org.onap.policy.apex.service.engine.runtime.ApexEventListener; import org.onap.policy.apex.service.engine.runtime.EngineService; import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; +import org.onap.policy.apex.service.parameters.ApexParameterConstants; import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; -import org.onap.policy.apex.testsuites.performance.benchmark.engine.utils.Utils; +import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -70,6 +83,37 @@ public class ApexServiceModelUpdateTest { private String apexSampleModelString; /** + * Set up parameters. + */ + @Before + public void setupParameters() { + ParameterService.register(new SchemaParameters()); + ParameterService.register(new ContextParameters()); + ParameterService.register(new DistributorParameters()); + ParameterService.register(new LockManagerParameters()); + ParameterService.register(new PersistorParameters()); + ParameterService.register(new EngineServiceParameters()); + + EngineParameters engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("JAVASCRIPT", new JavascriptExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * Clear down parameters. + */ + @After + public void teardownParameters() { + ParameterService.deregister(EngineParameterConstants.MAIN_GROUP_NAME); + ParameterService.deregister(ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.MAIN_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME); + } + + /** * Sets up the test by creating an engine and reading in the test policy. * * @throws ApexException if something goes wrong @@ -87,10 +131,10 @@ public class ApexServiceModelUpdateTest { LOGGER.debug("Running TestApexEngine. . ."); - apexSamplePolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + apexSamplePolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT"); assertNotNull(apexSamplePolicyModel); - apexSampleModelString = Utils.getModelString(apexSamplePolicyModel); + apexSampleModelString = getModelString(apexSamplePolicyModel); // create engine listener = new TestListener(); @@ -133,7 +177,7 @@ public class ApexServiceModelUpdateTest { @Test public void testModelUpdateStringNewNoForce() throws ApexException { service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); - service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); } @@ -145,7 +189,7 @@ public class ApexServiceModelUpdateTest { @Test public void testModelUpdateStringNewForce() throws ApexException { service.updateModel(parameters.getEngineKey(), apexSampleModelString, true); - service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); } @@ -157,7 +201,7 @@ public class ApexServiceModelUpdateTest { @Test public void testModelUpdateStringNewNewNoForce() throws ApexException { service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); - service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); sendEvents(); @@ -176,7 +220,7 @@ public class ApexServiceModelUpdateTest { @Test public void testModelUpdateIncoNoForce() throws ApexException { service.updateModel(parameters.getEngineKey(), apexSamplePolicyModel, false); - service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); // Different model name, incompatible @@ -189,8 +233,8 @@ public class ApexServiceModelUpdateTest { } catch (final Exception e) { System.err.println(e.getMessage()); assertEquals("apex model update failed, supplied model with key \"INCOMPATIBLE:0.0.1\" is not a compatible " - + "model update from the existing engine model with key \"SamplePolicyModelMVEL:0.0.1\"", - e.getMessage()); + + "model update from the existing engine model " + + "with key \"SamplePolicyModelJAVASCRIPT:0.0.1\"", e.getMessage()); } // Still on old model @@ -206,9 +250,9 @@ public class ApexServiceModelUpdateTest { } catch (final Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); - assertEquals("apex model update failed, supplied model with key \"SamplePolicyModelMVEL:1.0.1\" is not " - + "a compatible model update from the existing engine model with key " - + "\"SamplePolicyModelMVEL:0.0.1\"", e.getMessage()); + assertEquals("apex model update failed, supplied model with key \"SamplePolicyModelJAVASCRIPT:1.0.1\" " + + "is not a compatible model update from the existing engine model with key " + + "\"SamplePolicyModelJAVASCRIPT:0.0.1\"", e.getMessage()); } // Still on old model @@ -240,7 +284,7 @@ public class ApexServiceModelUpdateTest { @Test public void testModelUpdateIncoForce() throws ApexException { service.updateModel(parameters.getEngineKey(), apexSamplePolicyModel, false); - service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); // Different model name, incompatible @@ -359,4 +403,20 @@ public class ApexServiceModelUpdateTest { && ((byte) result.get("TestActCaseSelected") <= 3)); } } + + + /** + * Gets the model string. + * + * @param policyModel the eca policy model + * @return the model string + * @throws ApexModelException the apex model exception + * @throws IOException Signals that an I/O exception has occurred. + */ + private String getModelString(final AxPolicyModel policyModel) throws ApexModelException, IOException { + try (final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream()) { + new ApexModelWriter<AxPolicyModel>(AxPolicyModel.class).write(policyModel, baOutputStream); + return baOutputStream.toString(); + } + } } diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java index e66d1b791..f8e9f2c37 100644 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java @@ -18,33 +18,49 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.apex.testsuites.performance.benchmark.engine.runtime; +package org.onap.policy.apex.testsuites.integration.uservice.engine; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Map; +import org.junit.After; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.DistributorParameters; +import org.onap.policy.apex.context.parameters.LockManagerParameters; +import org.onap.policy.apex.context.parameters.PersistorParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameterConstants; +import org.onap.policy.apex.core.engine.EngineParameters; 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.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.runtime.ApexEventListener; import org.onap.policy.apex.service.engine.runtime.EngineService; import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; +import org.onap.policy.apex.service.parameters.ApexParameterConstants; import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; -import org.onap.policy.apex.testsuites.performance.benchmark.engine.utils.Utils; +import org.onap.policy.common.parameters.ParameterService; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -90,10 +106,10 @@ public class ApexServiceTest { LOGGER.debug("Running TestApexEngine. . ."); - apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT"); assertNotNull(apexPolicyModel); - apexModelString = Utils.getModelString(apexPolicyModel); + apexModelString = getModelString(apexPolicyModel); // create engine listener = new TestListener(); @@ -101,6 +117,37 @@ public class ApexServiceTest { } /** + * Set up parameters. + */ + @Before + public void setupParameters() { + ParameterService.register(new SchemaParameters()); + ParameterService.register(new ContextParameters()); + ParameterService.register(new DistributorParameters()); + ParameterService.register(new LockManagerParameters()); + ParameterService.register(new PersistorParameters()); + ParameterService.register(new EngineServiceParameters()); + + EngineParameters engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("JAVASCRIPT", new JavascriptExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * Clear down parameters. + */ + @After + public void teardownParameters() { + ParameterService.deregister(EngineParameterConstants.MAIN_GROUP_NAME); + ParameterService.deregister(ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.MAIN_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME); + } + + /** * Update the engine then test the engine with 2 sample events. * * @throws ApexException if there is a problem @@ -108,8 +155,7 @@ public class ApexServiceTest { @Test public void testExecutionSet1() throws ApexException { service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); + final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { LOGGER.info("{}", service.getStatus(engineKey)); @@ -172,8 +218,7 @@ public class ApexServiceTest { @Test public void testExecutionSet1Sync() throws ApexException { service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); + final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { LOGGER.info("{}", service.getStatus(engineKey)); @@ -261,8 +306,7 @@ public class ApexServiceTest { @Test public void testExecutionSet2() throws ApexException { service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); + final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { LOGGER.info("{}", service.getStatus(engineKey)); @@ -324,8 +368,7 @@ public class ApexServiceTest { @Test public void testExecutionSet2Sync() throws ApexException { service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); + final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { LOGGER.info("{}", service.getStatus(engineKey)); @@ -474,4 +517,19 @@ public class ApexServiceTest { ((byte) result.get("TestActCaseSelected")) >= 0 && ((byte) result.get("TestActCaseSelected") <= 3)); } } + + /** + * Gets the model string. + * + * @param policyModel the eca policy model + * @return the model string + * @throws ApexModelException the apex model exception + * @throws IOException Signals that an I/O exception has occurred. + */ + private static String getModelString(final AxPolicyModel policyModel) throws ApexModelException, IOException { + try (final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream()) { + new ApexModelWriter<AxPolicyModel>(AxPolicyModel.class).write(policyModel, baOutputStream); + return baOutputStream.toString(); + } + } } diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java deleted file mode 100644 index 0d239a8ef..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.testsuites.performance.benchmark.engine.utils; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -/** - * The Class Utils. - */ -public class Utils { - - /** - * Instantiates a new utils. - */ - private Utils() {} - - /** - * Gets the model string. - * - * @param ecaPolicyModel the eca policy model - * @return the model string - * @throws ApexModelException the apex model exception - * @throws IOException Signals that an I/O exception has occurred. - */ - public static String getModelString(final AxPolicyModel ecaPolicyModel) throws ApexModelException, IOException { - try (final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream()) { - new ApexModelWriter<AxPolicyModel>(AxPolicyModel.class).write(ecaPolicyModel, baOutputStream); - return baOutputStream.toString(); - } - } - -} |