Skip to content

Commit

Permalink
JAVA-2084: Implement server discovery and monitoring specification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jyemin committed Jan 13, 2016
1 parent 062a2bb commit 32c3c6c
Show file tree
Hide file tree
Showing 55 changed files with 3,282 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ sourceSets {
test {
groovy { srcDirs = ['src/test'] }
java { srcDirs = ['src/test', 'src/examples'] }
resources {
srcDir 'src/test-resources'
}
}
util.java { srcDirs = ['src/util'] }
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/com/mongodb/ServerMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private ServerDescription lookupServerDescription(final DBPort connection) throw
}

@SuppressWarnings("unchecked")
ServerDescription createDescription(final CommandResult commandResult, final ServerVersion serverVersion,
static ServerDescription createDescription(final CommandResult commandResult, final ServerVersion serverVersion,
final long averageLatencyNanos) {
return ServerDescription.builder()
.state(ServerConnectionState.Connected)
Expand All @@ -265,7 +265,7 @@ ServerDescription createDescription(final CommandResult commandResult, final Ser
.ok(commandResult.ok()).build();
}

private Set<String> listToSet(final List<String> list) {
private static Set<String> listToSet(final List<String> list) {
if (list == null || list.isEmpty()) {
return Collections.emptySet();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"description": "Discover arbiters",
"phases": [
{
"outcome": {
"servers": {
"a:27017": {
"setName": "rs",
"type": "RSPrimary"
},
"b:27017": {
"setName": null,
"type": "Unknown"
}
},
"setName": "rs",
"topologyType": "ReplicaSetWithPrimary"
},
"responses": [
[
"a:27017",
{
"arbiters": [
"b:27017"
],
"hosts": [
"a:27017"
],
"ismaster": true,
"ok": 1,
"setName": "rs"
}
]
]
}
],
"uri": "mongodb://a/?replicaSet=rs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"description": "Discover passives",
"phases": [
{
"outcome": {
"servers": {
"a:27017": {
"setName": "rs",
"type": "RSPrimary"
},
"b:27017": {
"setName": null,
"type": "Unknown"
}
},
"setName": "rs",
"topologyType": "ReplicaSetWithPrimary"
},
"responses": [
[
"a:27017",
{
"hosts": [
"a:27017"
],
"ismaster": true,
"ok": 1,
"passives": [
"b:27017"
],
"setName": "rs"
}
]
]
},
{
"outcome": {
"servers": {
"a:27017": {
"setName": "rs",
"type": "RSPrimary"
},
"b:27017": {
"setName": "rs",
"type": "RSSecondary"
}
},
"setName": "rs",
"topologyType": "ReplicaSetWithPrimary"
},
"responses": [
[
"b:27017",
{
"hosts": [
"a:27017"
],
"ismaster": false,
"ok": 1,
"passive": true,
"passives": [
"b:27017"
],
"secondary": true,
"setName": "rs"
}
]
]
}
],
"uri": "mongodb://a/?replicaSet=rs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"description": "Replica set discovery from primary",
"phases": [
{
"outcome": {
"servers": {
"a:27017": {
"setName": "rs",
"type": "RSPrimary"
},
"b:27017": {
"setName": null,
"type": "Unknown"
}
},
"setName": "rs",
"topologyType": "ReplicaSetWithPrimary"
},
"responses": [
[
"a:27017",
{
"hosts": [
"a:27017",
"b:27017"
],
"ismaster": true,
"ok": 1,
"setName": "rs"
}
]
]
}
],
"uri": "mongodb://a/?replicaSet=rs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"description": "Replica set discovery from secondary",
"phases": [
{
"outcome": {
"servers": {
"a:27017": {
"setName": null,
"type": "Unknown"
},
"b:27017": {
"setName": "rs",
"type": "RSSecondary"
}
},
"setName": "rs",
"topologyType": "ReplicaSetNoPrimary"
},
"responses": [
[
"b:27017",
{
"hosts": [
"a:27017",
"b:27017"
],
"ismaster": false,
"ok": 1,
"secondary": true,
"setName": "rs"
}
]
]
}
],
"uri": "mongodb://b/?replicaSet=rs"
}
163 changes: 163 additions & 0 deletions src/test-resources/server-discovery-and-monitoring/rs/discovery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"description": "Replica set discovery",
"phases": [
{
"outcome": {
"servers": {
"a:27017": {
"setName": "rs",
"type": "RSSecondary"
},
"b:27017": {
"setName": null,
"type": "Unknown"
},
"c:27017": {
"setName": null,
"type": "Unknown"
}
},
"setName": "rs",
"topologyType": "ReplicaSetNoPrimary"
},
"responses": [
[
"a:27017",
{
"hosts": [
"a:27017",
"b:27017",
"c:27017"
],
"ismaster": false,
"ok": 1,
"secondary": true,
"setName": "rs"
}
]
]
},
{
"outcome": {
"servers": {
"a:27017": {
"setName": "rs",
"type": "RSSecondary"
},
"b:27017": {
"setName": "rs",
"type": "RSSecondary"
},
"c:27017": {
"setName": null,
"type": "Unknown"
},
"d:27017": {
"setName": null,
"type": "PossiblePrimary"
}
},
"setName": "rs",
"topologyType": "ReplicaSetNoPrimary"
},
"responses": [
[
"b:27017",
{
"hosts": [
"b:27017",
"c:27017",
"d:27017"
],
"ismaster": false,
"ok": 1,
"primary": "d:27017",
"secondary": true,
"setName": "rs"
}
]
]
},
{
"outcome": {
"servers": {
"b:27017": {
"setName": "rs",
"type": "RSSecondary"
},
"c:27017": {
"setName": null,
"type": "Unknown"
},
"d:27017": {
"setName": "rs",
"type": "RSPrimary"
},
"e:27017": {
"setName": null,
"type": "Unknown"
}
},
"setName": "rs",
"topologyType": "ReplicaSetWithPrimary"
},
"responses": [
[
"d:27017",
{
"hosts": [
"b:27017",
"c:27017",
"d:27017",
"e:27017"
],
"ismaster": true,
"ok": 1,
"setName": "rs"
}
]
]
},
{
"outcome": {
"servers": {
"b:27017": {
"setName": "rs",
"type": "RSSecondary"
},
"c:27017": {
"setName": "rs",
"type": "RSSecondary"
},
"d:27017": {
"setName": "rs",
"type": "RSPrimary"
},
"e:27017": {
"setName": null,
"type": "Unknown"
}
},
"setName": "rs",
"topologyType": "ReplicaSetWithPrimary"
},
"responses": [
[
"c:27017",
{
"hosts": [
"a:27017",
"b:27017",
"c:27017"
],
"ismaster": false,
"ok": 1,
"secondary": true,
"setName": "rs"
}
]
]
}
],
"uri": "mongodb://a/?replicaSet=rs"
}
Loading

0 comments on commit 32c3c6c

Please sign in to comment.