From 21c93c23d37f1c0f7347519a4feaa1ebea7486d9 Mon Sep 17 00:00:00 2001
From: Joe Littlejohn <joe.littlejohn@nokia.com>
Date: Thu, 26 Jun 2014 11:31:51 +0100
Subject: [PATCH] WIP

---
 .../embedmongo/StartEmbeddedMongoMojo.java    | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java b/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java
index 4049995..1d9a7b6 100644
--- a/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java
+++ b/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java
@@ -55,6 +55,8 @@ import de.flapdoodle.embed.mongo.distribution.Versions;
 import de.flapdoodle.embed.process.config.IRuntimeConfig;
 import de.flapdoodle.embed.process.config.io.ProcessOutput;
 import de.flapdoodle.embed.process.config.store.IDownloadConfig;
+import de.flapdoodle.embed.process.config.store.ITimeoutConfig;
+import de.flapdoodle.embed.process.config.store.TimeoutConfigBuilder;
 import de.flapdoodle.embed.process.distribution.Distribution;
 import de.flapdoodle.embed.process.distribution.IVersion;
 import de.flapdoodle.embed.process.exceptions.DistributionException;
@@ -198,6 +200,16 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
      */
     private boolean authEnabled;
 
+    /**
+     * The number of <b>seconds</b> to allow (when downloading MongoDB) for the
+     * TCP handshake to complete (connection timeout), and the number of seconds
+     * to allow the download to be idle for (no bytes received) before throwing
+     * a timeout exception (read timeout).
+     * 
+     * @parameter expression="${embedmongo.timeout}" default-value="60"
+     */
+    private int timeout = 60;
+
     /**
      * The maven project.
      * 
@@ -304,7 +316,11 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
     }
 
     private IArtifactStore getArtifactStore() {
-        IDownloadConfig downloadConfig = new DownloadConfigBuilder().defaultsForCommand(Command.MongoD).downloadPath(downloadPath).build();
+        IDownloadConfig downloadConfig = new DownloadConfigBuilder()
+                .defaultsForCommand(Command.MongoD)
+                .downloadPath(downloadPath)
+                .timeoutConfig(getTimeoutConfig()).build();
+
         return new ArtifactStoreBuilder().defaults(Command.MongoD).download(downloadConfig).build();
     }
 
@@ -366,4 +382,9 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
         }
     }
 
+    private ITimeoutConfig getTimeoutConfig() {
+        int timeoutMillis = (int) TimeUnit.SECONDS.toMillis(timeout);
+        return new TimeoutConfigBuilder().defaults().readTimeout(timeoutMillis).build();
+    }
+
 }
-- 
GitLab