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_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); }
public void Setup() { Cache = new LockingInMemoryCache(); Cache.LoadHistory(CreateFrames("stream1", "stream2")); Cache.ConcurrentAppend("stream1", GetEventBytes(3), (version, storeVersion) => { }); }
public void given_empty_cache() { var cache = new LockingInMemoryCache(); cache.Clear(() => { }); Assert.AreEqual(0, cache.StoreVersion); }
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"))); }
public void given_reloaded_cache() { var cache = new LockingInMemoryCache(); cache.LoadHistory(CreateFrames("s1", "s2")); Assert.Throws <InvalidOperationException>(() => cache.LoadHistory(CreateFrames("s1"))); }
public void given_reloaded_cache() { var cache = new LockingInMemoryCache(); cache.LoadHistory(CreateFrames("stream2")); cache.Clear(() => { }); Assert.AreEqual(0, cache.StoreVersion); }
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"); }
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_appended_cache() { var cache = new LockingInMemoryCache(); cache.ConcurrentAppend("stream1", new byte[1], (version, storeVersion) => { }); cache.Clear(() => { }); Assert.AreEqual(0, 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); }
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 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); }
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); }
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"); }
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); }
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); }
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"); }
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); }
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"); }
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); }
public void Setup() { Cache = new LockingInMemoryCache(); }