diff options
Diffstat (limited to 'testsuites/performance/performance-benchmark-test')
-rw-r--r-- | testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java | 23 |
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() { |