mongo 2.4.0.rc1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongo/auth/cr/conversation.rb +1 -1
  5. data/lib/mongo/auth/ldap/conversation.rb +1 -1
  6. data/lib/mongo/auth/scram/conversation.rb +1 -1
  7. data/lib/mongo/auth/x509/conversation.rb +4 -2
  8. data/lib/mongo/client.rb +7 -4
  9. data/lib/mongo/cluster.rb +55 -5
  10. data/lib/mongo/cluster/app_metadata.rb +7 -1
  11. data/lib/mongo/cluster/topology.rb +7 -6
  12. data/lib/mongo/cluster/topology/replica_set.rb +48 -2
  13. data/lib/mongo/cluster/topology/sharded.rb +47 -1
  14. data/lib/mongo/cluster/topology/single.rb +55 -4
  15. data/lib/mongo/cluster/topology/unknown.rb +65 -9
  16. data/lib/mongo/error/invalid_server_preference.rb +3 -1
  17. data/lib/mongo/event.rb +8 -0
  18. data/lib/mongo/event/description_changed.rb +20 -2
  19. data/lib/mongo/event/member_discovered.rb +65 -0
  20. data/lib/mongo/event/primary_elected.rb +3 -1
  21. data/lib/mongo/event/standalone_discovered.rb +1 -1
  22. data/lib/mongo/monitoring.rb +41 -0
  23. data/lib/mongo/monitoring/event.rb +6 -0
  24. data/lib/mongo/monitoring/event/server_closed.rb +46 -0
  25. data/lib/mongo/monitoring/event/server_description_changed.rb +58 -0
  26. data/lib/mongo/monitoring/event/server_opening.rb +46 -0
  27. data/lib/mongo/monitoring/event/topology_changed.rb +46 -0
  28. data/lib/mongo/monitoring/event/topology_closed.rb +41 -0
  29. data/lib/mongo/monitoring/event/topology_opening.rb +41 -0
  30. data/lib/mongo/monitoring/publishable.rb +12 -0
  31. data/lib/mongo/monitoring/sdam_log_subscriber.rb +54 -0
  32. data/lib/mongo/monitoring/server_closed_log_subscriber.rb +30 -0
  33. data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +33 -0
  34. data/lib/mongo/monitoring/server_opening_log_subscriber.rb +30 -0
  35. data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +40 -0
  36. data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +30 -0
  37. data/lib/mongo/server.rb +6 -0
  38. data/lib/mongo/server/connection.rb +1 -1
  39. data/lib/mongo/server/description.rb +23 -3
  40. data/lib/mongo/server/description/inspector.rb +4 -2
  41. data/lib/mongo/server/description/inspector/description_changed.rb +2 -2
  42. data/lib/mongo/server/description/inspector/member_discovered.rb +59 -0
  43. data/lib/mongo/server/description/inspector/primary_elected.rb +2 -0
  44. data/lib/mongo/server_selector.rb +10 -5
  45. data/lib/mongo/server_selector/nearest.rb +1 -1
  46. data/lib/mongo/server_selector/primary_preferred.rb +1 -1
  47. data/lib/mongo/server_selector/secondary.rb +1 -1
  48. data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
  49. data/lib/mongo/server_selector/selectable.rb +24 -12
  50. data/lib/mongo/uri.rb +1 -1
  51. data/lib/mongo/version.rb +1 -1
  52. data/mongo.gemspec +1 -1
  53. data/spec/mongo/auth/cr_spec.rb +6 -1
  54. data/spec/mongo/auth/ldap_spec.rb +6 -1
  55. data/spec/mongo/auth/scram_spec.rb +6 -1
  56. data/spec/mongo/auth/x509/conversation_spec.rb +69 -0
  57. data/spec/mongo/auth/x509_spec.rb +9 -4
  58. data/spec/mongo/client_spec.rb +40 -2
  59. data/spec/mongo/cluster/topology/replica_set_spec.rb +218 -9
  60. data/spec/mongo/cluster/topology/sharded_spec.rb +17 -2
  61. data/spec/mongo/cluster/topology/single_spec.rb +19 -4
  62. data/spec/mongo/cluster/topology/unknown_spec.rb +19 -1
  63. data/spec/mongo/cluster/topology_spec.rb +11 -7
  64. data/spec/mongo/cluster_spec.rb +25 -7
  65. data/spec/mongo/max_staleness_spec.rb +40 -22
  66. data/spec/mongo/monitoring_spec.rb +2 -2
  67. data/spec/mongo/sdam_monitoring_spec.rb +60 -0
  68. data/spec/mongo/sdam_spec.rb +77 -0
  69. data/spec/mongo/server/connection_pool_spec.rb +6 -1
  70. data/spec/mongo/server/connection_spec.rb +6 -1
  71. data/spec/mongo/server/description_spec.rb +90 -1
  72. data/spec/mongo/server_selection_spec.rb +7 -6
  73. data/spec/mongo/server_selector/nearest_spec.rb +7 -7
  74. data/spec/mongo/server_selector/primary_preferred_spec.rb +7 -7
  75. data/spec/mongo/server_selector/primary_spec.rb +4 -4
  76. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  77. data/spec/mongo/server_selector/secondary_spec.rb +6 -6
  78. data/spec/mongo/server_selector_spec.rb +8 -0
  79. data/spec/mongo/server_spec.rb +6 -1
  80. data/spec/mongo/uri_spec.rb +4 -4
  81. data/spec/spec_helper.rb +2 -0
  82. data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +4 -4
  83. data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +3 -3
  84. data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +3 -3
  85. data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +3 -3
  86. data/spec/support/max_staleness/ReplicaSetNoPrimary/NoKnownServers.yml +15 -0
  87. data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +1 -1
  88. data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +3 -3
  89. data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +3 -3
  90. data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +1 -1
  91. data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +3 -3
  92. data/spec/support/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.yml +23 -0
  93. data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +4 -4
  94. data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +5 -5
  95. data/spec/support/max_staleness/ReplicaSetWithPrimary/{ShortHeartbeartShortMaxStaleness2.yml → LongHeartbeat.yml} +4 -4
  96. data/spec/support/max_staleness/ReplicaSetWithPrimary/{ShortHeartbeartShortMaxStaleness.yml → LongHeartbeat2.yml} +6 -10
  97. data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +3 -2
  98. data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +2 -2
  99. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +3 -3
  100. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +3 -3
  101. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +3 -3
  102. data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +2 -2
  103. data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +3 -3
  104. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +1 -1
  105. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +3 -3
  106. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +3 -3
  107. data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +3 -3
  108. data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +3 -3
  109. data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +7 -11
  110. data/spec/support/max_staleness/Sharded/Incompatible.yml +4 -4
  111. data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +10 -2
  112. data/spec/support/max_staleness/Single/Incompatible.yml +4 -4
  113. data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +2 -2
  114. data/spec/support/max_staleness/Unknown/SmallMaxStaleness.yml +14 -0
  115. data/spec/support/sdam/rs/primary_mismatched_me.yml +2 -2
  116. data/spec/support/sdam/rs/secondary_mismatched_me.yml +2 -2
  117. data/spec/support/sdam_monitoring.rb +144 -0
  118. data/spec/support/sdam_monitoring/replica_set_with_no_primary.yml +112 -0
  119. data/spec/support/sdam_monitoring/replica_set_with_primary.yml +111 -0
  120. data/spec/support/sdam_monitoring/replica_set_with_removal.yml +106 -0
  121. data/spec/support/sdam_monitoring/required_replica_set.yml +84 -0
  122. data/spec/support/sdam_monitoring/standalone.yml +70 -0
  123. data/spec/support/server_discovery_and_monitoring.rb +34 -1
  124. data/spec/support/server_selection.rb +14 -11
  125. data/spec/support/shared/server_selector.rb +6 -0
  126. metadata +49 -13
  127. metadata.gz.sig +0 -0
  128. data/spec/mongo/server_discovery_and_monitoring_spec.rb +0 -115
@@ -1,14 +1,14 @@
1
- # Users can configure a shorter ``heartbeatFrequencyMS`` than the default to
2
- # allow a smaller ``maxStalenessMS`` with replica sets.
1
+ # If users configure a longer ``heartbeatFrequencyMS`` than the default,
2
+ # ``maxStalenessSeconds`` might have a larger minimum.
3
3
  ---
4
- heartbeatFrequencyMS: 1000 # 1 second.
4
+ heartbeatFrequencyMS: 120000 # 120 seconds.
5
5
  topology_description:
6
6
  type: ReplicaSetWithPrimary
7
7
  servers:
8
8
  - &1
9
9
  address: a:27017
10
10
  type: RSPrimary
11
- avg_rtt_ms: 50 # Too far.
11
+ avg_rtt_ms: 5
12
12
  lastUpdateTime: 0
13
13
  maxWireVersion: 5
14
14
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
@@ -21,9 +21,5 @@ topology_description:
21
21
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
22
  read_preference:
23
23
  mode: Nearest
24
- maxStalenessMS: 2000 # 2 seconds, permitted.
25
- suitable_servers:
26
- - *1
27
- - *2
28
- in_latency_window:
29
- - *2
24
+ maxStalenessSeconds: 129 # Too small, must be 120 + 10 = 130 seconds.
25
+ error: true
@@ -1,7 +1,8 @@
1
1
  # A driver MUST raise an error
2
2
  # if the TopologyType is ReplicaSetWithPrimary or ReplicaSetNoPrimary
3
- # and ``maxStalenessMS`` is less than twice the client's `heartbeatFrequencyMS`.
3
+ # and ``maxStalenessSeconds`` is less than 90.
4
4
  ---
5
+ heartbeatFrequencyMS: 500
5
6
  topology_description:
6
7
  type: ReplicaSetWithPrimary
7
8
  servers:
@@ -21,5 +22,5 @@ topology_description:
21
22
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
23
  read_preference:
23
24
  mode: Nearest
24
- maxStalenessMS: 1 # Too small.
25
+ maxStalenessSeconds: 89 # Too small.
25
26
  error: true
@@ -1,4 +1,4 @@
1
- # Drivers MUST raise an error if ``maxStalenessMS`` is not zero or null
1
+ # Drivers MUST raise an error if maxStalenessSeconds is defined and not -1
2
2
  # and the ``mode`` field is 'primary'.
3
3
  ---
4
4
  topology_description:
@@ -19,5 +19,5 @@ topology_description:
19
19
  maxWireVersion: 5
20
20
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
21
21
  read_preference:
22
- maxStalenessMS: 120000
22
+ maxStalenessSeconds: 120
23
23
  error: true
@@ -7,14 +7,14 @@ topology_description:
7
7
  type: RSPrimary
8
8
  avg_rtt_ms: 5
9
9
  lastUpdateTime: 0
10
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
10
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
11
11
  maxWireVersion: 5
12
12
  - &2
13
13
  address: b:27017
14
14
  type: RSSecondary
15
15
  avg_rtt_ms: 50 # Too far.
16
16
  lastUpdateTime: 0
17
- lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
17
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 125 sec stale + 25 sec heartbeat <= 150 sec maxStaleness.
18
18
  maxWireVersion: 5
19
19
  - &3
20
20
  address: c:27017
@@ -25,7 +25,7 @@ topology_description:
25
25
  maxWireVersion: 5
26
26
  read_preference:
27
27
  mode: Nearest
28
- maxStalenessMS: 50000
28
+ maxStalenessSeconds: 150
29
29
  suitable_servers:
30
30
  - *1
31
31
  - *2
@@ -7,14 +7,14 @@ topology_description:
7
7
  type: RSPrimary
8
8
  avg_rtt_ms: 50 # Too far.
9
9
  lastUpdateTime: 0
10
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
10
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
11
11
  maxWireVersion: 5
12
12
  - &2
13
13
  address: b:27017
14
14
  type: RSSecondary
15
15
  avg_rtt_ms: 5
16
16
  lastUpdateTime: 0
17
- lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
17
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 125 sec stale + 25 sec heartbeat <= 150 sec maxStaleness.
18
18
  maxWireVersion: 5
19
19
  - &3
20
20
  address: c:27017
@@ -25,7 +25,7 @@ topology_description:
25
25
  maxWireVersion: 5
26
26
  read_preference:
27
27
  mode: Nearest
28
- maxStalenessMS: 50000
28
+ maxStalenessSeconds: 150
29
29
  suitable_servers:
30
30
  - *1
31
31
  - *2
@@ -1,4 +1,4 @@
1
- # maxStalenessMS is applied before tag sets. With tag sets
1
+ # maxStalenessSeconds is applied before tag sets. With tag sets
2
2
  # [{data_center: nyc}, {data_center: tokyo}], if the only node in NYC is stale
3
3
  # then use Tokyo.
4
4
  ---
@@ -11,7 +11,7 @@ topology_description:
11
11
  type: RSPrimary
12
12
  avg_rtt_ms: 5
13
13
  lastUpdateTime: 0
14
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
14
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
15
15
  maxWireVersion: 5
16
16
  tags:
17
17
  data_center: tokyo
@@ -26,7 +26,7 @@ topology_description:
26
26
  data_center: nyc
27
27
  read_preference:
28
28
  mode: Nearest
29
- maxStalenessMS: 50000
29
+ maxStalenessSeconds: 150
30
30
  tag_sets:
31
31
  - data_center: nyc
32
32
  - data_center: tokyo
@@ -1,4 +1,4 @@
1
- # Ignore maxStalenessMS is primary is available.
1
+ # Ignore maxStalenessSeconds if primary is available.
2
2
  ---
3
3
  heartbeatFrequencyMS: 25000 # 25 seconds.
4
4
  topology_description:
@@ -20,7 +20,7 @@ topology_description:
20
20
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
21
21
  read_preference:
22
22
  mode: PrimaryPreferred
23
- maxStalenessMS: 50000
23
+ maxStalenessSeconds: 150
24
24
  suitable_servers:
25
25
  - *1
26
26
  in_latency_window:
@@ -1,6 +1,6 @@
1
1
  # Primary has wire version 5, secondary has 4, read preference primaryPreferred
2
- # with maxStalenessMS. The client must error, even though it uses primary and
3
- # never applies maxStalenessMS. Proves that the compatibility check precedes
2
+ # with maxStalenessSeconds. The client must error, even though it uses primary and
3
+ # never applies maxStalenessSeconds. Proves that the compatibility check precedes
4
4
  # filtration.
5
5
  ---
6
6
  topology_description:
@@ -22,6 +22,6 @@ topology_description:
22
22
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
23
23
  read_preference:
24
24
  mode: PrimaryPreferred
25
- maxStalenessMS: 50000
25
+ maxStalenessSeconds: 150
26
26
  error: true
27
27
 
@@ -19,7 +19,7 @@ topology_description:
19
19
  lastWrite: {lastWriteDate: {$numberLong: "1"}} # Very stale.
20
20
  read_preference:
21
21
  mode: SecondaryPreferred
22
- maxStalenessMS: 120000
22
+ maxStalenessSeconds: 120
23
23
  suitable_servers:
24
24
  - *1
25
25
  in_latency_window:
@@ -10,14 +10,14 @@ topology_description:
10
10
  avg_rtt_ms: 5
11
11
  lastUpdateTime: 0
12
12
  maxWireVersion: 5
13
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
13
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
14
14
  - &2
15
15
  address: b:27017
16
16
  type: RSSecondary
17
17
  avg_rtt_ms: 5
18
18
  lastUpdateTime: 0
19
19
  maxWireVersion: 5
20
- lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
20
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 125 sec stale + 25 sec heartbeat <= 150 sec maxStaleness.
21
21
  tags:
22
22
  data_center: nyc
23
23
  - &3
@@ -49,7 +49,7 @@ topology_description:
49
49
  data_center: tokyo # No match.
50
50
  read_preference:
51
51
  mode: SecondaryPreferred
52
- maxStalenessMS: 50000
52
+ maxStalenessSeconds: 150
53
53
  tag_sets:
54
54
  - data_center: nyc
55
55
  suitable_servers:
@@ -1,4 +1,4 @@
1
- # maxStalenessMS is applied before tag sets. With tag sets
1
+ # maxStalenessSeconds is applied before tag sets. With tag sets
2
2
  # [{data_center: nyc}, {data_center: tokyo}], if the only secondary in NYC is
3
3
  # stale then use Tokyo.
4
4
  ---
@@ -11,7 +11,7 @@ topology_description:
11
11
  type: RSPrimary
12
12
  avg_rtt_ms: 5
13
13
  lastUpdateTime: 0
14
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
14
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
15
15
  maxWireVersion: 5
16
16
  - &2
17
17
  address: b:27017
@@ -33,7 +33,7 @@ topology_description:
33
33
  data_center: nyc
34
34
  read_preference:
35
35
  mode: SecondaryPreferred
36
- maxStalenessMS: 50000
36
+ maxStalenessSeconds: 150
37
37
  tag_sets:
38
38
  - data_center: nyc
39
39
  - data_center: tokyo
@@ -10,14 +10,14 @@ topology_description:
10
10
  avg_rtt_ms: 5
11
11
  lastUpdateTime: 0
12
12
  maxWireVersion: 5
13
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
13
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
14
14
  - &2
15
15
  address: b:27017
16
16
  type: RSSecondary
17
17
  avg_rtt_ms: 5
18
18
  lastUpdateTime: 0
19
19
  maxWireVersion: 5
20
- lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
20
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 125 sec stale + 25 sec heartbeat <= 150 sec maxStaleness.
21
21
  tags:
22
22
  data_center: nyc
23
23
  - &3
@@ -49,7 +49,7 @@ topology_description:
49
49
  data_center: tokyo # No match.
50
50
  read_preference:
51
51
  mode: Secondary
52
- maxStalenessMS: 50000
52
+ maxStalenessSeconds: 150
53
53
  tag_sets:
54
54
  - data_center: nyc
55
55
  suitable_servers:
@@ -1,4 +1,4 @@
1
- # maxStalenessMS is applied before tag sets. With tag sets
1
+ # maxStalenessSeconds is applied before tag sets. With tag sets
2
2
  # [{data_center: nyc}, {data_center: tokyo}], if the only secondary in NYC is
3
3
  # stale then use Tokyo.
4
4
  ---
@@ -11,7 +11,7 @@ topology_description:
11
11
  type: RSPrimary
12
12
  avg_rtt_ms: 5
13
13
  lastUpdateTime: 0
14
- lastWrite: {lastWriteDate: {$numberLong: "25002"}}
14
+ lastWrite: {lastWriteDate: {$numberLong: "125002"}}
15
15
  maxWireVersion: 5
16
16
  - &2
17
17
  address: b:27017
@@ -33,7 +33,7 @@ topology_description:
33
33
  data_center: nyc
34
34
  read_preference:
35
35
  mode: Secondary
36
- maxStalenessMS: 50000
36
+ maxStalenessSeconds: 150
37
37
  tag_sets:
38
38
  - data_center: nyc
39
39
  - data_center: tokyo
@@ -1,4 +1,4 @@
1
- # A ``maxStalenessMS`` of zero or null MUST mean "no maximum".
1
+ # maxStalenessSeconds=0 is prohibited.
2
2
  ---
3
3
  topology_description:
4
4
  type: ReplicaSetWithPrimary
@@ -6,22 +6,18 @@ topology_description:
6
6
  - &1
7
7
  address: a:27017
8
8
  type: RSPrimary
9
- avg_rtt_ms: 50 # Too far.
9
+ avg_rtt_ms: 5
10
10
  lastUpdateTime: 0
11
11
  maxWireVersion: 5
12
- lastWrite: {lastWriteDate: {$numberLong: "1000001"}}
12
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
13
13
  - &2
14
14
  address: b:27017
15
15
  type: RSSecondary
16
16
  avg_rtt_ms: 5
17
17
  lastUpdateTime: 0
18
- maxWireVersion: 5
19
- lastWrite: {lastWriteDate: {$numberLong: "1"}} # Very stale.
18
+ maxWireVersion: 4 # Incompatible.
19
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
20
20
  read_preference:
21
21
  mode: Nearest
22
- maxStalenessMS: 0 # Means "no max staleness".
23
- suitable_servers: # Very stale server is fine.
24
- - *1
25
- - *2
26
- in_latency_window:
27
- - *2
22
+ maxStalenessSeconds: 0
23
+ error: true
@@ -1,6 +1,6 @@
1
- # During server selection,
2
- # clients (drivers or mongos) MUST raise an error if ``maxStalenessMS`` is not zero or null,
3
- # and any server's ``maxWireVersion`` is less than 5 (`SERVER-23893`_).
1
+ # During server selection, clients (drivers or mongos) MUST raise an error if
2
+ # maxStalenessSeconds is defined and not -1 and any server's ``maxWireVersion``
3
+ # is less than 5 (`SERVER-23893`_).
4
4
  ---
5
5
  topology_description:
6
6
  type: Sharded
@@ -21,5 +21,5 @@ topology_description:
21
21
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
22
  read_preference:
23
23
  mode: Nearest
24
- maxStalenessMS: 120000
24
+ maxStalenessSeconds: 120
25
25
  error: true
@@ -1,4 +1,4 @@
1
- # Driver doesn't validate maxStalenessMS for mongos
1
+ # Driver doesn't validate maxStalenessSeconds for mongos
2
2
  ---
3
3
  heartbeatFrequencyMS: 10000
4
4
  topology_description:
@@ -11,10 +11,18 @@ topology_description:
11
11
  lastUpdateTime: 0
12
12
  maxWireVersion: 5
13
13
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
14
+ - &2
15
+ address: b:27017
16
+ type: Mongos
17
+ avg_rtt_ms: 50 # Too far.
18
+ lastUpdateTime: 0
19
+ maxWireVersion: 5
20
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
14
21
  read_preference:
15
22
  mode: Nearest
16
- maxStalenessMS: 1 # OK for sharding.
23
+ maxStalenessSeconds: 1 # OK for sharding.
17
24
  suitable_servers:
18
25
  - *1
26
+ - *2
19
27
  in_latency_window:
20
28
  - *1
@@ -1,6 +1,6 @@
1
- # During server selection,
2
- # clients (drivers or mongos) MUST raise an error if ``maxStalenessMS`` is not zero or null,
3
- # and any server's ``maxWireVersion`` is less than 5 (`SERVER-23893`_).
1
+ # During server selection, clients (drivers or mongos) MUST raise an error if
2
+ # maxStalenessSeconds is defined and not -1 and any server's ``maxWireVersion``
3
+ # is less than 5 (`SERVER-23893`_).
4
4
  ---
5
5
  topology_description:
6
6
  type: Single
@@ -14,5 +14,5 @@ topology_description:
14
14
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
15
15
  read_preference:
16
16
  mode: Nearest
17
- maxStalenessMS: 120000
17
+ maxStalenessSeconds: 120
18
18
  error: true
@@ -1,4 +1,4 @@
1
- # Driver doesn't validate maxStalenessMS for direct connection.
1
+ # Driver doesn't validate maxStalenessSeconds for direct connection.
2
2
  ---
3
3
  heartbeatFrequencyMS: 10000
4
4
  topology_description:
@@ -13,7 +13,7 @@ topology_description:
13
13
  lastWrite: {lastWriteDate: {$numberLong: "1"}}
14
14
  read_preference:
15
15
  mode: Nearest
16
- maxStalenessMS: 1
16
+ maxStalenessSeconds: 1
17
17
  suitable_servers:
18
18
  - *1
19
19
  in_latency_window:
@@ -0,0 +1,14 @@
1
+ # Driver doesn't validate maxStalenessSeconds while TopologyType is Unknown.
2
+ ---
3
+ heartbeatFrequencyMS: 10000
4
+ topology_description:
5
+ type: Unknown
6
+ servers:
7
+ - &1
8
+ address: a:27017
9
+ type: Unknown
10
+ read_preference:
11
+ mode: Nearest
12
+ maxStalenessSeconds: 1
13
+ suitable_servers: []
14
+ in_latency_window: []
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "responses": [
20
20
  [
21
- "localhost:27017",
21
+ "lhost:27017",
22
22
  {
23
23
  "me": "a:27017",
24
24
  "hosts": [
@@ -33,5 +33,5 @@
33
33
  ]
34
34
  }
35
35
  ],
36
- "uri": "mongodb://localhost:27017/?replicaSet=rs"
36
+ "uri": "mongodb://lhost:27017/?replicaSet=rs"
37
37
  }
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "responses": [
20
20
  [
21
- "localhost:27017",
21
+ "lhost:27017",
22
22
  {
23
23
  "me": "a:27017",
24
24
  "hosts": [
@@ -33,5 +33,5 @@
33
33
  ]
34
34
  }
35
35
  ],
36
- "uri": "mongodb://localhost:27017/?replicaSet=rs"
36
+ "uri": "mongodb://lhost:27017/?replicaSet=rs"
37
37
  }
@@ -0,0 +1,144 @@
1
+ # Copyright (C) 2014-2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+
16
+ RSpec::Matchers.define :match_topology_opening_event do |expectation|
17
+
18
+ match do |event|
19
+ event.topology != nil
20
+ end
21
+ end
22
+
23
+ RSpec::Matchers.define :match_topology_description_changed_event do |expectation|
24
+ include Mongo::SDAMMonitoring::Matchable
25
+
26
+ match do |event|
27
+ topologies_match?(event, expectation)
28
+ end
29
+ end
30
+
31
+ RSpec::Matchers.define :match_server_opening_event do |expectation|
32
+
33
+ match do |event|
34
+ true
35
+ end
36
+ end
37
+
38
+ RSpec::Matchers.define :match_server_description_changed_event do |expectation|
39
+ include Mongo::SDAMMonitoring::Matchable
40
+
41
+ match do |event|
42
+ descriptions_match?(event, expectation)
43
+ end
44
+ end
45
+
46
+ RSpec::Matchers.define :match_server_closed_event do |expectation|
47
+
48
+ match do |event|
49
+ event.address.to_s == expectation.data['address']
50
+ end
51
+ end
52
+
53
+ RSpec::Matchers.define :match_sdam_monitoring_event do |expectation|
54
+
55
+ match do |event|
56
+ expect(event).to send("match_#{expectation.name}", expectation)
57
+ end
58
+ end
59
+
60
+ module Mongo
61
+ module SDAMMonitoring
62
+ module Matchable
63
+
64
+ def descriptions_match?(event, expectation)
65
+ description_matches?(event.previous_description, expectation.data['previousDescription']) &&
66
+ description_matches?(event.new_description, expectation.data['newDescription'])
67
+ end
68
+
69
+ def topologies_match?(event, expectation)
70
+ topology_matches?(event.previous_topology, expectation.data['previousDescription']) &&
71
+ topology_matches?(event.new_topology, expectation.data['newDescription'])
72
+ end
73
+
74
+ def description_matches?(actual, expected)
75
+ case expected['type']
76
+ when 'Standalone' then actual.standalone?
77
+ when 'RSPrimary' then actual.primary?
78
+ when 'RSSecondary' then actual.secondary?
79
+ when 'RSArbiter' then actual.arbiter?
80
+ when 'Mongos' then actual.mongos?
81
+ when 'Unknown' then actual.unknown?
82
+ when 'PossiblePrimary' then actual.unknown?
83
+ when 'RSGhost' then actual.ghost?
84
+ when 'RSOther' then actual.other?
85
+ end
86
+ end
87
+
88
+ def topology_matches?(actual, expected)
89
+ case expected['topologyType']
90
+ when 'ReplicaSetWithPrimary' then actual.replica_set?
91
+ when 'ReplicaSetNoPrimary' then (actual.replica_set? || actual.unknown?)
92
+ when 'Sharded' then actual.sharded?
93
+ when 'Single' then actual.single?
94
+ when 'Unknown' then actual.unknown?
95
+ end
96
+ end
97
+ end
98
+
99
+ # Test subscriber for SDAM monitoring.
100
+ #
101
+ # @since 2.4.0
102
+ class TestSubscriber
103
+
104
+ # The mappings of event names to types.
105
+ #
106
+ # @since 2.4.0
107
+ MAPPINGS = {
108
+ 'topology_opening_event' => Mongo::Monitoring::Event::TopologyOpening,
109
+ 'topology_description_changed_event' => Mongo::Monitoring::Event::TopologyChanged,
110
+ 'server_opening_event' => Mongo::Monitoring::Event::ServerOpening,
111
+ 'server_description_changed_event' => Mongo::Monitoring::Event::ServerDescriptionChanged,
112
+ 'server_closed_event' => Mongo::Monitoring::Event::ServerClosed
113
+ }.freeze
114
+
115
+ # Implement the succeeded event.
116
+ #
117
+ # @param [ Event ] event The event.
118
+ #
119
+ # @since 2.4.0
120
+ def succeeded(event)
121
+ events.push(event)
122
+ end
123
+
124
+ # Get the first event fired for the name, and then delete it.
125
+ #
126
+ # @param [ String ] name The event name.
127
+ #
128
+ # @return [ Event ] The matching event.
129
+ def first_event(name)
130
+ matching = events.find do |event|
131
+ event.class == MAPPINGS[name]
132
+ end
133
+ events.delete(matching)
134
+ matching
135
+ end
136
+
137
+ private
138
+
139
+ def events
140
+ @events ||= []
141
+ end
142
+ end
143
+ end
144
+ end