167 lines
6 KiB
Java
167 lines
6 KiB
Java
/*
|
|
* Copyright 2004-2008 IDCA. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
|
* following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
|
* the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
|
* and the following disclaimer in the documentation and/or other materials provided with the
|
|
* distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* The views and conclusions contained in the software and documentation are those of the authors and
|
|
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
|
*/
|
|
|
|
package com.idcanet.foei;
|
|
|
|
import java.io.InputStream;
|
|
import java.util.Date;
|
|
import java.util.Properties;
|
|
|
|
import com.idcanet.foei.components.lang.DummyOutputPort;
|
|
import com.idcanet.foei.components.lang.Filter;
|
|
import com.idcanet.foei.core.FoeiConfigurator;
|
|
import com.idcanet.foei.core.FoeiContext;
|
|
import com.idcanet.foei.core.FoeiProcess;
|
|
import com.idcanet.foei.event.AbstractEventInput;
|
|
import com.idcanet.foei.event.EventPort;
|
|
import com.idcanet.foei.event.IllegalEventPortNameException;
|
|
import com.idcanet.foei.server.FoeiContextManager;
|
|
import com.idcanet.foei.server.FoeiContextManagerFactory;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @author Willem Cazander
|
|
* @version 1.0 Jul 27, 2006
|
|
*/
|
|
public class SimpleFoeiTests extends TestCase {
|
|
|
|
private static FoeiContext test0 = null;
|
|
|
|
private void start() throws Exception {
|
|
if (test0!=null) {
|
|
return;
|
|
}
|
|
|
|
// Creates FoeiContextManager
|
|
FoeiContextManager foeiContextManager = new FoeiContextManager();
|
|
FoeiContextManagerFactory.setFoeiContextManager(foeiContextManager);
|
|
|
|
InputStream foeiProperties = this.getClass().getResourceAsStream("/META-INF/test-foei.properties");
|
|
Properties properties = new Properties();
|
|
properties.load(foeiProperties);
|
|
foeiProperties.close();
|
|
//properties.put(FoeiConfigurator.ROOT_PATH,"/tmp");
|
|
foeiContextManager.createFoeiContext(properties);
|
|
|
|
test0 = foeiContextManager.getFoeiContext("TEST-0");
|
|
}
|
|
|
|
public void testStartup() throws Exception {
|
|
start();
|
|
assertNotNull(test0);
|
|
}
|
|
|
|
public void testFoeiProcessLife() throws Exception {
|
|
start();
|
|
FoeiProcess proc = test0.getFoeiProcessManager().createFoeiProcess("testProces",test0);
|
|
assertNotNull(proc);
|
|
test0.getFoeiProcessManager().destroyFoeiProcess("testProces");
|
|
assertNull(test0.getFoeiProcessManager().getFoeiProcess("testProces"));
|
|
}
|
|
|
|
|
|
|
|
public void testSimpleSpeed() throws Exception {
|
|
start();
|
|
FoeiProcess proc = test0.getFoeiProcessManager().createFoeiProcess("testSpeed0",test0);
|
|
assertNotNull(proc);
|
|
|
|
DummyOutputPort in = new DummyOutputPort();
|
|
Filter f1 = new Filter();
|
|
Filter f2 = new Filter();
|
|
Filter f3 = new Filter();
|
|
SpeedTestPort out = new SpeedTestPort();
|
|
|
|
//in.getOutputPort(EventPort.OUTPUT).setImmediate(true);
|
|
|
|
// saves 300ms on 100k records
|
|
f1.getOutputPort(EventPort.PASS).setImmediate(true);
|
|
f2.getOutputPort(EventPort.PASS).setImmediate(true);
|
|
f3.getOutputPort(EventPort.PASS).setImmediate(true);
|
|
|
|
// has no effect !!
|
|
//out.getInputPort(EventPort.INPUT).setImmediate(true);
|
|
|
|
proc.addBinding(in.getOutputPort(EventPort.OUTPUT), f1.getInputPort(EventPort.INPUT));
|
|
proc.addBinding(f1.getOutputPort(EventPort.PASS), f2.getInputPort(EventPort.INPUT));
|
|
proc.addBinding(f2.getOutputPort(EventPort.PASS), f3.getInputPort(EventPort.INPUT));
|
|
proc.addBinding(f3.getOutputPort(EventPort.PASS), out.getInputPort(EventPort.INPUT));
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
for (int i=0;i<100000;i++) {
|
|
SpeedModel m = new SpeedModel();
|
|
|
|
// IN FOEI it is;
|
|
//proc.executeEvent(in.getOutputPort(EventPort.OUTPUT), m);
|
|
|
|
// running outside foei context thread use;
|
|
proc.getFoeiContext().getEventExecutorManager().executeEvent(in.getOutputPort(EventPort.OUTPUT), m, proc);
|
|
}
|
|
proc.getFoeiContext().getEventExecutorManager().executeEvent(in.getOutputPort(EventPort.OUTPUT), new Date(), proc);
|
|
long endTime = System.currentTimeMillis();
|
|
System.out.println("Done sending in: "+(endTime-startTime)+" ms.");
|
|
Thread.sleep(5000); // todo: create destory context on end of event que
|
|
System.out.println("End speedtest");
|
|
test0.getFoeiProcessManager().destroyFoeiProcess("testSpeed0");
|
|
}
|
|
|
|
}
|
|
class SpeedModel {
|
|
Date dateCreated = new Date();
|
|
Date dateDone = null;
|
|
}
|
|
class SpeedTestPort extends AbstractEventInput {
|
|
|
|
/** v1.0 */
|
|
static final long serialVersionUID = 10l;
|
|
Date startTime = new Date();
|
|
|
|
|
|
/**
|
|
* Creates the output port
|
|
*/
|
|
public SpeedTestPort() {
|
|
addInputPort(EventPort.INPUT,Object.class);
|
|
}
|
|
|
|
/**
|
|
* @see com.idcanet.foei.event.AbstractEventInput#doEvent(com.idcanet.foei.event.EventPort, java.lang.Object)
|
|
*/
|
|
@Override
|
|
public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException {
|
|
if (object instanceof SpeedModel) {
|
|
SpeedModel m = (SpeedModel)object;
|
|
m.dateDone=new Date();
|
|
return;
|
|
}
|
|
// other object == end of test
|
|
long endTime = System.currentTimeMillis();
|
|
System.out.println("End of test: "+(endTime-startTime.getTime())+" ms.");
|
|
}
|
|
} |