Blame SOURCES/0003-Add-thread-stress-test.patch

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