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

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