2024-05-09 12:24:27 +02:00
|
|
|
require "spec"
|
2024-05-10 15:23:28 +02:00
|
|
|
require "./db-cars.cr"
|
2024-05-09 12:24:27 +02:00
|
|
|
|
|
|
|
corvet0 = Car.new "Corvet-0", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
|
|
|
|
2024-05-09 18:41:20 +02:00
|
|
|
describe "uncached, cached and ram indexes" do
|
|
|
|
it "RAM DB - add items, add indexes, search, reindex, search" do
|
|
|
|
|
2024-05-23 14:18:16 +02:00
|
|
|
cars_ram0 = SPECDB::RAMOnly(Car).new "-0"
|
|
|
|
cars_ram1 = SPECDB::RAMOnly(Car).new "-1"
|
|
|
|
cars_ram2 = SPECDB::RAMOnly(Car).new "-2"
|
2024-05-09 18:41:20 +02:00
|
|
|
|
|
|
|
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!
|
|
|
|
|
|
|
|
# Get the value even if not written on the disk since the index was written on the disk.
|
|
|
|
# The value is retrieved by the database, the index only reads its key in the database.
|
|
|
|
uncached_searchby_name.get?("Corvet-0").should eq corvet0
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2024-05-21 13:52:52 +02:00
|
|
|
cars_ram0.rm_storage_dir
|
|
|
|
cars_ram1.rm_storage_dir
|
|
|
|
cars_ram2.rm_storage_dir
|
2024-05-09 12:24:27 +02:00
|
|
|
end
|
|
|
|
end
|
2024-05-22 05:34:14 +02:00
|
|
|
|
|
|
|
describe "tracking inconsistencies between implementations" do
|
|
|
|
it "index - partitions - tags" do
|
2024-05-23 14:18:16 +02:00
|
|
|
cars_ram0 = SPECDB::RAMOnly(Car).new "-0"
|
|
|
|
cars_ram1 = SPECDB::RAMOnly(Car).new "-1"
|
|
|
|
cars_ram2 = SPECDB::RAMOnly(Car).new "-2"
|
2024-05-22 05:34:14 +02:00
|
|
|
|
|
|
|
uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords = uncached_indexes cars_ram0
|
2024-05-22 17:36:45 +02:00
|
|
|
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
|
2024-05-22 05:34:14 +02:00
|
|
|
|
|
|
|
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.
|
2024-05-22 17:36:45 +02:00
|
|
|
uncached_corvet_car = uncached_searchby_name.get? "Corvet-0"
|
|
|
|
cached_corvet_car = cached_searchby_name.get? "Corvet-0"
|
|
|
|
ram_corvet_car = ram_searchby_name.get? "Corvet-0"
|
2024-05-22 05:34:14 +02:00
|
|
|
uncached_corvet_car.should eq cached_corvet_car
|
|
|
|
uncached_corvet_car.should eq ram_corvet_car
|
2024-05-22 17:36:45 +02:00
|
|
|
uncached_corvet_car.should eq corvet0
|
2024-05-22 05:34:14 +02:00
|
|
|
|
|
|
|
# Partitions.
|
2024-05-22 17:36:45 +02:00
|
|
|
red_cars = [ Car.new("Corvet-0", "red", [ "shiny", "impressive", "fast", "elegant" ]),
|
|
|
|
Car.new("Ford-5-0", "red", [ "unknown" ])
|
|
|
|
]
|
2024-05-22 05:34:14 +02:00
|
|
|
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
|
2024-05-22 17:36:45 +02:00
|
|
|
uncached_red_cars.sort.should eq red_cars.sort
|
2024-05-22 05:34:14 +02:00
|
|
|
|
|
|
|
# Tags.
|
2024-05-22 17:36:45 +02:00
|
|
|
fast_cars = [ Car.new("Corvet-0", "red", [ "shiny", "impressive", "fast", "elegant" ]),
|
|
|
|
Car.new("Bullet-GT-0", "blue", [ "shiny", "fast", "expensive" ])
|
|
|
|
]
|
2024-05-22 05:34:14 +02:00
|
|
|
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
|
2024-05-22 17:36:45 +02:00
|
|
|
uncached_fast_cars.sort.should eq fast_cars.sort
|
2024-05-22 05:34:14 +02:00
|
|
|
|
|
|
|
cars_ram0.rm_storage_dir
|
|
|
|
cars_ram1.rm_storage_dir
|
|
|
|
cars_ram2.rm_storage_dir
|
|
|
|
end
|
|
|
|
end
|