You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/01/16 02:16:32 UTC
[06/11] james-project git commit: JAMES-2285 Use an Executor extension
JAMES-2285 Use an Executor extension
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/04f3c5b8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/04f3c5b8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/04f3c5b8
Branch: refs/heads/master
Commit: 04f3c5b8bffedcc3b855470487fd73876364d706
Parents: b2bd1b4
Author: benwa <bt...@linagora.com>
Authored: Mon Jan 15 17:12:54 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Jan 15 17:14:08 2018 +0700
----------------------------------------------------------------------
.../james/queue/api/ExecutorExtension.java | 55 ++++++++++++++++++++
1 file changed, 55 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/04f3c5b8/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ExecutorExtension.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ExecutorExtension.java b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ExecutorExtension.java
new file mode 100644
index 0000000..16ebc46
--- /dev/null
+++ b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ExecutorExtension.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.james.queue.api;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+public class ExecutorExtension implements ParameterResolver, BeforeEachCallback, AfterEachCallback {
+
+ private ExecutorService executorService;
+
+ @Override
+ public void beforeEach(ExtensionContext context) throws Exception {
+ executorService = Executors.newCachedThreadPool();
+ }
+
+ @Override
+ public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+ return (parameterContext.getParameter().getType() == ExecutorService.class);
+ }
+
+ @Override
+ public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+ return executorService;
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) throws Exception {
+ executorService.shutdownNow();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org