solr_wrapper 0.7.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.travis.yml +6 -2
- data/exe/solr_wrapper +14 -8
- data/lib/solr_wrapper/configuration.rb +54 -18
- data/lib/solr_wrapper/downloader.rb +15 -9
- data/lib/solr_wrapper/instance.rb +69 -14
- data/lib/solr_wrapper/settings.rb +13 -1
- data/lib/solr_wrapper/tasks/solr_wrapper.rake +1 -2
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +12 -4
- data/spec/fixtures/sample_config.yml +4 -0
- data/spec/lib/solr_wrapper/configuration_spec.rb +20 -0
- data/spec/lib/solr_wrapper/instance_spec.rb +45 -6
- data/spec/lib/solr_wrapper_spec.rb +8 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 355fb4da1493c8acef5c50b5592fbe773c220bf2
|
|
4
|
+
data.tar.gz: 028aaa504c0253da58d78ad498bdfe45849c0795
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5852f71aa91dca84cc24c4587a0300c3cafc218e621d6400a1a21eeab070a659dfa2f81a88417f347af032a9606ad850633548a1079a42cf113244fefcf185be
|
|
7
|
+
data.tar.gz: 78bc51949c8bf5c2a1dfa107a01144f748e4a3b834b9602fad88ad01785c20e5e74fcf1ea0ce48ef1081681baf79e9ca12d73e74414484206ee65d0db9177ef2
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/exe/solr_wrapper
CHANGED
|
@@ -5,14 +5,14 @@ require 'optparse'
|
|
|
5
5
|
|
|
6
6
|
options = {}
|
|
7
7
|
collection_options = {}
|
|
8
|
-
OptionParser.new do |opts|
|
|
8
|
+
args = OptionParser.new do |opts|
|
|
9
9
|
opts.banner = "Usage: solr_wrapper [options]"
|
|
10
10
|
|
|
11
11
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
|
12
12
|
options[:verbose] = v
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
opts.on("--config", "Load configuration from a file") do |v|
|
|
15
|
+
opts.on("--config FILE", "Load configuration from a file") do |v|
|
|
16
16
|
options[:config] = v
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ OptionParser.new do |opts|
|
|
|
20
20
|
options[:version] = v
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
opts.on("-pPORT", "--port PORT", "Specify the port Solr should run at (default:
|
|
23
|
+
opts.on("-pPORT", "--port PORT", "Specify the port Solr should run at (default: #{SolrWrapper.default_solr_port})") do |p|
|
|
24
24
|
if p == 'random'
|
|
25
25
|
options[:port] = nil
|
|
26
26
|
else
|
|
@@ -55,20 +55,26 @@ OptionParser.new do |opts|
|
|
|
55
55
|
opts.on("--no-checksum", "Skip running checksum validation on the downloaded file") do |d|
|
|
56
56
|
options[:ignore_md5sum] = true
|
|
57
57
|
end
|
|
58
|
-
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
args.parse!
|
|
62
|
+
rescue => error
|
|
63
|
+
$stderr.puts "ERROR: #{error}\n"
|
|
64
|
+
$stderr.puts args.help
|
|
65
|
+
exit 1
|
|
66
|
+
end
|
|
59
67
|
|
|
60
68
|
# default to verbose
|
|
61
69
|
options[:verbose] = true if options[:verbose].nil?
|
|
62
70
|
|
|
63
|
-
instance = SolrWrapper.
|
|
71
|
+
instance = SolrWrapper.instance(options)
|
|
64
72
|
$stderr.print "Starting Solr #{instance.version} on port #{instance.port} ... "
|
|
65
73
|
instance.wrap do |conn|
|
|
66
74
|
conn.with_collection(collection_options) do
|
|
67
75
|
$stderr.puts "http://#{instance.host}:#{instance.port}/solr/"
|
|
68
76
|
begin
|
|
69
|
-
|
|
70
|
-
sleep 1
|
|
71
|
-
end
|
|
77
|
+
conn.wait
|
|
72
78
|
rescue Interrupt
|
|
73
79
|
$stderr.puts "Solr is shutting down."
|
|
74
80
|
end
|
|
@@ -3,8 +3,8 @@ module SolrWrapper
|
|
|
3
3
|
attr_reader :options
|
|
4
4
|
|
|
5
5
|
def initialize(options)
|
|
6
|
-
@options = options
|
|
7
|
-
|
|
6
|
+
@options = read_config(options[:config], options[:verbose])
|
|
7
|
+
.merge options
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def solr_xml
|
|
@@ -35,7 +35,15 @@ module SolrWrapper
|
|
|
35
35
|
# Check if the port option has been explicitly set to nil.
|
|
36
36
|
# this means to start solr wrapper on a random open port
|
|
37
37
|
return nil if options.key?(:port) && !options[:port]
|
|
38
|
-
options
|
|
38
|
+
options.fetch(:port) { SolrWrapper.default_instance_options[:port] }.to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def zookeeper_host
|
|
42
|
+
options[:zookeeper_host]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def zookeeper_port
|
|
46
|
+
options[:zookeeper_port]
|
|
39
47
|
end
|
|
40
48
|
|
|
41
49
|
def download_path
|
|
@@ -43,7 +51,15 @@ module SolrWrapper
|
|
|
43
51
|
end
|
|
44
52
|
|
|
45
53
|
def download_dir
|
|
46
|
-
options[:download_dir]
|
|
54
|
+
options[:download_dir] || default_download_dir
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def default_download_dir
|
|
58
|
+
if defined?(Rails) && Rails.root
|
|
59
|
+
File.join(Rails.root, 'tmp')
|
|
60
|
+
else
|
|
61
|
+
Dir.tmpdir
|
|
62
|
+
end
|
|
47
63
|
end
|
|
48
64
|
|
|
49
65
|
def solr_options
|
|
@@ -78,27 +94,47 @@ module SolrWrapper
|
|
|
78
94
|
options[:version_file]
|
|
79
95
|
end
|
|
80
96
|
|
|
97
|
+
def collection_options
|
|
98
|
+
hash = options.fetch(:collection, {})
|
|
99
|
+
Configuration.slice(convert_keys(hash), :name, :dir)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def poll_interval
|
|
103
|
+
options.fetch(:poll_interval, 1)
|
|
104
|
+
end
|
|
105
|
+
|
|
81
106
|
private
|
|
82
107
|
|
|
83
|
-
def
|
|
84
|
-
|
|
108
|
+
def self.slice(source, *keys)
|
|
109
|
+
keys.each_with_object({}) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def read_config(config_file, verbose)
|
|
85
113
|
default_configuration_paths.each do |p|
|
|
86
114
|
path = File.expand_path(p)
|
|
87
|
-
|
|
115
|
+
config_file ||= path if File.exist? path
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
unless config_file
|
|
119
|
+
$stdout.puts "No config specified" if verbose
|
|
120
|
+
return {}
|
|
88
121
|
end
|
|
89
122
|
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
end
|
|
97
|
-
collection_config = config.delete(:collection) || {}
|
|
98
|
-
@options = config.merge(options)
|
|
99
|
-
elsif verbose?
|
|
100
|
-
$stdout.puts "No config specified"
|
|
123
|
+
$stdout.puts "Loading configuration from #{config_file}" if verbose
|
|
124
|
+
config = YAML.load(ERB.new(IO.read(config_file)).result(binding))
|
|
125
|
+
unless config
|
|
126
|
+
$stderr.puts "Unable to parse config #{config_file}" if verbose
|
|
127
|
+
return {}
|
|
101
128
|
end
|
|
129
|
+
convert_keys(config)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def convert_keys(hash)
|
|
133
|
+
hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def default_configuration_paths
|
|
137
|
+
['.solr_wrapper', '~/.solr_wrapper']
|
|
102
138
|
end
|
|
103
139
|
end
|
|
104
140
|
end
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
require 'ruby-progressbar'
|
|
2
|
+
|
|
1
3
|
module SolrWrapper
|
|
2
4
|
class Downloader
|
|
3
5
|
def self.fetch_with_progressbar(url, output)
|
|
4
|
-
pbar =
|
|
5
|
-
open(url, content_length_proc:
|
|
6
|
-
if t && 0 < t
|
|
7
|
-
pbar.total = t
|
|
8
|
-
end
|
|
9
|
-
end,
|
|
10
|
-
progress_proc: lambda do|s|
|
|
11
|
-
pbar.progress = s
|
|
12
|
-
end) do |io|
|
|
6
|
+
pbar = SafeProgressBar.new(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )')
|
|
7
|
+
open(url, content_length_proc: ->(bytes) { pbar.total = bytes }, progress_proc: ->(bytes) { pbar.progress = bytes }) do |io|
|
|
13
8
|
IO.copy_stream(io, output)
|
|
14
9
|
end
|
|
15
10
|
end
|
|
11
|
+
|
|
12
|
+
class SafeProgressBar < ProgressBar::Base
|
|
13
|
+
def progress=(new_progress)
|
|
14
|
+
self.total = new_progress if total <= new_progress
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def total=(new_total)
|
|
19
|
+
super if new_total && new_total > 0
|
|
20
|
+
end
|
|
21
|
+
end
|
|
16
22
|
end
|
|
17
23
|
end
|
|
@@ -2,7 +2,6 @@ require 'digest'
|
|
|
2
2
|
require 'fileutils'
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'open-uri'
|
|
5
|
-
require 'ruby-progressbar'
|
|
6
5
|
require 'securerandom'
|
|
7
6
|
require 'socket'
|
|
8
7
|
require 'stringio'
|
|
@@ -13,7 +12,7 @@ require 'yaml'
|
|
|
13
12
|
|
|
14
13
|
module SolrWrapper
|
|
15
14
|
class Instance
|
|
16
|
-
attr_reader :config, :md5
|
|
15
|
+
attr_reader :config, :md5
|
|
17
16
|
|
|
18
17
|
##
|
|
19
18
|
# @param [Hash] options
|
|
@@ -51,6 +50,10 @@ module SolrWrapper
|
|
|
51
50
|
config.url
|
|
52
51
|
end
|
|
53
52
|
|
|
53
|
+
def instance_dir
|
|
54
|
+
config.instance_dir
|
|
55
|
+
end
|
|
56
|
+
|
|
54
57
|
def version
|
|
55
58
|
config.version
|
|
56
59
|
end
|
|
@@ -72,7 +75,7 @@ module SolrWrapper
|
|
|
72
75
|
|
|
73
76
|
# Wait for solr to start
|
|
74
77
|
unless status
|
|
75
|
-
sleep
|
|
78
|
+
sleep config.poll_interval
|
|
76
79
|
end
|
|
77
80
|
end
|
|
78
81
|
end
|
|
@@ -81,15 +84,9 @@ module SolrWrapper
|
|
|
81
84
|
# Stop Solr and wait for it to finish exiting
|
|
82
85
|
def stop
|
|
83
86
|
if config.managed? && started?
|
|
84
|
-
|
|
85
87
|
exec('stop', p: port)
|
|
86
|
-
|
|
87
|
-
while status
|
|
88
|
-
sleep 1
|
|
89
|
-
end
|
|
88
|
+
wait
|
|
90
89
|
end
|
|
91
|
-
|
|
92
|
-
@pid = nil
|
|
93
90
|
end
|
|
94
91
|
|
|
95
92
|
##
|
|
@@ -111,12 +108,31 @@ module SolrWrapper
|
|
|
111
108
|
false
|
|
112
109
|
end
|
|
113
110
|
|
|
111
|
+
def pid
|
|
112
|
+
return unless config.managed?
|
|
113
|
+
|
|
114
|
+
@pid ||= begin
|
|
115
|
+
out = exec('status').read
|
|
116
|
+
out.match(/process (?<pid>\d+) running on port #{port}/) do |m|
|
|
117
|
+
m[:pid].to_i
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
rescue
|
|
121
|
+
nil
|
|
122
|
+
end
|
|
123
|
+
|
|
114
124
|
##
|
|
115
125
|
# Is Solr running?
|
|
116
126
|
def started?
|
|
117
127
|
!!status
|
|
118
128
|
end
|
|
119
129
|
|
|
130
|
+
def wait
|
|
131
|
+
while (Process.getpgid(pid) rescue status)
|
|
132
|
+
sleep config.poll_interval
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
120
136
|
##
|
|
121
137
|
# Create a new collection in solr
|
|
122
138
|
# @param [Hash] options
|
|
@@ -127,12 +143,49 @@ module SolrWrapper
|
|
|
127
143
|
|
|
128
144
|
create_options = { p: port }
|
|
129
145
|
create_options[:c] = options[:name] if options[:name]
|
|
146
|
+
create_options[:n] = options[:config_name] if options[:config_name]
|
|
130
147
|
create_options[:d] = options[:dir] if options[:dir]
|
|
131
148
|
exec("create", create_options)
|
|
132
149
|
|
|
133
150
|
options[:name]
|
|
134
151
|
end
|
|
135
152
|
|
|
153
|
+
##
|
|
154
|
+
# Update the collection configuration in zookeeper
|
|
155
|
+
# @param [Hash] options
|
|
156
|
+
# @option options [String] :config_name
|
|
157
|
+
# @option options [String] :dir
|
|
158
|
+
def upconfig(options = {})
|
|
159
|
+
options[:name] ||= SecureRandom.hex
|
|
160
|
+
options[:zkhost] ||= zkhost
|
|
161
|
+
|
|
162
|
+
upconfig_options = { upconfig: true, n: options[:name] }
|
|
163
|
+
upconfig_options[:d] = options[:dir] if options[:dir]
|
|
164
|
+
upconfig_options[:z] = options[:zkhost] if options[:zkhost]
|
|
165
|
+
|
|
166
|
+
exec 'zk', upconfig_options
|
|
167
|
+
|
|
168
|
+
options[:name]
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
##
|
|
172
|
+
# Copy the collection configuration from zookeeper to a local directory
|
|
173
|
+
# @param [Hash] options
|
|
174
|
+
# @option options [String] :config_name
|
|
175
|
+
# @option options [String] :dir
|
|
176
|
+
def downconfig(options = {})
|
|
177
|
+
options[:name] ||= SecureRandom.hex
|
|
178
|
+
options[:zkhost] ||= zkhost
|
|
179
|
+
|
|
180
|
+
downconfig_options = { downconfig: true, n: options[:name] }
|
|
181
|
+
downconfig_options[:d] = options[:dir] if options[:dir]
|
|
182
|
+
downconfig_options[:z] = options[:zkhost] if options[:zkhost]
|
|
183
|
+
|
|
184
|
+
exec 'zk', downconfig_options
|
|
185
|
+
|
|
186
|
+
options[:name]
|
|
187
|
+
end
|
|
188
|
+
|
|
136
189
|
##
|
|
137
190
|
# Create a new collection in solr
|
|
138
191
|
# @param [String] name collection name
|
|
@@ -146,6 +199,7 @@ module SolrWrapper
|
|
|
146
199
|
# @option options [String] :name
|
|
147
200
|
# @option options [String] :dir
|
|
148
201
|
def with_collection(options = {})
|
|
202
|
+
options = config.collection_options.merge(options)
|
|
149
203
|
return yield if options.empty?
|
|
150
204
|
|
|
151
205
|
name = create(options)
|
|
@@ -264,7 +318,6 @@ module SolrWrapper
|
|
|
264
318
|
# JRuby
|
|
265
319
|
env_str = config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(" ")
|
|
266
320
|
pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
|
|
267
|
-
@pid = pid
|
|
268
321
|
stringio = StringIO.new
|
|
269
322
|
if config.verbose? && !silence_output
|
|
270
323
|
IO.copy_stream(output, $stderr)
|
|
@@ -277,7 +330,7 @@ module SolrWrapper
|
|
|
277
330
|
input.close
|
|
278
331
|
output.close
|
|
279
332
|
error.close
|
|
280
|
-
exit_status = Process.waitpid2(
|
|
333
|
+
exit_status = Process.waitpid2(pid).last
|
|
281
334
|
else
|
|
282
335
|
IO.popen(config.env, args + [err: [:child, :out]]) do |io|
|
|
283
336
|
stringio = StringIO.new
|
|
@@ -288,8 +341,6 @@ module SolrWrapper
|
|
|
288
341
|
IO.copy_stream(io, stringio)
|
|
289
342
|
end
|
|
290
343
|
|
|
291
|
-
@pid = io.pid
|
|
292
|
-
|
|
293
344
|
_, exit_status = Process.wait2(io.pid)
|
|
294
345
|
end
|
|
295
346
|
end
|
|
@@ -314,6 +365,10 @@ module SolrWrapper
|
|
|
314
365
|
end
|
|
315
366
|
end
|
|
316
367
|
|
|
368
|
+
def zkhost
|
|
369
|
+
"#{config.zookeeper_host}:#{config.zookeeper_port}" if config.cloud
|
|
370
|
+
end
|
|
371
|
+
|
|
317
372
|
def raise_error_unless_extracted
|
|
318
373
|
raise RuntimeError, "there is no solr instance at #{config.instance_dir}. Run SolrWrapper.extract first." unless extracted?
|
|
319
374
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'delegate'
|
|
2
|
+
|
|
1
3
|
module SolrWrapper
|
|
2
4
|
# Configuraton that comes from static and dynamic sources.
|
|
3
5
|
class Settings < Delegator
|
|
@@ -23,6 +25,11 @@ module SolrWrapper
|
|
|
23
25
|
'127.0.0.1'
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
def zookeeper_host
|
|
29
|
+
@zookeeper_host ||= static_config.zookeeper_port
|
|
30
|
+
@zookeeper_host ||= host
|
|
31
|
+
end
|
|
32
|
+
|
|
26
33
|
##
|
|
27
34
|
# Get the port this Solr instance is running at
|
|
28
35
|
def port
|
|
@@ -30,6 +37,12 @@ module SolrWrapper
|
|
|
30
37
|
@port ||= random_open_port.to_s
|
|
31
38
|
end
|
|
32
39
|
|
|
40
|
+
def zookeeper_port
|
|
41
|
+
@zookeeper_port ||= static_config.zookeeper_port
|
|
42
|
+
@zookeeper_port ||= "#{port.to_i + 1000}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
33
46
|
##
|
|
34
47
|
# Get a (likely) URL to the solr instance
|
|
35
48
|
def url
|
|
@@ -83,7 +96,6 @@ module SolrWrapper
|
|
|
83
96
|
|
|
84
97
|
def download_dir
|
|
85
98
|
@download_dir ||= static_config.download_dir
|
|
86
|
-
@download_dir ||= Dir.tmpdir
|
|
87
99
|
FileUtils.mkdir_p @download_dir
|
|
88
100
|
@download_dir
|
|
89
101
|
end
|
|
@@ -4,8 +4,7 @@ require 'solr_wrapper'
|
|
|
4
4
|
namespace :solr do
|
|
5
5
|
desc "Load the solr options and solr instance"
|
|
6
6
|
task :environment do
|
|
7
|
-
|
|
8
|
-
@solr_instance = SolrWrapper.default_instance
|
|
7
|
+
@solr_instance = SolrWrapper.instance
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
desc 'Install a clean version of solr. Replaces the existing copy if there is one.'
|
data/lib/solr_wrapper/version.rb
CHANGED
data/lib/solr_wrapper.rb
CHANGED
|
@@ -7,12 +7,16 @@ require 'solr_wrapper/instance'
|
|
|
7
7
|
|
|
8
8
|
module SolrWrapper
|
|
9
9
|
def self.default_solr_version
|
|
10
|
-
'
|
|
10
|
+
'6.0.0'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.default_solr_port
|
|
14
|
+
'8983'
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def self.default_instance_options
|
|
14
18
|
@default_instance_options ||= {
|
|
15
|
-
port:
|
|
19
|
+
port: SolrWrapper.default_solr_port,
|
|
16
20
|
version: SolrWrapper.default_solr_version
|
|
17
21
|
}
|
|
18
22
|
end
|
|
@@ -22,12 +26,16 @@ module SolrWrapper
|
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def self.default_instance(options = {})
|
|
25
|
-
@default_instance ||=
|
|
29
|
+
@default_instance ||= instance(default_instance_options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.instance(options = {})
|
|
33
|
+
SolrWrapper::Instance.new(options)
|
|
26
34
|
end
|
|
27
35
|
|
|
28
36
|
##
|
|
29
37
|
# Ensures a Solr service is running before executing the block
|
|
30
38
|
def self.wrap(options = {}, &block)
|
|
31
|
-
|
|
39
|
+
instance(options).wrap &block
|
|
32
40
|
end
|
|
33
41
|
end
|
|
@@ -21,4 +21,24 @@ describe SolrWrapper::Configuration do
|
|
|
21
21
|
it { is_expected.to eq '8888' }
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
describe "#read_config" do
|
|
26
|
+
before do
|
|
27
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
28
|
+
end
|
|
29
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
30
|
+
it "uses values from the config file" do
|
|
31
|
+
expect(config.port).to eq '9999'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#collection_options" do
|
|
36
|
+
before do
|
|
37
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
38
|
+
end
|
|
39
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
40
|
+
it "uses values from the config file" do
|
|
41
|
+
expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
24
44
|
end
|
|
@@ -1,18 +1,52 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe SolrWrapper::Instance do
|
|
4
|
-
let(:
|
|
4
|
+
let(:options) { {} }
|
|
5
|
+
let(:solr_instance) { SolrWrapper::Instance.new(options) }
|
|
5
6
|
subject { solr_instance }
|
|
6
7
|
let(:client) { SimpleSolrClient::Client.new(subject.url) }
|
|
7
8
|
|
|
8
9
|
describe "#with_collection" do
|
|
9
|
-
|
|
10
|
+
context "without a name" do
|
|
11
|
+
it "creates a new anonymous collection" do
|
|
12
|
+
subject.wrap do |solr|
|
|
13
|
+
solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
|
|
14
|
+
core = client.core(collection_name)
|
|
15
|
+
unless defined? JRUBY_VERSION
|
|
16
|
+
expect(core.schema.field('id').name).to eq 'id'
|
|
17
|
+
expect(core.schema.field('id').stored).to eq true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
context "with a config file" do
|
|
24
|
+
before do
|
|
25
|
+
allow(solr_instance.config).to receive(:collection_options)
|
|
26
|
+
.and_return(name: 'project-development', dir: 'solr/config/')
|
|
27
|
+
allow(solr_instance).to receive(:delete)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "creates a new collection with options from the config" do
|
|
31
|
+
expect(solr_instance).to receive(:create).with(
|
|
32
|
+
hash_including(name: "project-development", dir: anything))
|
|
33
|
+
solr_instance.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) {}
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context 'with a SolrCloud instance' do
|
|
39
|
+
let(:options) { { cloud: true } }
|
|
40
|
+
it 'can upload configurations' do
|
|
10
41
|
subject.wrap do |solr|
|
|
11
|
-
solr.
|
|
42
|
+
config_name = solr.upconfig dir: File.join(FIXTURES_DIR, 'basic_configs')
|
|
43
|
+
Dir.mktmpdir do |dir|
|
|
44
|
+
solr.downconfig name: config_name, dir: dir
|
|
45
|
+
end
|
|
46
|
+
solr.with_collection(config_name: config_name) do |collection_name|
|
|
12
47
|
core = client.core(collection_name)
|
|
13
48
|
unless defined? JRUBY_VERSION
|
|
14
|
-
expect(core.
|
|
15
|
-
expect(core.schema.field('id').stored).to eq true
|
|
49
|
+
expect(core.all.size).to eq 0
|
|
16
50
|
end
|
|
17
51
|
end
|
|
18
52
|
end
|
|
@@ -56,9 +90,14 @@ describe SolrWrapper::Instance do
|
|
|
56
90
|
it { is_expected.to eq 'http://127.0.0.1:8983/solr/' }
|
|
57
91
|
end
|
|
58
92
|
|
|
93
|
+
describe "#instance_dir" do
|
|
94
|
+
subject { solr_instance.instance_dir }
|
|
95
|
+
it { is_expected.to start_with Dir.tmpdir }
|
|
96
|
+
end
|
|
97
|
+
|
|
59
98
|
describe "#version" do
|
|
60
99
|
subject { solr_instance.version }
|
|
61
|
-
it { is_expected.to eq '
|
|
100
|
+
it { is_expected.to eq '6.0.0' }
|
|
62
101
|
end
|
|
63
102
|
|
|
64
103
|
describe "#md5" do
|
|
@@ -13,6 +13,14 @@ describe SolrWrapper do
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
describe '.instance' do
|
|
17
|
+
context 'without arguments' do
|
|
18
|
+
it 'inherits the defaults' do
|
|
19
|
+
expect(SolrWrapper.instance.port).to eq '8983'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
16
24
|
describe ".default_instance_options=" do
|
|
17
25
|
it "sets default options" do
|
|
18
26
|
SolrWrapper.default_instance_options = { port: '1234' }
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solr_wrapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Beer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- spec/fixtures/basic_configs/solrconfig.xml
|
|
147
147
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
148
148
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
149
|
+
- spec/fixtures/sample_config.yml
|
|
149
150
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
150
151
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
151
152
|
- spec/lib/solr_wrapper_spec.rb
|
|
@@ -170,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
170
171
|
version: '0'
|
|
171
172
|
requirements: []
|
|
172
173
|
rubyforge_project:
|
|
173
|
-
rubygems_version: 2.5.1
|
|
174
|
+
rubygems_version: 2.4.5.1
|
|
174
175
|
signing_key:
|
|
175
176
|
specification_version: 4
|
|
176
177
|
summary: Solr 5 service wrapper
|
|
@@ -183,8 +184,8 @@ test_files:
|
|
|
183
184
|
- spec/fixtures/basic_configs/solrconfig.xml
|
|
184
185
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
185
186
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
187
|
+
- spec/fixtures/sample_config.yml
|
|
186
188
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
187
189
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
188
190
|
- spec/lib/solr_wrapper_spec.rb
|
|
189
191
|
- spec/spec_helper.rb
|
|
190
|
-
has_rdoc:
|