From 255cfe4162618af7c9aa8182a3f5b7dc1d285530 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Wed, 22 May 2024 05:34:14 +0200 Subject: [PATCH] New consistency verification for indexes. --- spec/db-cars.cr | 5 +++++ spec/test-cars.cr | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/spec/db-cars.cr b/spec/db-cars.cr index d767bb5..d3cb462 100644 --- a/spec/db-cars.cr +++ b/spec/db-cars.cr @@ -28,6 +28,11 @@ class Car def ==(other) @name == other.name && @color == other.color && @keywords == other.keywords end + + # Equality is true if every property is identical. + def <=>(other) + @name <=> other.name + end end def ram_indexes(storage : DODB::Storage) diff --git a/spec/test-cars.cr b/spec/test-cars.cr index dc5cdd2..6df4c97 100644 --- a/spec/test-cars.cr +++ b/spec/test-cars.cr @@ -39,3 +39,46 @@ describe "uncached, cached and ram indexes" do cars_ram2.rm_storage_dir end end + +describe "tracking inconsistencies between implementations" do + it "index - partitions - tags" do + cars_ram0 = DODB::RAMOnlySpecDataBase(Car).new "-0" + cars_ram1 = DODB::RAMOnlySpecDataBase(Car).new "-1" + cars_ram2 = DODB::RAMOnlySpecDataBase(Car).new "-2" + + uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords = uncached_indexes cars_ram0 + cached_searchby_name, cached_searchby_color, cached_searchby_keywords = cached_indexes cars_ram1 + ram_searchby_name, ram_searchby_color, ram_searchby_keywords = ram_indexes cars_ram2 + + add_cars cars_ram0, 1 + add_cars cars_ram1, 1 + add_cars cars_ram2, 1 + + # Searches should be consistent between all implementations of basic indexes, partitions and tags. + + # Basic index. + uncached_corvet_car = uncached_searchby_color.get_with_keys? "Corvet-0" + cached_corvet_car = cached_searchby_color.get_with_keys? "Corvet-0" + ram_corvet_car = ram_searchby_color.get_with_keys? "Corvet-0" + uncached_corvet_car.should eq cached_corvet_car + uncached_corvet_car.should eq ram_corvet_car + + # Partitions. + uncached_red_cars = uncached_searchby_color.get? "red" + cached_red_cars = cached_searchby_color.get? "red" + ram_red_cars = ram_searchby_color.get? "red" + uncached_red_cars.sort.should eq cached_red_cars.sort + uncached_red_cars.sort.should eq ram_red_cars.sort + + # Tags. + uncached_fast_cars = uncached_searchby_keywords.get? "fast" + cached_fast_cars = cached_searchby_keywords.get? "fast" + ram_fast_cars = ram_searchby_keywords.get? "fast" + uncached_fast_cars.sort.should eq cached_fast_cars.sort + uncached_fast_cars.sort.should eq ram_fast_cars.sort + + cars_ram0.rm_storage_dir + cars_ram1.rm_storage_dir + cars_ram2.rm_storage_dir + end +end