From: "Jeroen Frijters" <jeroen@sumatra.nl>
To: <mauve-discuss@sourceware.org>
Subject: New SocketChannel test that requires testing
Date: Mon, 18 Sep 2006 11:30:00 -0000 [thread overview]
Message-ID: <D92197D0A6547B44A1567814F851FA6827A98D@LEMBU.sumatrasoftware.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 703 bytes --]
Hi,
I've written a new test case for SocketChannel and I require some
assistance testing it on different platforms (and/or opinions on it)
because it uses a trick and I would like to know if the trick is
reliable or not.
The trick is that it creates a server socket with a backlog of 1 and
then it fills up that backlog queue by initiating a connection to make
sure that a subsequent connection attempt will block (to test if
asynchronous connections work correctly).
I tested this on Windows (JDK 1.5 and IKVM) and I would appreciate it if
people would run this test on their platform of choice. Other feedback
on the validity of this approach is also appreciated.
Thanks,
Jeroen
[-- Attachment #2: tests.java.txt --]
[-- Type: text/plain, Size: 3086 bytes --]
// Tags: JDK1.4
// Copyright (C) 2006 Jeroen Frijters
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// Mauve 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 for more details.
// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.nio.channels.SocketChannel;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class tests implements Testlet
{
public void test(TestHarness harness)
{
try
{
harness.checkPoint("test states");
testStates(harness);
}
catch (Exception x)
{
harness.check(false);
harness.debug(x);
}
}
private void testStates(TestHarness harness) throws Exception
{
ServerSocket srv = new ServerSocket(0, 1);
Socket consumeSocket = new Socket(InetAddress.getLocalHost(), srv.getLocalPort());
SocketChannel ch = SocketChannel.open();
harness.checkPoint("initial state");
harness.check(ch.isOpen());
harness.check(!ch.isConnected());
harness.check(!ch.isConnectionPending());
harness.checkPoint("initiate async connect");
ch.configureBlocking(false);
harness.check(!ch.connect(new InetSocketAddress(InetAddress.getLocalHost(), srv.getLocalPort())));
harness.check(!ch.isConnected());
harness.check(ch.isConnectionPending());
harness.check(!ch.finishConnect());
harness.checkPoint("establish the connection");
// free up the backlog
srv.accept().close();
ch.configureBlocking(true);
harness.check(ch.finishConnect());
harness.check(ch.isOpen());
harness.check(ch.isConnected());
harness.check(!ch.isConnectionPending());
harness.checkPoint("receive some data");
ch.configureBlocking(false);
ByteBuffer buf = ByteBuffer.allocate(4);
harness.check(ch.read(buf) == 0);
Socket otherSide = srv.accept();
otherSide.getOutputStream().write("TEST".getBytes(), 0, 4);
ch.configureBlocking(true);
harness.check(ch.read(buf) == 4);
harness.check(new String(buf.array()).equals("TEST"));
harness.checkPoint("close");
ch.close();
harness.check(!ch.isOpen());
harness.check(!ch.isConnected());
harness.check(!ch.isConnectionPending());
// clean up
consumeSocket.close();
srv.close();
}
}
next reply other threads:[~2006-09-18 11:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-18 11:30 Jeroen Frijters [this message]
2006-09-18 22:45 ` Casey Marshall
2006-09-19 5:32 ` Jeroen Frijters
2006-09-19 8:08 ` Casey Marshall
2006-09-19 8:21 ` Jeroen Frijters
2006-09-19 18:36 ` Casey Marshall
2006-09-20 4:34 ` Jeroen Frijters
2006-09-20 5:14 ` Casey Marshall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D92197D0A6547B44A1567814F851FA6827A98D@LEMBU.sumatrasoftware.com \
--to=jeroen@sumatra.nl \
--cc=mauve-discuss@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).