solr_wrapper 0.9.0 → 0.10.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21a2a6e484329fe66c2531342783d9ac4007a1a3
4
- data.tar.gz: 25cd86f3084f418c6a88192986b0ba6d6a2013b5
3
+ metadata.gz: 7916cf546d675d2a3f008f4a271aa4fc2cf7b8ae
4
+ data.tar.gz: 3d2e1456ff74edb606a60cef2fa1731ae5a74351
5
5
  SHA512:
6
- metadata.gz: 08b856eb075be3bb9521531f700ba0dd367f18917a787cda40537419707c16a69abc6c6ad27c1a64459a6642a73c7e0aa705d41e5fcc1a13d212dc5708b020fe
7
- data.tar.gz: 9ee588f5119ad0806f84178b2969e7b06f26d3a0407913e5f0a99ae5d80585249a6b360e64e032795d778b3bc04173ab8419ad1b6ef4616a6eb2ea38a7e97481
6
+ metadata.gz: ff2b8b312c13c8b68c233f0799c68f36761109beea56fe2648485a89be28980b53d16d5646479ce58c0575cdde11025ff9ed74b81c923eb923953dcfbcf862cf
7
+ data.tar.gz: 58a248017fd9ec7330af89ca300d686710a6c71c36d96d9af5cd1967e8c1a703be7618835d30d3f5f7066958e1046fef686f3fa2b0d2d308e3c8f4990c3963fe
data/.rubocop.yml CHANGED
@@ -10,4 +10,7 @@ Metrics/LineLength:
10
10
 
11
11
  # Offense count: 61
12
12
  Metrics/AbcSize:
13
- Max: 59
13
+ Max: 59
14
+
15
+ Style/RescueModifier:
16
+ Enabled: false
data/exe/solr_wrapper CHANGED
@@ -74,9 +74,7 @@ instance.wrap do |conn|
74
74
  conn.with_collection(collection_options) do
75
75
  $stderr.puts "http://#{instance.host}:#{instance.port}/solr/"
76
76
  begin
77
- while conn.status
78
- sleep 1
79
- end
77
+ conn.wait
80
78
  rescue Interrupt
81
79
  $stderr.puts "Solr is shutting down."
82
80
  end
@@ -55,7 +55,7 @@ module SolrWrapper
55
55
  end
56
56
 
57
57
  def default_download_dir
58
- if defined? Rails
58
+ if defined?(Rails) && Rails.root
59
59
  File.join(Rails.root, 'tmp')
60
60
  else
61
61
  Dir.tmpdir
@@ -99,6 +99,15 @@ module SolrWrapper
99
99
  Configuration.slice(convert_keys(hash), :name, :dir)
100
100
  end
101
101
 
102
+ def configsets
103
+ configsets = options[:configsets] || []
104
+ configsets.map { |x| convert_keys(x) }
105
+ end
106
+
107
+ def poll_interval
108
+ options.fetch(:poll_interval, 1)
109
+ end
110
+
102
111
  private
103
112
 
104
113
  def self.slice(source, *keys)
@@ -12,7 +12,7 @@ require 'yaml'
12
12
 
13
13
  module SolrWrapper
14
14
  class Instance
15
- attr_reader :config, :md5, :pid
15
+ attr_reader :config, :md5
16
16
 
17
17
  ##
18
18
  # @param [Hash] options
@@ -75,8 +75,10 @@ module SolrWrapper
75
75
 
76
76
  # Wait for solr to start
77
77
  unless status
78
- sleep 1
78
+ sleep config.poll_interval
79
79
  end
80
+
81
+ after_start
80
82
  end
81
83
  end
82
84
 
@@ -84,15 +86,9 @@ module SolrWrapper
84
86
  # Stop Solr and wait for it to finish exiting
85
87
  def stop
86
88
  if config.managed? && started?
87
-
88
89
  exec('stop', p: port)
89
- # Wait for solr to stop
90
- while status
91
- sleep 1
92
- end
90
+ wait
93
91
  end
94
-
95
- @pid = nil
96
92
  end
97
93
 
98
94
  ##
@@ -114,12 +110,31 @@ module SolrWrapper
114
110
  false
115
111
  end
116
112
 
113
+ def pid
114
+ return unless config.managed?
115
+
116
+ @pid ||= begin
117
+ out = exec('status').read
118
+ out.match(/process (?<pid>\d+) running on port #{port}/) do |m|
119
+ m[:pid].to_i
120
+ end
121
+ end
122
+ rescue
123
+ nil
124
+ end
125
+
117
126
  ##
118
127
  # Is Solr running?
119
128
  def started?
120
129
  !!status
121
130
  end
122
131
 
132
+ def wait
133
+ while (Process.getpgid(pid) rescue status)
134
+ sleep config.poll_interval
135
+ end
136
+ end
137
+
123
138
  ##
124
139
  # Create a new collection in solr
125
140
  # @param [Hash] options
@@ -305,7 +320,6 @@ module SolrWrapper
305
320
  # JRuby
306
321
  env_str = config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(" ")
307
322
  pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
308
- @pid = pid
309
323
  stringio = StringIO.new
310
324
  if config.verbose? && !silence_output
311
325
  IO.copy_stream(output, $stderr)
@@ -318,7 +332,7 @@ module SolrWrapper
318
332
  input.close
319
333
  output.close
320
334
  error.close
321
- exit_status = Process.waitpid2(@pid).last
335
+ exit_status = Process.waitpid2(pid).last
322
336
  else
323
337
  IO.popen(config.env, args + [err: [:child, :out]]) do |io|
324
338
  stringio = StringIO.new
@@ -329,8 +343,6 @@ module SolrWrapper
329
343
  IO.copy_stream(io, stringio)
330
344
  end
331
345
 
332
- @pid = io.pid
333
-
334
346
  _, exit_status = Process.wait2(io.pid)
335
347
  end
336
348
  end
@@ -345,6 +357,16 @@ module SolrWrapper
345
357
 
346
358
  private
347
359
 
360
+ def after_start
361
+ create_configsets if config.cloud
362
+ end
363
+
364
+ def create_configsets
365
+ config.configsets.each do |configset|
366
+ upconfig(configset)
367
+ end
368
+ end
369
+
348
370
  def extracted_version
349
371
  File.read(config.version_file).strip if File.exists? config.version_file
350
372
  end
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
data/lib/solr_wrapper.rb CHANGED
@@ -29,7 +29,7 @@ module SolrWrapper
29
29
  @default_instance ||= instance(default_instance_options)
30
30
  end
31
31
 
32
- def self.instance(options)
32
+ def self.instance(options = {})
33
33
  SolrWrapper::Instance.new(options)
34
34
  end
35
35
 
@@ -2,3 +2,6 @@ port: 9999
2
2
  collection:
3
3
  dir: solr/config/
4
4
  name: project-development
5
+ configsets:
6
+ - dir: solr/config/
7
+ name: project-development-configset
@@ -41,4 +41,15 @@ describe SolrWrapper::Configuration do
41
41
  expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
42
42
  end
43
43
  end
44
+
45
+ describe '#configsets' do
46
+ before do
47
+ allow(config).to receive(:default_configuration_paths).and_return([])
48
+ end
49
+ let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
50
+
51
+ it 'uses values from the config file' do
52
+ expect(config.configsets).to include(name: 'project-development-configset', dir: 'solr/config/')
53
+ end
54
+ end
44
55
  end
@@ -7,6 +7,7 @@ describe SolrWrapper::Instance do
7
7
  let(:client) { SimpleSolrClient::Client.new(subject.url) }
8
8
 
9
9
  describe "#with_collection" do
10
+ let(:options) { { cloud: false } }
10
11
  context "without a name" do
11
12
  it "creates a new anonymous collection" do
12
13
  subject.wrap do |solr|
@@ -51,6 +52,22 @@ describe SolrWrapper::Instance do
51
52
  end
52
53
  end
53
54
  end
55
+
56
+ context 'with a config file' do
57
+ before do
58
+ allow(solr_instance.config).to receive(:configsets)
59
+ .and_return([name: 'project-development', dir: 'solr/config/'])
60
+ end
61
+
62
+ it 'creates a new configsets with options from the config' do
63
+ expect(subject).to receive(:upconfig).with(
64
+ hash_including(name: 'project-development', dir: anything))
65
+
66
+ subject.wrap do
67
+ # no-op
68
+ end
69
+ end
70
+ end
54
71
  end
55
72
 
56
73
  describe 'exec' 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.9.0
4
+ version: 0.10.0
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-04-13 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip