diff --git a/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java b/src/main/java/com/github/joelittlejohn/embedmongo/StartEmbeddedMongoMojo.java index 4049995ea456fbe09feae8160e8fdc4fee7fa910..1d9a7b627df58d968047651c193a13fc54bd097c 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(); + } + }