コード例 #1
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));
        }
コード例 #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));
        }
コード例 #3
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);
        }
コード例 #4
0
        public void Setup()
        {
            Cache = new LockingInMemoryCache();

            Cache.LoadHistory(CreateFrames("stream1", "stream2"));
            Cache.ConcurrentAppend("stream1", GetEventBytes(3), (version, storeVersion) => { });
        }
コード例 #5
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #17
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);
        }
コード例 #18
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);
        }
コード例 #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);
        }
コード例 #20
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);
        }
コード例 #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);
        }
コード例 #22
0
        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);
        }
コード例 #25
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");
        }
コード例 #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");
        }
コード例 #27
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);
        }
コード例 #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");
        }
コード例 #30
0
        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");
        }
コード例 #32
0
        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);
        }
コード例 #34
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");
        }
コード例 #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(() => { });
 }
コード例 #37
0
 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();
 }
コード例 #39
0
 public void Setup()
 {
     Cache = new LockingInMemoryCache();
 }
コード例 #40
0
 public void given_empty_cache()
 {
     var cache = new LockingInMemoryCache();
     cache.Clear(() => { });
     Assert.AreEqual(0, cache.StoreVersion);
 }