Skip to content

Commit 1c7dcfb

Browse files
committed
Add connectivity test for async
JAVA-3038
1 parent 1cd73b2 commit 1c7dcfb

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.evergreen/run-connectivity-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export JAVA_HOME="/opt/java/jdk9"
2424

2525
for MONGODB_URI in $@; do
2626
./gradlew -PjdkHome=/opt/java/${JDK} -Dorg.mongodb.test.uri=${MONGODB_URI} --stacktrace --info -Dtest.single=ConnectivityTest --rerun-tasks driver-sync:test
27+
./gradlew -PjdkHome=/opt/java/${JDK} -Dorg.mongodb.test.uri=${MONGODB_URI} --stacktrace --info -Dtest.single=ConnectivityTest --rerun-tasks driver-async:test
2728
done
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.async.client;
18+
19+
import com.mongodb.async.FutureResultCallback;
20+
import org.bson.Document;
21+
import org.junit.Test;
22+
23+
import java.util.concurrent.TimeUnit;
24+
25+
public class ConnectivityTest {
26+
// the test succeeds if no exception is thrown, and fail otherwise
27+
@Test
28+
public void testConnectivity() throws InterruptedException {
29+
MongoClient client = MongoClients.create(Fixture.getMongoClientSettings());
30+
31+
try {
32+
FutureResultCallback<Document> commandCallback = new FutureResultCallback<Document>();
33+
// test that a command that doesn't require auth completes normally
34+
client.getDatabase("admin").runCommand(new Document("ismaster", 1), commandCallback);
35+
36+
commandCallback.get(10, TimeUnit.SECONDS);
37+
38+
FutureResultCallback<Long> countCallback = new FutureResultCallback<Long>();
39+
40+
// test that a command that requires auth completes normally
41+
client.getDatabase("test").getCollection("test").estimatedDocumentCount(countCallback);
42+
43+
countCallback.get(10, TimeUnit.SECONDS);
44+
} finally {
45+
client.close();
46+
}
47+
}
48+
49+
}

0 commit comments

Comments
 (0)