1 20 package org.apache.mina.transport.vmpipe; 21 22 import java.net.SocketAddress ; 23 import java.util.Collection ; 24 25 import junit.framework.Assert; 26 27 import org.apache.mina.common.ConnectFuture; 28 import org.apache.mina.common.IoConnector; 29 import org.apache.mina.common.IoHandlerAdapter; 30 import org.apache.mina.common.IoSession; 31 import org.apache.mina.transport.AbstractBindTest; 32 33 39 public class VmPipeBindTest extends AbstractBindTest { 40 41 public VmPipeBindTest() { 42 super(new VmPipeAcceptor()); 43 } 44 45 protected SocketAddress createSocketAddress(int port) { 46 return new VmPipeAddress(port); 47 } 48 49 protected int getPort(SocketAddress address) { 50 return ((VmPipeAddress) address).getPort(); 51 } 52 53 public void testUnbindDisconnectsClients() throws Exception { 54 bind(false); 56 57 SocketAddress addr = createSocketAddress(port); 58 59 IoConnector connector = new VmPipeConnector(); 60 IoSession[] sessions = new IoSession[5]; 61 for (int i = 0; i < sessions.length; i++) { 62 ConnectFuture future = connector.connect(addr, 63 new IoHandlerAdapter()); 64 future.join(); 65 sessions[i] = future.getSession(); 66 Assert.assertTrue(sessions[i].isConnected()); 67 } 68 69 Thread.sleep(500); 71 72 Collection managedSessions = acceptor.getManagedSessions(addr); 73 Assert.assertEquals(5, managedSessions.size()); 74 for (int i = 0; i < sessions.length; i++) { 76 Assert.assertFalse(managedSessions.contains(sessions[i])); 77 } 78 79 acceptor.unbind(addr); 80 81 Thread.sleep(500); 83 84 for (int i = 0; i < sessions.length; i++) { 85 Assert.assertFalse(sessions[i].isConnected()); 86 } 87 } 88 } 89 | Popular Tags |