2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.context.test.locking;
23 import java.io.Closeable;
25 import org.onap.policy.apex.context.ContextAlbum;
26 import org.onap.policy.apex.context.ContextException;
27 import org.onap.policy.apex.context.Distributor;
28 import org.onap.policy.apex.context.parameters.ContextParameters;
29 import org.onap.policy.apex.context.test.lock.modifier.AlbumModifier;
30 import org.onap.policy.apex.context.test.utils.ConfigrationProvider;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
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();
65 * @see java.lang.Runnable#run()
69 LOGGER.info("running TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
72 final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor_" + jvm + "_" + instance, "0.0.1");
73 final Distributor distributor = configrationProvider.getDistributor(distributorKey);
76 final long startTime = System.currentTimeMillis();
77 final ContextAlbum contextAlbum = configrationProvider.getContextAlbum(distributor);
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));
84 } catch (final Exception e) {
85 LOGGER.error("Unexpected error occured while processing", e);
88 distributor.shutdown();
89 } catch (final ContextException e) {
90 LOGGER.error("Unable to shutdown distributor", e);
93 LOGGER.info("finished TestConcurrentContextThread_" + jvm + "_" + instance + " . . .");
99 LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName());