Created
January 14, 2015 03:22
-
-
Save anonymous/8b6783ab067f04e483d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.BasicDBObject; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.MongoClient; | |
import com.mongodb.MongoClientURI; | |
import java.net.UnknownHostException; | |
import java.util.Random; | |
public class ShardingConfusion { | |
public static void main(String[] args) throws UnknownHostException { | |
MongoClient client = new MongoClient(new MongoClientURI("mongodb://localhost,localhost:27018")); | |
Random random = new Random(); | |
while (true) { | |
DB db = client.getDB("Java-driver-test"); | |
DBCollection c = db.getCollection("DBCursorTest" + random.nextLong()); | |
for (int i = 0; i < 100; i++) { | |
c.insert(new BasicDBObject("_id", i)); | |
} | |
long count = c.count(); | |
if (count != 100) { | |
System.out.println("Uh oh: count is " + count + " on collection " + c.getFullName()); | |
} else { | |
System.out.println("All is well"); | |
db.dropDatabase(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment