Created
August 21, 2013 14:05
-
-
Save ondrejbartas/6294885 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding : utf-8 -*- | |
require 'tire' | |
require 'tire/http/clients/curb' | |
Tire.configure do | |
# # logger 'log/elasticsearch.log', :level => 'debug' if Bandit.env == 'development' | |
# #logger STDOUT, :level => 'debug' | |
client Tire::HTTP::Client::Curb | |
end | |
class FirstItem | |
include Tire::Model::Persistence | |
settings :number_of_shards => 1 | |
index_name = "test_thread_first" | |
property :name , type: "string", index: 'not_analyzed' | |
property :first_property , type: "string", index: 'not_analyzed' | |
end | |
class SecondItem | |
include Tire::Model::Persistence | |
settings :number_of_shards => 1 | |
index_name = "test_thread_second" | |
property :name , type: "string", index: 'not_analyzed' | |
property :second_property , type: "string", index: 'not_analyzed' | |
end | |
class ThirdItem | |
include Tire::Model::Persistence | |
settings :number_of_shards => 1 | |
index_name = "test_thread_third" | |
property :name , type: "string", index: 'not_analyzed' | |
property :third_property , type: "string", index: 'not_analyzed' | |
end | |
puts "Creating nonexisting indexes" | |
[FirstItem, SecondItem, ThirdItem].each do |klass| | |
klass.index.delete if klass.index.exists? | |
end | |
[FirstItem, SecondItem, ThirdItem].each do |klass| | |
unless klass.index.exists? | |
puts "Creating Tire index: #{klass.index_name}" | |
klass.tire.create_elasticsearch_index | |
end | |
end | |
puts "Filling data" | |
first_item = FirstItem.new(name: "First item name", first_property: "foo") | |
first_item.save | |
second_item = SecondItem.new(name: "Second item name", second_property: "bar") | |
second_item.save | |
third_item = ThirdItem.new(name: "Third item name", third_property: "foobar") | |
third_item.save | |
puts "Test start" | |
10.times do | |
fork do | |
sleep 1 | |
puts Thread.current[:client] | |
puts FirstItem.find(first_item.id).name == "First item name" | |
puts SecondItem.find(second_item.id).name == "Second item name" | |
puts ThirdItem.find(third_item.id).name == "Third item name" | |
end | |
end | |
10.times do | |
fork do | |
puts Thread.current[:client] | |
puts FirstItem.find(first_item.id).name == "First item name" | |
puts SecondItem.find(second_item.id).name == "Second item name" | |
puts ThirdItem.find(third_item.id).name == "Third item name" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment