test/jdk/java/net/httpclient/DependentActionsTest.java
branchhttp-client-branch
changeset 56677 f57700f449bd
parent 56451 9585061fdb04
child 56771 73a6534bce94
--- a/test/jdk/java/net/httpclient/DependentActionsTest.java	Wed Jun 06 12:10:30 2018 +0100
+++ b/test/jdk/java/net/httpclient/DependentActionsTest.java	Wed Jun 06 13:57:19 2018 +0100
@@ -82,12 +82,14 @@
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Consumer;
+import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import static java.lang.System.out;
 import static java.lang.String.format;
+import static java.util.stream.Collectors.toList;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
@@ -374,13 +376,13 @@
     }
 
     final List<String> extractStream(HttpResponse<Stream<String>> resp) {
-        return resp.body().collect(Collectors.toList());
+        return resp.body().collect(toList());
     }
 
     final List<String> extractInputStream(HttpResponse<InputStream> resp) {
         try (InputStream is = resp.body()) {
             return new BufferedReader(new InputStreamReader(is))
-                    .lines().collect(Collectors.toList());
+                    .lines().collect(toList());
         } catch (IOException x) {
             throw new CompletionException(x);
         }
@@ -399,43 +401,27 @@
                 .findFirst();
     }
 
+    static final Predicate<StackFrame> DAT = sfe ->
+            sfe.getClassName().startsWith("DependentActionsTest");
+    static final Predicate<StackFrame> JUC = sfe ->
+            sfe.getClassName().startsWith("java.util.concurrent");
+    static final Predicate<StackFrame> JLT = sfe ->
+            sfe.getClassName().startsWith("java.lang.Thread");
+    static final Predicate<StackFrame> NotDATorJUCorJLT = Predicate.not(DAT.or(JUC).or(JLT));
+
+
     <T> void checkThreadAndStack(Thread thread,
                                  AtomicReference<RuntimeException> failed,
                                  T result,
                                  Throwable error) {
-        if (Thread.currentThread() == thread) {
-            //failed.set(new RuntimeException("Dependant action was executed in " + thread));
-            List<StackFrame> httpStack = WALKER.walk(s -> s.filter(f -> f.getDeclaringClass()
-                    .getModule().equals(HttpClient.class.getModule()))
-                    .collect(Collectors.toList()));
-            if (!httpStack.isEmpty()) {
-                System.out.println("Found unexpected trace: ");
-                httpStack.forEach(f -> System.out.printf("\t%s%n", f));
-                failed.set(new RuntimeException("Dependant action has unexpected frame in " +
-                        Thread.currentThread() + ": " + httpStack.get(0)));
+        //failed.set(new RuntimeException("Dependant action was executed in " + thread));
+        List<StackFrame> otherFrames = WALKER.walk(s -> s.filter(NotDATorJUCorJLT).collect(toList()));
+        if (!otherFrames.isEmpty()) {
+            System.out.println("Found unexpected trace: ");
+            otherFrames.forEach(f -> System.out.printf("\t%s%n", f));
+            failed.set(new RuntimeException("Dependant action has unexpected frame in " +
+                       Thread.currentThread() + ": " + otherFrames.get(0)));
 
-            }
-            return;
-        } else if (System.getSecurityManager() != null) {
-            Optional<StackFrame> sf = WALKER.walk(s -> findFrame(s, "PrivilegedRunnable"));
-            if (!sf.isPresent()) {
-                failed.set(new RuntimeException("Dependant action does not have expected frame in "
-                        + Thread.currentThread()));
-                return;
-            } else {
-                System.out.println("Found expected frame: " + sf.get());
-            }
-        } else {
-            List<StackFrame> httpStack = WALKER.walk(s -> s.filter(f -> f.getDeclaringClass()
-                    .getModule().equals(HttpClient.class.getModule()))
-                    .collect(Collectors.toList()));
-            if (!httpStack.isEmpty()) {
-                System.out.println("Found unexpected trace: ");
-                httpStack.forEach(f -> System.out.printf("\t%s%n", f));
-                failed.set(new RuntimeException("Dependant action has unexpected frame in " +
-                        Thread.currentThread() + ": " + httpStack.get(0)));
-
-            }
         }
     }