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;
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;
35 * The Class TestConcurrentContextThread tests concurrent use of context.
37 * @author Liam Fallon (liam.fallon@ericsson.com)
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;
50 * @param instance the instance
51 * @param configrationProvider the configuration provider
53 public ConcurrentContextThread(final int jvm, final int instance, final ConfigrationProvider configrationProvider) {
55 this.instance = instance;
56 this.configrationProvider = configrationProvider;
58 new ContextParameters();
66 LOGGER.info("running TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
69 final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor_" + jvm + "_" + instance, "0.0.1");
70 final Distributor distributor = configrationProvider.getDistributor(distributorKey);
73 final long startTime = System.currentTimeMillis();
74 final ContextAlbum contextAlbum = configrationProvider.getContextAlbum(distributor);
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));
81 } catch (final Exception e) {
82 LOGGER.error("Unexpected error occured while processing", e);
85 LOGGER.info("finished TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
90 LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName());