Skip to content

Commit

Permalink
no need of system property for this
Browse files Browse the repository at this point in the history
Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
  • Loading branch information
olamy committed Jul 8, 2020
1 parent 6c161ca commit 7bcbc21
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ public class MongoTestHelper

static MongoClient mongoClient;

static String mongoHost;
static int mongoPort;

public static void startMongo()
{
try
{
long start = System.currentTimeMillis();
mongo.start();
String containerIpAddress = mongo.getContainerIpAddress();
int mongoPort = mongo.getMappedPort(27017);
LOG.info("Mongo container started for {}:{} - {}ms", containerIpAddress, mongoPort,
mongoHost = mongo.getHost();
mongoPort = mongo.getMappedPort(27017);
LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort,
System.currentTimeMillis() - start);
System.setProperty("embedmongoHost", containerIpAddress);
System.setProperty("embedmongoPort", Integer.toString(mongoPort));
}
catch (Exception e)
{
Expand All @@ -93,7 +94,7 @@ public static MongoClient getMongoClient() throws UnknownHostException
}
if (mongoClient == null || restart)
{
mongoClient = new MongoClient(System.getProperty("embedmongoHost"), Integer.getInteger("embedmongoPort"));
mongoClient = new MongoClient(mongoHost, mongoPort);
}
return mongoClient;
}
Expand All @@ -116,8 +117,8 @@ public static DBCollection getCollection() throws UnknownHostException, MongoExc
public static MongoSessionDataStoreFactory newSessionDataStoreFactory()
{
MongoSessionDataStoreFactory storeFactory = new MongoSessionDataStoreFactory();
storeFactory.setHost(System.getProperty("embedmongoHost"));
storeFactory.setPort(Integer.getInteger("embedmongoPort"));
storeFactory.setHost(mongoHost);
storeFactory.setPort(mongoPort);
storeFactory.setCollectionName(COLLECTION_NAME);
storeFactory.setDbName(DB_NAME);
return storeFactory;
Expand Down

0 comments on commit 7bcbc21

Please sign in to comment.