use of org.exoplatform.container.xml.InitParams in project kernel by exoplatform.
the class TestCacheService method testCacheFactory.
public void testCacheFactory() throws Exception {
InitParams params = new InitParams();
ObjectParameter param = new ObjectParameter();
param.setName("NoImpl");
ExoCacheConfig config = new ExoCacheConfig();
config.setName(param.getName());
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("KnownImpl");
config = new ExoCacheConfig();
config.setName(param.getName());
config.setImplementation("org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImpl");
config = new ExoCacheConfig();
config.setName(param.getName());
config.setImplementation("fakeImpl");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImplButCorrectFQN");
config = new ExoCacheConfig();
config.setName(param.getName());
config.setImplementation("java.lang.String");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("NoImpl-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("KnownImpl-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
config.setImplementation("org.exoplatform.services.cache.FIFOExoCache");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImpl-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
config.setImplementation("fakeImpl");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImplButCorrectFQN-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
config.setImplementation("java.lang.String");
param.setObject(config);
params.addParameter(param);
CacheService cs = new CacheServiceImpl(params, new MyExoCacheFactory());
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("NoImpl").getClass(), cs.getCacheInstance("NoImpl") instanceof MyExoCache);
assertTrue("Expected type ConcurrentFIFOExoCache found " + cs.getCacheInstance("KnownImpl").getClass(), cs.getCacheInstance("KnownImpl") instanceof ConcurrentFIFOExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImpl").getClass(), cs.getCacheInstance("UnKnownImpl") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImplButCorrectFQN").getClass(), cs.getCacheInstance("UnKnownImplButCorrectFQN") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("NoImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("NoImpl-MyExoCacheConfig") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("KnownImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("KnownImpl-MyExoCacheConfig") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("UnKnownImpl-MyExoCacheConfig") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImplButCorrectFQN-MyExoCacheConfig").getClass(), cs.getCacheInstance("UnKnownImplButCorrectFQN-MyExoCacheConfig") instanceof MyExoCache);
}
use of org.exoplatform.container.xml.InitParams in project kernel by exoplatform.
the class TestRPCServiceImpl method testParameters.
public void testParameters() {
InitParams params = null;
try {
new RPCServiceImpl(container.getContext(), params, configManager);
fail("We expect a IllegalArgumentException since the jgroups config cannot be found");
} catch (IllegalArgumentException e) {
// OK
}
params = new InitParams();
try {
new RPCServiceImpl(container.getContext(), params, configManager);
fail("We expect a IllegalArgumentException since the jgroups config cannot be found");
} catch (IllegalArgumentException e) {
// OK
}
ValueParam paramConf = new ValueParam();
paramConf.setName(RPCServiceImpl.PARAM_JGROUPS_CONFIG);
params.addParameter(paramConf);
try {
new RPCServiceImpl(container.getContext(), params, configManager);
fail("We expect a IllegalArgumentException since the jgroups config cannot be found");
} catch (IllegalArgumentException e) {
// OK
}
paramConf.setValue("fakePath");
try {
new RPCServiceImpl(container.getContext(), params, configManager);
fail("We expect a IllegalArgumentException since the jgroups config cannot be found");
} catch (IllegalArgumentException e) {
// OK
}
paramConf.setValue("jar:/conf/portal/udp.xml");
RPCServiceImpl service = null;
try {
service = new RPCServiceImpl(container.getContext(), params, configManager);
assertEquals(RPCServiceImpl.DEFAULT_TIMEOUT, service.getDefaultTimeout());
assertEquals(RPCServiceImpl.DEFAULT_RETRY_TIMEOUT, service.getRetryTimeout());
assertEquals(true, service.isAllowFailover());
assertEquals(RPCServiceImpl.CLUSTER_NAME + "-" + container.getContext().getName(), service.getClusterName());
} finally {
if (service != null) {
service.stop();
}
}
ValueParam paramTimeout = new ValueParam();
paramTimeout.setName(RPCServiceImpl.PARAM_DEFAULT_TIMEOUT);
paramTimeout.setValue("fakeValue");
params.addParameter(paramTimeout);
try {
new RPCServiceImpl(container.getContext(), params, configManager);
fail("We expect a NumberFormatException since the timeout is not properly set");
} catch (NumberFormatException e) {
// OK
}
paramTimeout.setValue("60");
try {
service = new RPCServiceImpl(container.getContext(), params, configManager);
assertEquals(60, service.getDefaultTimeout());
assertEquals(RPCServiceImpl.DEFAULT_RETRY_TIMEOUT, service.getRetryTimeout());
assertEquals(true, service.isAllowFailover());
assertEquals(RPCServiceImpl.CLUSTER_NAME + "-" + container.getContext().getName(), service.getClusterName());
} finally {
if (service != null) {
service.stop();
}
}
ValueParam paramRetryTimeout = new ValueParam();
paramRetryTimeout.setName(RPCServiceImpl.PARAM_RETRY_TIMEOUT);
paramRetryTimeout.setValue("fakeValue");
params.addParameter(paramRetryTimeout);
try {
new RPCServiceImpl(container.getContext(), params, configManager);
fail("We expect a NumberFormatException since the retry timeout is not properly set");
} catch (NumberFormatException e) {
// OK
}
paramRetryTimeout.setValue("60");
try {
service = new RPCServiceImpl(container.getContext(), params, configManager);
assertEquals(60, service.getDefaultTimeout());
assertEquals(60, service.getRetryTimeout());
assertEquals(true, service.isAllowFailover());
assertEquals(RPCServiceImpl.CLUSTER_NAME + "-" + container.getContext().getName(), service.getClusterName());
} finally {
if (service != null) {
service.stop();
}
}
ValueParam paramAllowFailover = new ValueParam();
paramAllowFailover.setName(RPCServiceImpl.PARAM_ALLOW_FAILOVER);
paramAllowFailover.setValue("fakeValue");
params.addParameter(paramAllowFailover);
try {
service = new RPCServiceImpl(container.getContext(), params, configManager);
assertEquals(60, service.getDefaultTimeout());
assertEquals(60, service.getRetryTimeout());
assertEquals(false, service.isAllowFailover());
assertEquals(RPCServiceImpl.CLUSTER_NAME + "-" + container.getContext().getName(), service.getClusterName());
} finally {
if (service != null) {
service.stop();
}
}
paramAllowFailover.setValue("TRUE");
try {
service = new RPCServiceImpl(container.getContext(), params, configManager);
assertEquals(60, service.getDefaultTimeout());
assertEquals(60, service.getRetryTimeout());
assertEquals(true, service.isAllowFailover());
assertEquals(RPCServiceImpl.CLUSTER_NAME + "-" + container.getContext().getName(), service.getClusterName());
} finally {
if (service != null) {
service.stop();
}
}
ValueParam paramClusterName = new ValueParam();
paramClusterName.setName(RPCServiceImpl.PARAM_CLUSTER_NAME);
paramClusterName.setValue("MyName");
params.addParameter(paramClusterName);
try {
service = new RPCServiceImpl(container.getContext(), params, configManager);
assertEquals(60, service.getDefaultTimeout());
assertEquals(paramClusterName.getValue() + "-" + container.getContext().getName(), service.getClusterName());
} finally {
if (service != null) {
service.stop();
}
}
}
use of org.exoplatform.container.xml.InitParams in project kernel by exoplatform.
the class TestRPCServiceImpl method testExecOnCoordinator.
public void testExecOnCoordinator() throws Exception {
InitParams params = new InitParams();
ValueParam paramConf = new ValueParam();
paramConf.setName(RPCServiceImpl.PARAM_JGROUPS_CONFIG);
paramConf.setValue("jar:/conf/portal/udp.xml");
params.addParameter(paramConf);
final List<Boolean> calledCommands = Collections.synchronizedList(new ArrayList<Boolean>());
RPCServiceImpl service1 = null;
RPCServiceImpl service2 = null;
try {
service1 = new RPCServiceImpl(container.getContext(), params, configManager);
RemoteCommand service1Cmd = new RemoteCommand() {
public String getId() {
return "CoordinatorExecutedCommand";
}
public String execute(Serializable[] args) throws Throwable {
calledCommands.add(Boolean.TRUE);
return "service 1";
}
};
service1.registerCommand(service1Cmd);
service2 = new RPCServiceImpl(container.getContext(), params, configManager);
RemoteCommand service2Cmd = new RemoteCommand() {
public String getId() {
return "CoordinatorExecutedCommand";
}
public String execute(Serializable[] args) throws Throwable {
calledCommands.add(Boolean.TRUE);
return "service 2";
}
};
service2.registerCommand(service2Cmd);
// starting services
service1.start();
service2.start();
Object o = service1.executeCommandOnCoordinator(service1Cmd, true);
assertEquals("service 1", o);
// it should be executed once
assertEquals(1, calledCommands.size());
} finally {
if (service1 != null) {
service1.stop();
}
if (service2 != null) {
service2.stop();
}
}
}
use of org.exoplatform.container.xml.InitParams in project kernel by exoplatform.
the class TestField method getCollection.
private List getCollection(String... profiles) throws Exception {
RootContainer config = getKernel("field-configuration.xml", profiles);
InitParamsHolder holder = (InitParamsHolder) config.getComponentInstanceOfType(InitParamsHolder.class);
InitParams params = holder.getParams();
ObjectParameter op = params.getObjectParam("test.configuration");
ConfigParam cp = (ConfigParam) op.getObject();
return cp.getRole();
}
use of org.exoplatform.container.xml.InitParams in project kernel by exoplatform.
the class TestInitParamProfile method testFooProfile.
public void testFooProfile() throws Exception {
Configuration config = getConfiguration("init-param-configuration.xml", "foo");
Component component = config.getComponent("Component");
InitParams initParams = component.getInitParams();
ValueParam valueParam = initParams.getValueParam("param");
assertEquals("foo", valueParam.getValue());
}
Aggregations