Skip to content

Commit bb78598

Browse files
committed
CSHARP-2357: Add ReadConcern Available.
1 parent 7d8df8c commit bb78598

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

src/MongoDB.Driver.Core/ReadConcern.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ namespace MongoDB.Driver
2525
/// </summary>
2626
public sealed class ReadConcern : IEquatable<ReadConcern>, IConvertibleToBsonDocument
2727
{
28+
private static readonly ReadConcern __available = new ReadConcern(ReadConcernLevel.Available);
2829
private static readonly ReadConcern __default = new ReadConcern();
2930
private static readonly ReadConcern __linearizable = new ReadConcern(ReadConcernLevel.Linearizable);
3031
private static readonly ReadConcern __local = new ReadConcern(ReadConcernLevel.Local);
3132
private static readonly ReadConcern __majority = new ReadConcern(ReadConcernLevel.Majority);
3233
private static readonly ReadConcern __snapshot = new ReadConcern(ReadConcernLevel.Snapshot);
34+
35+
/// <summary>
36+
/// Gets an available read concern.
37+
/// </summary>
38+
public static ReadConcern Available => __available;
39+
3340
/// <summary>
3441
/// Gets a default read concern.
3542
/// </summary>
@@ -70,6 +77,8 @@ public static ReadConcern FromBsonDocument(BsonDocument document)
7077
var level = (ReadConcernLevel)Enum.Parse(typeof(ReadConcernLevel), (string)levelValue, true);
7178
switch (level)
7279
{
80+
case ReadConcernLevel.Available:
81+
return ReadConcern.Available;
7382
case ReadConcernLevel.Linearizable:
7483
return ReadConcern.Linearizable;
7584
case ReadConcernLevel.Local:
@@ -155,6 +164,9 @@ public BsonDocument ToBsonDocument()
155164
{
156165
switch (_level.Value)
157166
{
167+
case ReadConcernLevel.Available:
168+
level = "available";
169+
break;
158170
case ReadConcernLevel.Linearizable:
159171
level = "linearizable";
160172
break;

src/MongoDB.Driver.Core/ReadConcernLevel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace MongoDB.Driver
2626
/// </summary>
2727
public enum ReadConcernLevel
2828
{
29+
/// <summary>
30+
/// Reads available data.
31+
/// </summary>
32+
Available,
33+
2934
/// <summary>
3035
/// Reads data committed locally.
3136
/// </summary>

tests/MongoDB.Driver.Core.Tests/Core/Configuration/ConnectionStringTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,11 @@ public void When_password_is_specified(string connectionString, string password)
666666
}
667667

668668
[Theory]
669+
[InlineData("mongodb://localhost?readConcernLevel=available", ReadConcernLevel.Available)]
670+
[InlineData("mongodb://localhost?readConcernLevel=linearizable", ReadConcernLevel.Linearizable)]
669671
[InlineData("mongodb://localhost?readConcernLevel=local", ReadConcernLevel.Local)]
670672
[InlineData("mongodb://localhost?readConcernLevel=majority", ReadConcernLevel.Majority)]
673+
[InlineData("mongodb://localhost?readConcernLevel=snapshot", ReadConcernLevel.Snapshot)]
671674
public void When_readConcernLevel_is_specified(string connectionString, ReadConcernLevel readConcernLevel)
672675
{
673676
var subject = new ConnectionString(connectionString);

tests/MongoDB.Driver.Core.Tests/ReadConcernTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ namespace MongoDB.Driver
2828
{
2929
public class ReadConcernTests
3030
{
31+
[Fact]
32+
public void Available_should_return_expected_result()
33+
{
34+
var result = ReadConcern.Available;
35+
36+
result.Level.Should().Be(ReadConcernLevel.Available);
37+
}
38+
3139
[Fact]
3240
public void Default_should_return_expected_result()
3341
{
@@ -103,6 +111,7 @@ public void Equals_should_return_true_when_level_is_equal()
103111
}
104112

105113
[Theory]
114+
[InlineData(ReadConcernLevel.Available, "{ level: 'available' }")]
106115
[InlineData(ReadConcernLevel.Linearizable, "{ level: 'linearizable' }")]
107116
[InlineData(ReadConcernLevel.Local, "{ level: 'local' }")]
108117
[InlineData(ReadConcernLevel.Majority, "{ level: 'majority' }")]

tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,11 @@ public void TestMinConnectionPoolSize_Range()
802802
}
803803

804804
[Theory]
805+
[InlineData("mongodb://localhost/?readConcernLevel=available", ReadConcernLevel.Available)]
806+
[InlineData("mongodb://localhost/?readConcernLevel=linearizable", ReadConcernLevel.Linearizable)]
805807
[InlineData("mongodb://localhost/?readConcernLevel=local", ReadConcernLevel.Local)]
806808
[InlineData("mongodb://localhost/?readConcernLevel=majority", ReadConcernLevel.Majority)]
809+
[InlineData("mongodb://localhost/?readConcernLevel=snapshot", ReadConcernLevel.Snapshot)]
807810
public void TestReadConcernLevel(string connectionString, ReadConcernLevel readConcernLevel)
808811
{
809812
var built = new MongoUrlBuilder { ReadConcernLevel = readConcernLevel };

0 commit comments

Comments
 (0)