|
| 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