Reputation: 11
I wanted to setup mongodb junit environment with flapdoodle and I got a java.io.IOException
when it tries to download the mongodb archive.
I am using:
I am getting following error:
de.flapdoodle.embed.process.exceptions.DistributionException: java.io.IOException: Could not open inputStream for http://downloads.mongodb.org/win32/mongodb-win32-i386-3.0.2.zip
Caused by: java.net.UnknownHostException: downloads.mongodb.org at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
and also its pointing to mongodb-win32-i386-3.0.2.zip but I am using windows 64 bit.
here is my code
package com.bosch.test;
import junit.framework.TestCase;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.bosch.in.model.Device;
import com.bosch.in.service.imp.DeviceServiceImp;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.runtime.Network;
@ContextConfiguration(classes=ApplicationConfig.class,loader=AnnotationConfigContextLoader.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class DeviceServiceTest2 {
private static final MongodStarter starter = MongodStarter
.getDefaultInstance();
private static MongodExecutable mongodExe;
private static MongodProcess mongod;
private static MongoClient mongo;
private DeviceServiceImp deviceServiceImp;
private MongoTemplate template;
@BeforeClass
public static void setUp() throws Exception {
//System.out.println("1");
mongodExe = starter.prepare(new MongodConfigBuilder()
.version(Version.Main.V3_0)
.net(new Net(12345, Network.localhostIsIPv6())).build());
System.out.println("2");
mongod = mongodExe.start();
System.out.println("3");
System.out.println("4");
mongo = new MongoClient("12345", 12345);
System.out.println("5");
}
@AfterClass
public static void tearDown() throws Exception {
mongod.stop();
mongodExe.stop();
}
public Mongo getMongo() {
return mongo;
}
@Test
public void save(){
System.out.println("1");
}
}
Upvotes: 1
Views: 8741
Reputation: 498
I think the problem is that you are using a default MongodStarter that is not aware of your proxy configuration (it was my case). You just need to configure the mongodStarter.
Instead of using
private static final MongodStarter starter = MongodStarter
.getDefaultInstance();
you should have somthing like this in setUp()
Command command = Command.MongoD;
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
.defaults(command)
.artifactStore(new ArtifactStoreBuilder()
.defaults(command)
.download(new DownloadConfigBuilder()
.defaultsForCommand(command)
.proxyFactory(new HttpProxyFactory("proxy_host", 8080))))
.build();
MongodStarter starter = MongodStarter.getInstance(runtimeConfig);
This configuration is well explained on flapdoodle doc.
Upvotes: 2