Repository: james-project Updated Branches: refs/heads/master 3b223d537 -> 0f9024f3a
JAMES-2470 implement GuiceLifecycleHeathCheckTest without relying on implicit cleanup ordering Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0f9024f3 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0f9024f3 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0f9024f3 Branch: refs/heads/master Commit: 0f9024f3a9a55b853de6b07996ef8ab3b8d72b4e Parents: c51ae8f Author: Matthieu Baechler <[email protected]> Authored: Wed Dec 12 11:21:37 2018 +0100 Committer: Matthieu Baechler <[email protected]> Committed: Wed Dec 19 09:53:14 2018 +0100 ---------------------------------------------------------------------- .../james/GuiceLifecycleHeathCheckTest.java | 36 +++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/0f9024f3/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java index 1268c63..24c854c 100644 --- a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java @@ -27,19 +27,20 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + import org.apache.james.mailbox.extractor.TextExtractor; import org.apache.james.mailbox.store.search.PDFTextExtractor; import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.task.Task; import org.apache.james.utils.WebAdminGuiceProbe; import org.apache.james.webadmin.WebAdminConfiguration; +import org.apache.james.webadmin.WebAdminServer; import org.eclipse.jetty.http.HttpStatus; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import com.google.inject.multibindings.Multibinder; - import io.restassured.RestAssured; import io.restassured.builder.RequestSpecBuilder; import io.restassured.http.ContentType; @@ -80,17 +81,29 @@ class GuiceLifecycleHeathCheckTest { } } - @Nested - class Unhealthy { - CountDownLatch latch = new CountDownLatch(1); - CleanupTasksPerformer.CleanupTask awaitCleanupTask = () -> { + static class DestroyedBeforeWebAdmin { + WebAdminServer webAdminServer; + CountDownLatch latch; + + @Inject + DestroyedBeforeWebAdmin(WebAdminServer webAdminServer, CountDownLatch latch) { + this.webAdminServer = webAdminServer; + this.latch = latch; + } + + @PreDestroy + void cleanup() { try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } - return Task.Result.COMPLETED; - }; + } + } + + @Nested + class Unhealthy { + CountDownLatch latch = new CountDownLatch(1); @RegisterExtension JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder() @@ -99,9 +112,8 @@ class GuiceLifecycleHeathCheckTest { .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) .overrideWith(binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)) - .overrideWith(binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class) - .addBinding() - .toInstance(awaitCleanupTask))) + .overrideWith(binder -> binder.bind(CountDownLatch.class).toInstance(latch)) + .overrideWith(binder -> binder.bind(DestroyedBeforeWebAdmin.class).asEagerSingleton())) .build(); @Test --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
