Search in sources :

Example 1 with ValueParam

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();
        }
    }
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ValueParam(org.exoplatform.container.xml.ValueParam) RPCServiceImpl(org.exoplatform.services.rpc.jgv3.RPCServiceImpl)

Example 2 with ValueParam

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();
        }
    }
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) RemoteCommand(org.exoplatform.services.rpc.RemoteCommand) ValueParam(org.exoplatform.container.xml.ValueParam) RPCServiceImpl(org.exoplatform.services.rpc.jgv3.RPCServiceImpl)

Example 3 with ValueParam

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());
    }
}
Also used : ValueParam(org.exoplatform.container.xml.ValueParam)

Example 4 with ValueParam

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());
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) Configuration(org.exoplatform.container.xml.Configuration) Component(org.exoplatform.container.xml.Component) ValueParam(org.exoplatform.container.xml.ValueParam)

Example 5 with ValueParam

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());
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) Configuration(org.exoplatform.container.xml.Configuration) Component(org.exoplatform.container.xml.Component) ValueParam(org.exoplatform.container.xml.ValueParam)

Aggregations

ValueParam (org.exoplatform.container.xml.ValueParam)20 InitParams (org.exoplatform.container.xml.InitParams)16 RPCServiceImpl (org.exoplatform.services.rpc.jgv3.RPCServiceImpl)7 RemoteCommand (org.exoplatform.services.rpc.RemoteCommand)5 RPCException (org.exoplatform.services.rpc.RPCException)4 ArrayList (java.util.ArrayList)3 Component (org.exoplatform.container.xml.Component)3 Configuration (org.exoplatform.container.xml.Configuration)3 Serializable (java.io.Serializable)2 DataSource (javax.sql.DataSource)2 DataSourceProvider (org.exoplatform.services.jdbc.DataSourceProvider)2 MemberHasLeftException (org.exoplatform.services.rpc.impl.AbstractRPCService.MemberHasLeftException)2 URL (java.net.URL)1 Connection (java.sql.Connection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 InitialContext (javax.naming.InitialContext)1 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)1