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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.testsuites.integration.context.locking;
24 import java.io.Closeable;
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;
36 * The Class TestConcurrentContextThread tests concurrent use of context.
38 * @author Liam Fallon (liam.fallon@ericsson.com)
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;
51 * @param instance the instance
52 * @param configrationProvider the configuration provider
54 public ConcurrentContextThread(final int jvm, final int instance, final ConfigrationProvider configrationProvider) {
56 this.instance = instance;
57 this.configrationProvider = configrationProvider;
59 new ContextParameters();
67 LOGGER.info("running TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
70 final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor_" + jvm + "_" + instance, "0.0.1");
71 final Distributor distributor = configrationProvider.getDistributor(distributorKey);
74 final long startTime = System.currentTimeMillis();
75 final ContextAlbum contextAlbum = configrationProvider.getContextAlbum(distributor);
77 final AlbumModifier albumModifier = configrationProvider.getAlbumModifier();
78 albumModifier.modifyAlbum(contextAlbum, configrationProvider.getLoopSize(),
79 configrationProvider.getAlbumSize());
80 LOGGER.info("Took {} ms to modify album", (System.currentTimeMillis() - startTime));
82 } catch (final Exception e) {
83 LOGGER.error("Unexpected error occured while processing", e);
86 LOGGER.info("finished TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
91 LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName());