Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 123 lines (90 sloc) 3.637 kB
c45a060 @karmi [#209] Added support for creating index aliases with configuration, c…
authored
1 require 'test_helper'
2
67aa3a4 @karmi [ALIASES] Added `Tire::Alias`, interface and DSL to manage aliases as…
authored
3 require 'active_support/core_ext/numeric'
4 require 'active_support/core_ext/date/calculations'
5
c45a060 @karmi [#209] Added support for creating index aliases with configuration, c…
authored
6 module Tire
7
8 class IndexAliasesIntegrationTest < Test::Unit::TestCase
9 include Test::Integration
10
11 context "With a filtered alias" do
12 setup do
13
14 @index = Tire.index 'index-original' do
15 delete
16 create
17 end
18
19 end
20
21 teardown { Tire.index('index-original').delete }
22
23 should "create the alias" do
24 @index.add_alias 'index-aliased'
25 assert_equal 1, @index.aliases.size
26 end
27
28 should "find only portion of documents in the filtered alias" do
29 Tire.index 'index-original' do
30 add_alias 'index-aliased', :filter => { :term => { :user => 'anne' } }
31 store :title => 'Document 1', :user => 'anne'
32 store :title => 'Document 2', :user => 'mary'
33
34 refresh
35 end
36
37 assert_equal 2, Tire.search('index-original') { query { all } }.results.size
38 assert_equal 1, Tire.search('index-aliased') { query { all } }.results.size
39 end
40
41 should "remove the alias" do
42 @index.add_alias 'index-aliased'
43 assert_equal 1, @index.aliases.size
44
45 @index.remove_alias 'index-aliased'
46 assert_equal 0, @index.aliases.size
47
48 assert_raise Tire::Search::SearchRequestFailed do
49 Tire.search('index-aliased') { query { all } }.results
50 end
51 end
52
53 should "retrieve a list of aliases for an index" do
54 @index.add_alias 'index-aliased'
55
67aa3a4 @karmi [ALIASES] Added `Tire::Alias`, interface and DSL to manage aliases as…
authored
56 assert_equal ['index-aliased'], @index.aliases.map(&:name)
c45a060 @karmi [#209] Added support for creating index aliases with configuration, c…
authored
57 end
58
59 should "retrieve the properties of an alias" do
60 @index.add_alias 'index-aliased', :routing => '1'
61
67aa3a4 @karmi [ALIASES] Added `Tire::Alias`, interface and DSL to manage aliases as…
authored
62 assert_equal '1', @index.aliases('index-aliased').search_routing
63 end
64 end
65
66 context "In the 'sliding window' scenario" do
67
68 setup do
69 WINDOW_SIZE_IN_WEEKS = 4
70
71 @indices = WINDOW_SIZE_IN_WEEKS.times.map { |number| "articles_#{number.weeks.ago.strftime('%Y-%m-%d')}" }
72
73 @indices.each_with_index do |name,i|
74 Tire.index(name) do
75 delete
76 create
77 store :title => "Document #{i}"
78 refresh
79 end
80 Alias.new(:name => "articles_current") { |a| a.indices(name) and a.save }
81 end
82 end
83
84 teardown do
85 @indices.each { |index| Tire.index(index).delete }
c45a060 @karmi [#209] Added support for creating index aliases with configuration, c…
authored
86 end
67aa3a4 @karmi [ALIASES] Added `Tire::Alias`, interface and DSL to manage aliases as…
authored
87
88 should "add a new index to alias" do
89 @indices << "articles_#{(WINDOW_SIZE_IN_WEEKS+1).weeks.ago.strftime('%Y-%m-%d')}"
90 Tire.index(@indices.last).create
91 Alias.new(:name => "articles_current") { |a| a.index @indices.last and a.save }
92
93 a = Alias.find("articles_current")
94 assert_equal 5, a.indices.size
95 end
96
97 should "remove the stale index from the alias" do
98 Alias.find("articles_current") do |a|
99 # Remove all indices older then 2 weeks from the alias
100 a.indices.delete_if do |i|
101 Time.parse( i.gsub(/articles_/, '') ) < 2.weeks.ago rescue false
102 end
103 a.save
104 end
105
106 assert_equal 2, Alias.find("articles_current").indices.size
107 end
108
109 should "search within the alias" do
110 Alias.find("articles_current") do |a|
111 a.indices.clear and a.indices @indices[0..1] and a.save
112 end
113
114 assert_equal 4, Tire.search(@indices) { query {all} }.results.size
115 assert_equal 2, Tire.search("articles_current") { query {all} }.results.size
116 end
117
c45a060 @karmi [#209] Added support for creating index aliases with configuration, c…
authored
118 end
119
120 end
121
122 end
Something went wrong with that request. Please try again.