baad04e19d865a28bd6f09974fa90d8de7c1d809
[policy/apex-pdp.git] /
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
26 import org.onap.policy.apex.context.ContextAlbum;
27 import org.onap.policy.apex.context.Distributor;
28 import org.onap.policy.apex.context.parameters.ContextParameters;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.onap.policy.apex.testsuites.integration.context.lock.modifier.AlbumModifier;
31 import org.onap.policy.apex.testsuites.integration.context.utils.ConfigrationProvider;
32 import org.slf4j.ext.XLogger;
33 import org.slf4j.ext.XLoggerFactory;
34
35 /**
36  * The Class TestConcurrentContextThread tests concurrent use of context.
37  *
38  * @author Liam Fallon (liam.fallon@ericsson.com)
39  */
40 public class ConcurrentContextThread implements Runnable, Closeable {
41     // Logger for this class
42     private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextThread.class);
43     private final int jvm;
44     private final int instance;
45     private final ConfigrationProvider configrationProvider;
46
47     /**
48      * The Constructor.
49      *
50      * @param jvm the jvm
51      * @param instance the instance
52      * @param configrationProvider the configuration provider
53      */
54     public ConcurrentContextThread(final int jvm, final int instance, final ConfigrationProvider configrationProvider) {
55         this.jvm = jvm;
56         this.instance = instance;
57         this.configrationProvider = configrationProvider;
58
59         new ContextParameters();
60     }
61
62     /*
63      * (non-Javadoc)
64      *
65      * @see java.lang.Runnable#run()
66      */
67     @Override
68     public void run() {
69         LOGGER.info("running TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
70
71
72         final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor_" + jvm + "_" + instance, "0.0.1");
73         final Distributor distributor = configrationProvider.getDistributor(distributorKey);
74
75         try {
76             final long startTime = System.currentTimeMillis();
77             final ContextAlbum contextAlbum = configrationProvider.getContextAlbum(distributor);
78
79             final AlbumModifier albumModifier = configrationProvider.getAlbumModifier();
80             albumModifier.modifyAlbum(contextAlbum, configrationProvider.getLoopSize(),
81                     configrationProvider.getAlbumSize());
82             LOGGER.info("Took {} ms to modify album", (System.currentTimeMillis() - startTime));
83
84         } catch (final Exception e) {
85             LOGGER.error("Unexpected error occured while processing", e);
86         }
87
88         LOGGER.info("finished TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
89     }
90
91     @Override
92     public void close() {
93         LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName());
94     }
95 }