Blob Blame History Raw
From a0de4614f4cb8f8340f4df31049b9144e94a5f49 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Tue, 5 Nov 2013 10:20:15 +0100
Subject: [PATCH 03/39] Add thread stress test

Related to #21
Related to rhbz#1051483
---
 test/CMakeLists.txt        |  9 ++++++
 test/ThreadStressTest.java | 79 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 test/ThreadStressTest.java

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 22187da..c84ebe5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -52,6 +52,7 @@ _add_class_target(TryFinallyTest TEST_JAVA_TARGETS SimpleTest)
 _add_class_target(InnerExceptions TEST_JAVA_TARGETS SimpleTest)
 _add_class_target(OverridenEqualExceptionTest TEST_JAVA_TARGETS)
 _add_class_target(NoException TEST_JAVA_TARGETS)
+_add_class_target(ThreadStressTest TEST_JAVA_TARGETS SimpleTest)
 
 _add_jar_target(JarTest JAR_TEST_PATH SimpleTest)
 set(REMOTE_JAR_PATH ${HTTP_DIR}/JarTest.jar)
@@ -200,6 +201,14 @@ _add_test_target(
 #_add_test(run_overriden_eqauls 2)
 
 add_custom_target(
+    run_thread_stress
+    COMMAND LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src ${Java_JAVA_EXECUTABLE} -agentlib:${AGENT_NAME}=caught=java.lang.ArrayIndexOutOfBoundsException,output= ThreadStressTest
+    DEPENDS ${TEST_JAVA_TARGETS}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+add_test(test_thread_stress  make run_thread_stress)
+
+add_custom_target(
     run_empty_command_line_options
     COMMAND LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src ${Java_JAVA_EXECUTABLE} -agentlib:${AGENT_NAME} NoException
     DEPENDS AbrtChecker ${TEST_JAVA_TARGETS}
diff --git a/test/ThreadStressTest.java b/test/ThreadStressTest.java
new file mode 100644
index 0000000..3ebf9e0
--- /dev/null
+++ b/test/ThreadStressTest.java
@@ -0,0 +1,79 @@
+import java.io.*;
+import java.util.*;
+import java.net.*;
+
+
+/**
+ * @author Jakub Filak &lt;jfilak@redhat.com&gt;
+ */
+
+class ThreadCaughtException extends Thread {
+    private void level_three() {
+        SimpleTest.throwAndCatchAllExceptions();
+    }
+
+    private void level_two() {
+        try {
+            Thread.currentThread().sleep(5);
+        }
+        catch (InterruptedException ex) {
+            System.out.println("Interrupted");
+        }
+        level_three();
+    }
+
+    private void level_one() {
+        try {
+            Thread.currentThread().sleep(5);
+        }
+        catch (InterruptedException ex) {
+            System.out.println("Interrupted");
+        }
+        level_two();
+    }
+
+    public void run() {
+        level_one();
+    }
+}
+
+public class ThreadStressTest {
+    /**
+     * Entry point to this multi thread test.
+     */
+    public static void main(String args[]) {
+        System.out.println("Test.java");
+
+        List<Thread> tojoin = new LinkedList<Thread>();
+
+        for (int i = 100; i != 0; --i) {
+            for (int j = 300; j != 0; --j) {
+                Thread t = new ThreadCaughtException();
+                tojoin.add(t);
+                System.out.println("Starting Thread: " + Integer.toString((i * j) + j));
+                t.start();
+            }
+
+            try {
+                Thread.currentThread().sleep(1000);
+            }
+            catch (InterruptedException ex) {
+                System.out.println("Interrupted");
+            }
+        }
+
+        for (Thread t : tojoin) {
+            try {
+                t.join();
+            }
+            catch(InterruptedException ex) {
+                System.err.println("Can't join a thread because thread join() was interrupted.");
+            }
+        }
+
+        System.exit(0);
+    }
+}
+
+// finito
+
-- 
1.8.3.1