Skip to content

Commit

Permalink
LPS-54436 add new test rule to initialize PortalExecutorManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Han authored and brianchandotcom committed Mar 26, 2015
1 parent 82db433 commit 8f9a42f
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.portal.test.rule;

import com.liferay.portal.kernel.test.rule.BaseTestRule;
import com.liferay.portal.test.rule.callback.PortalExecutorManagerTestCallback;

/**
* @author Michael C. Han
*/
public class PortalExecutorManagerTestRule
extends BaseTestRule<Object, Object> {

public static final PortalExecutorManagerTestRule INSTANCE =
new PortalExecutorManagerTestRule();

private PortalExecutorManagerTestRule() {
super(PortalExecutorManagerTestCallback.INSTANCE);
}

}
@@ -0,0 +1,95 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.portal.test.rule.callback;

import com.liferay.portal.kernel.concurrent.ThreadPoolExecutor;
import com.liferay.portal.kernel.executor.PortalExecutorManager;
import com.liferay.portal.kernel.test.rule.callback.BaseTestCallback;
import com.liferay.registry.BasicRegistryImpl;
import com.liferay.registry.Registry;
import com.liferay.registry.RegistryUtil;

import org.junit.runner.Description;

/**
* @author Michael C. Han
*/
public class PortalExecutorManagerTestCallback
extends BaseTestCallback<Object, Object> {

public static final PortalExecutorManagerTestCallback INSTANCE =
new PortalExecutorManagerTestCallback();

@Override
public void doAfterClass(Description description, Object o)
throws Throwable {

_portalExecutorManager.shutdown(true);
}

protected class MockPortalExecutorManager implements PortalExecutorManager {

@Override
public ThreadPoolExecutor getPortalExecutor(String name) {
return _threadPoolExecutor;
}

@Override
public ThreadPoolExecutor getPortalExecutor(
String name, boolean createIfAbsent) {

return _threadPoolExecutor;
}

@Override
public ThreadPoolExecutor registerPortalExecutor(
String name, ThreadPoolExecutor threadPoolExecutor) {

return _threadPoolExecutor;
}

@Override
public void shutdown() {
shutdown(false);
}

@Override
public void shutdown(boolean interrupt) {
if (interrupt) {
_threadPoolExecutor.shutdownNow();
}
else {
_threadPoolExecutor.shutdown();
}
}

private final ThreadPoolExecutor _threadPoolExecutor =
new ThreadPoolExecutor(0, 1);

}

private PortalExecutorManagerTestCallback() {
RegistryUtil.setRegistry(new BasicRegistryImpl());
Registry registry = RegistryUtil.getRegistry();

_portalExecutorManager = new MockPortalExecutorManager();

registry.registerService(
PortalExecutorManager.class, _portalExecutorManager);
}

private final PortalExecutorManager _portalExecutorManager;

}
Expand Up @@ -61,6 +61,7 @@ public Statement apply(Statement statement, Description description) {
private static final String[] _ORDERED_RULE_CLASS_NAMES = new String[] {
HeapDumpTestRule.class.getName(), CodeCoverageAssertor.class.getName(),
NewEnvTestRule.class.getName(),
"com.liferay.portal.test.rule.PortalExecutorManagerTestRule",
"com.liferay.portal.test.rule.LiferayIntegrationTestRule",
"com.liferay.portal.test.rule.MainServletTestRule",
"com.liferay.portal.test.rule.PersistenceTestRule",
Expand Down

0 comments on commit 8f9a42f

Please sign in to comment.