You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2021/08/11 13:54:29 UTC
[uima-uimaj] 01/01: [UIMA-6372] Upgrade from JUnit 3 to JUnit 4 to
JUnit 5
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch refactoring/UIMA-6372-Upgrade-from-JUnit-3-to-JUnit-4-to-JUnit-5
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit 0bff3cca11c44713ea3b8a63d3873ea664649851
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Aug 11 15:54:04 2021 +0200
[UIMA-6372] Upgrade from JUnit 3 to JUnit 4 to JUnit 5
- Upgrade two additional test classes which had slipped through in the last refactoring iteration
---
.../uima/cas/impl/BinaryCasSerDesPerformance.java | 9 ++-
.../uima/internal/util/MultiThreadUtils.java | 78 +++---------------
.../uima/internal/util/MultiThreadUtilsTest.java | 94 ++++++++++++++++++++++
3 files changed, 109 insertions(+), 72 deletions(-)
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/impl/BinaryCasSerDesPerformance.java b/uimaj-core/src/test/java/org/apache/uima/cas/impl/BinaryCasSerDesPerformance.java
index b52e1e0..689b3a3 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/impl/BinaryCasSerDesPerformance.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/impl/BinaryCasSerDesPerformance.java
@@ -30,21 +30,22 @@ import org.apache.uima.cas.CAS;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.util.CasCreationUtils;
import org.apache.uima.util.XMLInputSource;
+import org.junit.jupiter.api.Test;
-import junit.framework.TestCase;
-
-public class BinaryCasSerDesPerformance extends TestCase {
+public class BinaryCasSerDesPerformance {
// Note: This test case requires an input directory that has
// 1) a file typesystem.xml which has the type system for the serialized files
// 2) a bunch of files having compressed serialized CASes
// Set the directory in the 2nd line below
+ @Test
public void testBinaryCasDeserialization6Performance() throws Exception {
File dir = new File("" /* "/au/t/data/bin-compr-6/shakespeare.txt_40_processed" */);
- if (!dir.exists())
+ if (!dir.exists()) {
return;
+ }
File typeSystemFile = new File(dir, "typesystem.xml");
XMLInputSource in = new XMLInputSource(typeSystemFile);
diff --git a/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtils.java b/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtils.java
index cdae914..ee6d5ab 100644
--- a/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtils.java
+++ b/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtils.java
@@ -18,17 +18,11 @@
*/
package org.apache.uima.internal.util;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import junit.framework.TestCase;
-
/**
* Helper class for running multi-core tests.
*
@@ -37,7 +31,7 @@ import junit.framework.TestCase;
* are reflected back.
*
*/
-public class MultiThreadUtils extends TestCase {
+public class MultiThreadUtils {
public final static boolean debug = false;
@@ -53,7 +47,7 @@ public class MultiThreadUtils extends TestCase {
// also serves as a lock
- private enum ThreadControl {
+ enum ThreadControl {
WAIT, // causes test thread to wait, is the initial state
RUN, // causes test thread to run; when run is done, thread goes back to waiting and sets global
// entry in thread array to WAIT
@@ -64,58 +58,6 @@ public class MultiThreadUtils extends TestCase {
private static final AtomicInteger numberOfExceptions = new AtomicInteger(0);
- public void testMultiThreadTimers() {
-
- final int numberOfTimers = 50;
- final Timer[] timers = new Timer[numberOfTimers];
-
- final ThreadControl[][] threadState = new ThreadControl[50][1];
-
- final int[] repeatNumber = { 0 };
-
- long startTime = System.nanoTime();
- for (int i = 0; i < numberOfTimers; i++) {
- final int finalI = i;
- threadState[i][0] = ThreadControl.WAIT;
-
- final Timer timer = new Timer();
- timers[i] = timer;
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- // System.out.format("%nTimer %d Popped%n", finalI);
- }
- }, 1);
- }
- System.out.format(
- "Time to create and start %d timers with separate Timer instances: %,d microsec%n",
- numberOfTimers, (System.nanoTime() - startTime) / 1000);
- }
-
- public static void testMultiThreadExecutors() {
-
- final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
- final int numberOfTimers = 50;
- final ScheduledFuture<?>[] timers = new ScheduledFuture<?>[numberOfTimers];
-
- long startTime = System.nanoTime();
- for (int i = 0; i < numberOfTimers; i++) {
- final int finalI = i;
-
- final ScheduledFuture<?> timer = scheduler.schedule(new Runnable() {
-
- @Override
- public void run() {
- // System.out.format("%nScheduled Timer %d Popped%n", finalI);
- }
- }, 1, TimeUnit.MILLISECONDS);
- timers[i] = timer;
- }
- System.out.format(
- "Time to create and start %d timers using a single, reused thread and ScheduledExecutorService: %,d microsec%n",
- numberOfTimers, (System.nanoTime() - startTime) / 1000);
- }
-
//@formatter:off
/**
* On a 2 GHz i7 running Windows, it seems to take about 1 millisecond to create and start up a thread.
@@ -195,11 +137,11 @@ public class MultiThreadUtils extends TestCase {
return;
}
}
- assertEquals(ThreadControl.RUN, threadState[finalI][0]);
+ assertThat(threadState[finalI][0]).isEqualTo(ThreadControl.RUN);
}
try {
- assertTrue(numberRunning.get() > 0);
+ assertThat(numberRunning.get()).isGreaterThan(0);
sb.append(name).append(", thread ").append(finalI).append(' ');
// System.out.println(sb.toString());
run2isb.call(finalI, repeatNumber[0], sb);
@@ -239,18 +181,18 @@ public class MultiThreadUtils extends TestCase {
beforeRepeat.run();
repeatNumber[0] = r;
- assertTrue(numberRunning.get() == 0);
+ assertThat(numberRunning.get()).isEqualTo(0);
if (numberOfExceptions.get() != 0) {
System.out.println("debug");
}
- assertTrue(numberOfExceptions.get() == 0);
+ assertThat(numberOfExceptions.get()).isEqualTo(0);
startTime = System.nanoTime();
// release all threads from wait point
for (int i = 0; i < numberOfThreads; i++) {
synchronized (threadState[i]) {
- assertEquals(ThreadControl.WAIT, threadState[i][0]);
+ assertThat(threadState[i][0]).isEqualTo(ThreadControl.WAIT);
threadState[i][0] = ThreadControl.RUN;
numberRunning.incrementAndGet();
threadState[i].notify();
@@ -270,7 +212,7 @@ public class MultiThreadUtils extends TestCase {
}
for (int i = 0; i < numberOfThreads; i++) {
synchronized (threadState[i]) {
- assertEquals(ThreadControl.WAIT, threadState[i][0]);
+ assertThat(threadState[i][0]).isEqualTo(ThreadControl.WAIT);
}
}
} // end of repeat loop
diff --git a/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtilsTest.java b/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtilsTest.java
new file mode 100644
index 0000000..7b0ba24
--- /dev/null
+++ b/uimaj-core/src/test/java/org/apache/uima/internal/util/MultiThreadUtilsTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.uima.internal.util;
+
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.uima.internal.util.MultiThreadUtils.ThreadControl;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Helper class for running multi-core tests.
+ *
+ * Runs a passed-in "runnable" inside loops for repetition and for multi-threads The threads run at
+ * the same time, and there's a "join" style wait at the end. Any exceptions thrown by the threads
+ * are reflected back.
+ *
+ */
+public class MultiThreadUtilsTest {
+
+ @Test
+ public void testMultiThreadTimers() {
+
+ final int numberOfTimers = 50;
+ final Timer[] timers = new Timer[numberOfTimers];
+
+ final ThreadControl[][] threadState = new ThreadControl[50][1];
+
+ final int[] repeatNumber = { 0 };
+
+ long startTime = System.nanoTime();
+ for (int i = 0; i < numberOfTimers; i++) {
+ final int finalI = i;
+ threadState[i][0] = ThreadControl.WAIT;
+
+ final Timer timer = new Timer();
+ timers[i] = timer;
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ // System.out.format("%nTimer %d Popped%n", finalI);
+ }
+ }, 1);
+ }
+ System.out.format(
+ "Time to create and start %d timers with separate Timer instances: %,d microsec%n",
+ numberOfTimers, (System.nanoTime() - startTime) / 1000);
+ }
+
+ @Test
+ public void testMultiThreadExecutors() {
+
+ final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ final int numberOfTimers = 50;
+ final ScheduledFuture<?>[] timers = new ScheduledFuture<?>[numberOfTimers];
+
+ long startTime = System.nanoTime();
+ for (int i = 0; i < numberOfTimers; i++) {
+ final int finalI = i;
+
+ final ScheduledFuture<?> timer = scheduler.schedule(new Runnable() {
+
+ @Override
+ public void run() {
+ // System.out.format("%nScheduled Timer %d Popped%n", finalI);
+ }
+ }, 1, TimeUnit.MILLISECONDS);
+ timers[i] = timer;
+ }
+ System.out.format(
+ "Time to create and start %d timers using a single, reused thread and ScheduledExecutorService: %,d microsec%n",
+ numberOfTimers, (System.nanoTime() - startTime) / 1000);
+ }
+}