spec/db-cars.cr updated for the new API.

This commit is contained in:
Philippe PITTOLI 2024-05-20 03:06:25 +02:00
parent 8a44828cf2
commit 143b2fa4b4

View File

@ -31,31 +31,31 @@ class Car
end
def ram_indexes(storage : DODB::Storage)
n = storage.new_nilable_RAM_index "name", &.name
c = storage.new_nilable_RAM_partition "color", &.color
k = storage.new_nilable_RAM_tags "keyword", &.keywords
n = storage.new_RAM_index "name", &.name
c = storage.new_RAM_partition "color", &.color
k = storage.new_RAM_tags "keyword", &.keywords
return n, c, k
end
def cached_indexes(storage : DODB::Storage)
n = storage.new_nilable_index "name", &.name
c = storage.new_nilable_partition "color", &.color
k = storage.new_nilable_tags "keyword", &.keywords
n = storage.new_index "name", &.name
c = storage.new_partition "color", &.color
k = storage.new_tags "keyword", &.keywords
return n, c, k
end
def uncached_indexes(storage : DODB::Storage)
n = storage.new_nilable_uncached_index "name", &.name
c = storage.new_nilable_uncached_partition "color", &.color
k = storage.new_nilable_uncached_tags "keyword", &.keywords
n = storage.new_uncached_index "name", &.name
c = storage.new_uncached_partition "color", &.color
k = storage.new_uncached_tags "keyword", &.keywords
return n, c, k
end
# `max_indexes` limits the number of indexes (partitions and tags).
# Once the last index (db last_index/5) is above this value, the following
# Once the last index (db last_key/5) is above this value, the following
# cars won't be tagged nor partitionned.
def add_cars(storage : DODB::Storage, nb_iterations : Int32, max_indexes = 5000)
last_index = ((storage.last_index + 1) / 5).to_i
last_key = ((storage.last_key + 1) / 5).to_i
i = 0
car1 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
car2 = Car.new "Bullet-GT", "blue", [ "shiny", "fast", "expensive" ]
@ -64,15 +64,15 @@ def add_cars(storage : DODB::Storage, nb_iterations : Int32, max_indexes = 5000)
car5 = Car.new "C-MAX", "gray", [ "spacious", "affordable" ]
while i < nb_iterations
car1.name = "Corvet-#{last_index}"
car2.name = "Bullet-GT-#{last_index}"
car3.name = "Deudeuche-#{last_index}"
car4.name = "Ford-5-#{last_index}"
car5.name = "C-MAX-#{last_index}"
car1.name = "Corvet-#{last_key}"
car2.name = "Bullet-GT-#{last_key}"
car3.name = "Deudeuche-#{last_key}"
car4.name = "Ford-5-#{last_key}"
car5.name = "C-MAX-#{last_key}"
last_index += 1
last_key += 1
if last_index > max_indexes
if last_key > max_indexes
car1.color = DODB.no_index
car2.color = DODB.no_index
car3.color = DODB.no_index
@ -86,11 +86,11 @@ def add_cars(storage : DODB::Storage, nb_iterations : Int32, max_indexes = 5000)
car5.keywords = DODB.no_index
end
storage << car1.clone
storage << car2.clone
storage << car3.clone
storage << car4.clone
storage << car5.clone
storage.unsafe_add car1.clone
storage.unsafe_add car2.clone
storage.unsafe_add car3.clone
storage.unsafe_add car4.clone
storage.unsafe_add car5.clone
i += 1
#STDOUT.write "\radding value #{i}".to_slice
end