diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2020-06-15 13:43:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-06-15 13:43:40 +0000 |
commit | 73470fb02d3d8a2fb37e80d9fb23a75955da32b5 (patch) | |
tree | 6460addf563cefb9264f7dd4fd3a847238b862cd /core | |
parent | 808600494c5cd0f7b83460dac45d12b3ca14fd57 (diff) | |
parent | 718a1611a1e580ed7874088e1a0e013416334989 (diff) |
Merge "Improve robustness of unit testing"
Diffstat (limited to 'core')
2 files changed, 5 insertions, 108 deletions
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java index 23f458a67..ba6d4c627 100644 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java +++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java @@ -71,30 +71,19 @@ public class ThreadingTest { * @param threadFactory the thread factory */ private void testThreadFactory(final ApplicationThreadFactory threadFactory) { - final List<ThreadingTestThread> threadList = new ArrayList<>(); + final List<Thread> threadList = new ArrayList<>(); for (int i = 0; i < 5; i++) { - final ThreadingTestThread runnable = new ThreadingTestThread(); - threadList.add(runnable); - - final Thread thread = threadFactory.newThread(runnable); + final Thread thread = threadFactory.newThread(() -> { + }); + threadList.add(thread); thread.start(); - - if (i == 4) { - await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> thread.isAlive()); - } - - } - - for (int i = 0; i < 5; i++) { - threadList.get(i).interrupt(); } for (int i = 0; i < 5; i++) { - ThreadingTestThread thread = threadList.get(i); + Thread thread = threadList.get(i); assertTrue(thread.getName().startsWith("Apex-" + LOCAL_NAME)); assertTrue(thread.getName().contains(":" + i)); - assertTrue("Thread (" + i + ") count should be greater than 0 ", thread.getCounter() > 0); } } } diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java deleted file mode 100644 index ee2212159..000000000 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTestThread.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.core.infrastructure.threading; - -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class ThreadingTestThread. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ThreadingTestThread implements Runnable { - - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(ThreadingTestThread.class); - - private boolean interrupted = false; - - private long counter = -1; - - private String threadName; - - /** - * {@inheritDoc}. - */ - @Override - public void run() { - this.threadName = Thread.currentThread().getName(); - if (logger.isDebugEnabled()) { - logger.debug("starting threading test thread \"" + threadName + "\" . . ."); - } - - while (!interrupted) { - counter++; - if (logger.isDebugEnabled()) { - logger.debug("in threading test thread \"" + threadName + "\", counter=" + counter + " . . ."); - } - if (!ThreadUtilities.sleep(50)) { - interrupted = true; - } - } - - if (logger.isDebugEnabled()) { - logger.debug("stopped threading test thread \"" + threadName + "\""); - } - } - - /** - * Gets the name. - * - * @return the name - */ - public String getName() { - return threadName; - } - - /** - * Interrupt. - */ - public void interrupt() { - interrupted = true; - } - - /** - * Gets the counter. - * - * @return the counter - */ - public Long getCounter() { - return counter; - } -} |