public Object[] incomingDataCloner(Channel channel, DataChunk chunk) {
			ByteBuffer b = chunk.getData();
			return new Object[] { channel, CloneByteBuffer.clone(b) };
		}		
		
	}
	
	public void testClientThrowsIntoDataHandlerFarEndClosed() throws Exception {
		setNumberOfExpectedWarnings(1);

		//make sure we are testing the right one....
		Class c = Class.forName(getChannelImplName());
		assertEquals("should be instance of correct channel type", c, client1.getClass());
	
		String msg = "some exception message";
		IOException e = new IOException(msg);
		mockServer.addThrowException("farEndClosed", e);
		
		client1.bind(loopBackAnyPort);		
		client1.oldConnect(svrAddr, (ConnectionCallback)mockConnect);
		client1.registerForReads((DataListener)mockHandler);
		
		mockConnect.expect("connected");
		TCPChannel svrChan = expectServerChannel(mockServer, c);

		verifyDataPassing(svrChan);
		verifyTearDown();
		//shutdown of threaded CM is complicated...set stop method on threaded CM.
		//We must sleep or thread could be interrupted and never log an error.
		//This is a race condition, but only when we are stopping the ChannelManager
		specialCaseThreadedCM();
	}
	protected void specialCaseThreadedCM() throws InterruptedException {
		
	}
		
//	public void testClientThrowsIntoAcceptHandlerConnect() throws Exception {
//		setNumberOfExpectedWarnings(1);
//
//		//make sure we are testing the right one....
//		Class c = Class.forName(getChannelImplName());
//		assertEquals("should be instance of correct channel type", c, client1.getClass());
//	
//		String msg = "some exception message";
//		IOException e = new IOException(msg);
//		mockServer.addThrowException("connected", e);
//		
//		client1.bind(loopBackAnyPort);
//		client1.oldConnect(svrAddr, (ConnectionCallback)mockConnect);
//		client1.registerForReads((DataListener)mockHandler);
//		
//		mockConnect.expect("connected");
//		TCPChannel svrChan = expectServerChannel(mockServer, c);
//
//		verifyDataPassing(svrChan);
//		verifyTearDown();		
//	}
	
	private ByteBuffer verifyDataPassing(TCPChannel svrChan) throws Exception {
		ByteBuffer b = ByteBuffer.allocate(10);
		helper.putString(b, "de");
		helper.doneFillingBuffer(b);
		int expectedWrote = b.remaining();
		int actualWrite = client1.oldWrite(b);
		assertEquals(expectedWrote, actualWrite);
		
		CalledMethod m = mockServer.expect(MockNIOServer.INCOMING_DATA);
		TCPChannel actualChannel = (TCPChannel)m.getAllParams()[0];
		Class c = Class.forName(getChannelImplName());
		assertEquals("should be correct type of channel", c, actualChannel.getClass());
		
		ByteBuffer actualBuf = (ByteBuffer)m.getAllParams()[1];
		String result = helper.readString(actualBuf, actualBuf.remaining());
		log.info("result len="+result.length());
		
		assertEquals("de", result);
		
		b.rewind();
		svrChan.oldWrite(b);
		
		m = mockHandler.expect(MockDataHandler.INCOMING_DATA);
		actualBuf = (ByteBuffer)m.getAllParams()[1];
		log.info("buffer remain="+actualBuf.remaining());
		result = helper.readString(actualBuf, actualBuf.remaining());
		log.info("---1st char="+(result.substring(0, 1).equals("de".substring(0, 1))));
		log.info("---2nd char="+(result.substring(1, 2).equals("de".substring(1, 2))));
		log.info("substring='"+result.substring(0,1)+"'");
		log.info("len="+"de".length()+"  2ndlen="+result.length());
		log.info("'de'"+" actual='"+result+"'"+"  result="+("de".equals(result)));
		assertEquals("de", result);	
		return b;
	}
	
	private void verifyTearDown() throws IOException {
		client1.oldClose();
		mockServer.expect(MockNIOServer.FAR_END_CLOSED);
	}