public void Execute_should_send_session_id_when_supported( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); VerifySessionIdWasSentWhenSupported(subject, "mapreduce", async); }
public void CreateOutputOptions_should_return_expected_result() { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); var subjectReflector = new Reflector(subject); var result = subjectReflector.CreateOutputOptions(); result.Should().Be("{ inline : 1 }"); }
public void ResultSerializer_should_get_value() { #pragma warning disable CS0618 // Type or member is obsolete var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); #pragma warning restore CS0618 // Type or member is obsolete var result = subject.ResultSerializer; result.Should().BeSameAs(_resultSerializer); }
public void Execute_should_throw_when_binding_is_null( [Values(false, true)] bool async) { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); Action act = () => ExecuteOperation(subject, null, async); act.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("binding"); }
public void ReadConcern_set_should_throw_when_value_is_null() { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); var exception = Record.Exception(() => subject.ReadConcern = null); var argumentNullException = exception.Should().BeOfType <ArgumentNullException>().Subject; argumentNullException.ParamName.Should().Be("value"); }
public void CreateOutputOptions_should_return_expected_result() { #pragma warning disable CS0618 // Type or member is obsolete var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); #pragma warning restore CS0618 // Type or member is obsolete var subjectReflector = new Reflector(subject); var result = subjectReflector.CreateOutputOptions(); result.Should().Be("{ inline : 1 }"); }
public void CreateCommand_should_throw_when_ReadConcern_is_set_but_not_supported() { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = ReadConcern.Majority }; var exception = Record.Exception(() => subject.CreateCommand(Feature.ReadConcern.LastNotSupportedVersion)); exception.Should().BeOfType <MongoClientException>(); }
public void constructor_should_initialize_instance() { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace); subject.MapFunction.Should().BeSameAs(_mapFunction); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); subject.Filter.Should().BeNull(); subject.ReduceFunction.Should().BeSameAs(_reduceFunction); subject.ResultSerializer.Should().BeSameAs(_resultSerializer); }
public void Execute_should_throw_when_binding_is_null( [Values(false, true)] bool async) { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); var exception = Record.Exception(() => ExecuteOperation(subject, (IReadBinding)null, async)); var argumentNullException = exception.Should().BeOfType <ArgumentNullException>().Subject; argumentNullException.ParamName.Should().Be("binding"); }
public void ReadConcern_get_and_set_should_work( [Values(ReadConcernLevel.Linearizable, ReadConcernLevel.Local)] ReadConcernLevel level) { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); var value = new ReadConcern(level); subject.ReadConcern = value; var result = subject.ReadConcern; result.Should().Be(value); }
public void CreateCommand_should_throw_when_read_concern_is_not_supported() { var mapFunction = "function() { emit(this.x, this.v); }"; var reduceFunction = "function(key, values) { var sum = 0; for (var i = 0; i < values.length; i++) { sum += values[i]; }; return sum; }"; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, mapFunction, reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = ReadConcern.Majority }; Action act = () => subject.CreateCommand(new SemanticVersion(3, 0, 0)); act.ShouldThrow <MongoClientException>(); }
// constructors public Builder(MapReduceOperation other) { _collectionName = other.CollectionName; _databaseName = other.DatabaseName; _finalizeFunction = other.FinalizeFunction; _javaScriptMode = other.JavaScriptMode; _limit = other.Limit; _mapFunction = other.MapFunction; _query = other.Query; _reduceFunction = other.ReduceFunction; _scope = other.Scope; _sort = other.Sort; _verbose = other.Verbose; }
public void Execute_should_return_expected_results_when_ResultSerializer_is_set( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var resultSerializer = new ElementDeserializer <double>("value", new DoubleSerializer()); var subject = new MapReduceOperation <double>(_collectionNamespace, _mapFunction, _reduceFunction, resultSerializer, _messageEncoderSettings); var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().Equal(3, 4); }
public void Execute_should_return_expected_results( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().Equal( BsonDocument.Parse("{ _id : 1, value : 3 }"), BsonDocument.Parse("{ _id : 2, value : 4 }")); }
public void Execute_should_throw_when_maxTime_is_exceeded( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet); var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); subject.MaxTime = TimeSpan.FromSeconds(9001); using (var failPoint = FailPoint.ConfigureAlwaysOn(_cluster, _session, FailPointName.MaxTimeAlwaysTimeout)) { var exception = Record.Exception(() => ExecuteOperation(subject, failPoint.Binding, async)); exception.Should().BeOfType <MongoExecutionTimeoutException>(); } }
public void Execute_should_throw_when_ReadConcern_is_set_but_not_supported( [Values(false, true)] bool async) { RequireServer.Check().DoesNotSupport(Feature.ReadConcern); EnsureTestData(); var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = new ReadConcern(ReadConcernLevel.Local) }; var exception = Record.Exception(() => ExecuteOperation(subject, async)); exception.Should().BeOfType <MongoClientException>(); }
public void Execute_should_return_expected_results_when_FinalizeFunction_is_set( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var finalizeFunction = new BsonJavaScript("function(key, reduced) { return -reduced; }"); var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { FinalizeFunction = finalizeFunction }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().Equal( BsonDocument.Parse("{ _id : 1, value : -3 }"), BsonDocument.Parse("{ _id : 2, value : -4 }")); }
public void Execute_should_return_expected_results_when_Collation_is_set( [Values(false, true)] bool caseSensitive, [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var collation = new Collation("en_US", caseLevel: caseSensitive, strength: CollationStrength.Primary); var filter = BsonDocument.Parse("{ y : 'a' }"); #pragma warning disable CS0618 // Type or member is obsolete var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) #pragma warning restore CS0618 // Type or member is obsolete { Collation = collation, Filter = filter }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); BsonDocument[] expectedResults; if (caseSensitive) { expectedResults = new[] { BsonDocument.Parse("{ _id : 1, value : 1 }"), BsonDocument.Parse("{ _id : 2, value : 4 }") }; } else { expectedResults = new[] { BsonDocument.Parse("{ _id : 1, value : 3 }"), BsonDocument.Parse("{ _id : 2, value : 4 }") }; } results.Should().BeEquivalentTo(expectedResults); }
public void constructor_should_initialize_instance() { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings); subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace); subject.MapFunction.Should().BeSameAs(_mapFunction); subject.ReduceFunction.Should().BeSameAs(_reduceFunction); subject.ResultSerializer.Should().BeSameAs(_resultSerializer); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); subject.Collation.Should().BeNull(); subject.Filter.Should().BeNull(); subject.FinalizeFunction.Should().BeNull(); subject.JavaScriptMode.Should().NotHaveValue(); subject.Limit.Should().NotHaveValue(); subject.MaxTime.Should().NotHaveValue(); subject.ReadConcern.Should().BeSameAs(ReadConcern.Default); subject.Scope.Should().BeNull(); subject.Sort.Should().BeNull(); subject.Verbose.Should().NotHaveValue(); }
public void Execute_should_return_expected_results_when_MaxTime_is_set( [Values(null, 1000)] int?seconds, [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.MaxTime); EnsureTestData(); var maxTime = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { MaxTime = maxTime }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); // results should be the same whether MaxTime was used or not results.Should().Equal( BsonDocument.Parse("{ _id : 1, value : 3 }"), BsonDocument.Parse("{ _id : 2, value : 4 }")); }
public void Execute_should_return_expected_results_when_Sort_is_set( [Values(1, -1)] int direction, [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var sort = new BsonDocument("_id", direction); #pragma warning disable CS0618 // Type or member is obsolete var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) #pragma warning restore CS0618 // Type or member is obsolete { Limit = 2, Sort = sort }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); BsonDocument[] expectedResults; if (direction == 1) { expectedResults = new[] { BsonDocument.Parse("{ _id : 1, value : 3 }") }; } else { expectedResults = new[] { BsonDocument.Parse("{ _id : 1, value : 2 }"), BsonDocument.Parse("{ _id : 2, value : 4 }") }; } results.Should().BeEquivalentTo(expectedResults); }
public void CreateCommand_should_include_read_concern_when_appropriate( [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel) { var readConcern = new ReadConcern(readConcernLevel); var mapFunction = "function() { emit(this.x, this.v); }"; var reduceFunction = "function(key, values) { var sum = 0; for (var i = 0; i < values.length; i++) { sum += values[i]; }; return sum; }"; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, mapFunction, reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var command = subject.CreateCommand(new SemanticVersion(3, 2, 0)); if (readConcern.IsServerDefault) { command.Contains("readConcern").Should().BeFalse(); } else { command["readConcern"].Should().Be(readConcern.ToBsonDocument()); } }
public void Execute_should_return_expected_results_when_ReadConcern_is_set( [Values(null, ReadConcernLevel.Local)] // only use values that are valid on StandAlone servers ReadConcernLevel?readConcernLevel, [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.ReadConcern); EnsureTestData(); var readConcern = new ReadConcern(readConcernLevel); var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; // results should be the same whether ReadConcern was used or not var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().Equal( BsonDocument.Parse("{ _id : 1, value : 3 }"), BsonDocument.Parse("{ _id : 2, value : 4 }")); }
public void Execute_should_return_expected_results_when_Filter_is_set( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var filter = BsonDocument.Parse("{ y : 'a' }"); #pragma warning disable CS0618 // Type or member is obsolete var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) #pragma warning restore CS0618 // Type or member is obsolete { Filter = filter }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().BeEquivalentTo( BsonDocument.Parse("{ _id : 1, value : 1 }"), BsonDocument.Parse("{ _id : 2, value : 4 }")); }
public async Task ExecuteAsync_should_return_expected_results() { await EnsureTestDataAsync(); var mapFunction = "function() { emit(this.x, this.v); }"; var reduceFunction = "function(key, values) { var sum = 0; for (var i = 0; i < values.length; i++) { sum += values[i]; }; return sum; }"; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, mapFunction, reduceFunction, _resultSerializer, _messageEncoderSettings); var expectedResults = new List <BsonDocument> { new BsonDocument { { "_id", 1 }, { "value", 3 } }, new BsonDocument { { "_id", 2 }, { "value", 4 } }, }; var cursor = await ExecuteOperationAsync(subject); var results = await cursor.ToListAsync(); results.Should().Equal(expectedResults); }
public void CreateCommand_should_return_expected_result_when_ReadConcern_is_set( [Values(null, ReadConcernLevel.Linearizable, ReadConcernLevel.Local)] ReadConcernLevel?level) { var readConcern = level.HasValue ? new ReadConcern(level.Value) : ReadConcern.Default; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var result = subject.CreateCommand(Feature.ReadConcern.FirstSupportedVersion); var expectedResult = new BsonDocument { { "mapreduce", _collectionNamespace.CollectionName }, { "map", _mapFunction }, { "reduce", _reduceFunction }, { "out", new BsonDocument("inline", 1) }, { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault } }; result.Should().Be(expectedResult); }
public void Execute_should_return_expected_results( [Values(false, true)] bool async) { EnsureTestData(); var mapFunction = "function() { emit(this.x, this.v); }"; var reduceFunction = "function(key, values) { var sum = 0; for (var i = 0; i < values.length; i++) { sum += values[i]; }; return sum; }"; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, mapFunction, reduceFunction, _resultSerializer, _messageEncoderSettings); var expectedResults = new List <BsonDocument> { new BsonDocument { { "_id", 1 }, { "value", 3 } }, new BsonDocument { { "_id", 2 }, { "value", 4 } }, }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().Equal(expectedResults); }
public void Execute_should_return_expected_results_when_Scope_is_set( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var finalizeFunction = new BsonJavaScript("function(key, reduced) { return reduced + zeroFromScope; }"); var scope = new BsonDocument("zeroFromScope", 0); #pragma warning disable CS0618 // Type or member is obsolete var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) #pragma warning restore CS0618 // Type or member is obsolete { FinalizeFunction = finalizeFunction, Scope = scope }; var cursor = ExecuteOperation(subject, async); var results = ReadCursorToEnd(cursor, async); results.Should().BeEquivalentTo( BsonDocument.Parse("{ _id : 1, value : 3 }"), BsonDocument.Parse("{ _id : 2, value : 4 }")); }
// constructor public Reflector(MapReduceOperation <BsonDocument> instance) { _instance = instance; }