예제 #1
0
        public void ExpandCapacity_should_throw_when_expanded_capacity_exceeds_2GB()
        {
            RequireProcess.Is64Bit();

            using (var subject = new MultiChunkBuffer(BsonChunkPool.Default))
            {
                subject.EnsureCapacity(int.MaxValue - 128 * 1024 * 1024);

                Action action = () => subject.EnsureCapacity(int.MaxValue); // indirectly calls private ExpandCapacity method

                action.ShouldThrow <InvalidOperationException>();
            }
        }
예제 #2
0
        public void TestLargeDocumentDeserialization()
        {
            RequireProcess.Is64Bit();

            var bsonDocument = new BsonDocument {
                { "stringfield", "A" }
            };
            var noOfDoubleFields = 200000;

            for (var i = 0; i < noOfDoubleFields; i++)
            {
                bsonDocument.Add("doublefield_" + i, i * 1.0);
            }
            var bson = bsonDocument.ToBson();

            using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson))
            {
                Assert.Equal(noOfDoubleFields + 1, lazyBsonDocument.ElementCount);
            }
        }
        public void BackpatchSize_should_throw_when_size_is_larger_than_2GB()
        {
            RequireProcess.Is64Bit();

            using (var stream = new NullBsonStream())
                using (var binaryWriter = new BsonBinaryWriter(stream))
                {
                    var bytes      = new byte[int.MaxValue / 2]; // 1GB
                    var binaryData = new BsonBinaryData(bytes);

                    binaryWriter.WriteStartDocument();
                    binaryWriter.WriteName("array");
                    binaryWriter.WriteStartArray();
                    binaryWriter.WriteBinaryData(binaryData);
                    binaryWriter.WriteBinaryData(binaryData);

                    Action action = () => binaryWriter.WriteEndArray(); // indirectly calls private BackpatchSize method

                    action.ShouldThrow <FormatException>();
                }
        }
        public void BsonBinaryWriter_should_support_writing_more_than_2GB()
        {
            RequireProcess.Is64Bit();

            using (var stream = new NullBsonStream())
                using (var binaryWriter = new BsonBinaryWriter(stream))
                {
                    var bigBinaryData = new BsonBinaryData(new byte[int.MaxValue / 2 - 1000]);
                    for (var i = 0; i < 3; i++)
                    {
                        binaryWriter.WriteStartDocument();
                        binaryWriter.WriteName("x");
                        binaryWriter.WriteBinaryData(bigBinaryData);
                        binaryWriter.WriteEndDocument();
                    }

                    var smallBinaryData = new BsonBinaryData(new byte[2000]);
                    binaryWriter.WriteStartDocument();
                    binaryWriter.WriteName("x");
                    binaryWriter.WriteBinaryData(smallBinaryData);
                    binaryWriter.WriteEndDocument();
                }
        }