You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by rm...@apache.org on 2017/11/26 16:12:23 UTC
[2/2] deltaspike git commit: fixing test setup
fixing test setup
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/8e27c82f
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/8e27c82f
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/8e27c82f
Branch: refs/heads/master
Commit: 8e27c82feac12df8036a8db6dbb9c393c59eb12c
Parents: c4006cc
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Sun Nov 26 17:10:00 2017 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Sun Nov 26 17:10:00 2017 +0100
----------------------------------------------------------------------
.../core/impl/future/ThreadPoolManager.java | 30 +++--
.../core/impl/future/ThreadPoolManagerTest.java | 116 ------------------
.../core/impl/future/ThreadPoolManagerTest.java | 117 +++++++++++++++++++
3 files changed, 135 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e27c82f/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/future/ThreadPoolManager.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/future/ThreadPoolManager.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/future/ThreadPoolManager.java
index 4e1f2a1..e85f847 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/future/ThreadPoolManager.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/future/ThreadPoolManager.java
@@ -36,10 +36,8 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.SynchronousQueue;
@@ -48,7 +46,6 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static java.util.Arrays.asList;
-import static java.util.Locale.ENGLISH;
@ApplicationScoped
public class ThreadPoolManager
@@ -115,28 +112,34 @@ public class ThreadPoolManager
final Bean<?> bean = beanManager.resolve(beans);
if (bean.getTypes().contains(ExecutorService.class))
{
- final CreationalContext<Object> creationalContext = beanManager.createCreationalContext(null);
+ final CreationalContext<Object> creationalContext =
+ beanManager.createCreationalContext(null);
if (!beanManager.isNormalScope(bean.getScope()))
{
contexts.add(creationalContext);
}
- pool = ExecutorService.class.cast(beanManager.getReference(bean, ExecutorService.class, creationalContext));
+ pool = ExecutorService.class.cast(beanManager.getReference(
+ bean, ExecutorService.class, creationalContext));
}
}
if (pool == null) // 2.
{
for (final String prefix : asList(
- "", "java:app/", "java:global/", "java:global/threads/", "java:global/deltaspike/", "java:"))
+ "", "java:app/", "java:global/", "java:global/threads/",
+ "java:global/deltaspike/", "java:"))
{
- try {
+ try
+ {
final Object instance = new InitialContext().lookup(prefix + name);
if (ExecutorService.class.isInstance(instance))
{
pool = ExecutorService.class.cast(instance);
break;
}
- } catch (final NamingException e) {
+ }
+ catch (final NamingException e)
+ {
// no-op
}
}
@@ -187,7 +190,7 @@ public class ThreadPoolManager
.getValue();
queue = new SynchronousQueue<Runnable>(fair);
}
- else/* (queueType.equalsIgnoreCase("LINKED")) */
+ else
{
final int capacity = ConfigResolver.resolve(configPrefix + "queue.capacity")
.as(Integer.class)
@@ -196,7 +199,8 @@ public class ThreadPoolManager
queue = new LinkedBlockingQueue<Runnable>(capacity);
}
- final String threadFactoryName = ConfigResolver.getPropertyValue(configPrefix + "threadFactory.name");
+ final String threadFactoryName = ConfigResolver.getPropertyValue(
+ configPrefix + "threadFactory.name");
final ThreadFactory threadFactory;
if (threadFactoryName != null)
{
@@ -207,7 +211,8 @@ public class ThreadPoolManager
threadFactory = Executors.defaultThreadFactory();
}
- final String rejectedHandlerName = ConfigResolver.getPropertyValue(configPrefix + "rejectedExecutionHandler.name");
+ final String rejectedHandlerName = ConfigResolver.getPropertyValue(
+ configPrefix + "rejectedExecutionHandler.name");
final RejectedExecutionHandler rejectedHandler;
if (rejectedHandlerName != null)
{
@@ -231,7 +236,8 @@ public class ThreadPoolManager
return pool;
}
- private <T> T lookupByName(final String name, final Class<T> type) {
+ private <T> T lookupByName(final String name, final Class<T> type)
+ {
final Set<Bean<?>> tfb = beanManager.getBeans(name);
final Bean<?> bean = beanManager.resolve(tfb);
final CreationalContext<?> ctx = beanManager.createCreationalContext(null);
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e27c82f/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/impl/future/ThreadPoolManagerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/impl/future/ThreadPoolManagerTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/impl/future/ThreadPoolManagerTest.java
deleted file mode 100644
index 111dda4..0000000
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/impl/future/ThreadPoolManagerTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.core.impl.future;
-
-import org.apache.deltaspike.core.api.config.ConfigResolver;
-import org.apache.deltaspike.core.impl.config.PropertiesConfigSource;
-import org.apache.deltaspike.core.impl.scope.conversation.ConversationBeanHolder;
-import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessBeanAccessHistory;
-import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessBeanHolder;
-import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessViewHistory;
-import org.apache.deltaspike.core.impl.scope.window.DefaultWindowContextQuotaHandler;
-import org.apache.deltaspike.core.impl.scope.window.WindowBeanHolder;
-import org.apache.deltaspike.core.impl.scope.window.WindowContextProducer;
-import org.apache.deltaspike.core.impl.scope.window.WindowContextQuotaHandlerCache;
-import org.apache.deltaspike.core.impl.scope.window.WindowIdHolder;
-import org.apache.deltaspike.core.spi.config.ConfigSource;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import javax.inject.Inject;
-import java.util.Collections;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ThreadPoolExecutor;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
-@RunWith(Arquillian.class)
-public class ThreadPoolManagerTest
-{
- @Deployment
- public static WebArchive deploy()
- {
- return ShrinkWrap.create(WebArchive.class, "ThreadPoolManagerTest.war")
- .addAsLibraries(ShrinkWrap.create(JavaArchive.class, "deltaspike-core-fake.jar")
- .addClasses(
- ThreadPoolManager.class,
- WindowContextProducer.class, WindowBeanHolder.class, WindowIdHolder.class,
- DefaultWindowContextQuotaHandler.class, WindowContextQuotaHandlerCache.class,
- ConversationBeanHolder.class, ViewAccessBeanHolder.class,
- ViewAccessBeanAccessHistory.class, ViewAccessViewHistory.class)
- .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"))
- .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
- }
-
- @Inject
- private ThreadPoolManager manager;
-
- @Test
- public void defaultPool() throws ExecutionException, InterruptedException
- {
- final ExecutorService auto = manager.find("auto");
- assertEquals(auto, auto);
- assertSame(auto, auto);
- assertEquals(Runtime.getRuntime().availableProcessors(), ThreadPoolExecutor.class.cast(auto).getCorePoolSize());
- assertUsable(auto);
- }
-
- @Test // this test validates we read the config properly but also it is lazy
- public void configuredPool() throws ExecutionException, InterruptedException
- {
- ConfigResolver.addConfigSources(Collections.<ConfigSource>singletonList(new PropertiesConfigSource(new Properties()
- {{
- setProperty("futurable.pool.custom.coreSize", "5");
- }})
- {
- @Override
- public String getConfigName()
- {
- return "configuredPool";
- }
- }));
- final ExecutorService custom = manager.find("custom");
- assertEquals(custom, custom);
- assertSame(custom, custom);
- assertEquals(5, ThreadPoolExecutor.class.cast(custom).getCorePoolSize());
- assertUsable(custom);
- }
-
- private void assertUsable(final ExecutorService pool) throws InterruptedException, ExecutionException
- {
- assertEquals("ok", pool.submit(new Callable<String>()
- {
- @Override
- public String call() throws Exception
- {
- return "ok";
- }
- }).get());
- }
-}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e27c82f/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/ThreadPoolManagerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/ThreadPoolManagerTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/ThreadPoolManagerTest.java
new file mode 100644
index 0000000..f7f43bc
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/ThreadPoolManagerTest.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.core.impl.future;
+
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.impl.config.PropertiesConfigSource;
+import org.apache.deltaspike.core.impl.future.ThreadPoolManager;
+import org.apache.deltaspike.core.impl.scope.conversation.ConversationBeanHolder;
+import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessBeanAccessHistory;
+import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessBeanHolder;
+import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessViewHistory;
+import org.apache.deltaspike.core.impl.scope.window.DefaultWindowContextQuotaHandler;
+import org.apache.deltaspike.core.impl.scope.window.WindowBeanHolder;
+import org.apache.deltaspike.core.impl.scope.window.WindowContextProducer;
+import org.apache.deltaspike.core.impl.scope.window.WindowContextQuotaHandlerCache;
+import org.apache.deltaspike.core.impl.scope.window.WindowIdHolder;
+import org.apache.deltaspike.core.spi.config.ConfigSource;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+@RunWith(Arquillian.class)
+public class ThreadPoolManagerTest
+{
+ @Deployment
+ public static WebArchive deploy()
+ {
+ return ShrinkWrap.create(WebArchive.class, "ThreadPoolManagerTest.war")
+ .addAsLibraries(ShrinkWrap.create(JavaArchive.class, "deltaspike-core-fake.jar")
+ .addClasses(
+ ThreadPoolManager.class,
+ WindowContextProducer.class, WindowBeanHolder.class, WindowIdHolder.class,
+ DefaultWindowContextQuotaHandler.class, WindowContextQuotaHandlerCache.class,
+ ConversationBeanHolder.class, ViewAccessBeanHolder.class,
+ ViewAccessBeanAccessHistory.class, ViewAccessViewHistory.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"))
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Inject
+ private ThreadPoolManager manager;
+
+ @Test
+ public void defaultPool() throws ExecutionException, InterruptedException
+ {
+ final ExecutorService auto = manager.find("auto");
+ assertEquals(auto, auto);
+ assertSame(auto, auto);
+ assertEquals(Runtime.getRuntime().availableProcessors(), ThreadPoolExecutor.class.cast(auto).getCorePoolSize());
+ assertUsable(auto);
+ }
+
+ @Test // this test validates we read the config properly but also it is lazy
+ public void configuredPool() throws ExecutionException, InterruptedException
+ {
+ ConfigResolver.addConfigSources(Collections.<ConfigSource>singletonList(new PropertiesConfigSource(new Properties()
+ {{
+ setProperty("futurable.pool.custom.coreSize", "5");
+ }})
+ {
+ @Override
+ public String getConfigName()
+ {
+ return "configuredPool";
+ }
+ }));
+ final ExecutorService custom = manager.find("custom");
+ assertEquals(custom, custom);
+ assertSame(custom, custom);
+ assertEquals(5, ThreadPoolExecutor.class.cast(custom).getCorePoolSize());
+ assertUsable(custom);
+ }
+
+ private void assertUsable(final ExecutorService pool) throws InterruptedException, ExecutionException
+ {
+ assertEquals("ok", pool.submit(new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ return "ok";
+ }
+ }).get());
+ }
+}