File tree Expand file tree Collapse file tree 5 files changed +34
-7
lines changed Expand file tree Collapse file tree 5 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,23 @@ public ReadOnlyCollection<MongoServerInstance> Instances
96
96
}
97
97
}
98
98
99
+ /// <summary>
100
+ /// Gets the name of the replica set (null if not connected to a replica set).
101
+ /// </summary>
102
+ public string ReplicaSetName
103
+ {
104
+ get
105
+ {
106
+ var replicaSetProxy = _serverProxy as ReplicaSetMongoServerProxy ;
107
+ if ( replicaSetProxy != null )
108
+ {
109
+ return replicaSetProxy . ReplicaSetName ;
110
+ }
111
+
112
+ return null ;
113
+ }
114
+ }
115
+
99
116
/// <summary>
100
117
/// Gets the state.
101
118
/// </summary>
Original file line number Diff line number Diff line change @@ -1780,7 +1780,7 @@ private TCommandResult RunCommandAs<TCommandResult>(
1780
1780
resultSerializationOptions ,
1781
1781
resultSerializer ) ;
1782
1782
1783
- var connection = _server . AcquireConnection ( ReadPreference . Primary ) ;
1783
+ var connection = _server . AcquireConnection ( readPreference ) ;
1784
1784
try
1785
1785
{
1786
1786
return commandOperation . Execute ( connection ) ;
Original file line number Diff line number Diff line change @@ -295,10 +295,16 @@ public virtual string ReplicaSetName
295
295
{
296
296
get
297
297
{
298
- var instanceManager = _serverProxy as ReplicaSetMongoServerProxy ;
299
- if ( instanceManager != null )
298
+ var replicaSetProxy = _serverProxy as ReplicaSetMongoServerProxy ;
299
+ if ( replicaSetProxy != null )
300
300
{
301
- return instanceManager . ReplicaSetName ;
301
+ return replicaSetProxy . ReplicaSetName ;
302
+ }
303
+
304
+ var discoveringProxy = _serverProxy as DiscoveringMongoServerProxy ;
305
+ if ( discoveringProxy != null )
306
+ {
307
+ return discoveringProxy . ReplicaSetName ;
302
308
}
303
309
304
310
return null ;
Original file line number Diff line number Diff line change 18
18
using System . Text ;
19
19
using System . Threading ;
20
20
using MongoDB . Driver ;
21
+ using MongoDB . Driver . GridFS ;
21
22
using NUnit . Framework ;
23
+ using MongoDB . Driver . Builders ;
22
24
23
25
namespace MongoDB . DriverUnitTests . Jira . CSharp269
24
26
{
@@ -43,19 +45,21 @@ public void TestFixtureSetup()
43
45
[ Test ]
44
46
public void TestUploadAndDownload ( )
45
47
{
48
+ MongoGridFSFileInfo uploadedFileInfo ;
49
+
46
50
var text = "HelloWorld" ;
47
51
var bytes = Encoding . UTF8 . GetBytes ( text ) ;
48
52
using ( var stream = new MemoryStream ( bytes ) )
49
53
{
50
- _database . GridFS . Upload ( stream , "HelloWorld.txt" ) ;
54
+ uploadedFileInfo = _database . GridFS . Upload ( stream , "HelloWorld.txt" ) ;
51
55
}
52
56
53
57
// use RequestStart so that if we are running this test against a replica set we will bind to a specific secondary
54
58
using ( _server . RequestStart ( _database , ReadPreference . SecondaryPreferred ) )
55
59
{
56
60
// wait for the GridFS file to be replicated before trying to Download it
57
61
var timeoutAt = DateTime . UtcNow . AddSeconds ( 30 ) ;
58
- while ( ! _database . GridFS . Exists ( "HelloWorld.txt" ) )
62
+ while ( ! _database . GridFS . Exists ( Query . EQ ( "_id" , uploadedFileInfo . Id ) ) )
59
63
{
60
64
if ( DateTime . UtcNow >= timeoutAt )
61
65
{
Original file line number Diff line number Diff line change @@ -218,7 +218,7 @@ public void TestPrimary()
218
218
public void TestReconnect ( )
219
219
{
220
220
_server . Reconnect ( ) ;
221
- Assert . AreEqual ( MongoServerState . Connected , _server . State ) ;
221
+ Assert . IsTrue ( _server . State == MongoServerState . Connected || _server . State == MongoServerState . ConnectedToSubset ) ;
222
222
}
223
223
224
224
[ Test ]
You can’t perform that action at this time.
0 commit comments