public void should_have_entries_in_sorted_order() { var streamId = "account--696193173"; var result = _tableIndex.GetRange(streamId, 0, 4).ToArray(); var hash = (ulong)_lowHasher.Hash(streamId) << 32 | _highHasher.Hash(streamId); Assert.That(result.Count(), Is.EqualTo(5)); Assert.That(result[0].Stream, Is.EqualTo(hash)); Assert.That(result[0].Version, Is.EqualTo(4)); Assert.That(result[0].Position, Is.EqualTo(10)); Assert.That(result[1].Stream, Is.EqualTo(hash)); Assert.That(result[1].Version, Is.EqualTo(3)); Assert.That(result[1].Position, Is.EqualTo(8)); Assert.That(result[2].Stream, Is.EqualTo(hash)); Assert.That(result[2].Version, Is.EqualTo(2)); Assert.That(result[2].Position, Is.EqualTo(6)); Assert.That(result[3].Stream, Is.EqualTo(hash)); Assert.That(result[3].Version, Is.EqualTo(1)); Assert.That(result[3].Position, Is.EqualTo(4)); Assert.That(result[4].Stream, Is.EqualTo(hash)); Assert.That(result[4].Version, Is.EqualTo(0)); Assert.That(result[4].Position, Is.EqualTo(2)); streamId = "LPN-FC002_LPK51001"; result = _tableIndex.GetRange(streamId, 0, 4).ToArray(); hash = (ulong)_lowHasher.Hash(streamId) << 32 | _highHasher.Hash(streamId); Assert.That(result.Count(), Is.EqualTo(5)); Assert.That(result[0].Stream, Is.EqualTo(hash)); Assert.That(result[0].Version, Is.EqualTo(4)); Assert.That(result[0].Position, Is.EqualTo(9)); Assert.That(result[1].Stream, Is.EqualTo(hash)); Assert.That(result[1].Version, Is.EqualTo(3)); Assert.That(result[1].Position, Is.EqualTo(7)); Assert.That(result[2].Stream, Is.EqualTo(hash)); Assert.That(result[2].Version, Is.EqualTo(2)); Assert.That(result[2].Position, Is.EqualTo(5)); Assert.That(result[3].Stream, Is.EqualTo(hash)); Assert.That(result[3].Version, Is.EqualTo(1)); Assert.That(result[3].Position, Is.EqualTo(3)); Assert.That(result[4].Stream, Is.EqualTo(hash)); Assert.That(result[4].Version, Is.EqualTo(0)); Assert.That(result[4].Position, Is.EqualTo(1)); }
public void should_still_have_all_entries_in_sorted_order() { var streamId = "testStream-1"; var result = _tableIndex.GetRange(streamId, 0, 5).ToArray(); var hash = (ulong)_lowHasher.Hash(streamId) << 32 | _highHasher.Hash(streamId); Assert.That(result.Count(), Is.EqualTo(6)); Assert.That(result[0].Stream, Is.EqualTo(hash)); Assert.That(result[0].Version, Is.EqualTo(5)); Assert.That(result[0].Position, Is.EqualTo(500)); Assert.That(result[1].Stream, Is.EqualTo(hash)); Assert.That(result[1].Version, Is.EqualTo(4)); Assert.That(result[1].Position, Is.EqualTo(400)); Assert.That(result[2].Stream, Is.EqualTo(hash)); Assert.That(result[2].Version, Is.EqualTo(3)); Assert.That(result[2].Position, Is.EqualTo(300)); Assert.That(result[3].Stream, Is.EqualTo(hash)); Assert.That(result[3].Version, Is.EqualTo(2)); Assert.That(result[3].Position, Is.EqualTo(200)); Assert.That(result[4].Stream, Is.EqualTo(hash)); Assert.That(result[4].Version, Is.EqualTo(1)); Assert.That(result[4].Position, Is.EqualTo(100)); Assert.That(result[5].Stream, Is.EqualTo(hash)); Assert.That(result[5].Version, Is.EqualTo(0)); Assert.That(result[5].Position, Is.EqualTo(0)); }
public void should_return_only_one_element_if_concurrency_duplicate_happens_on_range_query_as_well() { var res = _tableIndex.GetRange(0xADA, 0, 100).ToList(); Assert.That(res.Count(), Is.EqualTo(1)); Assert.That(res[0].Stream, Is.EqualTo(0xADA)); Assert.That(res[0].Version, Is.EqualTo(0)); Assert.That(res[0].Position, Is.EqualTo(0xFF00)); }
public void should_return_only_one_element_if_concurrency_duplicate_happens_on_range_query_as_well() { var res = _tableIndex.GetRange("0xADA", 0, 100).ToList(); ulong hash = (ulong)_lowHasher.Hash("0xADA"); hash = _ptableVersion == PTableVersions.Index32Bit ? hash : hash << 32 | _highHasher.Hash("0xADA"); Assert.That(res.Count(), Is.EqualTo(1)); Assert.That(res[0].Stream, Is.EqualTo(hash)); Assert.That(res[0].Version, Is.EqualTo(0)); Assert.That(res[0].Position, Is.EqualTo(0xFF00)); }
public void throws_maybe_corrupt_index_exception_if_verification_disabled(byte version) { //the MaybeCorruptIndexException is caught internally and should trigger an index file deletion if caught ConstructTableIndexWithCorruptIndexEntries(version, true); Assert.Throws <MaybeCorruptIndexException>(() => { //since index entries are sorted in descending order, the corrupted index entry corresponds to NumIndexEntries/2+1 _tableIndex.GetRange(StreamName, NumIndexEntries / 2 + 1, NumIndexEntries / 2 + 1, null).ToArray(); }); //force verify file should be created Assert.True(File.Exists(Path.Combine(PathName, TableIndex.ForceIndexVerifyFilename))); }
public void should_return_empty_collection_when_stream_is_not_in_db() { var res = _tableIndex.GetRange("0xFEED", 0, 100); Assert.That(res, Is.Empty); }
public void throw_argumentoutofrangeexception_on_range_query_when_provided_with_negative_start_version() { Assert.Throws <ArgumentOutOfRangeException>(() => _tableIndex.GetRange(0x0000, -1, int.MaxValue).ToArray()); }
public void should_return_empty_range_for_nonexisting_stream() { var range = _tableIndex.GetRange(0xFEED, 0, int.MaxValue).ToArray(); Assert.AreEqual(0, range.Length); }