Package de.netseeker.ejoe.test

Source Code of de.netseeker.ejoe.test.DirectByteBufferTest

/*********************************************************************
* AssistedRemotingTest.java
* created on 20.03.2005 by netseeker
* $Source$
* $Date$
* $Revision$
*********************************************************************/
package de.netseeker.ejoe.test;

import java.io.IOException;
import java.nio.ByteBuffer;

import de.netseeker.ejoe.EJClient;
import de.netseeker.ejoe.EJConstants;
import de.netseeker.ejoe.cache.ByteBufferAllocator;
import de.netseeker.ejoe.io.IOUtil;

/**
* @author netseeker
*/
public class DirectByteBufferTest extends BaseClientTest
{
    private EJClient client;

    /*
     * (non-Javadoc)
     *
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        handler = new ByteBufferHandler();
        nonBlockingIO = true;
        persistent = false;
        super.setUp();
        client = getNewClient();
    }

    public void testNonBlocking()
    {
        getServer().enableNonBlockingIO( false );

        try
        {
            client.setAdapterStrategy( EJConstants.ADAPTER_STRATEGY_DIRECT );
            String result = execute();
            client.close();
            assertEquals( result, "test" );
        }
        catch ( IOException e )
        {
            e.printStackTrace();
            fail( e.getMessage() );
        }
    }

    public void testBlocking()
    {
        getServer().enableNonBlockingIO( false );

        try
        {
            client.setAdapterStrategy( EJConstants.ADAPTER_STRATEGY_DIRECT );
            String result = execute();
            client.close();
            assertEquals( result, "test" );
        }
        catch ( IOException e )
        {
            e.printStackTrace();
            fail( e.getMessage() );
        }
    }

    private String execute() throws IOException
    {
        byte[] tmp = IOUtil.encodeToBytes( "test" );
        ByteBuffer input = ByteBufferAllocator.allocate( tmp.length );
        input.put( tmp );
        input.flip();
        input = (ByteBuffer) client.execute( input );
        input.get( tmp );
        return new String( tmp, "UTF8" );
    }
}
TOP

Related Classes of de.netseeker.ejoe.test.DirectByteBufferTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.