public void Dispose_can_be_called_more_than_once()
        {
            var subject = new BsonChunkPool(1, 16);

            subject.Dispose();
            subject.Dispose();
        }
        public void Dispose_should_return_chunk_to_the_pool_after_all_handles_have_been_disposed(
            [Values(0, 1, 2, 3, 4, 16)]
            int numberOfHandles,
            [Values(false, true)]
            bool disposeSubjectLast)
        {
            var pool    = new BsonChunkPool(1, 16);
            var subject = pool.GetChunk(1);

            var handles = new List <IBsonChunk>();

            for (var n = 0; n < numberOfHandles; n++)
            {
                handles.Add(subject.Fork());
            }

            if (disposeSubjectLast)
            {
                handles.Add(subject);
            }
            else
            {
                handles.Insert(0, subject);
            }

            foreach (var handle in handles)
            {
                pool.ChunkCount.Should().Be(0);
                handle.Dispose();
            }

            pool.ChunkCount.Should().Be(1);
        }
        public void ChunkSize_get_should_return_expected_result()
        {
            var subject = new BsonChunkPool(1, 16);

            var result = subject.ChunkSize;

            result.Should().Be(16);
        }
        public void MaxChunkCount_get_should_return_expected_result()
        {
            var subject = new BsonChunkPool(1, 16);

            var result = subject.MaxChunkCount;

            result.Should().Be(1);
        }
        public void Dispose_should_return_chunk_to_the_pool()
        {
            var pool    = new BsonChunkPool(1, 16);
            var subject = pool.GetChunk(1);

            subject.Dispose();

            pool.ChunkCount.Should().Be(1);
        }
Exemple #6
0
        public void Create_should_return_SingleChunkBuffer_when_a_single_chunk_is_sufficient(
            [Values(1, 63, 64)]
            int minimumCapacity)
        {
            var chunkSource = new BsonChunkPool(1, 64);

            var result = ByteBufferFactory.Create(chunkSource, minimumCapacity);

            result.Should().BeOfType <SingleChunkBuffer>();
        }
        public void GetChunk_should_throw_when_subject_is_disposed()
        {
            var subject = new BsonChunkPool(1, 16);

            subject.Dispose();

            Action action = () => subject.GetChunk(1);

            action.ShouldThrow <ObjectDisposedException>().And.ObjectName.Should().Be("BsonChunkPool");
        }
        public void GetChunk_should_return_expected_result(
            [Values(1, 15, 16, 17, 32)]
            int requestedSize)
        {
            var subject = new BsonChunkPool(1, 16);

            var result = subject.GetChunk(requestedSize);

            result.Bytes.Count.Should().Be(16);
        }
        public void Dispose_should_dispose_subject()
        {
            var subject = new BsonChunkPool(1, 16);

            subject.Dispose();

            var reflector = new Reflector(subject);

            reflector._disposed.Should().BeTrue();
        }
Exemple #10
0
        public void Create_should_return_MultiChunkBuffer_when_multiple_chunks_are_required(
            [Values(65, 128)]
            int minimumCapacity)
        {
            var chunkSource = new BsonChunkPool(1, 64);

            var result = ByteBufferFactory.Create(chunkSource, minimumCapacity);

            result.Should().BeOfType <MultiChunkBuffer>();
        }
Exemple #11
0
        public void Create_should_return_expected_result(
            [Values(1, 63, 64, 65, 128)]
            int minimumCapacity)
        {
            var chunkSource = new BsonChunkPool(1, 64);

            var result = ByteBufferFactory.Create(chunkSource, minimumCapacity);

            result.Capacity.Should().BeGreaterOrEqualTo(minimumCapacity);
        }
        public void Fork_should_throw_when_subject_is_disposed()
        {
            var pool    = new BsonChunkPool(1, 16);
            var subject = pool.GetChunk(1);

            subject.Dispose();

            Action action = () => subject.Fork();

            action.ShouldThrow <ObjectDisposedException>().And.ObjectName.Should().Be("DisposableChunk");
        }
        public void Fork_should_return_expected_result()
        {
            var pool    = new BsonChunkPool(1, 16);
            var subject = pool.GetChunk(1);

            var handle = subject.Fork();

            handle.Bytes.Array.Should().BeSameAs(subject.Bytes.Array);
            handle.Bytes.Offset.Should().Be(subject.Bytes.Offset);
            handle.Bytes.Count.Should().Be(subject.Bytes.Count);
        }
        public void Bytes_get_should_return_expected_result()
        {
            var pool    = new BsonChunkPool(1, 16);
            var subject = pool.GetChunk(1);

            var result = subject.Bytes;

            result.Array.Length.Should().Be(16);
            result.Offset.Should().Be(0);
            result.Count.Should().Be(16);
        }
        public void constructor_should_initialize_subject()
        {
            var maxChunkCount = 1;
            var chunkSize     = 16;

            var subject = new BsonChunkPool(maxChunkCount, chunkSize);

            var reflector = new Reflector(subject);

            subject.MaxChunkCount.Should().Be(maxChunkCount);
            subject.ChunkSize.Should().Be(chunkSize);
            reflector._disposed.Should().BeFalse();
        }
        public void GetChunk_should_return_pooled_chunk_when_one_is_availabe()
        {
            var subject        = new BsonChunkPool(1, 16);
            var pooledChunk    = subject.GetChunk(1);
            var expectedArray  = pooledChunk.Bytes.Array;
            var expectedOffset = pooledChunk.Bytes.Offset;

            pooledChunk.Dispose();

            var result = subject.GetChunk(1);

            result.Bytes.Array.Should().BeSameAs(expectedArray);
            result.Bytes.Offset.Should().Be(expectedOffset);
            result.Bytes.Count.Should().Be(16);
        }
        public void Default_set_should_have_expected_effect()
        {
            var originalDefaultPool = BsonChunkPool.Default;

            try
            {
                var newDefaultPool = new BsonChunkPool(1, 16);

                BsonChunkPool.Default = newDefaultPool;

                BsonChunkPool.Default.Should().BeSameAs(newDefaultPool);
            }
            finally
            {
                BsonChunkPool.Default = originalDefaultPool;
            }
        }
 public Reflector(BsonChunkPool instance)
 {
     _instance = instance;
 }