changeset 45026:bc9b3e93b6c5

8178912: Remove sample/chatserver/ChatTest.java and sample/mergesort/MergeSortTest.java Reviewed-by: psandoz
author xiaofeya
date Sun, 07 May 2017 19:01:13 -0700
parents 9ad3afa82b5e
children 0cf367e546fb
files jdk/test/ProblemList.txt jdk/test/TEST.groups jdk/test/sample/TEST.properties jdk/test/sample/chatserver/ChatTest.java jdk/test/sample/mergesort/MergeSortTest.java
diffstat 5 files changed, 1 insertions(+), 514 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/test/ProblemList.txt	Sat May 06 14:58:04 2017 -0700
+++ b/jdk/test/ProblemList.txt	Sun May 07 19:01:13 2017 -0700
@@ -301,7 +301,4 @@
 
 org/omg/CORBA/OrbPropertiesTest.java			        8175177 generic-all
 
-sample/mergesort/MergeSortTest.java				8178912 generic-all
-sample/chatserver/ChatTest.java					8178912 generic-all
-
 ############################################################################
--- a/jdk/test/TEST.groups	Sat May 06 14:58:04 2017 -0700
+++ b/jdk/test/TEST.groups	Sun May 07 19:01:13 2017 -0700
@@ -272,8 +272,7 @@
     com/sun/jndi \
     com/sun/corba \
     org/omg/CORBA \
-    lib/testlibrary \
-    sample
+    lib/testlibrary
 
 #
 # SCTP is its own group as it is highly sensitive to kernel/network config
@@ -774,7 +773,6 @@
   javax \
   jdk \
   lib \
-  sample \
   sun \
   vm \
  -:needs_full_vm_compact1 \
--- a/jdk/test/sample/TEST.properties	Sat May 06 14:58:04 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-external.lib.roots = ../../
--- a/jdk/test/sample/chatserver/ChatTest.java	Sat May 06 14:58:04 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,402 +0,0 @@
-/*
- * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-
-/* @test
- * @summary Test chat server chatserver test
- *
- * @library /src/sample/share/nio/chatserver
- * @build ChatTest ChatServer Client ClientReader DataReader MessageReader NameReader
- * @run testng ChatTest
- */
-
-import java.io.*;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CyclicBarrier;
-
-import org.testng.annotations.Test;
-
-public class ChatTest {
-    public static int listeningPort = 0;
-
-    @Test
-    public static void doTest() throws Throwable {
-        testStartStop();
-        testPortOpen();
-        testAsksForName();
-        testUseName();
-        testConnectDisconnectConnect();
-        testUsernameAndMessage();
-        testDontReceiveMessageInNameState();
-    }
-
-    private static ChatServer startServer() throws IOException {
-        ChatServer server = new ChatServer(0);
-        InetSocketAddress address = (InetSocketAddress) server.getSocketAddress();
-        listeningPort = address.getPort();
-        server.run();
-        return server;
-    }
-
-    public static void testStartStop() throws Exception {
-        ChatServer server = startServer();
-        server.shutdown();
-    }
-
-    public static void testPortOpen() throws Exception {
-        ChatServer server = startServer();
-        try {
-            Socket socket = new Socket("localhost", listeningPort);
-            if (!socket.isConnected()) {
-                throw new RuntimeException("Failed to connect to server: port not open");
-            }
-        } finally {
-            server.shutdown();
-        }
-    }
-
-    public static void testAsksForName() throws Exception {
-        ChatServer server = startServer();
-        try {
-            Socket socket = new Socket("localhost", listeningPort);
-
-            Reader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-            String string = readAvailableString(reader);
-            if (!string.equals("Name: ")) {
-                throw new RuntimeException("Server doesn't send Name: ");
-            }
-        } finally {
-            server.shutdown();
-        }
-    }
-
-    public static void testUseName() throws Throwable {
-        ChatServer server = startServer();
-        try {
-            performTestUseName();
-        } finally {
-            server.shutdown();
-        }
-    }
-
-    public static void testConnectDisconnectConnect() throws Exception {
-        ChatServer server = startServer();
-        try {
-            performTestConnectDisconnectConnect();
-        } finally {
-            server.shutdown();
-        }
-    }
-
-    public static void testUsernameAndMessage() throws Exception {
-        ChatServer server = startServer();
-        try {
-            performTestUsernameAndMessage();
-        } finally {
-            server.shutdown();
-        }
-    }
-
-    public static void testDontReceiveMessageInNameState() throws Exception {
-        ChatServer server = startServer();
-        try {
-            performDontReceiveMessageInNameState();
-        } finally {
-            server.shutdown();
-        }
-    }
-
-    private static void assertEqual(List<Exception> exception, Object value, Object expected) {
-        if (expected == value) {
-            return;
-        }
-        if (expected == null) {
-            exception.add(new RuntimeException("Expected null, but was: " + value));
-            return;
-        }
-        if (!expected.equals(value)) {
-            exception.add(new RuntimeException("Expected: " + expected + " but was: " + value));
-            return;
-        }
-    }
-
-    private static void performDontReceiveMessageInNameState() throws Exception {
-        final CyclicBarrier barrier1 = new CyclicBarrier(2);
-        final CyclicBarrier barrier2 = new CyclicBarrier(2);
-        final CyclicBarrier barrier3 = new CyclicBarrier(2);
-        final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
-
-        ChatConnection chatConnection = new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "Name: ");
-                writer.write("testClient1\n");
-                waitForJoin(reader, "testClient1");
-                barrier1.await();
-                writer.write("Ignore this!\n");
-                barrier2.await();
-                barrier3.await();
-            }
-        };
-
-        Thread client2 = new Thread(new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                barrier1.await();
-                barrier2.await();
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "Name: ");
-                string = readAvailableString(reader, true);
-                assertEqual(exceptions, string, null);
-                writer.write("testClient2\n");
-                barrier3.await();
-            }
-        });
-
-        client2.start();
-        chatConnection.run();
-        if (!exceptions.isEmpty()) {
-            throw exceptions.get(0);
-        }
-
-    }
-
-    private static void waitForJoin(BufferedReader reader, String s) throws IOException {
-        String joined;
-        do {
-            joined = readAvailableString(reader);
-        } while (!(joined != null && joined.contains("Welcome " + s)));
-    }
-
-    private static void performTestUsernameAndMessage() throws Exception {
-        final CyclicBarrier barrier1 = new CyclicBarrier(2);
-        final CyclicBarrier barrier2 = new CyclicBarrier(2);
-        final CyclicBarrier barrier3 = new CyclicBarrier(2);
-        final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
-
-        ChatConnection chatConnection = new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "Name: ");
-                writer.write("testClient1\n");
-                waitForJoin(reader, "testClient1");
-                barrier1.await();
-                barrier2.await();
-                string = readAvailableString(reader);
-                assertEqual(exceptions, string, "testClient2: Hello world!\n");
-                barrier3.await();
-            }
-        };
-
-        Thread client2 = new Thread(new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "Name: ");
-                barrier1.await();
-                writer.write("testClient2\nHello world!\n");
-                barrier2.await();
-                barrier3.await();
-            }
-        });
-
-        client2.start();
-        chatConnection.run();
-        if (!exceptions.isEmpty()) {
-            throw exceptions.get(0);
-        }
-    }
-
-    private static void performTestConnectDisconnectConnect() throws Exception {
-        final CyclicBarrier barrier1 = new CyclicBarrier(2);
-        final CyclicBarrier barrier2 = new CyclicBarrier(2);
-        final CyclicBarrier barrier3 = new CyclicBarrier(2);
-        final List<Exception> exceptions = new ArrayList<Exception>();
-
-        ChatConnection chatConnection = new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "Name: ");
-                writer.write("testClient1\n");
-            }
-        };
-
-        ChatConnection chatConnection2 = new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                readAvailableString(reader);
-                writer.write("testClient1\n");
-                waitForJoin(reader, "testClient1");
-                barrier1.await();
-                writer.write("Good morning!\n");
-                barrier2.await();
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "testClient2: Hello world!\n");
-                barrier3.await();
-            }
-        };
-
-        Thread client2 = new Thread(new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                readAvailableString(reader);
-                writer.write("testClient2\n");
-                waitForJoin(reader, "testClient2");
-                barrier1.await();
-                writer.write("Hello world!\n");
-                barrier2.await();
-                String string = readAvailableString(reader);
-                assertEqual(exceptions, string, "testClient1: Good morning!\n");
-                barrier3.await();
-            }
-        });
-
-        client2.start();
-        chatConnection.run();
-        chatConnection2.run();
-        if (!exceptions.isEmpty()) {
-            throw exceptions.get(0);
-        }
-    }
-
-    private static void performTestUseName() throws Exception {
-        final CyclicBarrier barrier1 = new CyclicBarrier(2);
-        final CyclicBarrier barrier2 = new CyclicBarrier(2);
-        final CyclicBarrier barrier3 = new CyclicBarrier(2);
-        final List<Exception> exceptions = new ArrayList<Exception>();
-
-        ChatConnection chatConnection = new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                String string = readAvailableString(reader);
-                if (!"Name: ".equals(string)) {
-                    exceptions.add(new RuntimeException("Expected Name: "));
-                }
-                writer.write("testClient1\n");
-                waitForJoin(reader, "testClient1");
-                barrier1.await();
-                barrier2.await();
-                string = readAvailableString(reader);
-                if (!"testClient2: Hello world!\n".equals(string)) {
-                    exceptions.add(new RuntimeException("testClient2: Hello world!\n"));
-                }
-                barrier3.await();
-            }
-        };
-
-        Thread client2 = new Thread(new ChatConnection() {
-            @Override
-            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
-                String string = readAvailableString(reader);
-                if (!"Name: ".equals(string)) {
-                    exceptions.add(new RuntimeException("Expected Name: "));
-                }
-                writer.write("testClient2\n");
-                waitForJoin(reader, "testClient2");
-                barrier1.await();
-                writer.write("Hello world!\n");
-                barrier2.await();
-                barrier3.await();
-            }
-        });
-
-        client2.start();
-        chatConnection.run();
-        if (!exceptions.isEmpty()) {
-            throw exceptions.get(0);
-        }
-    }
-
-    private static String readAvailableString(Reader reader) throws IOException {
-        return readAvailableString(reader, false);
-    }
-
-    private static String readAvailableString(Reader reader, boolean now) throws IOException {
-        StringBuilder builder = new StringBuilder();
-        int bytes;
-        if (now && !reader.ready()) {
-            return null;
-        }
-        do {
-            char[] buf = new char[256];
-            bytes = reader.read(buf);
-            builder.append(buf, 0, bytes);
-        } while (bytes == 256);
-        return builder.toString();
-    }
-
-    private abstract static class ChatConnection implements Runnable {
-        public Exception exception;
-
-        @Override
-        public void run() {
-            try (Socket socket = new Socket("localhost", listeningPort);
-            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-            Writer writer = new FlushingWriter(new OutputStreamWriter(socket.getOutputStream()))) {
-                socket.setTcpNoDelay(true);
-
-                run(socket, reader, writer);
-            } catch (Exception e) {
-                exception = e;
-            }
-        }
-
-        public abstract void run(Socket socket, BufferedReader reader, Writer writer) throws Exception;
-    }
-
-    private static class FlushingWriter extends Writer {
-        public final Writer delegate;
-
-        private FlushingWriter(Writer delegate) {
-            this.delegate = delegate;
-        }
-
-        @Override
-        public void write(char[] cbuf, int off, int len) throws IOException {
-            delegate.write(cbuf, off, len);
-        }
-
-        @Override
-        public void flush() throws IOException {
-            delegate.flush();
-        }
-
-        @Override
-        public void close() throws IOException {
-            delegate.close();
-        }
-
-        @Override
-        public void write(String str) throws IOException {
-            super.write(str);
-            flush();
-        }
-    }
-}
--- a/jdk/test/sample/mergesort/MergeSortTest.java	Sat May 06 14:58:04 2017 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-
-/* @test
- * @summary Test MergeSort
- *
- * @library /src/sample/share/forkjoin/mergesort
- * @build MergeSortTest MergeDemo MergeSort
- * @run testng MergeSortTest
- */
-
-import java.util.Arrays;
-import java.util.Random;
-
-import org.testng.annotations.Test;
-
-public class MergeSortTest {
-    private Random random;
-    private MergeSort target;
-
-    public MergeSortTest(Random random, MergeSort target) {
-        this.random = random;
-        this.target = target;
-    }
-
-    @Test
-    public static void doTest() {
-        MergeSortTest test = new MergeSortTest(new Random(), new MergeSort(Runtime.getRuntime().availableProcessors() * 4));
-        test.run();
-    }
-
-    private int[] generateArray(int elements) {
-        int[] array = new int[elements];
-        for (int i = 0; i < array.length; ++i) {
-            array[i] = random.nextInt(10);
-        }
-        return array;
-    }
-
-    private void run() {
-        testSort();
-        testSortSingle();
-        testSortEmpty();
-        testLong();
-    }
-
-    public void testLong() {
-        for (int i = 0; i < 1000; ++i) {
-            int elements = 1 + i * 100;
-
-            int[] array = generateArray(elements);
-            int[] copy = Arrays.copyOf(array, array.length);
-            Arrays.sort(copy);
-            target.sort(array);
-            assertEqual(copy, array);
-        }
-   }
-
-    private void testSortEmpty() {
-        int[] array = { };
-        target.sort(array);
-        assertEqual(new int[] { }, array);
-    }
-
-    private void testSortSingle() {
-        int[] array = { 1 };
-        target.sort(array);
-        assertEqual(new int[] { 1 }, array);
-    }
-
-    private void testSort() {
-        int[] array = { 7, 3, 9, 0, -6, 12, 54, 3, -6, 88, 1412};
-        target.sort(array);
-        assertEqual(new int[] { -6, -6, 0, 3, 3, 7, 9, 12, 54, 88, 1412 }, array);
-    }
-
-    private void assertEqual(int[] expected, int[] array) {
-        if (!Arrays.equals(expected, array)) {
-            throw new RuntimeException("Invalid sorted array!");
-        }
-    }
-
-
-}