Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batch/framework/controller/pool
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28391
Added Files:
CollectionJobPoolTest.java
Log Message:
no message
--- NEW FILE: CollectionJobPoolTest.java ---
/*
* CollectionJobPoolTest.java
* JUnit based test
*
* Created on May 13, 2006, 11:35 PM
*/
package org.jmonks.batch.framework.controller.pool;
import java.util.HashMap;
import junit.framework.*;
/**
*
* @author Suresh Pragada
*/
public class CollectionJobPoolTest extends TestCase
{
public CollectionJobPoolTest(String testName)
{
super(testName);
}
public static Test suite()
{
TestSuite suite = new TestSuite(CollectionJobPoolTest.class);
return suite;
}
/**
* Method to test entire collection job pool.
*/
public void testCollectionJobPool() throws Exception
{
JobPool pool=new CollectionJobPool();
pool.initialize(new HashMap());
Thread loader=new Thread(this.getLoaderRunnable(pool));
Thread processor1=new Thread(this.getProcessorRunnable(pool));
Thread processor2=new Thread(this.getProcessorRunnable(pool));
Thread processor3=new Thread(this.getProcessorRunnable(pool));
loader.start();
processor1.start();
processor2.start();
processor3.start();
}
private Runnable getLoaderRunnable(final JobPool pool)
{
return new Runnable()
{
public void run()
{
for(int i=0;i<100;i++)
{
System.out.println("Going to load " + i);
boolean loaded=pool.loadJobData(new Integer(i));
System.out.println("Loader = " + i + " status = " + loaded);
}
System.out.println("Done loading the jobs");
pool.loadJobData(null);
System.out.println("Done loading the null");
}
};
}
private Runnable getProcessorRunnable(final JobPool pool)
{
return new Runnable()
{
public void run()
{
Object data=null;
while((data=pool.getNextJobData())!=null)
{
System.out.println(Thread.currentThread().getName() + " = " + ((Integer)data).intValue());
}
System.out.println(Thread.currentThread().getName() + " Done reading all the jobs from the buffer");
}
};
}
}
|