Permalink
Browse files

JAVA-725: Removing use of deprecated methods/constructors, mostly in …

…tests
  • Loading branch information...
1 parent 093a2cb commit 1d2e6faa80aeb5287a26d0348f18f4b51d566759 @jyemin jyemin committed Mar 5, 2013
Showing with 288 additions and 311 deletions.
  1. +1 −0 src/main/com/mongodb/ConnectionStatus.java
  2. +1 −0 src/main/com/mongodb/DBPort.java
  3. +3 −0 src/main/com/mongodb/MongoClient.java
  4. +1 −0 src/main/com/mongodb/MongoURI.java
  5. +8 −5 src/main/com/mongodb/gridfs/CLI.java
  6. +8 −10 src/test/com/mongodb/ByteTest.java
  7. +1 −2 src/test/com/mongodb/DBCollectionTest.java
  8. +4 −6 src/test/com/mongodb/DBCursorTest.java
  9. +9 −16 src/test/com/mongodb/DBObjectTest.java
  10. +2 −0 src/test/com/mongodb/DBPortPoolTest.java
  11. +2 −1 src/test/com/mongodb/DBPortTest.java
  12. +2 −9 src/test/com/mongodb/DBRefTest.java
  13. +64 −35 src/test/com/mongodb/DBTCPConnectorTest.java
  14. +2 −4 src/test/com/mongodb/DBTest.java
  15. +4 −6 src/test/com/mongodb/DBTests.java
  16. +0 −1 src/test/com/mongodb/ErrorTest.java
  17. +26 −16 src/test/com/mongodb/JavaClientTest.java
  18. +17 −17 src/test/com/mongodb/LazyDBObjectTest.java
  19. +1 −0 src/test/com/mongodb/MongoClientTest.java
  20. +2 −0 src/test/com/mongodb/MongoOptionsTest.java
  21. +3 −2 src/test/com/mongodb/MongoTest.java
  22. +1 −0 src/test/com/mongodb/MongoURITest.java
  23. +6 −9 src/test/com/mongodb/ObjectIdTest.java
  24. +1 −1 src/test/com/mongodb/OutMessageTest.java
  25. +5 −4 src/test/com/mongodb/PerformanceTest.java
  26. +1 −5 src/test/com/mongodb/QueryBuilderTest.java
  27. +2 −7 src/test/com/mongodb/ReflectionTest.java
  28. +1 −1 src/test/com/mongodb/ReplPairTest.java
  29. +2 −2 src/test/com/mongodb/ReplSetTest.java
  30. +1 −0 src/test/com/mongodb/ReplicaSetStatusDomainModelTest.java
  31. +20 −18 src/test/com/mongodb/ReplicaSetStatusTest.java
  32. +3 −2 src/test/com/mongodb/SecondaryReadTest.java
  33. +3 −3 src/test/com/mongodb/SingleThreadedMongoPerfTest.java
  34. +0 −50 src/test/com/mongodb/ThreadingTest.java
  35. +8 −5 src/test/com/mongodb/framework/Capped.java
  36. +1 −1 src/test/com/mongodb/framework/Circular.java
  37. +1 −1 src/test/com/mongodb/framework/Count1.java
  38. +10 −5 src/test/com/mongodb/framework/Dbs.java
  39. +6 −4 src/test/com/mongodb/framework/Find.java
  40. +6 −6 src/test/com/mongodb/framework/Find1.java
  41. +5 −6 src/test/com/mongodb/framework/Remove.java
  42. +1 −1 src/test/com/mongodb/framework/Stress1.java
  43. +6 −6 src/test/com/mongodb/framework/Test1.java
  44. +14 −30 src/test/com/mongodb/gridfs/GridFSTest.java
  45. +0 −6 src/test/com/mongodb/tools/ConnectionPoolStatTest.java
  46. +18 −3 src/test/com/mongodb/util/TestCase.java
  47. +5 −5 src/test/com/mongodb/util/TestNGListener.java
View
1 src/main/com/mongodb/ConnectionStatus.java
@@ -41,6 +41,7 @@
protected static int updaterIntervalMS;
protected static int updaterIntervalNoMasterMS;
+ @SuppressWarnings("deprecation")
protected static final MongoOptions mongoOptionsDefaults = new MongoOptions();
protected static final float latencySmoothFactor;
protected static final DBObject isMasterCmd = new BasicDBObject("ismaster", 1);
View
1 src/main/com/mongodb/DBPort.java
@@ -67,6 +67,7 @@
* creates a new DBPort
* @param addr the server address
*/
+ @SuppressWarnings("deprecation")
public DBPort( ServerAddress addr ){
this( addr , null , new MongoOptions() );
}
View
3 src/main/com/mongodb/MongoClient.java
@@ -163,6 +163,7 @@ public MongoClient(ServerAddress addr, MongoClientOptions options) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
+ @SuppressWarnings("deprecation")
public MongoClient(ServerAddress addr, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.direct(addr, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
this.options = options;
@@ -247,6 +248,7 @@ public MongoClient(List<ServerAddress> seeds, MongoClientOptions options) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
+ @SuppressWarnings("deprecation")
public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.dynamicSet(seeds, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
this.options = options;
@@ -262,6 +264,7 @@ public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsL
* @see MongoURI
* @dochub connections
*/
+ @SuppressWarnings("deprecation")
public MongoClient(MongoClientURI uri) throws UnknownHostException {
super(new MongoURI(uri));
this.options = uri.getOptions();
View
1 src/main/com/mongodb/MongoURI.java
@@ -215,6 +215,7 @@ public MongoOptions getOptions(){
* @throws MongoException
* @throws UnknownHostException
*/
+ @SuppressWarnings("deprecation")
public Mongo connect()
throws UnknownHostException {
// TODO caching?
View
13 src/main/com/mongodb/gridfs/CLI.java
@@ -18,14 +18,15 @@
package com.mongodb.gridfs;
-import java.io.File;
-import java.security.DigestInputStream;
-import java.security.MessageDigest;
-
import com.mongodb.DBObject;
import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
import com.mongodb.util.Util;
+import java.io.File;
+import java.security.DigestInputStream;
+import java.security.MessageDigest;
+
/**
* a simple CLI for Gridfs
@@ -48,10 +49,12 @@ private static void printUsage() {
private static String db = "test";
private static Mongo _mongo = null;
+
+ @SuppressWarnings("deprecation")
private static Mongo getMongo()
throws Exception {
if ( _mongo == null )
- _mongo = new Mongo( host );
+ _mongo = new MongoClient( host );
return _mongo;
}
View
18 src/test/com/mongodb/ByteTest.java
@@ -16,6 +16,14 @@
package com.mongodb;
+import com.mongodb.util.TestCase;
+import org.bson.BSON;
+import org.bson.BSONDecoder;
+import org.bson.BSONObject;
+import org.bson.BasicBSONDecoder;
+import org.bson.types.ObjectId;
+import org.testng.annotations.Test;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -28,22 +36,12 @@
import java.util.Set;
import java.util.regex.Pattern;
-import org.bson.BSON;
-import org.bson.BSONDecoder;
-import org.bson.BSONObject;
-import org.bson.BasicBSONDecoder;
-import org.bson.types.ObjectId;
-import org.testng.annotations.Test;
-
-import com.mongodb.util.TestCase;
-
@SuppressWarnings({"unchecked", "rawtypes"})
public class ByteTest extends TestCase {
public ByteTest() throws IOException , MongoException {
super();
- cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_ByteTest";
_db = cleanupMongo.getDB( cleanupDB );
}
View
3 src/test/com/mongodb/DBCollectionTest.java
@@ -30,7 +30,6 @@
public DBCollectionTest()
throws IOException , MongoException {
super();
- cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_DBCollectionTest";
_db = cleanupMongo.getDB( cleanupDB );
}
@@ -166,7 +165,7 @@ public void testFindOneSort(){
*/
@Test
public void testDropDatabase() throws Exception {
- final Mongo mongo = new Mongo( "127.0.0.1" );
+ final Mongo mongo = new MongoClient( "127.0.0.1" );
mongo.getDB("com_mongodb_unittest_dropDatabaseTest").dropDatabase();
mongo.close();
}
View
10 src/test/com/mongodb/DBCursorTest.java
@@ -35,9 +35,8 @@
public DBCursorTest() throws IOException , MongoException {
super();
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_DBCursorTest";
- _db = cleanupMongo.getDB( cleanupDB );
+ cleanupDB = "com_mongodb_unittest_DBCursorTest";
+ _db = cleanupMongo.getDB(cleanupDB);
}
@Test(groups = {"basic"})
@@ -502,9 +501,8 @@ public void testHasFinalizer() throws UnknownHostException {
cursor.close();
// finally, no finalizer if disabled in mongo options
- MongoOptions mongoOptions = new MongoOptions();
- mongoOptions.cursorFinalizerEnabled = false;
- Mongo m = new Mongo("127.0.0.1", mongoOptions);
+ MongoClientOptions mongoOptions = new MongoClientOptions.Builder().cursorFinalizerEnabled(false).build();
+ Mongo m = new MongoClient("127.0.0.1", mongoOptions);
try {
c = m.getDB(cleanupDB).getCollection("HasFinalizerTest");
cursor = c.find();
View
25 src/test/com/mongodb/DBObjectTest.java
@@ -16,30 +16,23 @@
package com.mongodb;
-import java.net.*;
-import java.util.*;
-
-
+import com.mongodb.util.TestCase;
+import org.bson.types.BasicBSONList;
+import org.bson.types.ObjectId;
import org.testng.annotations.Test;
-import com.mongodb.util.*;
-
-import org.bson.*;
-import org.bson.types.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
@SuppressWarnings({"unchecked", "deprecation"})
public class DBObjectTest extends TestCase {
public DBObjectTest() {
super();
- try {
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_monogodb_unittest_DBObjectTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
- catch(UnknownHostException e) {
- throw new MongoException("couldn't connect");
- }
+ cleanupDB = "com_monogodb_unittest_DBObjectTest";
+ _db = cleanupMongo.getDB(cleanupDB);
}
@Test(groups = {"basic"})
View
2 src/test/com/mongodb/DBPortPoolTest.java
@@ -33,6 +33,7 @@
public class DBPortPoolTest extends com.mongodb.util.TestCase {
@Test
+ @SuppressWarnings("deprecation")
public void testReuse() throws Exception {
MongoOptions options = new MongoOptions();
options.connectionsPerHost = 10;
@@ -85,6 +86,7 @@ public void run(){
}
@Test
+ @SuppressWarnings("deprecation")
public void testInterruptedException() throws UnknownHostException, InterruptedException {
MongoOptions options = new MongoOptions();
options.connectionsPerHost = 1;
View
3 src/test/com/mongodb/DBPortTest.java
@@ -26,8 +26,9 @@
public class DBPortTest extends TestCase {
@Test
+ @SuppressWarnings("deprecation")
public void testAuthentication() throws IOException {
- Mongo m = new Mongo();
+ Mongo m = new MongoClient();
DB db1 = m.getDB("DBPortTest1");
DB db2 = m.getDB("DBPortTest2");
db1.dropDatabase();
View
11 src/test/com/mongodb/DBRefTest.java
@@ -24,21 +24,14 @@
import org.bson.types.ObjectId;
import org.testng.annotations.Test;
-import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
public class DBRefTest extends TestCase {
public DBRefTest() {
- try {
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_monogodb_unittest_DBRefTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
- catch(UnknownHostException e) {
- throw new MongoException("couldn't connect");
- }
+ cleanupDB = "com_monogodb_unittest_DBRefTest";
+ _db = cleanupMongo.getDB(cleanupDB);
}
@Test(groups = {"basic"})
View
99 src/test/com/mongodb/DBTCPConnectorTest.java
@@ -19,6 +19,7 @@
package com.mongodb;
import com.mongodb.util.TestCase;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -27,21 +28,33 @@
import java.util.Arrays;
/**
- * Testing functionality of database TCP connector
+ * Testing functionality of database TCP connector. The structure of this class is a bit unusual,
+ * as it creates its own MongoClient, yet still extends TestCase, which has its own.
*/
public class DBTCPConnectorTest extends TestCase {
+ private MongoClient _mongoClient;
+ private DB _db;
+ private DBCollection _collection;
+ private DBTCPConnector _connector;
+
@BeforeClass
public void beforeClass() throws UnknownHostException {
- cleanupMongo = new Mongo(Arrays.asList(new ServerAddress("127.0.0.1"), new ServerAddress("127.0.0.1:27018")));
- cleanupDB = "com_mongodb_unittest_DBTCPConnectorTest";
- _db = cleanupMongo.getDB(cleanupDB);
+ _mongoClient = new MongoClient(Arrays.asList(new ServerAddress("localhost:27017"), new ServerAddress("localhost:27018")));
+ cleanupDB = "com_mongodb_DBTCPConnectorTest";
+ _db = _mongoClient.getDB(cleanupDB);
_collection = _db.getCollection("testCol");
}
+ @AfterClass
+ public void afterClass() {
+ _mongoClient.close();
+ _connector.close();
+ }
+
@BeforeMethod
public void beforeMethod() throws UnknownHostException {
- _connector = new DBTCPConnector(cleanupMongo);
+ _connector = new DBTCPConnector(_mongoClient);
_connector.start();
}
@@ -52,10 +65,14 @@ public void beforeMethod() throws UnknownHostException {
public void testRequestReservation() {
assertEquals(false, _connector.getMyPort()._inRequest);
_connector.requestStart();
- assertNull(_connector.getMyPort()._requestPort);
- assertEquals(true, _connector.getMyPort()._inRequest);
- _connector.requestDone();
- assertEquals(false, _connector.getMyPort()._inRequest);
+ try {
+ assertNull(_connector.getMyPort()._requestPort);
+ assertEquals(true, _connector.getMyPort()._inRequest);
+ _connector.requestDone();
+ assertEquals(false, _connector.getMyPort()._inRequest);
+ } finally {
+ _connector.requestDone();
+ }
}
/**
@@ -64,11 +81,15 @@ public void testRequestReservation() {
@Test
public void testConnectionReservationForWrites() {
_connector.requestStart();
- _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
- assertNotNull(_connector.getMyPort()._requestPort);
- DBPort requestPort = _connector.getMyPort()._requestPort;
- _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
- assertEquals(requestPort, _connector.getMyPort()._requestPort);
+ try {
+ _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
+ assertNotNull(_connector.getMyPort()._requestPort);
+ DBPort requestPort = _connector.getMyPort()._requestPort;
+ _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
+ assertEquals(requestPort, _connector.getMyPort()._requestPort);
+ } finally {
+ _connector.requestDone();
+ }
}
/**
@@ -77,12 +98,16 @@ public void testConnectionReservationForWrites() {
@Test
public void testConnectionReservationForWriteThenRead() {
_connector.requestStart();
- _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
- DBPort requestPort = _connector.getMyPort()._requestPort;
- _connector.call(_db, _collection,
- OutMessage.query(_collection, 0, 0, -1, new BasicDBObject(), new BasicDBObject(), ReadPreference.primary()),
- null, 0);
- assertEquals(requestPort, _connector.getMyPort()._requestPort);
+ try {
+ _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
+ DBPort requestPort = _connector.getMyPort()._requestPort;
+ _connector.call(_db, _collection,
+ OutMessage.query(_collection, 0, 0, -1, new BasicDBObject(), new BasicDBObject(), ReadPreference.primary()),
+ null, 0);
+ assertEquals(requestPort, _connector.getMyPort()._requestPort);
+ } finally {
+ _connector.requestDone();
+ }
}
/**
@@ -95,13 +120,17 @@ public void testConnectionReservationForReadThenWrite() {
}
_connector.requestStart();
- _connector.call(_db, _collection,
- OutMessage.query(_collection, 0, 0, -1, new BasicDBObject(), new BasicDBObject(), ReadPreference.secondary()),
- null, 0, ReadPreference.secondary(), null);
- DBPort requestPort = _connector.getMyPort()._requestPort;
- _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
- assertNotEquals(requestPort, _connector.getMyPort()._requestPort);
- assertEquals(_connector.getReplicaSetStatus().getMaster(), _connector.getMyPort()._requestPort.serverAddress());
+ try {
+ _connector.call(_db, _collection,
+ OutMessage.query(_collection, 0, 0, -1, new BasicDBObject(), new BasicDBObject(), ReadPreference.secondary()),
+ null, 0, ReadPreference.secondary(), null);
+ DBPort requestPort = _connector.getMyPort()._requestPort;
+ _connector.say(_db, createOutMessageForInsert(), WriteConcern.SAFE);
+ assertNotEquals(requestPort, _connector.getMyPort()._requestPort);
+ assertEquals(_connector.getReplicaSetStatus().getMaster(), _connector.getMyPort()._requestPort.serverAddress());
+ } finally {
+ _connector.requestDone();
+ }
}
/**
@@ -110,10 +139,14 @@ public void testConnectionReservationForReadThenWrite() {
@Test
public void testConnectionReservationForReads() {
_connector.requestStart();
- _connector.call(_db, _collection,
- OutMessage.query(_collection, 0, 0, -1, new BasicDBObject(), new BasicDBObject(), ReadPreference.primary()),
- null, 0);
- assertNotNull(_connector.getMyPort()._requestPort);
+ try {
+ _connector.call(_db, _collection,
+ OutMessage.query(_collection, 0, 0, -1, new BasicDBObject(), new BasicDBObject(), ReadPreference.primary()),
+ null, 0);
+ assertNotNull(_connector.getMyPort()._requestPort);
+ } finally {
+ _connector.requestDone();
+ }
}
@@ -123,8 +156,4 @@ private OutMessage createOutMessageForInsert() {
return om;
}
-
- private DB _db;
- private DBCollection _collection;
- private DBTCPConnector _connector;
}
View
6 src/test/com/mongodb/DBTest.java
@@ -23,10 +23,8 @@
public class DBTest extends TestCase {
- public DBTest()
- throws UnknownHostException {
+ public DBTest() {
super();
- cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_DBTest";
_db = cleanupMongo.getDB( cleanupDB );
}
@@ -126,7 +124,7 @@ public void testReadPreferenceObedience() {
@Test(groups = {"basic"})
public void testEnsureConnection() throws UnknownHostException {
- Mongo m = new Mongo(Arrays.asList(new ServerAddress("localhost")));
+ Mongo m = new MongoClient(Arrays.asList(new ServerAddress("localhost")));
if (isStandalone(m)) {
return;
View
10 src/test/com/mongodb/DBTests.java
@@ -30,10 +30,8 @@
final Mongo _mongo;
final DB _db;
- public DBTests()
- throws Exception {
- _mongo = new Mongo("127.0.0.1");
- cleanupMongo = _mongo;
+ public DBTests() {
+ _mongo = cleanupMongo;
cleanupDB = "java_com_mongodb_unittest_DBTests";
_db = cleanupMongo.getDB(cleanupDB);
}
@@ -132,7 +130,7 @@ public void testRenameAndDrop() throws MongoException {
@Test
public void testGetCollectionNamesToSecondary() throws MongoException, UnknownHostException {
- Mongo mongo = new Mongo(Arrays.asList(new ServerAddress("127.0.0.1"), new ServerAddress("127.0.0.1", 27018)));
+ Mongo mongo = new MongoClient(Arrays.asList(new ServerAddress("127.0.0.1"), new ServerAddress("127.0.0.1", 27018)));
try {
if (isStandalone(mongo)) {
@@ -141,7 +139,7 @@ public void testGetCollectionNamesToSecondary() throws MongoException, UnknownHo
String secondary = getASecondaryAsString(mongo);
mongo.close();
- mongo = new Mongo(secondary);
+ mongo = new MongoClient(secondary);
DB db = mongo.getDB("secondaryTest");
db.setReadPreference(ReadPreference.secondary());
db.getCollectionNames();
View
1 src/test/com/mongodb/ErrorTest.java
@@ -29,7 +29,6 @@
@BeforeClass
public void setUp() throws Exception{
- cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_ErrorTest";
_db = cleanupMongo.getDB(cleanupDB);
}
View
42 src/test/com/mongodb/JavaClientTest.java
@@ -22,21 +22,29 @@
import com.mongodb.util.Util;
import org.bson.BSON;
import org.bson.Transformer;
-import org.bson.types.*;
+import org.bson.types.BSONTimestamp;
+import org.bson.types.Binary;
+import org.bson.types.Code;
+import org.bson.types.CodeWScope;
+import org.bson.types.MaxKey;
+import org.bson.types.MinKey;
+import org.bson.types.ObjectId;
import org.testng.annotations.Test;
-import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import java.util.regex.Pattern;
public class JavaClientTest extends TestCase {
- public JavaClientTest()
- throws IOException , MongoException {
- _mongo = new Mongo( "localhost" );
- cleanupMongo = _mongo;
+ public JavaClientTest() {
+ _mongo = cleanupMongo;
cleanupDB = "com_mongodb_unittest_JavaClientTest";
_db = cleanupMongo.getDB( cleanupDB );
}
@@ -493,7 +501,8 @@ public void testMapReduceInline(){
@Test
@SuppressWarnings("deprecation")
public void testMapReduceInlineSecondary() throws Exception {
- Mongo mongo = new Mongo(Arrays.asList(new ServerAddress("127.0.0.1", 27017), new ServerAddress("127.0.0.1", 27018)));
+ Mongo mongo = new MongoClient(Arrays.asList(new ServerAddress("127.0.0.1", 27017), new ServerAddress("127.0.0.1", 27018)),
+ MongoClientOptions.builder().writeConcern(WriteConcern.UNACKNOWLEDGED).build());
if (isStandalone(mongo)) {
return;
@@ -646,7 +655,7 @@ public void testMulti(){
public void testAuthenticate() throws UnknownHostException {
assertEquals( "26e3d12bd197368526409177b3e8aab6" , _db._hash( "e" , "j".toCharArray() ) );
- Mongo m = new Mongo();
+ Mongo m = new MongoClient();
DB db = m.getDB(cleanupDB);
DBCollection usersCollection = db.getCollection( "system.users" );
@@ -680,7 +689,7 @@ public void testAuthenticate() throws UnknownHostException {
@Test
public void testAuthenticateCommand() throws UnknownHostException {
- Mongo m = new Mongo();
+ Mongo m = new MongoClient();
DB db = m.getDB(cleanupDB);
DBCollection usersCollections = db.getCollection( "system.users" );
@@ -715,7 +724,7 @@ public void testAuthenticateCommand() throws UnknownHostException {
@Test
public void testAuthenticateWithCredentialsInURIAndNoDatabase() throws UnknownHostException {
// First add the user
- Mongo m = new Mongo(new MongoURI("mongodb://localhost"));
+ Mongo m = new MongoClient(new MongoClientURI("mongodb://localhost"));
DB db = m.getDB("admin");
DBCollection usersCollection = db.getCollection( "system.users" );
try {
@@ -729,7 +738,7 @@ public void testAuthenticateWithCredentialsInURIAndNoDatabase() throws UnknownHo
m.close();
}
- m = new Mongo(new MongoURI("mongodb://xx:e@localhost"));
+ m = new MongoClient(new MongoClientURI("mongodb://xx:e@localhost"));
db = m.getDB("admin");
try {
@@ -745,7 +754,7 @@ public void testAuthenticateWithCredentialsInURIAndNoDatabase() throws UnknownHo
@Test
public void testAuthenticateWithCredentialsInURI() throws UnknownHostException {
// First add the user
- Mongo m = new Mongo(new MongoURI("mongodb://localhost"));
+ Mongo m = new MongoClient(new MongoClientURI("mongodb://localhost"));
DB db = m.getDB(cleanupDB);
DBCollection usersCollection = db.getCollection( "system.users" );
try {
@@ -759,7 +768,7 @@ public void testAuthenticateWithCredentialsInURI() throws UnknownHostException {
m.close();
}
- m = new Mongo(new MongoURI("mongodb://xx:e@localhost/" + cleanupDB));
+ m = new MongoClient(new MongoClientURI("mongodb://xx:e@localhost/" + cleanupDB));
db = m.getDB(cleanupDB);
try {
@@ -775,7 +784,7 @@ public void testAuthenticateWithCredentialsInURI() throws UnknownHostException {
@Test
public void testAuthenticateCommandWithCredentialsInURI() throws UnknownHostException {
// First add the user
- Mongo m = new Mongo(new MongoURI("mongodb://localhost"));
+ Mongo m = new MongoClient(new MongoClientURI("mongodb://localhost"));
DB db = m.getDB(cleanupDB);
DBCollection usersCollection = db.getCollection( "system.users" );
try {
@@ -789,7 +798,7 @@ public void testAuthenticateCommandWithCredentialsInURI() throws UnknownHostExce
m.close();
}
- m = new Mongo(new MongoURI("mongodb://xx:e@localhost/" + cleanupDB));
+ m = new MongoClient(new MongoClientURI("mongodb://xx:e@localhost/" + cleanupDB));
db = m.getDB(cleanupDB);
try {
@@ -1134,6 +1143,7 @@ public void testAllTypes(){
}
@Test
+ @SuppressWarnings("deprecation")
public void testMongoHolder() throws MongoException, UnknownHostException {
Mongo m1 = Mongo.Holder.singleton().connect( new MongoURI( "mongodb://localhost" ) );
Mongo m2 = Mongo.Holder.singleton().connect( new MongoURI( "mongodb://localhost" ) );
View
34 src/test/com/mongodb/LazyDBObjectTest.java
@@ -17,37 +17,37 @@
package com.mongodb;
import com.mongodb.util.TestCase;
-import org.bson.types.*;
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeMethod;
-
-import java.net.UnknownHostException;
-import java.util.Date;
-import java.util.UUID;
import org.bson.BSONEncoder;
import org.bson.BasicBSONEncoder;
import org.bson.io.BasicOutputBuffer;
import org.bson.io.OutputBuffer;
+import org.bson.types.BSONTimestamp;
+import org.bson.types.Binary;
+import org.bson.types.Code;
+import org.bson.types.MaxKey;
+import org.bson.types.MinKey;
+import org.bson.types.ObjectId;
+import org.bson.types.Symbol;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
import java.util.regex.Pattern;
@SuppressWarnings( { "unchecked" , "deprecation" } )
public class LazyDBObjectTest extends TestCase {
public LazyDBObjectTest(){
- super();
- try {
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_LazyDBObjectTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
- catch ( UnknownHostException e ) {
- throw new MongoException( "couldn't connect" );
- }
+ cleanupDB = "com_mongodb_unittest_LazyDBObjectTest";
+ _db = cleanupMongo.getDB(cleanupDB);
}
BSONEncoder e;
View
1 src/test/com/mongodb/MongoClientTest.java
@@ -26,6 +26,7 @@
public class MongoClientTest {
@Test
+ @SuppressWarnings("deprecation")
public void testConstructors() throws UnknownHostException {
MongoClientOptions customClientOptions = new MongoClientOptions.Builder().connectionsPerHost(500).build();
MongoOptions customOptions = new MongoOptions(customClientOptions);
View
2 src/test/com/mongodb/MongoOptionsTest.java
@@ -77,6 +77,7 @@ public void testCopy() throws Exception {
}
@Test
+ @SuppressWarnings("deprecation")
public void testGetterSetters() throws Exception {
final MongoOptions options = new MongoOptions();
@@ -125,6 +126,7 @@ public void testGetterSetters() throws Exception {
}
@Test
+ @SuppressWarnings("deprecation")
public void testGetWriteConcern() {
MongoOptions options = new MongoOptions();
assertEquals(WriteConcern.NORMAL, options.getWriteConcern());
View
5 src/test/com/mongodb/MongoTest.java
@@ -26,11 +26,12 @@
import java.io.IOException;
import java.net.UnknownHostException;
+@SuppressWarnings("deprecation")
public class MongoTest extends TestCase {
public MongoTest()
throws IOException , MongoException {
- _db = new Mongo().getDB( "mongotest" );
+ _db = new MongoClient().getDB( "mongotest" );
}
final DB _db;
@@ -46,7 +47,7 @@ public void setUp() {
public void testClose_shouldNotReturnUntilCleanupThreadIsFinished() throws Exception {
Mongo.cleanerIntervalMS = 250000; //set to a suitably large value to avoid race conditions in the test
- Mongo mongo = new Mongo();
+ Mongo mongo = new MongoClient();
assertNotEquals(mongo._cleaner.getState(), Thread.State.NEW);
mongo.close();
View
1 src/test/com/mongodb/MongoURITest.java
@@ -25,6 +25,7 @@
import java.util.Arrays;
+@SuppressWarnings("deprecation")
public class MongoURITest extends TestCase {
@Test
View
15 src/test/com/mongodb/ObjectIdTest.java
@@ -18,23 +18,20 @@
package com.mongodb;
-import java.util.*;
-
+import com.mongodb.util.TestCase;
+import org.bson.types.ObjectId;
import org.testng.annotations.Test;
-import com.mongodb.util.*;
-import org.bson.*;
-import org.bson.types.*;
+import java.util.Date;
+import java.util.Random;
public class ObjectIdTest extends TestCase {
final Mongo _mongo;
final DB _db;
- public ObjectIdTest()
- throws Exception {
- _mongo = new Mongo();
- cleanupMongo = _mongo;
+ public ObjectIdTest() {
+ _mongo = cleanupMongo;
cleanupDB = "com_mongodb_unittest_ObjectIdTest";
_db = cleanupMongo.getDB(cleanupDB);
}
View
2 src/test/com/mongodb/OutMessageTest.java
@@ -32,7 +32,7 @@
@BeforeTest
public void setup() throws UnknownHostException {
- m = new Mongo();
+ m = new MongoClient();
}
// Ensure defensive code is in place after doneWithMessage is called.
View
9 src/test/com/mongodb/PerformanceTest.java
@@ -16,10 +16,11 @@
package com.mongodb;
-import java.util.*;
-import java.net.UnknownHostException;
+import org.bson.types.BasicBSONList;
-import org.bson.types.*;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Date;
@SuppressWarnings("unchecked")
public class PerformanceTest {
@@ -240,7 +241,7 @@ public static void findRange(String name) {
public static void main(String[] args) {
try {
- _db = new Mongo().getDB( "performance" );
+ _db = new MongoClient().getDB( "performance" );
}
catch (MongoException e) {
return;
View
6 src/test/com/mongodb/QueryBuilderTest.java
@@ -26,7 +26,6 @@
import com.mongodb.util.TestCase;
import org.testng.annotations.Test;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
@@ -38,10 +37,7 @@
public class QueryBuilderTest extends TestCase {
private DB _testDB;
- public QueryBuilderTest()
- throws IOException, MongoException {
- super();
- cleanupMongo = new Mongo( "127.0.0.1" );
+ public QueryBuilderTest() {
_testDB = cleanupMongo.getDB( "queryBuilderTest" );
_testDB.dropDatabase();
}
View
9 src/test/com/mongodb/ReflectionTest.java
@@ -16,12 +16,9 @@
package com.mongodb;
-import java.io.*;
-
+import com.mongodb.util.TestCase;
import org.testng.annotations.Test;
-import com.mongodb.util.*;
-
public class ReflectionTest extends TestCase {
public static class Person extends ReflectionDBObject {
@@ -40,9 +37,7 @@ public void setName(String name){
String _name;
}
- public ReflectionTest()
- throws IOException , MongoException {
- cleanupMongo = new Mongo( "127.0.0.1" );
+ public ReflectionTest() {
cleanupDB = "com_mongodb_unittest_ReflectionTest";
_db = cleanupMongo.getDB( cleanupDB );
}
View
2 src/test/com/mongodb/ReplPairTest.java
@@ -26,7 +26,7 @@
@SuppressWarnings("deprecation")
R( ServerAddress a ){
_a = a;
- _mongo = new Mongo(a);
+ _mongo = new MongoClient(a);
_db = _mongo.getDB( "test" );
_coll = _db.getCollection( "foo" );
View
4 src/test/com/mongodb/ReplSetTest.java
@@ -31,7 +31,7 @@ static void _sleep()
@SuppressWarnings("deprecation")
R( ServerAddress a ){
_a = a;
- _mongo = new Mongo(a);
+ _mongo = new MongoClient(a);
_db = _mongo.getDB( "test" );
_coll = _db.getCollection( "foo" );
@@ -73,7 +73,7 @@ public static void main( String args[] )
addrs.add( new ServerAddress( "localhost" , 27021 ) );
}
- Mongo m = rs ? new Mongo( addrs ) : new Mongo();
+ Mongo m = rs ? new MongoClient( addrs ) : new MongoClient();
DB db = m.getDB( "test" );
DBCollection c = db.getCollection( "foo" );
c.drop();
View
1 src/test/com/mongodb/ReplicaSetStatusDomainModelTest.java
@@ -253,6 +253,7 @@ private void addNodeToLists(String address, boolean isSecondary, float pingTime,
true, !isSecondary, isSecondary, tags, Bytes.MAX_OBJECT_SIZE));
}
+ @SuppressWarnings("deprecation")
private final MongoOptions _mongoOptions = new MongoOptions();
private final AtomicReference<String> _setName = new AtomicReference<String>("test");
private final AtomicReference<Logger> _logger = new AtomicReference<Logger>(Logger.getLogger("test"));
View
38 src/test/com/mongodb/ReplicaSetStatusTest.java
@@ -17,50 +17,52 @@
package com.mongodb;
import com.mongodb.ReplicaSetStatus.ReplicaSetNode;
-import com.mongodb.util.TestCase;
-
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
+import java.net.UnknownHostException;
import java.util.List;
-import java.util.Random;
/**
* This is a placeholder. A node needs to be able to be created outside of ReplicaSetStatus.
*/
-public class ReplicaSetStatusTest extends TestCase {
- public ReplicaSetStatusTest() throws IOException, MongoException {
- cleanupMongo = new Mongo(new MongoURI("mongodb://127.0.0.1:27017,127.0.0.1:27018"));
+public class ReplicaSetStatusTest {
+ private Mongo mongoClient;
+
+ @BeforeClass
+ public void beforeClass() throws UnknownHostException {
+ mongoClient = new MongoClient(new MongoClientURI("mongodb://127.0.0.1:27017,127.0.0.1:27018"));
+ }
- cleanupDB = "com_mongodb_unittest_ReplicaSetStatusUpdaterTest";
+ @AfterClass
+ public void afterClass() {
+ mongoClient.close();
}
@Test
public void testClose() throws InterruptedException {
- ReplicaSetStatus replicaSetStatus = new ReplicaSetStatus(cleanupMongo, cleanupMongo.getAllAddress());
+ ReplicaSetStatus replicaSetStatus = new ReplicaSetStatus(mongoClient, mongoClient.getAllAddress());
replicaSetStatus.start();
- assertNotNull(replicaSetStatus._replicaSetHolder.get());
+ Assert.assertNotNull(replicaSetStatus._replicaSetHolder.get());
replicaSetStatus.close();
replicaSetStatus._updater.join(5000);
- assertTrue(!replicaSetStatus._updater.isAlive());
+ Assert.assertTrue(!replicaSetStatus._updater.isAlive());
}
@Test
public void testSetNames() throws Exception {
- String replicaSetName = cleanupMongo.getConnector().getReplicaSetStatus().getName();
+ String replicaSetName = mongoClient.getConnector().getReplicaSetStatus().getName();
- List<ReplicaSetNode> nodes = cleanupMongo.getConnector().getReplicaSetStatus()._replicaSetHolder.get().getAll();
+ List<ReplicaSetNode> nodes = mongoClient.getConnector().getReplicaSetStatus()._replicaSetHolder.get().getAll();
for(ReplicaSetNode node : nodes){
- assertEquals(replicaSetName, node.getSetName());
+ Assert.assertEquals(replicaSetName, node.getSetName());
}
}
View
5 src/test/com/mongodb/SecondaryReadTest.java
@@ -172,7 +172,8 @@ private boolean serverIsSecondary(final ServerAddress pServerAddr, final List<Te
}
private Mongo loadMongo() throws Exception {
- return new Mongo(new MongoURI("mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/?connectTimeoutMS=30000;socketTimeoutMS=30000;maxpoolsize=5;autoconnectretry=true"));
+ return new MongoClient(new MongoClientURI(
+ "mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/?connectTimeoutMS=30000;socketTimeoutMS=30000;maxpoolsize=5;autoconnectretry=true"));
}
@SuppressWarnings({"unchecked"})
@@ -246,7 +247,7 @@ private void verifySecondaryCounts(final int pSecondaryCount, final List<TestHos
private static void loadQueryCount(final List<TestHost> pHosts, final boolean pBefore) throws Exception {
for (final TestHost testHost : pHosts) {
- final Mongo mongoHost = new Mongo(new MongoURI("mongodb://"+testHost.hostnameAndPort+"/?connectTimeoutMS=30000;socketTimeoutMS=30000;maxpoolsize=5;autoconnectretry=true"));
+ final Mongo mongoHost = new MongoClient(new MongoClientURI("mongodb://"+testHost.hostnameAndPort+"/?connectTimeoutMS=30000;socketTimeoutMS=30000;maxpoolsize=5;autoconnectretry=true"));
try {
final CommandResult serverStatusResult
= mongoHost.getDB("com_mongodb_unittest_SecondaryReadTest").command(new BasicDBObject("serverStatus", 1));
View
6 src/test/com/mongodb/SingleThreadedMongoPerfTest.java
@@ -20,11 +20,11 @@
public class SingleThreadedMongoPerfTest {
public static void main(String... args) throws Exception {
// connection pool size is 10
- MongoOptions opts = new MongoOptions();
- opts.connectionsPerHost = 10;
+ MongoClientOptions opts = new MongoClientOptions.Builder().
+ writeConcern(WriteConcern.UNACKNOWLEDGED).connectionsPerHost(10).build();
ServerAddress addr = new ServerAddress("127.0.0.1", 27017);
- Mongo mongo = new Mongo(addr, opts);
+ MongoClient mongo = new MongoClient(addr, opts);
DB db = mongo.getDB("mongotest");
DBCollection collection = db.getCollection("mongoperftest");
View
50 src/test/com/mongodb/ThreadingTest.java
@@ -1,50 +0,0 @@
-// ThreadingTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import com.mongodb.util.TestCase;
-import org.testng.annotations.Test;
-
-public class ThreadingTest extends TestCase {
-
- final static String DB = "java_threading_tests";
-
- public ThreadingTest(){
- cleanupDB = DB;
- }
-
- @Test
- public void test2Mongos()
- throws Exception {
- Mongo a = new Mongo();
- a.getDB( DB ).getCollection( "test2Mongos" ).insert( new BasicDBObject( "_id" , 1 ) );
- assertEquals( 1 , a.getDB( DB ).getCollection( "test2Mongos" ).findOne().get( "_id" ) );
-
- Mongo b = new Mongo();
- assertEquals( 1 , b.getDB( DB ).getCollection( "test2Mongos" ).findOne().get( "_id" ) );
- a.close();
- b.close();
- }
-
- public static void main( String args[] )
- throws Exception {
- (new ThreadingTest()).runConsole();
- }
-
-}
View
13 src/test/com/mongodb/framework/Capped.java
@@ -15,19 +15,22 @@
*/
package com.mongodb.framework;
-import java.util.*;
-import java.net.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoException;
-import com.mongodb.*;
-import com.mongodb.util.*;
+import java.net.UnknownHostException;
public class Capped {
public static void main(String[] args)
throws MongoException , UnknownHostException {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBObject foo = new BasicDBObject();
foo.put( "create", "capped1" );
foo.put( "capped", true );
View
2 src/test/com/mongodb/framework/Circular.java
@@ -30,7 +30,7 @@
public static void main(String[] args)
throws Exception {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBObject foo = new BasicDBObject();
DBCollection b = db.getCollection( "b" );
foo.put( "c", b );
View
2 src/test/com/mongodb/framework/Count1.java
@@ -27,7 +27,7 @@
public static void main(String[] args)
throws Exception {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
System.out.println( db.getCollection( "test1" ).find().count() );
System.out.println( db.getCollection( "test2" ).find().count() );
DBCollection coll = db.getCollection( "test3" );
View
15 src/test/com/mongodb/framework/Dbs.java
@@ -15,18 +15,23 @@
*/
package com.mongodb.framework;
-import java.util.*;
-import java.net.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoException;
-import com.mongodb.*;
-import com.mongodb.util.*;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Set;
public class Dbs {
public static void main(String[] args)
throws UnknownHostException , MongoException {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBCollection coll = db.getCollection( "dbs_1" );
DBObject o = new BasicDBObject();
o.put( "foo", "bar" );
View
10 src/test/com/mongodb/framework/Find.java
@@ -16,16 +16,18 @@
package com.mongodb.framework;
-import java.net.*;
-
-import com.mongodb.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
public class Find {
public static void main(String[] args)
throws Exception {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBCollection c = db.getCollection( "test" );
DBObject foo = new BasicDBObject();
View
12 src/test/com/mongodb/framework/Find1.java
@@ -15,19 +15,19 @@
*/
package com.mongodb.framework;
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
public class Find1 {
public static void main(String[] args)
throws Exception {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBObject foo = new BasicDBObject();
foo.put( "x", 1 );
DBObject bar = new BasicDBObject();
View
11 src/test/com/mongodb/framework/Remove.java
@@ -16,19 +16,18 @@
package com.mongodb.framework;
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
public class Remove {
public static void main(String[] args)
throws Exception {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBObject foo = new BasicDBObject();
db.getCollection( "remove1" ).remove( foo );
View
2 src/test/com/mongodb/framework/Stress1.java
@@ -36,7 +36,7 @@ public static void doStuff( DBCollection c, int count )
public static void main(String[] args)
throws UnknownHostException , MongoException {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBCollection c = db.getCollection( "stress1" );
String blah = "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" +
View
12 src/test/com/mongodb/framework/Test1.java
@@ -17,18 +17,18 @@
package com.mongodb.framework;
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
public class Test1 {
public static void main(String[] args)
throws Exception {
- DB db = new Mongo().getDB( "driver_test_framework" );
+ DB db = new MongoClient().getDB( "driver_test_framework" );
DBCollection coll = db.getCollection( "part1" );
for( int i=0; i<100; i++) {
View
44 src/test/com/mongodb/gridfs/GridFSTest.java
@@ -16,41 +16,25 @@
package com.mongodb.gridfs;
-import java.io.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCursor;
+import com.mongodb.MongoException;
+import com.mongodb.util.TestCase;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.List;
-import org.testng.annotations.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
public class GridFSTest extends TestCase {
- public GridFSTest()
- throws IOException , MongoException {
- super();
- try {
- cleanupMongo = new Mongo( "127.0.0.1" );
+ public GridFSTest() {
cleanupDB = "com_mongodb_unittest_GridFSTest";
- _db = cleanupMongo.getDB( cleanupDB );
- _fs = new GridFS( _db );
- }
- catch ( MongoException e ){
- e.printStackTrace();
- throw e;
- }
- catch ( IOException io ){
- io.printStackTrace();
- throw io;
- }
- catch ( RuntimeException re ){
- re.printStackTrace();
- throw re;
- }
- catch ( Throwable t ){
- t.printStackTrace();
- throw new RuntimeException( t );
- }
+ _db = cleanupMongo.getDB(cleanupDB);
+ _fs = new GridFS(_db);
}
int[] _get(){
View
6 src/test/com/mongodb/tools/ConnectionPoolStatTest.java
@@ -17,8 +17,6 @@
package com.mongodb.tools;
import com.mongodb.DBObject;
-import com.mongodb.Mongo;
-import com.mongodb.MongoException;
import com.mongodb.util.JSON;
import com.mongodb.util.TestCase;
import org.testng.annotations.Test;
@@ -27,9 +25,6 @@
import java.io.IOException;
public class ConnectionPoolStatTest extends TestCase {
- public ConnectionPoolStatTest() throws IOException, MongoException {
- cleanupMongo = new Mongo();
- }
@Test
public void testBasic() throws IOException, JMException {
@@ -39,5 +34,4 @@ public void testBasic() throws IOException, JMException {
DBObject obj = (DBObject) JSON.parse(stats);
assertNotNull(obj);
}
-
}
View
21 src/test/com/mongodb/util/TestCase.java
@@ -21,12 +21,16 @@
import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult;
import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
+import com.mongodb.WriteConcern;
+import org.testng.annotations.AfterClass;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
@@ -105,7 +109,17 @@ public TestCase(){
this( null );
}
- public TestCase( String name ){
+ public TestCase( String name ) {
+ if (staticMongoClient == null) {
+ try {
+ staticMongoClient = new MongoClient();
+ staticMongoClient.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
+ } catch (UnknownHostException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ cleanupMongo = staticMongoClient;
+
for ( Method m : getClass().getMethods() ){
if ( ! m.getName().startsWith( "test" ) )
@@ -137,13 +151,14 @@ public void add( TestCase tc ){
public String cleanupDB = null;
public Mongo cleanupMongo = null;
- @org.testng.annotations.AfterClass
+ private static MongoClient staticMongoClient;
+
+ @AfterClass
public void cleanup() {
if (cleanupMongo != null) {
if (cleanupDB != null) {
cleanupMongo.dropDatabase(cleanupDB);
}
- cleanupMongo.close();
}
}
View
10 src/test/com/mongodb/util/TestNGListener.java
@@ -18,13 +18,13 @@
package com.mongodb.util;
-import org.testng.ITestContext;
-import org.testng.ITestResult;
-import org.testng.TestListenerAdapter;
-
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
+import org.testng.ITestContext;
+import org.testng.ITestResult;
+import org.testng.TestListenerAdapter;
import java.net.UnknownHostException;
@@ -83,7 +83,7 @@ private void _recordResults( ITestContext context ) throws UnknownHostException
obj.put( "total", context.getEndDate().getTime()-context.getStartDate().getTime() );
obj.put( "time", System.currentTimeMillis() );
- Mongo mongo = new Mongo();
+ Mongo mongo = new MongoClient();
try {
mongo.getDB( "results" ).getCollection( "testng" ).save( obj );
}

0 comments on commit 1d2e6fa

Please sign in to comment.