Changes for checkstyle 8.32
[policy/apex-pdp.git] / testsuites / integration / integration-context-test / src / test / java / org / onap / policy / apex / testsuites / integration / context / locking / ConcurrentContextThread.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.testsuites.integration.context.locking;
23
24 import java.io.Closeable;
25 import org.onap.policy.apex.context.ContextAlbum;
26 import org.onap.policy.apex.context.Distributor;
27 import org.onap.policy.apex.context.parameters.ContextParameters;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
29 import org.onap.policy.apex.testsuites.integration.context.lock.modifier.AlbumModifier;
30 import org.onap.policy.apex.testsuites.integration.context.utils.ConfigrationProvider;
31 import org.slf4j.ext.XLogger;
32 import org.slf4j.ext.XLoggerFactory;
33
34 /**
35  * The Class TestConcurrentContextThread tests concurrent use of context.
36  *
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public class ConcurrentContextThread implements Runnable, Closeable {
40     // Logger for this class
41     private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextThread.class);
42     private final int jvm;
43     private final int instance;
44     private final ConfigrationProvider configrationProvider;
45
46     /**
47      * The Constructor.
48      *
49      * @param jvm the jvm
50      * @param instance the instance
51      * @param configrationProvider the configuration provider
52      */
53     public ConcurrentContextThread(final int jvm, final int instance, final ConfigrationProvider configrationProvider) {
54         this.jvm = jvm;
55         this.instance = instance;
56         this.configrationProvider = configrationProvider;
57
58         new ContextParameters();
59     }
60
61     /**
62      * {@inheritDoc}.
63      */
64     @Override
65     public void run() {
66         LOGGER.info("running TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
67
68
69         final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor_" + jvm + "_" + instance, "0.0.1");
70         final Distributor distributor = configrationProvider.getDistributor(distributorKey);
71
72         try {
73             final long startTime = System.currentTimeMillis();
74             final ContextAlbum contextAlbum = configrationProvider.getContextAlbum(distributor);
75
76             final AlbumModifier albumModifier = configrationProvider.getAlbumModifier();
77             albumModifier.modifyAlbum(contextAlbum, configrationProvider.getLoopSize(),
78                     configrationProvider.getAlbumSize());
79             LOGGER.info("Took {} ms to modify album", (System.currentTimeMillis() - startTime));
80
81         } catch (final Exception e) {
82             LOGGER.error("Unexpected error occured while processing", e);
83         }
84
85         LOGGER.info("finished TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
86     }
87
88     @Override
89     public void close() {
90         LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName());
91     }
92 }