public void TestDictionaryBasedWith1()
        {
            IndexMap map = new IndexMap.DictionaryBased();

            map = map.Add(0, 1);
            Assert.AreEqual(1, map.Map(0));
            Assert.Throws <KeyNotFoundException>(() => map.Map(1));
        }
Ejemplo n.º 2
0
            // private methods
            private Batch GetNextBatch()
            {
                var batchType = _unprocessed[0].Request.RequestType;

                List <WriteRequest> requests;
                IndexMap            indexMap;

                if (_isOrdered)
                {
                    var index = _unprocessed.FindIndex(r => r.Request.RequestType != batchType);
                    var count = index == -1 ? _unprocessed.Count : index;
                    requests = _unprocessed.Take(count).Select(r => r.Request).ToList();
                    indexMap = new IndexMap.RangeBased(0, _unprocessed[0].Index, count);
                    _unprocessed.RemoveRange(0, count);
                }
                else
                {
                    var matching = _unprocessed.Where(r => r.Request.RequestType == batchType).ToList();
                    requests = matching.Select(r => r.Request).ToList();
                    indexMap = new IndexMap.DictionaryBased();
                    for (var i = 0; i < matching.Count; i++)
                    {
                        indexMap.Add(i, matching[i].Index);
                    }
                    _unprocessed = _unprocessed.Where(r => r.Request.RequestType != batchType).ToList();
                }

                var writeConcern = _writeConcern;

                if (!writeConcern.IsAcknowledged && _isOrdered && _unprocessed.Count > 0)
                {
                    writeConcern = WriteConcern.W1; // explicitly do not use the server's default
                }

                return(new Batch
                {
                    BatchType = batchType,
                    Requests = requests,
                    IndexMap = indexMap,
                    WriteConcern = writeConcern
                });
            }
        public void TestDictionaryBasedWith0()
        {
            var map = new IndexMap.DictionaryBased();

            Assert.Throws <KeyNotFoundException>(() => map.Map(0));
        }