jadex.micro.testcases.killcomponent.KillerAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-micro Show documentation
Show all versions of jadex-applications-micro Show documentation
The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.
package jadex.micro.testcases.killcomponent;
import java.util.Collection;
import java.util.Map;
import jadex.base.test.TestReport;
import jadex.base.test.Testcase;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IExternalAccess;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.commons.Tuple2;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.micro.annotation.Agent;
import jadex.micro.testcases.TestAgent;
/**
*
*/
@Agent
public class KillerAgent extends TestAgent
{
/**
* Perform the tests.
*/
protected IFuture performTests(final Testcase tc)
{
tc.setTestCount(2);
final Future ret = new Future();
testLocal(1).addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new ExceptionDelegationResultListener(ret)
{
public void customResultAvailable(TestReport result)
{
tc.addReport(result);
// ret.setResult(null);
testRemote(2).addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new ExceptionDelegationResultListener(ret)
{
public void customResultAvailable(TestReport result)
{
tc.addReport(result);
ret.setResult(null);
}
}));
}
}));
return ret;
}
@Override
protected int getTestCount() {
return 2;
}
/**
* Test local.
*/
protected IFuture testLocal(final int testno)
{
final Future ret = new Future();
performTest(agent.getComponentIdentifier().getRoot(), testno, true)
.addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new DelegationResultListener(ret)
{
public void customResultAvailable(final TestReport result)
{
ret.setResult(result);
}
}));
return ret;
}
/**
* Test remote.
*/
protected IFuture testRemote(final int testno)
{
final Future ret = new Future();
setupRemotePlatform(false).addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(
new ExceptionDelegationResultListener(ret)
{
public void customResultAvailable(final IExternalAccess platform)
{
performTest(platform.getComponentIdentifier(), testno, false)
.addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new DelegationResultListener(ret)));
}
}));
return ret;
}
/**
* Perform the test. Consists of the following steps:
* Create provider agent
* kill it
*/
protected IFuture performTest(final IComponentIdentifier root, final int testno, final boolean hassectrans)
{
final Future ret = new Future();
final Future>> resfut = new Future>>();
IResultListener>> reslis = new DelegationResultListener>>(resfut);
createComponent(ProviderAgent.class.getName()+".class", root, reslis)
.addResultListener(new ExceptionDelegationResultListener(ret)
{
public void customResultAvailable(final IComponentIdentifier cid)
{
IComponentManagementService cms = getCms().get();
IExternalAccess exta = cms.getExternalAccess(cid).get();
final TestReport tr = new TestReport("#"+testno, "Test if kill returns result");
System.out.println("Killing my subcomponent...");
exta.killComponent().addResultListener(new IResultListener