test/java/lang/invoke/lambda/LogGeneratedClassesTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff test/java/lang/invoke/lambda

test/java/lang/invoke/lambda/LogGeneratedClassesTest.java

Print this page
rev 10007 : 8035186: j2se_jdk/jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java - assertion error
Reviewed-by: ?


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8023524
  27  * @summary tests logging generated classes for lambda
  28  * @library /java/nio/file
  29  * @run testng LogGeneratedClassesTest
  30  */
  31 import java.io.File;
  32 import java.io.IOException;
  33 import java.util.ArrayList;
  34 import java.util.List;
  35 import java.nio.file.Files;
  36 import java.nio.file.LinkOption;
  37 import java.nio.file.Path;
  38 import java.nio.file.Paths;
  39 import java.nio.file.attribute.PosixFileAttributeView;
  40 import java.util.stream.Stream;
  41 
  42 import org.testng.annotations.AfterClass;
  43 import org.testng.annotations.BeforeClass;
  44 import org.testng.annotations.Test;
  45 import org.testng.SkipException;
  46 
  47 import static java.nio.file.attribute.PosixFilePermissions.*;
  48 import static org.testng.Assert.assertEquals;
  49 import static org.testng.Assert.assertFalse;
  50 import static org.testng.Assert.assertTrue;
  51 
  52 public class LogGeneratedClassesTest extends LUtils {
  53     String longFQCN;
  54 
  55     @BeforeClass
  56     public void setup() throws IOException {
  57         final List<String> scratch = new ArrayList<>();
  58         scratch.clear();
  59         scratch.add("package com.example;");
  60         scratch.add("public class TestLambda {");


 146                      1, "only show error once");
 147         tr.assertZero("Should still return 0");
 148     }
 149 
 150     @Test
 151     public void testDumpDirIsFile() throws IOException {
 152         assertTrue(Files.isRegularFile(Paths.get("file")));
 153         TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),
 154                                "-cp", ".",
 155                                "-Djdk.internal.lambda.dumpProxyClasses=file",
 156                                "-Djava.security.manager",
 157                                "com.example.TestLambda");
 158         assertEquals(tr.testOutput.stream()
 159                                   .filter(s -> s.startsWith("WARNING"))
 160                                   .peek(s -> assertTrue(s.contains("not a directory")))
 161                                   .count(),
 162                      1, "only show error once");
 163         tr.assertZero("Should still return 0");
 164     }
 165 

























 166     @Test
 167     public void testDumpDirNotWritable() throws IOException {
 168         if (! Files.getFileStore(Paths.get("."))
 169                    .supportsFileAttributeView(PosixFileAttributeView.class)) {
 170             // No easy way to setup readonly directory without POSIX
 171             // We would like to skip the test with a cause with
 172             //     throw new SkipException("Posix not supported");
 173             // but jtreg will report failure so we just pass the test
 174             // which we can look at if jtreg changed its behavior
 175             return;
 176         }
 177 
 178         Files.createDirectory(Paths.get("readOnly"),
 179                               asFileAttribute(fromString("r-xr-xr-x")));







 180 
 181         TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),
 182                                "-cp", ".",
 183                                "-Djdk.internal.lambda.dumpProxyClasses=readOnly",
 184                                "-Djava.security.manager",
 185                                "com.example.TestLambda");
 186         assertEquals(tr.testOutput.stream()
 187                                   .filter(s -> s.startsWith("WARNING"))
 188                                   .peek(s -> assertTrue(s.contains("not writable")))
 189                                   .count(),
 190                      1, "only show error once");
 191         tr.assertZero("Should still return 0");
 192 
 193         TestUtil.removeAll(Paths.get("readOnly"));
 194     }

 195 
 196     @Test
 197     public void testLoggingException() throws IOException {
 198         assertTrue(Files.exists(Paths.get("dumpLong")));
 199         TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),
 200                                "-cp", ".",
 201                                "-Djdk.internal.lambda.dumpProxyClasses=dumpLong",
 202                                "-Djava.security.manager",
 203                                longFQCN);
 204         assertEquals(tr.testOutput.stream()
 205                                   .filter(s -> s.startsWith("WARNING: Exception"))
 206                                   .count(),
 207                      2, "show error each capture");
 208         // dumpLong/com/example/nosense/nosense
 209         assertEquals(Files.walk(Paths.get("dumpLong")).count(), 5, "Two lambda captured failed to log");
 210         tr.assertZero("Should still return 0");
 211     }
 212 }


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8023524
  27  * @summary tests logging generated classes for lambda
  28  * @library /java/nio/file
  29  * @run testng LogGeneratedClassesTest
  30  */
  31 import java.io.File;
  32 import java.io.IOException;
  33 import java.util.ArrayList;
  34 import java.util.List;
  35 import java.nio.file.Files;

  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.nio.file.attribute.PosixFileAttributeView;

  39 
  40 import org.testng.annotations.AfterClass;
  41 import org.testng.annotations.BeforeClass;
  42 import org.testng.annotations.Test;
  43 import org.testng.SkipException;
  44 
  45 import static java.nio.file.attribute.PosixFilePermissions.*;
  46 import static org.testng.Assert.assertEquals;
  47 import static org.testng.Assert.assertFalse;
  48 import static org.testng.Assert.assertTrue;
  49 
  50 public class LogGeneratedClassesTest extends LUtils {
  51     String longFQCN;
  52 
  53     @BeforeClass
  54     public void setup() throws IOException {
  55         final List<String> scratch = new ArrayList<>();
  56         scratch.clear();
  57         scratch.add("package com.example;");
  58         scratch.add("public class TestLambda {");


 144                      1, "only show error once");
 145         tr.assertZero("Should still return 0");
 146     }
 147 
 148     @Test
 149     public void testDumpDirIsFile() throws IOException {
 150         assertTrue(Files.isRegularFile(Paths.get("file")));
 151         TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),
 152                                "-cp", ".",
 153                                "-Djdk.internal.lambda.dumpProxyClasses=file",
 154                                "-Djava.security.manager",
 155                                "com.example.TestLambda");
 156         assertEquals(tr.testOutput.stream()
 157                                   .filter(s -> s.startsWith("WARNING"))
 158                                   .peek(s -> assertTrue(s.contains("not a directory")))
 159                                   .count(),
 160                      1, "only show error once");
 161         tr.assertZero("Should still return 0");
 162     }
 163 
 164     private static boolean isWriteableDirectory(Path p) {
 165         if (!Files.isDirectory(p)) {
 166             return false;
 167         }
 168         Path test = p.resolve(Paths.get("test"));
 169         try {
 170             try {
 171                 Files.createFile(test);
 172                 assertTrue(Files.exists(test));
 173                 return true;
 174             } catch (IOException e) {
 175                 assertFalse(Files.exists(test));
 176                 return false;
 177             }
 178         } finally {
 179             if (Files.exists(test)) {
 180                 try {
 181                     Files.delete(test);
 182                 } catch (IOException e) {
 183                     throw new Error(e);
 184                 }
 185             }
 186         }
 187     }
 188 
 189     @Test
 190     public void testDumpDirNotWritable() throws IOException {
 191         if (!Files.getFileStore(Paths.get("."))
 192                   .supportsFileAttributeView(PosixFileAttributeView.class)) {
 193             // No easy way to setup readonly directory without POSIX
 194             // We would like to skip the test with a cause with
 195             //     throw new SkipException("Posix not supported");
 196             // but jtreg will report failure so we just pass the test
 197             // which we can look at if jtreg changed its behavior
 198             return;
 199         }
 200 
 201         Files.createDirectory(Paths.get("readOnly"),
 202                               asFileAttribute(fromString("r-xr-xr-x")));
 203         try {
 204             if (isWriteableDirectory(Paths.get("readOnly"))) {
 205                 // Skipping the test: it's allowed to write into read-only directory
 206                 // (e.g. current user is super user).
 207                 System.out.println("WARNING: readOnly directory is writeable. Skipping testDumpDirNotWritable test.");
 208                 return;
 209             }
 210 
 211             TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),
 212                                    "-cp", ".",
 213                                    "-Djdk.internal.lambda.dumpProxyClasses=readOnly",
 214                                    "-Djava.security.manager",
 215                                    "com.example.TestLambda");
 216             assertEquals(tr.testOutput.stream()
 217                                       .filter(s -> s.startsWith("WARNING"))
 218                                       .peek(s -> assertTrue(s.contains("not writable")))
 219                                       .count(),
 220                          1, "only show error once");
 221             tr.assertZero("Should still return 0");
 222         } finally {
 223             TestUtil.removeAll(Paths.get("readOnly"));
 224         }
 225     }
 226 
 227     @Test
 228     public void testLoggingException() throws IOException {
 229         assertTrue(Files.exists(Paths.get("dumpLong")));
 230         TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),
 231                                "-cp", ".",
 232                                "-Djdk.internal.lambda.dumpProxyClasses=dumpLong",
 233                                "-Djava.security.manager",
 234                                longFQCN);
 235         assertEquals(tr.testOutput.stream()
 236                                   .filter(s -> s.startsWith("WARNING: Exception"))
 237                                   .count(),
 238                      2, "show error each capture");
 239         // dumpLong/com/example/nosense/nosense
 240         assertEquals(Files.walk(Paths.get("dumpLong")).count(), 5, "Two lambda captured failed to log");
 241         tr.assertZero("Should still return 0");
 242     }
 243 }
test/java/lang/invoke/lambda/LogGeneratedClassesTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File