equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
61 scratch.add("public class TestLambda {"); |
61 scratch.add("public class TestLambda {"); |
62 scratch.add(" interface I {"); |
62 scratch.add(" interface I {"); |
63 scratch.add(" int foo();"); |
63 scratch.add(" int foo();"); |
64 scratch.add(" }"); |
64 scratch.add(" }"); |
65 scratch.add(" public static void main(String[] args) {"); |
65 scratch.add(" public static void main(String[] args) {"); |
|
66 scratch.add(" System.setSecurityManager(new SecurityManager());"); |
66 scratch.add(" I lam = () -> 10;"); |
67 scratch.add(" I lam = () -> 10;"); |
67 scratch.add(" Runnable r = () -> {"); |
68 scratch.add(" Runnable r = () -> {"); |
68 scratch.add(" System.out.println(\"Runnable\");"); |
69 scratch.add(" System.out.println(\"Runnable\");"); |
69 scratch.add(" };"); |
70 scratch.add(" };"); |
70 scratch.add(" r.run();"); |
71 scratch.add(" r.run();"); |
112 |
113 |
113 @Test |
114 @Test |
114 public void testNotLogging() { |
115 public void testNotLogging() { |
115 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
116 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
116 "-cp", ".", |
117 "-cp", ".", |
117 "-Djava.security.manager", |
|
118 "com.example.TestLambda"); |
118 "com.example.TestLambda"); |
119 tr.assertZero("Should still return 0"); |
119 tr.assertZero("Should still return 0"); |
120 } |
120 } |
121 |
121 |
122 @Test |
122 @Test |
123 public void testLogging() throws IOException { |
123 public void testLogging() throws IOException { |
124 assertTrue(Files.exists(Paths.get("dump"))); |
124 assertTrue(Files.exists(Paths.get("dump"))); |
125 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
125 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
126 "-cp", ".", |
126 "-cp", ".", |
127 "-Djdk.internal.lambda.dumpProxyClasses=dump", |
127 "-Djdk.internal.lambda.dumpProxyClasses=dump", |
128 "-Djava.security.manager", |
|
129 "com.example.TestLambda"); |
128 "com.example.TestLambda"); |
130 // 2 our own class files. We don't care about the others |
129 // 2 our own class files. We don't care about the others |
131 assertEquals(Files.find( |
130 assertEquals(Files.find( |
132 Paths.get("dump"), |
131 Paths.get("dump"), |
133 99, |
132 99, |
141 public void testDumpDirNotExist() throws IOException { |
140 public void testDumpDirNotExist() throws IOException { |
142 assertFalse(Files.exists(Paths.get("notExist"))); |
141 assertFalse(Files.exists(Paths.get("notExist"))); |
143 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
142 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
144 "-cp", ".", |
143 "-cp", ".", |
145 "-Djdk.internal.lambda.dumpProxyClasses=notExist", |
144 "-Djdk.internal.lambda.dumpProxyClasses=notExist", |
146 "-Djava.security.manager", |
|
147 "com.example.TestLambda"); |
145 "com.example.TestLambda"); |
148 assertEquals(tr.testOutput.stream() |
146 assertEquals(tr.testOutput.stream() |
149 .filter(s -> s.startsWith("WARNING")) |
147 .filter(s -> s.startsWith("WARNING")) |
150 .peek(s -> assertTrue(s.contains("does not exist"))) |
148 .peek(s -> assertTrue(s.contains("does not exist"))) |
151 .count(), |
149 .count(), |
157 public void testDumpDirIsFile() throws IOException { |
155 public void testDumpDirIsFile() throws IOException { |
158 assertTrue(Files.isRegularFile(Paths.get("file"))); |
156 assertTrue(Files.isRegularFile(Paths.get("file"))); |
159 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
157 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
160 "-cp", ".", |
158 "-cp", ".", |
161 "-Djdk.internal.lambda.dumpProxyClasses=file", |
159 "-Djdk.internal.lambda.dumpProxyClasses=file", |
162 "-Djava.security.manager", |
|
163 "com.example.TestLambda"); |
160 "com.example.TestLambda"); |
164 assertEquals(tr.testOutput.stream() |
161 assertEquals(tr.testOutput.stream() |
165 .filter(s -> s.startsWith("WARNING")) |
162 .filter(s -> s.startsWith("WARNING")) |
166 .peek(s -> assertTrue(s.contains("not a directory"))) |
163 .peek(s -> assertTrue(s.contains("not a directory"))) |
167 .count(), |
164 .count(), |
216 } |
213 } |
217 |
214 |
218 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
215 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
219 "-cp", ".", |
216 "-cp", ".", |
220 "-Djdk.internal.lambda.dumpProxyClasses=readOnly", |
217 "-Djdk.internal.lambda.dumpProxyClasses=readOnly", |
221 "-Djava.security.manager", |
|
222 "com.example.TestLambda"); |
218 "com.example.TestLambda"); |
223 assertEquals(tr.testOutput.stream() |
219 assertEquals(tr.testOutput.stream() |
224 .filter(s -> s.startsWith("WARNING")) |
220 .filter(s -> s.startsWith("WARNING")) |
225 .peek(s -> assertTrue(s.contains("not writable"))) |
221 .peek(s -> assertTrue(s.contains("not writable"))) |
226 .count(), |
222 .count(), |
235 public void testLoggingException() throws IOException { |
231 public void testLoggingException() throws IOException { |
236 assertTrue(Files.exists(Paths.get("dumpLong"))); |
232 assertTrue(Files.exists(Paths.get("dumpLong"))); |
237 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
233 TestResult tr = doExec(JAVA_CMD.getAbsolutePath(), |
238 "-cp", ".", |
234 "-cp", ".", |
239 "-Djdk.internal.lambda.dumpProxyClasses=dumpLong", |
235 "-Djdk.internal.lambda.dumpProxyClasses=dumpLong", |
240 "-Djava.security.manager", |
|
241 longFQCN); |
236 longFQCN); |
242 assertEquals(tr.testOutput.stream() |
237 assertEquals(tr.testOutput.stream() |
243 .filter(s -> s.startsWith("WARNING: Exception")) |
238 .filter(s -> s.startsWith("WARNING: Exception")) |
244 .count(), |
239 .count(), |
245 2, "show error each capture"); |
240 2, "show error each capture"); |