diff options
Diffstat (limited to 'testsuites/performance/performance-benchmark-test/src/test/java/org/onap')
12 files changed, 958 insertions, 484 deletions
diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java deleted file mode 100644 index fdefd5583..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java +++ /dev/null @@ -1,175 +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.benchmark; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.core.engine.ExecutorParameters; -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.plugins.context.schema.avro.AvroSchemaHelperParameters; -import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; -import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; -import org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters; -import org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters; -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.engineservice.EngineServiceParameters; -import org.onap.policy.apex.testsuites.performance.benchmark.engine.runtime.ApexServiceModelUpdateTest; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class ApexBaseBenchMarkTest. - */ -public class ApexBaseBenchMarkTest { - private static final long STOP_TIME_OUT = TimeUnit.SECONDS.toMillis(30); - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceModelUpdateTest.class); - private static final long MAX_START_WAIT = TimeUnit.SECONDS.toMillis(10); - private final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); - private final String model; - private final int threads; - private final ApexEventListener listener; - private EngineService service; - private EngineServiceEventInterface engineServiceEventInterface; - - - /** - * Instantiates a new apex base bench mark test. - * - * @param model the model - * @param threads the threads - * @param listener the listener - */ - public ApexBaseBenchMarkTest(final String model, final int threads, final ApexEventListener listener) { - this.model = model; - this.threads = threads; - this.listener = listener; - } - - /** - * Sets the up. - * - * @throws Exception the exception - */ - public void setUp() throws Exception { - final EngineServiceParameters parameters = new EngineServiceParameters(); - parameters.setInstanceCount(threads); - parameters.setName(engineServiceKey.getName()); - parameters.setVersion(engineServiceKey.getVersion()); - parameters.setId(100); - - final EngineParameters engineParameters = parameters.getEngineParameters(); - final Map<String, ExecutorParameters> executorParameterMap = engineParameters.getExecutorParameterMap(); - executorParameterMap.put("MVEL", new MvelExecutorParameters()); - executorParameterMap.put("JAVASCRIPT", new JavascriptExecutorParameters()); - executorParameterMap.put("JYTHON", new JythonExecutorParameters()); - executorParameterMap.put("JAVA", new JavaExecutorParameters()); - executorParameterMap.put("JRUBY", new JrubyExecutorParameters()); - - final ContextParameters contextParameters = engineParameters.getContextParameters(); - final SchemaParameters schemaParameters = contextParameters.getSchemaParameters(); - schemaParameters.getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - schemaParameters.getSchemaHelperParameterMap().put("Java", new JavaSchemaHelperParameters()); - service = EngineServiceImpl.create(parameters); - - service = EngineServiceImpl.create(parameters); - service.registerActionListener("listener", listener); - service.updateModel(parameters.getEngineKey(), model, true); - - LOGGER.info("Starting EngineService ... "); - service.startAll(); - - final long starttime = System.currentTimeMillis(); - while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { - ThreadUtilities.sleep(50); - } - if (!service.isStarted()) { - LOGGER.error("Apex Service {} failed to start after {} ms", service.getKey(), MAX_START_WAIT); - new ApexException("Unable to start engine service "); - } - - engineServiceEventInterface = service.getEngineServiceEventInterface(); - } - - /** - * Send events. - * - * @param events the events - */ - public void sendEvents(final List<ApexEvent> events) { - for (final ApexEvent event : events) { - engineServiceEventInterface.sendEvent(event); - } - } - - /** - * Send event. - * - * @param event the event - */ - public void sendEvent(final ApexEvent event) { - engineServiceEventInterface.sendEvent(event); - } - - - /** - * Gets the service. - * - * @return the service - */ - public EngineService getService() { - return service; - } - - /** - * Destroy. - * - * @throws Exception the exception - */ - public void destroy() throws Exception { - if (service != null) { - LOGGER.info("Stopping EngineService ... "); - service.stop(); - final long currentTimeInMillSec = System.currentTimeMillis(); - while (!service.isStopped()) { - if (System.currentTimeMillis() - currentTimeInMillSec > STOP_TIME_OUT) { - LOGGER.warn("Timed Out EngineService status: ", service.isStopped()); - break; - } - ThreadUtilities.sleep(500); - } - service = null; - } - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmarkTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmarkTest.java deleted file mode 100644 index 99035f7bf..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmarkTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-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.benchmark; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.TimeUnit; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.testsuites.integration.common.model.EvalDomainModelFactory; -import org.onap.policy.apex.testsuites.performance.benchmark.engine.utils.Utils; -import org.python.icu.impl.Assert; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class ApexEngineBenchmark. - */ -public class ApexEngineBenchmarkTest { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineBenchmarkTest.class); - - private static final String TARGET = "apex"; - private static final String SOURCE = "test"; - private static final String NAME = "Event0000"; - private static final String VERSION = "0.0.1"; - private static final String PACKAGE = "org.onap.policy.apex.domains.sample.events"; - - private static final long TIME_OUT_IN_MILLISEC = TimeUnit.MINUTES.toMillis(1); - - private String apexEcaModelString; - private String apexOodaModelString; - - /** - * Sets the up. - * - * @throws Exception the exception - */ - @Before - public void setUp() throws Exception { - apexEcaModelString = Utils.getModelString(new EvalDomainModelFactory().getEcaPolicyModel()); - apexOodaModelString = Utils.getModelString(new EvalDomainModelFactory().getOodaPolicyModel()); - } - - /** - * Test benchmark singleton worker. - * - * @throws Exception the exception - */ - @Test - public void testBenchmark_SingletonWorker() throws Exception { - executeTest(apexEcaModelString, 100, 1, 20); - executeTest(apexOodaModelString, 100, 1, 20); - } - - /** - * Test benchmark 3 thread worker. - * - * @throws Exception the exception - */ - @Test - public void testBenchmark_3ThreadWorker() throws Exception { - executeTest(apexEcaModelString, 1000, 3, 10); - executeTest(apexOodaModelString, 100, 3, 10); - } - - /** - * Test benchmark 10 thread worker. - * - * @throws Exception the exception - */ - @Test - public void testBenchmark_10ThreadWorker() throws Exception { - executeTest(apexEcaModelString, 2000, 10, 10); - executeTest(apexOodaModelString, 2000, 10, 10); - } - - /** - * Test benchmark 50 thread worker. - * - * @throws Exception the exception - */ - @Test - public void testBenchmark_50ThreadWorker() throws Exception { - executeTest(apexEcaModelString, 3000, 50, 10); - executeTest(apexOodaModelString, 3000, 50, 10); - } - - /** - * Test available processors thread worker. - * - * @throws Exception the exception - */ - @Test - public void testAvailableProcessorsThreadWorker() throws Exception { - final int cores = Runtime.getRuntime().availableProcessors(); - executeTest(apexEcaModelString, 3000, cores, 10); - executeTest(apexOodaModelString, 3000, cores, 10); - } - - /** - * Execute test. - * - * @param policyModel the policy model - * @param eventsCount the events count - * @param threads the threads - * @param loop the loop - * @throws Exception the exception - */ - private void executeTest(final String policyModel, final int eventsCount, final int threads, final int loop) - throws Exception { - - LOGGER.info("Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, threads, loop); - final ApexEventListenerTest apexEventListener = new ApexEventListenerTest(); - - final ApexBaseBenchMarkTest apexBaseBenchMarkTest = - new ApexBaseBenchMarkTest(policyModel, threads, apexEventListener); - - try { - apexBaseBenchMarkTest.setUp(); - for (int i = 0; i < loop; i++) { - sendEvents(apexBaseBenchMarkTest, eventsCount); - final long currentTimeInMillSec = System.currentTimeMillis(); - while (apexEventListener.getEventReceived() < eventsCount) { - if (System.currentTimeMillis() - currentTimeInMillSec > TIME_OUT_IN_MILLISEC) { - LOGGER.warn("Wait timed out ... "); - break; - } - ThreadUtilities.sleep(500); - } - assertEquals(eventsCount, apexEventListener.getEventReceived()); - apexEventListener.printResult(); - apexEventListener.reset(); - } - } catch (final Exception exception) { - Assert.fail(exception); - } finally { - apexBaseBenchMarkTest.destroy(); - LOGGER.info("Finished Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, - threads, loop); - } - } - - /** - * Send events. - * - * @param apexBaseBenchMarkTest the apex base bench mark test - * @param eventsCount the events count - * @throws Exception the exception - */ - public void sendEvents(final ApexBaseBenchMarkTest apexBaseBenchMarkTest, final int eventsCount) throws Exception { - for (int eventNum = 0; eventNum < eventsCount; eventNum++) { - final long currentTimeMillis = System.currentTimeMillis(); - final ApexEvent event = new ApexEvent(NAME, VERSION, PACKAGE, SOURCE, TARGET); - event.put("TestTemperature", eventNum); - event.put("FirstEventTimestamp", currentTimeMillis); - event.put("SentTimestamp", currentTimeMillis); - event.put("EventNumber", eventNum); - apexBaseBenchMarkTest.sendEvent(event); - } - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEventListenerTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEventListenerTest.java deleted file mode 100644 index a5950df97..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEventListenerTest.java +++ /dev/null @@ -1,126 +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.benchmark; - -import static org.junit.Assert.assertNull; - -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicLong; - -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.service.engine.runtime.ApexEventListener; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The listener interface for receiving testApexEvent events. - * The class that is interested in processing a testApexEvent - * event implements this interface, and the object created - * with that class is registered with a component using the - * component's <code>addTestApexEventListener</code> method. When - * the testApexEvent event occurs, that object's appropriate - * method is invoked. - * - * @see TestApexEventEvent - */ -public class ApexEventListenerTest implements ApexEventListener { - - private static final String SENT_TIMESTAMP = "SentTimestamp"; - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEventListenerTest.class); - private static final String RECVD_TIMESTAMP = "RecvdTimestamp"; - private Queue<ApexEvent> queue; - - private final AtomicLong eventReceived = new AtomicLong(); - - /** - * Instantiates a new test apex event listener. - */ - public ApexEventListenerTest() { - this.queue = new ConcurrentLinkedQueue<ApexEvent>(); - } - - /* (non-Javadoc) - * @see org.onap.policy.apex.service.engine.runtime.ApexEventListener#onApexEventApexEvent) - */ - @Override - public void onApexEvent(final ApexEvent apexEvent) { - apexEvent.put(RECVD_TIMESTAMP, System.currentTimeMillis()); - eventReceived.incrementAndGet(); - queue.add(apexEvent); - } - - /** - * Prints the result. - */ - public void printResult() { - if (!queue.isEmpty()) { - long maxTimeInMilliSeconds = 0; - long minTimeInMilliSeconds = Long.MAX_VALUE; - final long numEvents = queue.size(); - long totalTimeInMilliSeconds = 0; - for (final ApexEvent apexEvent : queue) { - assertNull(apexEvent.getExceptionMessage()); - final Long endTimeInMilliSeconds = (Long) apexEvent.get(RECVD_TIMESTAMP); - final Long startTimeInMilliSeconds = (Long) apexEvent.get(SENT_TIMESTAMP); - final long timeTaken = endTimeInMilliSeconds - startTimeInMilliSeconds; - totalTimeInMilliSeconds += timeTaken; - if (timeTaken > maxTimeInMilliSeconds) { - maxTimeInMilliSeconds = timeTaken; - } - if (timeTaken < minTimeInMilliSeconds) { - minTimeInMilliSeconds = timeTaken; - } - } - LOGGER.info("Average Time Taken to process {} events: {} ms", numEvents, - (totalTimeInMilliSeconds / numEvents)); - LOGGER.info("Max Time Taken: {} ms", maxTimeInMilliSeconds); - LOGGER.info("Min Time Taken: {} ms", minTimeInMilliSeconds); - } - } - - /** - * Reset. - */ - public void reset() { - this.queue = new ConcurrentLinkedQueue<ApexEvent>(); - eventReceived.set(0);; - } - - /** - * Gets the queue. - * - * @return the queue - */ - public Queue<ApexEvent> getQueue() { - return queue; - } - - /** - * Gets the event received. - * - * @return the event received - */ - public long getEventReceived() { - return eventReceived.get(); - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStatsTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStatsTest.java new file mode 100644 index 000000000..b53eb7ace --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStatsTest.java @@ -0,0 +1,57 @@ +/*- + * ============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.eventgenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +/** + * Test the EventBatchStats class. + * + */ +public class EventBatchStatsTest { + + @Test + public void test() { + EventBatchStats stats = new EventBatchStats(new EventBatch(1, "Label")); + assertNotNull(stats); + + assertTrue(stats.getBatchNumber() >= 0); + assertEquals(1, stats.getBatchSize()); + assertEquals("Label", stats.getApexClient()); + + List<EventBatchStats> statsList = new ArrayList<>(); + statsList.add(stats); + + EventBatchStats totalStats = new EventBatchStats(statsList); + assertEquals(stats.getBatchSize(), totalStats.getBatchSize()); + + List<EventBatchStats> emptyStatsList = new ArrayList<>(); + EventBatchStats emptyStats = new EventBatchStats(emptyStatsList); + assertEquals(0, emptyStats.getBatchSize()); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchTest.java new file mode 100644 index 000000000..f315f6402 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchTest.java @@ -0,0 +1,48 @@ +/*- + * ============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.eventgenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.events.InputEvent; + +/** + * Test the EventBatch class. + * + */ +public class EventBatchTest { + + @Test + public void testEventBatch() { + EventBatch batch = new EventBatch(1, "TheApexClient"); + assertNotNull(batch); + + assertEquals("\"nameSpace\": \"org.onap.policy.apex.sample.events\"", batch.getBatchAsJsonString().substring(4, 53)); + + EventBatchStats stats = batch.getStats(); + assertEquals(1, stats.getBatchSize()); + + InputEvent ie = batch.getInputEvent(0); + assertEquals("org.onap.policy.apex.sample.events",ie.getNameSpace()); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpointTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpointTest.java new file mode 100644 index 000000000..2add69857 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpointTest.java @@ -0,0 +1,115 @@ +/*- + * ============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.eventgenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.inject.Provider; +import javax.ws.rs.core.Response; + +import org.glassfish.grizzly.http.server.Request; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.events.OutputEvent; + +/** + * Test the EventGeneratorEndpoint class. + * + */ +public class EventGeneratorEndpointTest { + @Mock + private Provider<Request> httpRequestProviderMock; + + @Mock + private Request httpRequestMock; + + /** + * Set up mocking of the engine service facade. + * + * @throws ApexException on engine service facade setup errors + */ + @Before + public void initializeMocking() throws ApexException { + MockitoAnnotations.initMocks(this); + + Mockito.doReturn(httpRequestMock).when(httpRequestProviderMock).get(); + + Mockito.doReturn("zooby").when(httpRequestMock).getRemoteHost(); + Mockito.doReturn(12345).when(httpRequestMock).getRemotePort(); + + } + + @Test + public void testEventGeneratorEndpointGetStats() { + EventGeneratorEndpoint.clearEventGenerationStats(); + EventGeneratorEndpoint.setFinished(false); + + EventGeneratorEndpoint egep = new EventGeneratorEndpoint(null); + assertNotNull(egep); + + Response stats = egep.serviceGetStats(); + assertEquals(200, stats.getStatus()); + } + + @Test + public void testEventGeneratorEndpointGetEventsZeroBatchCount() { + EventGeneratorParameters incomingParameters = new EventGeneratorParameters(); + incomingParameters.setBatchCount(1); + + EventGeneratorEndpoint.setParameters(incomingParameters); + EventGeneratorEndpoint.clearEventGenerationStats(); + EventGeneratorEndpoint.setFinished(false); + + EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock); + assertNotNull(egep); + + Response events = egep.getEvents(); + assertEquals(200, events.getStatus()); + + incomingParameters.setBatchCount(1); + events = egep.getEvents(); + assertEquals(204, events.getStatus()); + } + + @Test + public void testEventGeneratorEndpointPostBadEvent() { + EventGeneratorParameters incomingParameters = new EventGeneratorParameters(); + incomingParameters.setBatchCount(1); + + EventGeneratorEndpoint.setParameters(incomingParameters); + EventGeneratorEndpoint.clearEventGenerationStats(); + EventGeneratorEndpoint.setFinished(false); + + EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock); + assertNotNull(egep); + + OutputEvent oe = new OutputEvent(); + oe.setTestSlogan("99-99: Whatever"); + + Response events = egep.postEventResponse(oe.asJson()); + assertEquals(409, events.getStatus()); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java new file mode 100644 index 000000000..dd8766dc3 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java @@ -0,0 +1,325 @@ +/*- + * ============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.eventgenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.apache.commons.cli.ParseException; +import org.junit.Test; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGenerator; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGeneratorParameterHandler; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGeneratorParameters; + +/** + * Test event generator parameters. + */ +public class EventGeneratorParametersHandlerTest { + + @Test + public void testEventGeneratorParameterhandler() { + EventGeneratorParameterHandler handler = new EventGeneratorParameterHandler(); + assertNotNull(handler); + + try { + String[] args = + { "-h" }; + EventGeneratorParameters parameters = handler.parse(args); + assertNull(parameters); + assertEquals("usage: EventGenerator [options...]", + handler.getHelp(EventGenerator.class.getSimpleName()).substring(0, 34)); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + {}; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals("localhost", parameters.getHost()); + assertEquals(32801, parameters.getPort()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-H", "MyHost" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals("MyHost", parameters.getHost()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-p", "12345" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals(12345, parameters.getPort()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-H", "MyHost", "-p", "12345" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals("MyHost", parameters.getHost()); + assertEquals(12345, parameters.getPort()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Valid.json" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals("ValidPars", parameters.getName()); + assertEquals("FileHost", parameters.getHost()); + assertEquals(54321, parameters.getPort()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals("localhost", parameters.getHost()); + assertEquals(32801, parameters.getPort()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "100" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals(100, parameters.getBatchCount()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "-1" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("specified parameters are not valid: parameter group \"EventGeneratorParameters\" " + + "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator." + + "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n" + + " field \"batchCount\" type \"int\" value \"-1\" INVALID, " + + "batchCount must be an integer with a value of zero or more, " + + "zero means generate batches forever\n", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "12345" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals(12345, parameters.getBatchSize()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "0" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("specified parameters are not valid: parameter group \"EventGeneratorParameters\" " + + "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator." + + "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n" + + " field \"batchSize\" type \"int\" value \"0\" INVALID, " + + "batchSize must be an integer greater than zero\n", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "1000" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals(1000, parameters.getDelayBetweenBatches()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "-1" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("specified parameters are not valid: parameter group \"EventGeneratorParameters\" " + + "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator." + + "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n" + + " field \"batchSize\" type \"int\" value \"1\" INVALID, " + + "batchSize must be an integer with a value of zero or more\n", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Default.json", "-o", "Zooby" }; + EventGeneratorParameters parameters = handler.parse(args); + assertEquals("Zooby", parameters.getOutFile()); + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-z" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Unrecognized option: -z", pe.getMessage()); + } + + try { + String[] args = + { "-H" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Missing argument for option: H", pe.getMessage()); + } + + try { + String[] args = + { "-p" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Missing argument for option: p", pe.getMessage()); + } + + try { + String[] args = + { "-p", "12345", "-z" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Unrecognized option: -z", pe.getMessage()); + } + + try { + String[] args = + { "-p", "12345", "somethingElse" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("too many command line arguments specified : [somethingElse]", pe.getMessage()); + } + + try { + String[] args = + { "-c" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Missing argument for option: c", pe.getMessage()); + } + + try { + String[] args = + { "-H", "MyHost", "-c", "src/test/resources/parameters/unit/Valid.json" }; + EventGeneratorParameters pars = handler.parse(args); + assertEquals("MyHost", pars.getHost()); + + } catch (ParseException pe) { + fail("test should not throw an exception"); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/NonExistant.json" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Could not read parameters from configuration file " + + "\"src/test/resources/parameters/unit/NonExistant.json\": " + + "src/test/resources/parameters/unit/NonExistant.json", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/BadHost.json" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Error parsing JSON parameters from configuration file " + + "\"src/test/resources/parameters/unit/BadHost.json\": " + + "com.google.gson.stream.MalformedJsonException: " + + "Unexpected value at line 3 column 14 path $.host", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/BadPort.json" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("Error parsing JSON parameters from configuration file " + + "\"src/test/resources/parameters/unit/BadPort.json\": " + + "java.lang.IllegalStateException: Expected an int " + + "but was BOOLEAN at line 4 column 18 path $.port", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/Empty.json" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("No parameters found in configuration file " + + "\"src/test/resources/parameters/unit/Empty.json\"", pe.getMessage()); + } + + try { + String[] args = + { "-c", "src/test/resources/parameters/unit/NullHost.json" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("specified parameters are not valid: parameter group \"ValidPars\" " + + "type \"org.onap.policy.apex.testsuites.performance." + + "benchmark.eventgenerator.EventGeneratorParameters\" INVALID, " + + "parameter group has status INVALID\n" + " field \"host\" type \"java.lang.String\" " + + "value \"null\" INVALID, host must be a non-blank string\n", pe.getMessage()); + } + + try { + String[] args = + { "-p", "1023" }; + handler.parse(args); + fail("test should throw an exception"); + } catch (ParseException pe) { + assertEquals("specified parameters are not valid: parameter group \"" + + "EventGeneratorParameters\" type \"org.onap.policy.apex.testsuites.performance.benchmark." + + "eventgenerator.EventGeneratorParameters\" INVALID, parameter group has status INVALID\n" + + " field \"port\" type \"int\" value \"1023\" INVALID, " + + "port must be an integer between 1024 and 65535 inclusive\n" + "", pe.getMessage()); + } + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersTest.java new file mode 100644 index 000000000..1071c2f8e --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.eventgenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGeneratorParameters; + +/** + * Test event generator parameters. + */ +public class EventGeneratorParametersTest { + + @Test + public void testEventGeneratorParameters() { + EventGeneratorParameters parameters = new EventGeneratorParameters(); + + parameters.setName("TheName"); + assertEquals("TheName", parameters.getName()); + + parameters.setHost("TheHost"); + assertEquals("TheHost", parameters.getHost()); + + parameters.setPort(12345); + assertEquals(12345, parameters.getPort()); + + assertTrue(parameters.isValid()); + + parameters.setName(null); + assertFalse(parameters.isValid()); + parameters.setName(" "); + assertFalse(parameters.isValid()); + parameters.setName("TheName"); + assertTrue(parameters.isValid()); + + parameters.setHost(null); + assertFalse(parameters.isValid()); + parameters.setHost(" "); + assertFalse(parameters.isValid()); + parameters.setHost("TheHost"); + assertTrue(parameters.isValid()); + + parameters.setPort(1023); + assertFalse(parameters.isValid()); + parameters.setPort(65536); + assertFalse(parameters.isValid()); + parameters.setPort(12345); + assertTrue(parameters.isValid()); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorStatsTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorStatsTest.java new file mode 100644 index 000000000..a40bcb5f1 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorStatsTest.java @@ -0,0 +1,44 @@ +/*- + * ============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.eventgenerator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.Test; + +/** + * Test the EventGeneratorStats class. + * + */ +public class EventGeneratorStatsTest { + @Test + public void testEventGeneratorStats() { + Map<Integer, EventBatch> batchMap = new LinkedHashMap<>(); + EventGeneratorStats egs = new EventGeneratorStats(batchMap ); + assertNotNull(egs); + + assertEquals(-1, egs.getTotalStats().getBatchNumber()); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorTest.java new file mode 100644 index 000000000..e37ea963c --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorTest.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-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.eventgenerator; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.PrintStream; + +import org.junit.Test; +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 org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGenerator; +import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGeneratorParameters; + +/** + * This class tests the event generator. + */ +public class EventGeneratorTest { + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + + private final PrintStream stdout = System.out; + + /** + * Test event generation. + * + * @throws ApexException on Apex exceptions + */ + @Test + public void testEventGeneration() throws ApexException { + EventGeneratorParameters pars = new EventGeneratorParameters(); + pars.setBatchCount(1); + pars.setBatchSize(10); + + EventGenerator eventGenerator = new EventGenerator(pars); + + final String[] args = + { "-rfr", "target", "-c", "target/examples/config/SampleDomain/REST2RESTJsonEventJavascript.json" }; + + final ApexMain apexMain = new ApexMain(args); + + while (!eventGenerator.isFinished()) { + ThreadUtilities.sleep(200); + } + + apexMain.shutdown(); + + ThreadUtilities.sleep(5000); + eventGenerator.tearDown(); + + assertTrue(eventGenerator.getEventGenerationStats().contains("\"apexClient\": \"TOTAL\"")); + } + + @Test + public void testEventGeneratorBadParams() { + System.setOut(new PrintStream(outContent)); + + final String[] args = + { "-zzz" }; + + EventGenerator.main(args); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Start of event generator failed: Unrecognized option: -zzz")); + } + + @Test + public void testEventGeneratorHelp() { + System.setOut(new PrintStream(outContent)); + + final String[] args = { + "-h" + }; + + EventGenerator.main(args); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("outputs the usage of this command")); + } + + @Test + public void testEventGeneratorStart() { + + System.setOut(new PrintStream(outContent)); + + (new Thread() { + public void run() { + EventGenerator.main(null); + } + }).start(); + + ThreadUtilities.sleep(1000); + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Event generator started")); + assertTrue(outString.contains("Event generator shut down")); + } + + @Test + public void testEventGeneratorOutfileGood() { + EventGeneratorParameters pars =new EventGeneratorParameters(); + pars.setOutFile("target/statsOutFile.json"); + + EventGenerator generator = new EventGenerator(pars); + assertNotNull(generator); + + generator.tearDown(); + + File outFile = new File("target/statsOutFile.json"); + assertTrue(outFile.exists()); + outFile.delete(); + } + + @Test + public void testEventGeneratorOutfileBad() { + EventGeneratorParameters pars = new EventGeneratorParameters(); + pars.setOutFile("/I/Dont/Exist"); + + EventGenerator generator = new EventGenerator(pars); + assertNotNull(generator); + + System.setOut(new PrintStream(outContent)); + + generator.tearDown(); + + final String outString = outContent.toString(); + System.setOut(stdout); + + assertTrue(outString.contains("could not output statistics to file \"/I/Dont/Exist\"")); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/events/InputEventTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/events/InputEventTest.java new file mode 100644 index 000000000..82b4cca88 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/events/InputEventTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.eventgenerator.events; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +/** + * Test the InputEvent class. + * + */ +public class InputEventTest { + + @Test + public void testInputEvent() { + InputEvent ie = new InputEvent(); + assertNotNull(ie); + + ie.setName("EventName"); + assertEquals("EventName", ie.getName()); + + ie.setNameSpace("a.b.c.d"); + assertEquals("a.b.c.d", ie.getNameSpace()); + + ie.setSource("Source"); + assertEquals("Source", ie.getSource()); + + ie.setTarget("Target"); + assertEquals("Target", ie.getTarget()); + + ie.setTestMatchCase(123); + assertEquals(123, ie.getTestMatchCase()); + + ie.setTestSlogan("A Slogan"); + assertEquals("A Slogan", ie.getTestSlogan()); + + ie.setTestTemperature(123.45); + assertEquals((Double)123.45, (Double)ie.getTestTemperature()); + + ie.setTestTimestamp(1234567879); + assertEquals(1234567879, ie.getTestTimestamp()); + + ie.setVersion("1.2.3"); + assertEquals("1.2.3", ie.getVersion()); + + assertEquals("\"nameSpace\": \"a.b.c.d\",", ie.asJson().substring(4, 27)); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/events/OutputEventTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/events/OutputEventTest.java new file mode 100644 index 000000000..8af87ddbd --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/events/OutputEventTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.eventgenerator.events; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +/** + * Test the OutputEvent class. + * + */ +public class OutputEventTest { + + @Test + public void test() { + OutputEvent oe = new OutputEvent(); + assertNotNull(oe); + + oe.setTestMatchCaseSelected(32112); + assertEquals(32112, oe.getTestMatchCaseSelected()); + + oe.setTestMatchStateTime(34455778822L); + assertEquals(34455778822L, oe.getTestMatchStateTime()); + + oe.setTestEstablishCaseSelected(1321); + assertEquals(1321, oe.getTestEstablishCaseSelected()); + + oe.setTestEstablishStateTime(13445566778822L); + assertEquals(13445566778822L, oe.getTestEstablishStateTime()); + + oe.setTestDecideCaseSelected(321); + assertEquals(321, oe.getTestDecideCaseSelected()); + + oe.setTestDecideStateTime(3445566778822L); + assertEquals(3445566778822L, oe.getTestDecideStateTime()); + + oe.setTestActCaseSelected(332); + assertEquals(332, oe.getTestActCaseSelected()); + + oe.setTestActStateTime(34455667788L); + assertEquals(34455667788L, oe.getTestActStateTime()); + + oe.setTestReceviedTimestamp(134455667788222L); + assertEquals(134455667788222L, oe.getTestReceviedTimestamp()); + + oe.setTestSlogan("0-0: Whatever"); + assertEquals(0, oe.findBatchNumber()); + assertEquals(0, oe.findEventNumber()); + } +} |