Search in sources :

Example 36 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ZPerformanceSuper method profilerTestConnectCloseBatches.

/**
         * Test used to test with netbeans profiler.  Was seeing bizarre results where profiler
         * claimed server selector thread was stuck on a monitor for 10 seconds but this is 
         * never shown in the snapshot, and is very bizarre.  The most time spent in one
         * of my methods if looked at the hotspot is from the main test thread, not the server
         * selector thread which is bizarre as that thread showed no indication of being on a
         * monitor.
         */
public void profilerTestConnectCloseBatches() throws Exception {
    try {
        log.info("test beginning");
        int size = 10;
        String[] methodNames = new String[size];
        for (int i = 0; i < size; i++) {
            methodNames[i] = "connected";
        }
        for (int j = 0; j < 10000; j++) {
            TCPChannel[] clients = new TCPChannel[size];
            for (int i = 0; i < size; i++) {
                clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", getClientFactoryHolder());
            }
            for (int i = 0; i < size; i++) {
                clients[i].oldConnect(svrAddr, (ConnectionCallback) mockConnect);
            }
            mockConnect.expect(methodNames);
            for (TCPChannel channel : clients) {
                channel.oldClose();
            }
        }
    } catch (Exception e) {
        log.error("the exception", e);
    } finally {
        log.erroring("test ending*********************");
    }
//		long timePerConnect = result/size;
//		log.info("time for initiating connects          ="+result2);
//		log.info("time for initiating/finishing connects="+result);
//		log.info("connected per connection time         ="+timePerConnect);		
//		log.info("--time to beat           ="+getBasicConnectTimeLimit());
//	assertTrue(timePerConnect < getBasicConnectTimeLimit());
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Example 37 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ZNioFailureSuperclass method testClientThrowsIntoConnectCallback.

public void testClientThrowsIntoConnectCallback() throws Exception {
    setNumberOfExpectedWarnings(1);
    log.info("hello");
    //make sure we are testing the right one....
    Class c = Class.forName(getChannelImplName());
    assertEquals("should be instance of correct channel type", c, client1.getClass());
    log.info("class name" + client1.getClass().getName());
    String msg = "some exception message";
    IOException e = new IOException(msg);
    mockConnect.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();
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) IOException(java.io.IOException)

Example 38 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ZNioFailureSuperclass method testClientThrowsIntoDataHandlerIncomingData.

public void testClientThrowsIntoDataHandlerIncomingData() 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());
    mockHandler.addBehavior("incomingData", new ThrowAndClone());
    log.info("class name" + client1.getClass());
    client1.bind(loopBackAnyPort);
    client1.oldConnect(svrAddr, (ConnectionCallback) mockConnect);
    client1.registerForReads((DataListener) mockHandler);
    mockConnect.expect("connected");
    TCPChannel svrChan = expectServerChannel(mockServer, c);
    verifyDataPassing(svrChan);
    verifyTearDown();
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Example 39 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ZNioSuperclassTest method testCloseSvrSocketBeforeChannelMgrShutdown.

/**
	 * Test closing socket before ChannelManager shutdown works.
	 * @throws Exception
	 */
public void testCloseSvrSocketBeforeChannelMgrShutdown() throws Exception {
    Class c = Class.forName(getChannelImplName());
    client1.bind(loopBackAnyPort);
    client1.oldConnect(svrAddr);
    boolean isConnected = client1.isConnected();
    assertTrue("Client should be connected", isConnected);
    TCPChannel svrChan = ZNioFailureSuperclass.expectServerChannel(mockServer, c);
    client1.registerForReads((DataListener) mockHandler);
    verifyDataPassing(svrChan);
    svrChan.oldClose();
    //shutdown channel manager first
    mockServer.stop();
    mockHandler.expect(MockNIOServer.FAR_END_CLOSED);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Aggregations

TCPChannel (org.webpieces.nio.api.channels.TCPChannel)39 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)10 CalledMethod (biz.xsoftware.mock.CalledMethod)8 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)6 ChannelManager (org.webpieces.nio.api.ChannelManager)5 Channel (org.webpieces.nio.api.channels.Channel)5 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)4 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)4 FutureOperation (org.webpieces.nio.api.handlers.FutureOperation)4 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)3 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)3 BufferPool (org.webpieces.data.api.BufferPool)3 PerfTimer (org.webpieces.nio.test.PerfTimer)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Executor (java.util.concurrent.Executor)2 Test (org.junit.Test)2 TCPServerChannel (org.webpieces.nio.api.channels.TCPServerChannel)2