Search in sources :

Example 6 with InitParams

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);
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) CacheServiceImpl(org.exoplatform.services.cache.impl.CacheServiceImpl) ExoCacheConfig(org.exoplatform.services.cache.ExoCacheConfig) ConcurrentFIFOExoCache(org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache) CacheService(org.exoplatform.services.cache.CacheService)

Example 7 with InitParams

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

Example 8 with InitParams

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();
        }
    }
}
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 9 with InitParams

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

Example 10 with InitParams

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());
}
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

InitParams (org.exoplatform.container.xml.InitParams)26 ValueParam (org.exoplatform.container.xml.ValueParam)16 RPCServiceImpl (org.exoplatform.services.rpc.jgv3.RPCServiceImpl)7 HashSet (java.util.HashSet)5 ConfigurationManagerImpl (org.exoplatform.container.configuration.ConfigurationManagerImpl)5 Component (org.exoplatform.container.xml.Component)5 PropertiesParam (org.exoplatform.container.xml.PropertiesParam)5 RemoteCommand (org.exoplatform.services.rpc.RemoteCommand)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)4 RPCException (org.exoplatform.services.rpc.RPCException)4 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)3 Configuration (org.exoplatform.container.xml.Configuration)3 Serializable (java.io.Serializable)2 DataSource (javax.sql.DataSource)2 RootContainer (org.exoplatform.container.RootContainer)2 DataSourceProvider (org.exoplatform.services.jdbc.DataSourceProvider)2 MemberHasLeftException (org.exoplatform.services.rpc.impl.AbstractRPCService.MemberHasLeftException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1