|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 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 |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 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 | +import java.io.ByteArrayOutputStream; |
| 25 | +import java.io.PrintStream; |
| 26 | +import java.util.List; |
| 27 | +import java.util.stream.Collectors; |
| 28 | +import jdk.jshell.JShell; |
| 29 | +import org.testng.annotations.Test; |
| 30 | +import static org.testng.Assert.assertEquals; |
| 31 | + |
| 32 | +/* |
| 33 | + * @test |
| 34 | + * @bug 8274734 |
| 35 | + * @summary Verify multiple SourceCodeAnalysis instances can concurrently provide documentation. |
| 36 | + * @library /tools/lib |
| 37 | + * @modules jdk.compiler/com.sun.tools.javac.api |
| 38 | + * jdk.compiler/com.sun.tools.javac.main |
| 39 | + * jdk.jdeps/com.sun.tools.javap |
| 40 | + * jdk.jshell/jdk.internal.jshell.tool |
| 41 | + * @build Compiler toolbox.ToolBox |
| 42 | + * @run testng MultipleDocumentationTest |
| 43 | + */ |
| 44 | +@Test |
| 45 | +public class MultipleDocumentationTest { |
| 46 | + |
| 47 | + public void testMultipleDocumentation() { |
| 48 | + String input = "java.lang.String"; |
| 49 | + |
| 50 | + try (var state1 = JShell.builder() |
| 51 | + .out(new PrintStream(new ByteArrayOutputStream())) |
| 52 | + .err(new PrintStream(new ByteArrayOutputStream())) |
| 53 | + .build()) { |
| 54 | + var sca1 = state1.sourceCodeAnalysis(); |
| 55 | + List<String> javadocs1 = |
| 56 | + sca1.documentation(input, input.length(), true) |
| 57 | + .stream() |
| 58 | + .map(d -> d.javadoc()) |
| 59 | + .collect(Collectors.toList()); |
| 60 | + |
| 61 | + try (var state2 = JShell.builder() |
| 62 | + .out(new PrintStream(new ByteArrayOutputStream())) |
| 63 | + .err(new PrintStream(new ByteArrayOutputStream())) |
| 64 | + .build()) { |
| 65 | + var sca2 = state2.sourceCodeAnalysis(); |
| 66 | + List<String> javadocs2 = sca2.documentation(input, input.length(), true) |
| 67 | + .stream() |
| 68 | + .map(d -> d.javadoc()) |
| 69 | + .collect(Collectors.toList()); |
| 70 | + |
| 71 | + assertEquals(javadocs2, javadocs1); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments