View Javadoc

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
    10   *    http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   *  Unless required by applicable law or agreed to in writing,
    13   *  software distributed under the License is distributed on an
    14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   *  KIND, either express or implied.  See the License for the
    16   *  specific language governing permissions and limitations
    17   *  under the License.
    18   *
    19   */
    20  package org.apache.mina.transport.nio;
    21
    22  import java.io.IOException;
    23  import java.net.InetSocketAddress;
    24  import java.net.ServerSocket;
    25  import java.util.concurrent.ExecutionException;
    26
    27  import org.apache.mina.api.IoFuture;
    28  import org.apache.mina.api.IoSession;
    29  import org.apache.mina.transport.nio.NioTcpClient;
    30  import org.junit.Assert;
    31  import org.junit.Ignore;
    32  import org.junit.Test;
    33
    34  /**
    35   * Test if the {@link NioTcpClient} handle correctly session connection timeout.
    36   *
    37   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
    38   */
    39  public class NioTcpClientTimeoutTest {
    40
    41      @Test
    42      @Ignore
    43      public void timeout() throws IOException, InterruptedException {
    44          NioTcpClient client = new NioTcpClient();
    45          client.setConnectTimeoutMillis(1000);
    46
    47          ServerSocket server = new ServerSocket();
    48          try {
    49              server.bind(null);
    50              IoFuture<IoSession> cf = client.connect(new InetSocketAddress("localhost", server.getLocalPort()));
    51              Thread.sleep(5000);
    52              IoSession session = cf.get();
    53              System.err.println(session);
    54              Assert.fail();
    55          } catch (ExecutionException ex) {
    56              // happy
    57              ex.printStackTrace();
    58          } finally {
    59              server.close();
    60          }
    61      }
    62  }