jdk/test/java/rmi/module/ModuleTest.java
author mchung
Wed, 10 Aug 2016 15:51:25 -0700
changeset 40261 86a49ba76f52
parent 38588 1186d7bd7de9
child 45393 de4e1efc8eec
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers Reviewed-by: alanb, ksrini, henryjen, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38588
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     1
/*
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     4
 *
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     8
 *
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    13
 * accompanied this code).
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    14
 *
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    18
 *
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    21
 * questions.
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    22
 */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    23
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    24
/**
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    25
 * @test
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    26
 * @library /lib/testlibrary
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    27
 * @build jdk.testlibrary.ProcessTools
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    28
 *        ModuleTest CompilerUtils JarUtils
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    29
 * @run testng ModuleTest
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    30
 * @summary Basic tests for using rmi in module world
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    31
 */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    32
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    33
import static jdk.testlibrary.ProcessTools.executeTestJava;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    34
import static org.testng.Assert.assertEquals;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    35
import static org.testng.Assert.assertTrue;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    36
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    37
import java.io.File;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    38
import java.nio.file.Paths;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    39
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    40
import org.testng.annotations.BeforeTest;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    41
import org.testng.annotations.Test;
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    42
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    43
public class ModuleTest {
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    44
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    45
    static String fileJoin(String... names) {
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    46
        return String.join(File.separator, names);
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    47
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    48
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    49
    static String pathJoin(String... paths) {
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    50
        return String.join(File.pathSeparator, paths);
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    51
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    52
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    53
    private static final String TEST_SRC = System.getProperty("test.src");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    54
    private static final String CLIENT_EXP = fileJoin("exploded", "mclient");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    55
    private static final String SERVER_EXP = fileJoin("exploded", "mserver");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    56
    private static final String MTEST_EXP  = fileJoin("exploded", "mtest");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    57
    private static final String CLIENT_JAR = fileJoin("mods", "mclient.jar");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    58
    private static final String SERVER_JAR = fileJoin("mods", "mserver.jar");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    59
    private static final String MTEST_JAR  = fileJoin("mods", "mtest.jar");
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    60
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    61
    private static final String DUMMY_MAIN = "testpkg.DummyApp";
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    62
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    63
    /**
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    64
     * Compiles all sample classes
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    65
     */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    66
    @BeforeTest
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    67
    public void compileAll() throws Exception {
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    68
        assertTrue(CompilerUtils.compile(
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    69
                Paths.get(TEST_SRC, "src", "mserver"),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    70
                Paths.get(SERVER_EXP)));
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    71
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    72
        JarUtils.createJarFile(
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    73
                Paths.get(SERVER_JAR),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    74
                Paths.get(SERVER_EXP));
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    75
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    76
        assertTrue(CompilerUtils.compile(
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    77
                Paths.get(TEST_SRC, "src", "mclient"),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    78
                Paths.get(CLIENT_EXP),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    79
                "-cp", SERVER_JAR));
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    80
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    81
        JarUtils.createJarFile(
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    82
                Paths.get(CLIENT_JAR),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    83
                Paths.get(CLIENT_EXP));
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    84
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    85
        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "mtest"),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    86
                Paths.get(MTEST_EXP),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    87
                "-cp", pathJoin(CLIENT_JAR, SERVER_JAR)));
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    88
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    89
        JarUtils.createJarFile(
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    90
                Paths.get(MTEST_JAR),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    91
                Paths.get(MTEST_EXP));
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    92
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    93
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    94
    /**
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    95
     * Test the client, server and dummy application in different modules
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    96
     * @throws Exception
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    97
     */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    98
    @Test
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
    99
    public void testAllInModule() throws Exception {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   100
        assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, CLIENT_JAR, SERVER_JAR),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   101
                "--add-modules", "mclient,mserver",
38588
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   102
                "-m", "mtest/" + DUMMY_MAIN)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   103
                .outputTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   104
                .errorTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   105
                .getExitValue(),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   106
                0);
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   107
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   108
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   109
    /**
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   110
     * Test the client and server in unnamed modules,
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   111
     * while the dummy application is in automatic module
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   112
     * @throws Exception
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   113
     */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   114
    @Test
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   115
    public void testAppInModule() throws Exception {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   116
        assertEquals(executeTestJava("--module-path", MTEST_JAR,
38588
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   117
                "-cp", pathJoin(CLIENT_JAR, SERVER_JAR),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   118
                "-m", "mtest/" + DUMMY_MAIN)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   119
                .outputTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   120
                .errorTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   121
                .getExitValue(),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   122
                0);
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   123
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   124
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   125
    /**
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   126
     * Test the client and server in automatic modules,
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   127
     * while the dummy application is in unnamed module
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   128
     * @throws Exception
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   129
     */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   130
    @Test
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   131
    public void testAppInUnnamedModule() throws Exception {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   132
        assertEquals(executeTestJava("--module-path", pathJoin(CLIENT_JAR, SERVER_JAR),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   133
                "--add-modules", "mclient,mserver",
38588
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   134
                "-cp", MTEST_JAR,
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   135
                DUMMY_MAIN)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   136
                .outputTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   137
                .errorTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   138
                .getExitValue(),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   139
                0);
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   140
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   141
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   142
    /**
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   143
     * Test the server and test application in automatic modules,
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   144
     * with client in unnamed module
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   145
     * @throws Exception
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   146
     */
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   147
    @Test
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   148
    public void testClientInUnamedModule() throws Exception {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   149
        assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, SERVER_JAR),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38588
diff changeset
   150
                "--add-modules", "mserver",
38588
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   151
                "-cp", CLIENT_JAR,
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   152
                "-m", "mtest/" + DUMMY_MAIN)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   153
                .outputTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   154
                .errorTo(System.out)
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   155
                .getExitValue(),
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   156
                0);
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   157
    }
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   158
}
1186d7bd7de9 8078812: Test RMI with client and servers as modules
xiaofeya
parents:
diff changeset
   159