Bael 5369 new (#12073)

* BAEL-5369: Checking Connection to MongoDB

* BAEL-5369:- Minor Fix Checking Connection to MongoDB
This commit is contained in:
Kapil Khandelwal
2022-04-19 05:05:55 +05:30
committed by GitHub
parent 3e62ed5cdb
commit 13fa098e80
2 changed files with 8 additions and 31 deletions

View File

@@ -3,45 +3,22 @@ package com.baeldung.mongo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.ConnectionCheck;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.ServerAddress;
public class ConnectionCheckLiveTest {
private static MongoClient mongoClient;
private static MongoClientOptions.Builder builder;
private static ServerAddress ServerAddress;
@BeforeClass
public static void setup() throws IOException {
if (mongoClient == null) {
builder = MongoClientOptions.builder();
builder.connectionsPerHost(100);
builder.maxWaitTime(60000);
builder.connectTimeout(1500);
builder.socketTimeout(60000);
builder.socketKeepAlive(true);
ServerAddress = new ServerAddress("localhost", 27017);
mongoClient = new MongoClient(ServerAddress, builder.build());
}
}
ConnectionCheck ConnectionCheck = new ConnectionCheck();
@Test
public void givenMongoClient_whenConnectionCheck_thenCheckingForConnectionPoint() {
MongoClient mongoClient = ConnectionCheck.checkingConnection();
String connectionPoint = mongoClient.getConnectPoint();
assertNotNull(connectionPoint);
assertFalse(connectionPoint.isEmpty());
}
}
}