Permalink
Browse files

[#449] Added an integration test for Index#bulk

  • Loading branch information...
1 parent 34cc508 commit 3ed745330616216f53d6ee30bb0ea6e37acc8aa2 @karmi committed Nov 11, 2012
Showing with 81 additions and 0 deletions.
  1. +81 −0 test/integration/bulk_test.rb
@@ -0,0 +1,81 @@
+require 'test_helper'
+
+module Tire
+
+ class BulkIntegrationTest < Test::Unit::TestCase
+ include Test::Integration
+
+ context "Bulk" do
+ setup do
+ @index = Tire.index('bulk-test') { delete; create }
+ @articles = [
+ { id: '1', type: 'article', title: 'one', tags: ['ruby'] },
+ { id: '2', type: 'article', title: 'two', tags: ['ruby', 'python'] },
+ { id: '3', type: 'article', title: 'three', tags: ['java'] }
+ ]
+ end
+
+ teardown do
+ @index.delete
+ Tire.index('bulk-test-fresh').delete
+ end
+
+ should "store a collection of documents and refresh the index" do
+ @index.bulk_store @articles, refresh: true
+ assert_equal 3, Tire.search('bulk-test/article').query { all }.results.size
+ end
+
+ should "extract the routing value from documents" do
+ @index.bulk_store [ { id: '1', title: 'A', _routing: 'a'}, { id: '2', title: 'B', _routing: 'b'} ]
+ @index.refresh
+
+ assert_equal 2, Tire.search('bulk-test') { query {all} }.results.size
+ assert_equal 1, Tire.search('bulk-test', routing: 'a') { query {all} }.results.size
+ assert_equal 1, Tire.search('bulk-test', routing: 'b') { query {all} }.results.size
+ end
+
+ should "delete documents in bulk" do
+ (1..10).to_a.each { |i| @index.store id: i }
+ @index.refresh
+ assert_equal 10, Tire.search('bulk-test') { query {all} }.results.size
+
+ documents = (1..10).to_a.map { |i| { id: i } }
+ @index.bulk_delete documents, refresh: true
+ assert_equal 0, Tire.search('bulk-test') { query {all} }.results.size
+ end
+
+ should "allow to feed search results to bulk API" do
+ (1..10).to_a.each { |i| @index.store id: i }
+ @index.refresh
+ assert_equal 10, Tire.search('bulk-test') { query {all} }.results.size
+
+ documents = Tire.search('bulk-test') { query {all} }.results.to_a
+
+ @index.bulk_delete documents, refresh: true
+ assert_equal 0, Tire.search('bulk-test') { query {all} }.results.size
+
+ Tire.index('bulk-test-fresh').bulk_create documents, refresh: true
+ assert_equal 10, Tire.search('bulk-test-fresh') { query {all} }.results.size
+ end
+
+ should "timeout when consistency factor is not met" do
+ # Tire.configure { logger STDERR, level: 'debug' }
+
+ Tire.index 'bulk-test' do
+ delete
+ create index: { number_of_shards: 1, number_of_replicas: 15 }
+ end
+
+ assert_raise Timeout::Error do
+ Timeout::timeout(3) do
+ Tire.index('bulk-test').bulk_store [ {id: '1', title: 'One' } ],
+ consistency: 'all',
+ raise: true
+ end
+ end
+ end
+ end
+
+ end
+
+end

0 comments on commit 3ed7453

Please sign in to comment.