Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LPS-54436 add new test rule to initialize PortalExecutorManager
- Loading branch information
1 parent
82db433
commit 8f9a42f
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
portal-test-internal/src/com/liferay/portal/test/rule/PortalExecutorManagerTestRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
...internal/src/com/liferay/portal/test/rule/callback/PortalExecutorManagerTestCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters