use of org.exoplatform.container.xml.ValueParam 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.ValueParam 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.ValueParam in project kernel by exoplatform.
the class PortalContainerConfig method initRealmName.
/**
* Initialize the value of the realm name
*/
private void initRealmName(InitParams params, PortalContainerDefinition def) {
if (def.getRealmName() == null || def.getRealmName().trim().length() == 0) {
// The realm name is empty
// We first set the default value
def.setRealmName(DEFAULT_REALM_NAME);
if (params == null) {
return;
}
final ValueParam vp = params.getValueParam("default.realm.name");
if (vp != null && vp.getValue().trim().length() > 0) {
// A realm name has been defined in the value parameter, thus we use it
def.setRealmName(Deserializer.resolveVariables(vp.getValue().trim()));
}
} else {
// We ensure that the realm name doesn't contain any useless characters
def.setRealmName(def.getRealmName().trim());
}
}
use of org.exoplatform.container.xml.ValueParam 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());
}
use of org.exoplatform.container.xml.ValueParam in project kernel by exoplatform.
the class TestInitParamProfile method testNoProfile.
public void testNoProfile() throws Exception {
Configuration config = getConfiguration("init-param-configuration.xml");
Component component = config.getComponent("Component");
InitParams initParams = component.getInitParams();
ValueParam valueParam = initParams.getValueParam("param");
assertEquals("empty", valueParam.getValue());
}
Aggregations