summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2020-03-10 13:49:32 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-10 13:49:32 +0000
commit4eb64b73443620c8588ee48b54d225326ff4550e (patch)
treeacabf7c324d0d9edf9bc79183491f7f69ca3831d /testsuites
parent6bda5d7e4e80d1aefb4f19203361b7199448e70f (diff)
parentc1ed44a4fa0231438f4e01599a4e31da9c43828a (diff)
Merge "Sonar Bug fix"
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java23
1 files changed, 14 insertions, 9 deletions
diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java
index ed624fb83..3d5adfc09 100644
--- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java
+++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +25,7 @@ import com.google.gson.Gson;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.GET;
@@ -42,11 +44,13 @@ import org.slf4j.ext.XLoggerFactory;
*/
@Path("/")
public class EventGeneratorEndpoint {
+
// Get a reference to the logger
private static final XLogger LOGGER = XLoggerFactory.getXLogger(EventGeneratorEndpoint.class);
// Parameters for event generation
- private static EventGeneratorParameters parameters = new EventGeneratorParameters();
+ private static AtomicReference<EventGeneratorParameters> parameters = new AtomicReference<>(
+ new EventGeneratorParameters());
// The map of event batches sent in the test
private static ConcurrentHashMap<Integer, EventBatch> batchMap = new ConcurrentHashMap<>();
@@ -59,6 +63,7 @@ public class EventGeneratorEndpoint {
/**
* Inject the HTTP request with a constructor.
+ *
* @param httpRequest the current request
*/
@Inject
@@ -72,9 +77,7 @@ public class EventGeneratorEndpoint {
* @param incomingParameters the new parameters
*/
public static void setParameters(EventGeneratorParameters incomingParameters) {
- synchronized (parameters) {
- parameters = incomingParameters;
- }
+ parameters.set(incomingParameters);
}
/**
@@ -96,7 +99,7 @@ public class EventGeneratorEndpoint {
@Path("/GetEvents")
@GET
public Response getEvents() {
- ThreadUtilities.sleep(parameters.getDelayBetweenBatches());
+ ThreadUtilities.sleep(parameters.get().getDelayBetweenBatches());
// Check if event generation is finished
if (isFinished()) {
@@ -104,12 +107,12 @@ public class EventGeneratorEndpoint {
}
// A batch count of 0 means to continue to handle events for ever
- if (parameters.getBatchCount() > 0 && batchMap.size() >= parameters.getBatchCount()) {
+ if (parameters.get().getBatchCount() > 0 && batchMap.size() >= parameters.get().getBatchCount()) {
setFinished(true);
return Response.status(204).build();
}
- EventBatch batch = new EventBatch(parameters.getBatchSize(), getApexClient());
+ EventBatch batch = new EventBatch(parameters.get().getBatchSize(), getApexClient());
batchMap.put(batch.getBatchNumber(), batch);
return Response.status(200).entity(batch.getBatchAsJsonString()).build();
@@ -144,12 +147,13 @@ public class EventGeneratorEndpoint {
* @return the Apex client
*/
private String getApexClient() {
- return httpRequest.get().getRemoteHost() + '(' + httpRequest.get().getRemoteAddr() + "):"
- + httpRequest.get().getRemotePort();
+ return httpRequest.get().getRemoteHost() + '(' + httpRequest.get().getRemoteAddr() + "):" + httpRequest.get()
+ .getRemotePort();
}
/**
* Get event generation statistics.
+ *
* @return the statistics on event generation
*/
protected static String getEventGenerationStats() {
@@ -165,6 +169,7 @@ public class EventGeneratorEndpoint {
/**
* Check if event generation has finished.
+ *
* @return true if event generation has finished
*/
protected static boolean isFinished() {