Skip to content

Commit 60081fa

Browse files
committed
Added Fixture methods to determine cluster type
1 parent bae2487 commit 60081fa

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/com/mongodb/Fixture.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ public static boolean serverIsAtLeastVersion(double version) {
6262
return Double.parseDouble(serverVersion.substring(0, 3)) >= version;
6363
}
6464

65+
public static boolean isStandalone() {
66+
return !isReplicaSet() && !isSharded();
67+
}
68+
69+
public static boolean isSharded() {
70+
CommandResult isMasterResult = runIsMaster();
71+
Object msg = isMasterResult.get("msg");
72+
return msg != null && msg.equals("isdbgrid");
73+
}
74+
75+
public static boolean isReplicaSet() {
76+
return runIsMaster().get("setName") != null;
77+
}
78+
79+
private static CommandResult runIsMaster() {
80+
// Check to see if this is a replica set... if not, get out of here.
81+
return getMongoClient().getDB("admin").command(new BasicDBObject("ismaster", 1));
82+
}
83+
6584
static class ShutdownHook extends Thread {
6685
@Override
6786
public void run() {

0 commit comments

Comments
 (0)