/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.serial.benchmarks;
import java.io.*;
import java.util.HashMap;
import junit.framework.Test;
import org.jboss.jrunit.controller.ThreadLocalBenchmark;
import org.jboss.jrunit.decorators.ThreadLocalDecorator;
import org.jboss.serial.DataSerializationTest;
import org.jboss.serial.io.JBossObjectOutputStream;
import org.jboss.serial.io.JBossObjectInputStream;
import org.jboss.serial.classmetamodel.ClassMetamodelFactoryTestCase;
import org.jboss.serial.data.NonSerializableTest;
/**
* $Id: MultiThreadJBossPerformanceTestCase.java 306 2006-05-23 19:22:26Z csuconic $
* @author Clebert Suconic
*/
public class MultiThreadJBossPerformanceTestCase extends DataSerializationTest
{
public static Test suite() throws Exception
{
return new ThreadLocalDecorator(MultiThreadJBossPerformanceTestCase.class,THREADS,1,0,true)
{
public void threadsTearDown()
{
super.threadsTearDown();
}
};
}
static ThreadLocal count = new ThreadLocal();
static class CountHolder
{
int i=0;
}
private static CountHolder getCount()
{
if (count.get()==null)
{
count.set(new CountHolder());
}
return ((CountHolder)count.get());
}
/* (non-Javadoc)
* @see org.jboss.serial.DataSerializationTest#executTest(java.lang.Object)
*/
public void executTest(Object dataObject) throws Throwable
{
if (dataObject instanceof NonSerializableTest)
{
return;
}
CountHolder count = getCount();
doJBossSerialization(dataObject, count);
count.i++;
}
static HashMap metaData = new HashMap();
static
{
metaData.put("test","JBoss");
}
private void doJBossSerialization(Object dataObject, CountHolder count) throws Exception, Throwable
{
try
{
for (int i=0;i<LOOPS;i++)
{
if (i==START_MEASURE)
ThreadLocalBenchmark.openBench(dataObject.getClass().getName(),metaData);
ByteArrayOutputStream outByte = new ByteArrayOutputStream();
BufferedOutputStream buffOut = new BufferedOutputStream(outByte);
ObjectOutputStream output = new JBossObjectOutputStream(buffOut);
output.writeObject(dataObject);
output.flush();
buffOut.flush();
ByteArrayInputStream inptByte = new ByteArrayInputStream(outByte.toByteArray());
ObjectInputStream input = new JBossObjectInputStream(inptByte);
Object obj = input.readObject();
if (!(dataObject instanceof Object[]))
assertEquals(obj,dataObject);
}
ThreadLocalBenchmark.closeBench(dataObject.getClass().getName());
}
// I was to be able to capture assertions also before doing the clear
catch (Throwable e)
{
e.printStackTrace();
ThreadLocalBenchmark.clear();
throw e;
}
}
}