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

            map = map.Add(0, 1);
            map = map.Add(1, 3);
            Assert.AreEqual(1, map.Map(0));
            Assert.AreEqual(3, map.Map(1));
            Assert.Throws <KeyNotFoundException>(() => map.Map(2));
        }
Beispiel #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
                });
            }