public int Size => 0; // FIXME

        public FastPipeQueueCache(IObjectPool <FixedSizeBuffer> bufferPool, QueueId id)
        {
            if (bufferPool == null)
            {
                throw new ArgumentNullException("bufferPool");
            }
            this.bufferPool = bufferPool;
            Id         = id;
            operations = new CacheDataAdapter(bufferPool, disposable => cache.Purge(disposable));
            cache      = new PooledQueueCache <PlainBatchContainer, CachedMessage>(operations);
        }
Пример #2
0
 private void Purge(IDisposable disposable)
 {
     cache.Purge(disposable);
 }
Пример #3
0
        public void CacheDrainTest()
        {
            var bufferPool = new TestBlockPool();
            PooledQueueCache <TestQueueMessage, TestCachedMessage>  cache       = null;
            ICacheDataAdapter <TestQueueMessage, TestCachedMessage> dataAdapter = new TestCacheDataAdapter(bufferPool,
                                                                                                           disposable => cache.Purge(disposable));

            cache = new PooledQueueCache <TestQueueMessage, TestCachedMessage>(dataAdapter);
            int startSequenceNuber = 222;

            startSequenceNuber = RunGoldenPath(cache, startSequenceNuber);
            bufferPool.PurgeAll();
            RunGoldenPath(cache, startSequenceNuber);
        }
Пример #4
0
        public void QueueCacheMissTest()
        {
            var bufferPool = new TestBlockPool();
            PooledQueueCache <TestQueueMessage, TestCachedMessage>  cache       = null;
            ICacheDataAdapter <TestQueueMessage, TestCachedMessage> dataAdapter = new TestCacheDataAdapter(bufferPool, disposable => cache.Purge(disposable));

            cache = new PooledQueueCache <TestQueueMessage, TestCachedMessage>(dataAdapter);
            int             sequenceNumber = 10;
            IBatchContainer batch;

            Guid streamGuid = Guid.NewGuid();

            // No data in cache, cursors should not throw.
            object cursor = cache.GetCursor(streamGuid, StreamNamespace, new EventSequenceToken(sequenceNumber++));

            Assert.IsNotNull(cursor);

            // try to iterate, should throw
            bool gotNext = cache.TryGetNextMessage(cursor, out batch);

            Assert.IsNotNull(cursor);
            Assert.IsFalse(gotNext);

            // now add messages into cache newer than cursor
            // Adding enough to fill the pool
            for (int i = 0; i < MessagesPerBuffer * PooledBufferCount; i++)
            {
                cache.Add(new TestQueueMessage
                {
                    StreamGuid      = streamGuid,
                    StreamNamespace = StreamNamespace,
                    SequenceNumber  = sequenceNumber++,
                });
            }

            // now that there is data, and the cursor should point to data older than in the cache, using cursor should throw
            Exception ex = null;

            try
            {
                cache.TryGetNextMessage(cursor, out batch);
            }
            catch (QueueCacheMissException cacheMissException)
            {
                ex = cacheMissException;
            }
            Assert.IsNotNull(ex);

            // Try getting new cursor into cache from data before the cache.  Should throw
            ex = null;
            try
            {
                cursor = cache.GetCursor(streamGuid, StreamNamespace, new EventSequenceToken(10));
            }
            catch (QueueCacheMissException cacheMissException)
            {
                ex = cacheMissException;
            }
            Assert.IsNotNull(ex);

            // Get valid cursor into cache
            cursor = cache.GetCursor(streamGuid, StreamNamespace, new EventSequenceToken(13));
            // query once, to make sure cursor is good
            gotNext = cache.TryGetNextMessage(cursor, out batch);
            Assert.IsNotNull(cursor);
            Assert.IsTrue(gotNext);
            // Since pool should be full, adding one more message should trigger the cache to purge.
            cache.Add(new TestQueueMessage
            {
                StreamGuid      = streamGuid,
                StreamNamespace = StreamNamespace,
                SequenceNumber  = sequenceNumber++,
            });
            // After purge, use of cursor should throw.
            ex = null;
            try
            {
                cache.TryGetNextMessage(cursor, out batch);
            }
            catch (QueueCacheMissException cacheMissException)
            {
                ex = cacheMissException;
            }
            Assert.IsNotNull(ex);
        }
Пример #5
0
        public void GoldenPathTest()
        {
            var bufferPool = new TestBlockPool();
            PooledQueueCache <TestQueueMessage, TestCachedMessage>  cache       = null;
            ICacheDataAdapter <TestQueueMessage, TestCachedMessage> dataAdapter = new TestCacheDataAdapter(bufferPool,
                                                                                                           disposable => cache.Purge(disposable));

            cache = new PooledQueueCache <TestQueueMessage, TestCachedMessage>(dataAdapter);
            RunGoldenPath(cache, 111);
        }