From 0b4cdf00b7211afe84f98eb59ea63326cf04132c Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Thu, 9 May 2024 12:24:27 +0200 Subject: [PATCH] Test some reindex stuff with the Car database. --- spec/test-cars.cr | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spec/test-cars.cr diff --git a/spec/test-cars.cr b/spec/test-cars.cr new file mode 100644 index 0000000..0ed9c43 --- /dev/null +++ b/spec/test-cars.cr @@ -0,0 +1,45 @@ +require "spec" +require "./benchmark-utilities.cr" +require "./cars.cr" + +corvet0 = Car.new "Corvet-0", "red", [ "shiny", "impressive", "fast", "elegant" ] + +describe "DODB car" do + describe "behavior of uncached, cached and ram indexes:" do + it "RAM DB - add items, add indexes, search, reindex, search" do + + cars_ram0 = DODB::RAMOnlySpecDataBase(Car).new "-0" + cars_ram1 = DODB::RAMOnlySpecDataBase(Car).new "-1" + cars_ram2 = DODB::RAMOnlySpecDataBase(Car).new "-2" + + add_cars cars_ram0, 1 + add_cars cars_ram1, 1 + add_cars cars_ram2, 1 + + 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 + + uncached_searchby_name.get?("Corvet-0").should be_nil + cached_searchby_name.get?("Corvet-0").should be_nil + ram_searchby_name.get?("Corvet-0").should be_nil + + cars_ram0.reindex_everything! + cars_ram1.reindex_everything! + cars_ram2.reindex_everything! + + # Cannot get the value since it's not written on disk. + # FIXME: should only retrieve the key with the index, not the actual value. + # So, this should work. + uncached_searchby_name.get?("Corvet-0").should be_nil + + # Both cached and RAM indexes can retrieve the value since they store the key. + cached_searchby_name.get?("Corvet-0").should eq corvet0 + ram_searchby_name.get?("Corvet-0").should eq corvet0 + + cars_ram0.rm_storage_dir + cars_ram1.rm_storage_dir + cars_ram2.rm_storage_dir + end + end +end