package org.craft.atom.nio;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.craft.atom.io.Channel;
import org.craft.atom.io.IoConnector;
import org.craft.atom.nio.api.NioFactory;
import org.craft.atom.test.AvailablePortFinder;
import org.craft.atom.test.CaseCounter;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Tests for {@link NioTcpConnector}
 *
 * @author mindwind
 * @version 1.0, 2011-12-20
 */
public class TestNioTcpConnector {
	
	
	private static final Logger LOG = LoggerFactory.getLogger(TestNioTcpConnector.class);
	
	
	@Test
	public void testTimeout() {
		IoConnector connector =  NioFactory.newTcpConnector(new NioConnectorHandler());
		Future<Channel<byte[]>> future = connector.connect("127.0.0.1", AvailablePortFinder.getNextAvailable());
		
		try {
			future.get(1, TimeUnit.SECONDS);
		} catch (InterruptedException e) {
			
		} catch (ExecutionException e) {
			
		} catch (TimeoutException e) {
			LOG.debug("[CRAFT-ATOM-NIO] Test catch timeout exception");
			Assert.assertTrue(true);
		}
		System.out.println(String.format("[CRAFT-ATOM-NIO] (^_^)  <%s>  Case -> test nio tcp connector timeout. ", CaseCounter.incr(1)));
	}
	
}

@@ -20,24 +20,53 @@
 tom.nio;%0D%0A%0D%0A
+import java.io.IOException;%0D%0A
 import java.
@@ -817,16 +817,35 @@
 imeout()
+ throws IOException
  %7B%0D%0A%09%09Io

fix - unit test for NioTcpConnector throws IOE