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