public void given_empty_cache_and_valid_commit_function()
        {
            var cache = new LockingInMemoryCache();

            long? commitStoreVersion = null;
            long? commitStreamVersion = null;

            cache.ConcurrentAppend("stream", GetEventBytes(1), (version, storeVersion) =>
                {
                    commitStoreVersion = storeVersion;
                    commitStreamVersion = version;
                });

            Assert.AreEqual(1, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(1, commitStreamVersion, "commitStreamVersion");

            Assert.AreEqual(1, cache.StoreVersion);

            var expected = new[]
                {
                    CreateKey(1, 1, "stream"),
                };
            DataAssert.AreEqual(expected, cache.ReadStream("stream",0,100));
            DataAssert.AreEqual(expected, cache.ReadAll(0, 100));
        }
Пример #2
0
        public void given_empty_cache_and_valid_commit_function()
        {
            var cache = new LockingInMemoryCache();

            long?commitStoreVersion  = null;
            long?commitStreamVersion = null;

            cache.ConcurrentAppend("stream", GetEventBytes(1), (version, storeVersion) =>
            {
                commitStoreVersion  = storeVersion;
                commitStreamVersion = version;
            });

            Assert.AreEqual(1, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(1, commitStreamVersion, "commitStreamVersion");

            Assert.AreEqual(1, cache.StoreVersion);

            var expected = new[]
            {
                CreateKey(1, 1, "stream"),
            };

            DataAssert.AreEqual(expected, cache.ReadStream("stream", 0, 100));
            DataAssert.AreEqual(expected, cache.ReadAll(0, 100));
        }
        public void given_cache_with_one_appended_record()
        {
            var cache = new LockingInMemoryCache();
            cache.ConcurrentAppend("Stream", new byte[0], (version, storeVersion) => { }, -1);

            Assert.AreEqual(1, cache.StoreVersion);
        }
Пример #4
0
        public void Setup()
        {
            Cache = new LockingInMemoryCache();

            Cache.LoadHistory(CreateFrames("stream1", "stream2"));
            Cache.ConcurrentAppend("stream1", GetEventBytes(3), (version, storeVersion) => { });
        }
        public void Setup()
        {
            Cache = new LockingInMemoryCache();

            Cache.LoadHistory(CreateFrames("stream1", "stream2"));
            Cache.ConcurrentAppend("stream1", GetEventBytes(3), (version, storeVersion) => { });
        }
Пример #6
0
        public void given_empty_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.Clear(() => { });
            Assert.AreEqual(0, cache.StoreVersion);
        }
Пример #7
0
        public void given_empty_reload()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(Enumerable.Empty <StorageFrameDecoded>());
            Assert.AreEqual(0, cache.StoreVersion);
        }
        public void given_reloaded_cache()
        {
            var cache = new LockingInMemoryCache();
            cache.LoadHistory(CreateFrames("s1", "s2"));

            Assert.Throws<InvalidOperationException>(() => cache.LoadHistory(CreateFrames("s1")));
        }
Пример #9
0
        public void given_reloaded_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("s1", "s2"));

            Assert.Throws <InvalidOperationException>(() => cache.LoadHistory(CreateFrames("s1")));
        }
Пример #10
0
        public void given_cache_with_one_appended_record()
        {
            var cache = new LockingInMemoryCache();

            cache.ConcurrentAppend("Stream", new byte[0], (version, storeVersion) => { }, -1);

            Assert.AreEqual(1, cache.StoreVersion);
        }
Пример #11
0
        public void given_reloaded_cache()
        {
            var cache = new LockingInMemoryCache();
            cache.LoadHistory(CreateFrames("stream2"));
            cache.Clear(() => { });

            Assert.AreEqual(0, cache.StoreVersion);
        }
Пример #12
0
        public void given_reloaded_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream2"));
            cache.Clear(() => { });

            Assert.AreEqual(0, cache.StoreVersion);
        }
Пример #13
0
        public void given_cleared_cache()
        {
            var cache = new LockingInMemoryCache();
            cache.LoadHistory(CreateFrames("s1", "s2"));
            cache.Clear(() => { });
            cache.LoadHistory(CreateFrames("s1"));

            Assert.AreEqual(1, cache.StoreVersion, "storeVersion");
        }
Пример #14
0
        public void given_cleared_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("s1", "s2"));
            cache.Clear(() => { });
            cache.LoadHistory(CreateFrames("s1"));

            Assert.AreEqual(1, cache.StoreVersion, "storeVersion");
        }
Пример #15
0
        public void given_filled_cache_and_concurrent_append_with_non_specified_version_expectation()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            cache.ConcurrentAppend("stream", GetEventBytes(3), (version, storeVersion) => { }, -1);

            Assert.AreEqual(3, cache.StoreVersion);
        }
Пример #16
0
        public void given_appended_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.ConcurrentAppend("stream1", new byte[1], (version, storeVersion) => { });

            cache.Clear(() => { });

            Assert.AreEqual(0, cache.StoreVersion);
        }
        public void given_filled_cache_and_concurrent_append_with_non_specified_version_expectation()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            cache.ConcurrentAppend("stream", GetEventBytes(3), (version, storeVersion) => { }, -1);
            
            Assert.AreEqual(3, cache.StoreVersion);
        }
        public void given_non_empty_reload()
        {
            var cache = new LockingInMemoryCache();
            cache.LoadHistory(new StorageFrameDecoded[]
                {
                    new StorageFrameDecoded(new byte[1], "test",0), 
                });

            Assert.AreEqual(1, cache.StoreVersion);
        }
Пример #19
0
        public void given_appended_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.ConcurrentAppend("stream1", new byte[1], (version, storeVersion) => { });

            cache.Clear(() => { });

            Assert.AreEqual(0, cache.StoreVersion);
        }
        public void given_filled_cache_and_failing_commit_function()
        {
            var cache = new LockingInMemoryCache();

            cache.ConcurrentAppend("stream1", new byte[1], (version, storeVersion) => { });

            Assert.Throws<FileNotFoundException>(() => cache.Clear(() => { throw new FileNotFoundException(); }));

            Assert.AreEqual(1, cache.StoreVersion);
        }
Пример #21
0
        public void given_filled_cache_and_failing_commit_function()
        {
            var cache = new LockingInMemoryCache();

            cache.ConcurrentAppend("stream1", new byte[1], (version, storeVersion) => { });

            Assert.Throws <FileNotFoundException>(() => cache.Clear(() => { throw new FileNotFoundException(); }));

            Assert.AreEqual(1, cache.StoreVersion);
        }
        public void Name()
        {
            var cache = new LockingInMemoryCache();

            var watch = Stopwatch.StartNew();
            var count = 100000;
            cache.ReloadEverything(Generate(count, new byte[200], i => string.Format("stream_{0}", i % 100)));
            watch.Stop();
            Console.WriteLine("Cached {0} events in {1:0.00} sec. {2:0.00} eps", count, (watch.Elapsed.TotalSeconds),
                count / watch.Elapsed.TotalSeconds);
        }
Пример #23
0
        public void given_non_empty_reload()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(new StorageFrameDecoded[]
            {
                new StorageFrameDecoded(new byte[1], "test", 0),
            });

            Assert.AreEqual(1, cache.StoreVersion);
        }
Пример #24
0
        public void Name()
        {
            var cache = new LockingInMemoryCache();

            var watch = Stopwatch.StartNew();
            var count = 100000;

            cache.LoadHistory(Generate(count, new byte[200], i => string.Format("stream_{0}", i % 100)));
            watch.Stop();
            Console.WriteLine("Cached {0} events in {1:0.00} sec. {2:0.00} eps", count, (watch.Elapsed.TotalSeconds),
                              count / watch.Elapsed.TotalSeconds);
        }
        public void given_empty_cache_and_matching_version_expectation()
        {
            var cache = new LockingInMemoryCache();
            long? commitStoreVersion = null;
            long? commitStreamVersion = null;

            cache.ConcurrentAppend("stream", new byte[1],(version, storeVersion) =>
                {
                    commitStoreVersion = 1;
                    commitStreamVersion = 1;
                },0 );
            Assert.AreEqual(1, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(1, commitStreamVersion, "commitStreamVersion");
        }
Пример #26
0
        public void given_empty_cache_and_matching_version_expectation()
        {
            var  cache = new LockingInMemoryCache();
            long?commitStoreVersion  = null;
            long?commitStreamVersion = null;

            cache.ConcurrentAppend("stream", new byte[1], (version, storeVersion) =>
            {
                commitStoreVersion  = 1;
                commitStreamVersion = 1;
            }, 0);
            Assert.AreEqual(1, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(1, commitStreamVersion, "commitStreamVersion");
        }
        public void given_reloaded_cache_and_commit_function_that_fails()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            Assert.Throws<FileNotFoundException>(
                () => cache.ConcurrentAppend("stream", new byte[1], (version, storeVersion) =>
                    {
                        throw new FileNotFoundException();
                    }));

            Assert.AreEqual(2, cache.StoreVersion);
        }
Пример #28
0
        public void given_reloaded_cache_and_commit_function_that_fails()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            Assert.Throws <FileNotFoundException>(
                () => cache.ConcurrentAppend("stream", new byte[1], (version, storeVersion) =>
            {
                throw new FileNotFoundException();
            }));

            Assert.AreEqual(2, cache.StoreVersion);
        }
Пример #29
0
        public void given_reloaded_cache_and_concurrent_append_with_invalid_expected_version()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            bool commitWasCalled = false;

            Assert.Throws <AppendOnlyStoreConcurrencyException>(() => cache.
                                                                ConcurrentAppend("stream", new byte[1],
                                                                                 (streamVersion, storeVersion) =>
                                                                                 commitWasCalled = true, 2));

            Assert.IsFalse(commitWasCalled, "commit should not be called");
        }
        public void given_reloaded_cache_and_invalid_expected_version()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            bool commitWasCalled = false;

            Assert.Throws<AppendOnlyStoreConcurrencyException>(
                () =>
                    cache.ConcurrentAppend("stream", new byte[1],
                        (streamVersion, storeVersion) => commitWasCalled = true, 2));

            Assert.IsFalse(commitWasCalled, "commit should not be called");
        }
Пример #31
0
        public void given_reloaded_cache_and_matching_stream_version()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            long?commitStoreVersion  = null;
            long?commitStreamVersion = null;

            cache.ConcurrentAppend("stream", new byte[1], (streamVersion, storeVersion) =>
            {
                commitStoreVersion  = storeVersion;
                commitStreamVersion = streamVersion;
            }, 1);

            Assert.AreEqual(3, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(2, commitStreamVersion, "commitStreamVersion");
        }
        public void given_reloaded_and_appended_cache_with_valid_version_expectation()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));
            cache.ConcurrentAppend("stream", GetEventBytes(4), (version, storeVersion) => { });

            long? commitStoreVersion = null;
            long? commitStreamVersion = null;

            cache.ConcurrentAppend("stream", GetEventBytes(5), (version, storeVersion) =>
                {
                    commitStoreVersion = storeVersion;
                    commitStreamVersion = version;
                },2);

            Assert.AreEqual(4, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(3, commitStreamVersion, "commitStreamVersion");
            Assert.AreEqual(4, cache.StoreVersion);
        }
Пример #33
0
        public void given_filled_cache_and_concurrent_append_with_valid_version_expectation()
        {
            // GIVEN
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));
            cache.ConcurrentAppend("stream", GetEventBytes(4), (version, storeVersion) => { });

            long?commitStoreVersion  = null;
            long?commitStreamVersion = null;

            // WHEN
            cache.ConcurrentAppend("stream", GetEventBytes(5), (version, storeVersion) =>
            {
                commitStoreVersion  = storeVersion;
                commitStreamVersion = version;
            }, 2);


            // EXPECT
            Assert.AreEqual(4, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(3, commitStreamVersion, "commitStreamVersion");
            Assert.AreEqual(4, cache.StoreVersion);
        }
        public void given_reloaded_cache_and_matching_stream_version()
        {
            var cache = new LockingInMemoryCache();

            cache.LoadHistory(CreateFrames("stream", "otherStream"));

            long? commitStoreVersion = null;
            long? commitStreamVersion = null;

            cache.ConcurrentAppend("stream", new byte[1], (streamVersion, storeVersion) =>
                {
                    commitStoreVersion = storeVersion;
                    commitStreamVersion = streamVersion;
                }, 1 );

            Assert.AreEqual(3, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(2, commitStreamVersion, "commitStreamVersion");
        }
Пример #35
0
        public void given_empty_cache()
        {
            var cache = new LockingInMemoryCache();

            cache.Clear(() => { });
        }
Пример #36
0
 public void given_empty_cache()
 {
     var cache = new LockingInMemoryCache();
     cache.Clear(() => { });
 }
 public void given_empty_reload()
 {
     var cache = new LockingInMemoryCache();
     cache.LoadHistory(Enumerable.Empty<StorageFrameDecoded>());
     Assert.AreEqual(0, cache.StoreVersion);
 }
Пример #38
0
 public void Setup()
 {
     Cache = new LockingInMemoryCache();
 }
 public void Setup()
 {
     Cache = new LockingInMemoryCache();
 }
Пример #40
0
 public void given_empty_cache()
 {
     var cache = new LockingInMemoryCache();
     cache.Clear(() => { });
     Assert.AreEqual(0, cache.StoreVersion);
 }