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

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