/*
* 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.
*/
/*
*
*
* This unit test checks that closing the channel returned by
* System.inheritedChannel closes the underlying network socket.
*
* The test launches the "echo service" with arguments to instruct the
* service to close the channel after it receives a small message. The
* prove that the close works we check that we see EOF (meaning the
* peer has closed the connection) in less than 15 seconds.
*/
public class CloseTest {
// Launch the service with arguments to tell it to close
// the connection after reading 5 bytes ("HELLO"). After
// closing the connection the service should hang around
// for 15 seconds.
// send message - service will echo the message and close the connection.
// read the reply (with timeout)
sc.configureBlocking(false);
for (;;) {
if (sk.isReadable()) {
// EOF
if (n < 0) {
break;
}
}
if (to <= 0) {
throw new RuntimeException("Timed out waiting for connection to close");
}
}
// finally check that the reply length is okay
throw new RuntimeException("Premature EOF from echo service");
}
}
}