search_flip 2.0.0.beta2 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +0,0 @@
1
-
2
- require File.expand_path("../test_helper", __dir__)
3
-
4
- class SearchFlip::BulkTest < SearchFlip::TestCase
5
- def test_bulk
6
- product1, product2 = create_list(:product, 2)
7
-
8
- assert_difference "ProductIndex.total_entries", 2 do
9
- ProductIndex.bulk do |bulk|
10
- bulk.create product1.id, ProductIndex.serialize(product1)
11
- bulk.create product2.id, ProductIndex.serialize(product1)
12
- end
13
- end
14
-
15
- assert_difference "ProductIndex.total_entries", -2 do
16
- ProductIndex.bulk do |bulk|
17
- bulk.delete product1.id
18
- bulk.delete product2.id
19
- end
20
- end
21
- end
22
-
23
- def test_bulk_with_options
24
- product1, product2 = create_list(:product, 2)
25
-
26
- ProductIndex.import [product1, product2]
27
-
28
- assert_raises "SearchFlip::Bulk::Error" do
29
- ProductIndex.bulk do |bulk|
30
- bulk.create product1.id, ProductIndex.serialize(product1)
31
- bulk.create product2.id, ProductIndex.serialize(product1)
32
- end
33
- end
34
-
35
- ProductIndex.bulk(ignore_errors: [409]) do |bulk|
36
- bulk.create product1.id, ProductIndex.serialize(product1)
37
- bulk.create product2.id, ProductIndex.serialize(product1)
38
- end
39
- end
40
-
41
- def test_bulk_with_item_options
42
- product = create(:product)
43
-
44
- ProductIndex.bulk do |bulk|
45
- bulk.index product.id, ProductIndex.serialize(product), version: 1, version_type: "external_gt"
46
- end
47
-
48
- assert_raises "SearchFlip::Bulk::Error" do
49
- ProductIndex.bulk do |bulk|
50
- bulk.index product.id, ProductIndex.serialize(product), version: 1, version_type: "external_gt"
51
- end
52
- end
53
- end
54
- end
55
-
@@ -1,161 +0,0 @@
1
-
2
- require File.expand_path("../test_helper", __dir__)
3
-
4
- class SearchFlip::ConnectionTest < SearchFlip::TestCase
5
- def test_base_url
6
- assert_equal SearchFlip::Connection.new(base_url: "base url").base_url, "base url"
7
- end
8
-
9
- def test_msearch
10
- ProductIndex.import create(:product)
11
- CommentIndex.import create(:comment)
12
-
13
- responses = SearchFlip::Connection.new.msearch([ProductIndex.match_all, CommentIndex.match_all])
14
-
15
- assert_equal 2, responses.size
16
- assert_equal 1, responses[0].total_entries
17
- assert_equal 1, responses[1].total_entries
18
- end
19
-
20
- def test_update_aliases
21
- connection = SearchFlip::Connection.new
22
-
23
- assert connection.update_aliases(actions: [add: { index: "products", alias: "alias1" }])
24
- assert connection.update_aliases(actions: [remove: { index: "products", alias: "alias1" }])
25
- end
26
-
27
- def test_get_index_aliases
28
- connection = SearchFlip::Connection.new
29
-
30
- connection.update_aliases(actions: [
31
- { add: { index: "comments", alias: "alias1" } },
32
- { add: { index: "products", alias: "alias2" } },
33
- { add: { index: "products", alias: "alias3" } }
34
- ])
35
-
36
- assert_equal connection.get_aliases.keys.sort, ["comments", "products"].sort
37
- assert_equal connection.get_aliases["products"]["aliases"].keys, ["alias2", "alias3"]
38
- assert_equal connection.get_aliases["comments"]["aliases"].keys, ["alias1"]
39
- assert_equal connection.get_aliases(index_name: "products").keys, ["products"]
40
- assert_equal connection.get_aliases(index_name: "comments,products").keys.sort, ["comments", "products"]
41
- assert_equal connection.get_aliases(alias_name: "alias1,alias2").keys.sort, ["comments", "products"]
42
- assert_equal connection.get_aliases(alias_name: "alias1,alias2")["products"]["aliases"].keys, ["alias2"]
43
- ensure
44
- connection.update_aliases(actions: [
45
- { remove: { index: "comments", alias: "alias1" } },
46
- { remove: { index: "products", alias: "alias2" } },
47
- { remove: { index: "products", alias: "alias3" } }
48
- ])
49
- end
50
-
51
- def test_alias_exists?
52
- connection = SearchFlip::Connection.new
53
-
54
- refute connection.alias_exists?(:some_alias)
55
-
56
- connection.update_aliases(actions: [add: { index: "products", alias: "some_alias" }])
57
-
58
- assert connection.alias_exists?(:some_alias)
59
- ensure
60
- connection.update_aliases(actions: [remove: { index: "products", alias: "some_alias" }])
61
- end
62
-
63
- def test_get_indices
64
- connection = SearchFlip::Connection.new
65
-
66
- assert_equal connection.get_indices.map { |index| index["index"] }.sort, ["comments", "products"]
67
- assert_equal connection.get_indices("com*").map { |index| index["index"] }.sort, ["comments"]
68
- end
69
-
70
- def test_create_index
71
- connection = SearchFlip::Connection.new
72
-
73
- assert connection.create_index("index_name")
74
- assert connection.index_exists?("index_name")
75
- ensure
76
- connection.delete_index("index_name") if connection.index_exists?("index_name")
77
- end
78
-
79
- def test_create_index_with_index_payload
80
- connection = SearchFlip::Connection.new
81
-
82
- connection.create_index("index_name", settings: { number_of_shards: 3 })
83
-
84
- assert_equal connection.get_index_settings("index_name")["index_name"]["settings"]["index"]["number_of_shards"], "3"
85
- ensure
86
- connection.delete_index("index_name") if connection.index_exists?("index_name")
87
- end
88
-
89
- def test_update_index_settings
90
- connection = SearchFlip::Connection.new
91
-
92
- connection.create_index("index_name")
93
- connection.update_index_settings("index_name", settings: { number_of_replicas: 3 })
94
-
95
- assert_equal "3", connection.get_index_settings("index_name")["index_name"]["settings"]["index"]["number_of_replicas"]
96
- ensure
97
- connection.delete_index("index_name") if connection.index_exists?("index_name")
98
- end
99
-
100
- def test_get_index_settings
101
- connection = SearchFlip::Connection.new
102
-
103
- connection.create_index("index_name", settings: { number_of_shards: 3 })
104
-
105
- assert_equal connection.get_index_settings("index_name")["index_name"]["settings"]["index"]["number_of_shards"], "3"
106
- ensure
107
- connection.delete_index("index_name") if connection.index_exists?("index_name")
108
- end
109
-
110
- def test_update_mapping
111
- connection = SearchFlip::Connection.new
112
-
113
- mapping = { "type_name" => { "properties" => { "id" => { "type" => "long" } } } }
114
-
115
- connection.create_index("index_name")
116
- connection.update_mapping("index_name", "type_name", mapping)
117
-
118
- assert_equal connection.get_mapping("index_name", "type_name"), "index_name" => { "mappings" => mapping }
119
- ensure
120
- connection.delete_index("index_name") if connection.index_exists?("index_name")
121
- end
122
-
123
- def test_delete_index
124
- connection = SearchFlip::Connection.new
125
-
126
- connection.create_index("index_name")
127
- assert connection.index_exists?("index_name")
128
-
129
- connection.delete_index("index_name")
130
- refute connection.index_exists?("index_name")
131
- ensure
132
- connection.delete_index("index_name") if connection.index_exists?("index_name")
133
- end
134
-
135
- def test_refresh
136
- connection = SearchFlip::Connection.new
137
-
138
- connection.create_index("index1")
139
- connection.create_index("index2")
140
-
141
- assert connection.refresh
142
- assert connection.refresh("index1")
143
- assert connection.refresh(["index1", "index2"])
144
- ensure
145
- connection.delete_index("index1") if connection.index_exists?("index1")
146
- connection.delete_index("index2") if connection.index_exists?("index2")
147
- end
148
-
149
- def test_index_url
150
- connection = SearchFlip::Connection.new(base_url: "base_url")
151
-
152
- assert_equal "base_url/index_name", connection.index_url("index_name")
153
- end
154
-
155
- def test_type_url
156
- connection = SearchFlip::Connection.new(base_url: "base_url")
157
-
158
- assert_equal "base_url/index_name/type_name", connection.type_url("index_name", "type_name")
159
- end
160
- end
161
-