Basic.java revision 3003
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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
* @bug 4607272
* @summary Unit test for AsynchronousChannelGroup
* @build Basic
*/
public class Basic {
return new Thread(r);
}};
miscTests();
}
static void shutdownTests() throws Exception {
// test shutdown with no channels in groups
for (int i=0; i<500; i++) {
if (rand.nextBoolean()) {
} else {
}
if (!group.isShutdown())
throw new RuntimeException("Group should be shutdown");
// group should terminate quickly
if (!terminated)
throw new RuntimeException("Group should have terminated");
throw new RuntimeException("Executor should have terminated");
}
// shutdown with channel in group
for (int i=0; i<500; i++) {
if (rand.nextBoolean()) {
} else {
}
// create channel that is bound to group
default : throw new AssertionError();
}
if (!group.isShutdown())
throw new RuntimeException("Group should be shutdown");
// last channel so should terminate after this channel is closed
// group should terminate quickly
if (!terminated)
throw new RuntimeException("Group should have terminated");
throw new RuntimeException("Executor should have terminated");
}
}
static void shutdownNowTests() throws Exception {
for (int i=0; i< 10; i++) {
if (rand.nextBoolean()) {
} else {
}
// I/O in progress
// forceful shutdown
group.shutdownNow();
// shutdownNow is required to close all channels
throw new RuntimeException("Channel should be closed");
if (!terminated)
throw new RuntimeException("Group should have terminated");
throw new RuntimeException("Executor should have terminated");
}
}
// test creating channels in group after group is shutdown
static void afterShutdownTests() throws Exception {
// initiate accept
// shutdown group
if (!group.isShutdown())
throw new RuntimeException("Group should be shutdown");
// attempt to create another channel
try {
throw new RuntimeException("ShutdownChannelGroupException expected");
} catch (ShutdownChannelGroupException x) {
}
try {
throw new RuntimeException("ShutdownChannelGroupException expected");
} catch (ShutdownChannelGroupException x) {
}
// attempt to create another channel by connecting. This should cause
// the accept operation to fail.
try {
throw new RuntimeException("Connection was accepted");
} catch (ExecutionException x) {
if (!(cause instanceof IOException))
throw new RuntimeException("Cause should be IOException");
if (!(cause instanceof ShutdownChannelGroupException))
throw new RuntimeException("IOException cause should be ShutdownChannelGroupException");
}
// initiate another accept even though channel group is shutdown.
try {
throw new RuntimeException("TimeoutException expected");
} catch (TimeoutException x) {
}
// connect to the listener which should cause the accept to complete
try {
throw new RuntimeException("Connection was accepted");
} catch (ExecutionException x) {
if (!(cause instanceof IOException))
throw new RuntimeException("Cause should be IOException");
if (!(cause instanceof ShutdownChannelGroupException))
throw new RuntimeException("IOException cause should be ShutdownChannelGroupException");
}
// group should *not* terminate as channels are open
if (terminated)
throw new RuntimeException("Group should not have terminated");
// close channel; group should terminate quickly
if (!terminated)
throw new RuntimeException("Group should have terminated");
}
try {
throw new RuntimeException("NPE expected");
} catch (NullPointerException x) {
}
try {
throw new RuntimeException("IAE expected");
} catch (IllegalArgumentException e) {
}
try {
throw new RuntimeException("NPE expected");
} catch (NullPointerException x) {
}
}
}