chef-solr 0.10.8 → 0.10.10.beta.1
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.
- data/Rakefile +2 -0
- data/lib/chef/solr/application/solr.rb +51 -9
- data/lib/chef/solr/version.rb +1 -1
- data/solr/solr-home.tar.gz +0 -0
- data/solr/solr-jetty.tar.gz +0 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/unit/application/solr_spec.rb +569 -0
- metadata +9 -22
data/Rakefile
CHANGED
@@ -21,6 +21,7 @@ require File.dirname(__FILE__) + '/lib/chef/solr/version'
|
|
21
21
|
require 'rubygems'
|
22
22
|
require 'rake'
|
23
23
|
require 'rubygems/package_task'
|
24
|
+
require '../chef/tasks/rspec.rb'
|
24
25
|
|
25
26
|
spec = eval(File.read(File.dirname(__FILE__) + "/chef-solr.gemspec"))
|
26
27
|
|
@@ -62,3 +63,4 @@ RDoc::Task.new do |rdoc|
|
|
62
63
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
63
64
|
end
|
64
65
|
|
66
|
+
task :default => :spec
|
@@ -28,6 +28,8 @@ class Chef
|
|
28
28
|
class Application
|
29
29
|
class Solr < Chef::Application
|
30
30
|
|
31
|
+
attr_accessor :logfile
|
32
|
+
|
31
33
|
option :config_file,
|
32
34
|
:short => "-c CONFIG",
|
33
35
|
:long => "--config CONFIG",
|
@@ -120,6 +122,9 @@ class Chef
|
|
120
122
|
@schema_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'schema.xml')
|
121
123
|
end
|
122
124
|
|
125
|
+
def solr_config_file_path
|
126
|
+
@solr_config_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'solrconfig.xml')
|
127
|
+
end
|
123
128
|
|
124
129
|
def schema_document
|
125
130
|
@schema_document ||= begin
|
@@ -129,10 +134,23 @@ class Chef
|
|
129
134
|
end
|
130
135
|
end
|
131
136
|
|
137
|
+
def config_document
|
138
|
+
@config_document ||=begin
|
139
|
+
File.open(solr_config_file_path, 'r') do |xmlsux|
|
140
|
+
REXML::Document.new(xmlsux)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
132
145
|
def schema_attributes
|
133
146
|
@schema_attributes ||= REXML::XPath.first(schema_document, '/schema').attributes
|
134
147
|
end
|
135
148
|
|
149
|
+
def solr_main_index_elements
|
150
|
+
location = '/config/mainIndex/'
|
151
|
+
@solr_main_index_elements ||= REXML::XPath.first(config_document, location).elements
|
152
|
+
end
|
153
|
+
|
136
154
|
def solr_schema_name
|
137
155
|
schema_attributes["name"]
|
138
156
|
end
|
@@ -141,6 +159,16 @@ class Chef
|
|
141
159
|
schema_attributes["version"]
|
142
160
|
end
|
143
161
|
|
162
|
+
def solr_main_index_max_field_length
|
163
|
+
@solr_main_index_max_field_length ||=begin
|
164
|
+
field_length_el = solr_main_index_elements.select do |el|
|
165
|
+
el.name == 'maxFieldLength'
|
166
|
+
end
|
167
|
+
|
168
|
+
field_length_el.empty? ? nil : field_length_el.first.text.to_i
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
144
172
|
def valid_schema_name?
|
145
173
|
solr_schema_name == Chef::Solr::SCHEMA_NAME
|
146
174
|
end
|
@@ -149,6 +177,18 @@ class Chef
|
|
149
177
|
solr_schema_version == Chef::Solr::SCHEMA_VERSION
|
150
178
|
end
|
151
179
|
|
180
|
+
def check_value_of_main_index_max_field_length
|
181
|
+
if solr_main_index_max_field_length
|
182
|
+
unless solr_main_index_max_field_length > 10000
|
183
|
+
message = "The maxFieldLimit for the mainIndex is set to #{solr_main_index_max_field_length}. "
|
184
|
+
message << "It's recommended to increase this value (in #{solr_config_file_path})."
|
185
|
+
Chef::Log.warn message
|
186
|
+
end
|
187
|
+
else
|
188
|
+
Chef::Log.warn "Unable to determine the maxFieldLimit for the mainIndex (in #{solr_config_file_path})"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
152
192
|
def solr_home_exist?
|
153
193
|
File.directory?(Chef::Config[:solr_home_path])
|
154
194
|
end
|
@@ -185,6 +225,7 @@ class Chef
|
|
185
225
|
def setup_application
|
186
226
|
assert_solr_installed!
|
187
227
|
assert_valid_schema!
|
228
|
+
check_value_of_main_index_max_field_length
|
188
229
|
|
189
230
|
# Need to redirect stdout and stderr so Java process inherits them.
|
190
231
|
# If -L wasn't specified, Chef::Config[:log_location] will be an IO
|
@@ -213,21 +254,22 @@ class Chef
|
|
213
254
|
command << " -jar #{File.join(Chef::Config[:solr_jetty_path], 'start.jar')}"
|
214
255
|
Chef::Log.info("Starting Solr with #{command}")
|
215
256
|
|
216
|
-
# Opened earlier before we dropped privileges
|
217
|
-
if @logfile
|
218
|
-
# Don't need it anymore
|
219
|
-
Chef::Log.close
|
220
|
-
|
221
|
-
STDOUT.reopen(@logfile)
|
222
|
-
STDERR.reopen(@logfile)
|
223
|
-
end
|
257
|
+
# Opened earlier before we dropped privileges, don't need it anymore
|
258
|
+
close_and_reopen_log_file if @logfile
|
224
259
|
|
225
260
|
Kernel.exec(command)
|
226
261
|
|
227
262
|
end
|
228
263
|
end
|
264
|
+
|
265
|
+
def close_and_reopen_log_file
|
266
|
+
Chef::Log.close
|
267
|
+
|
268
|
+
STDOUT.reopen(@logfile)
|
269
|
+
STDERR.reopen(@logfile)
|
270
|
+
end
|
271
|
+
|
229
272
|
end
|
230
273
|
end
|
231
274
|
end
|
232
275
|
end
|
233
|
-
|
data/lib/chef/solr/version.rb
CHANGED
data/solr/solr-home.tar.gz
CHANGED
Binary file
|
data/solr/solr-jetty.tar.gz
CHANGED
Binary file
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-cbfs
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Thomas Bishop (<bishop.thomas@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Thomas Bishop
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'rspec'
|
20
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
|
21
|
+
$:.unshift(File.expand_path('../../lib/', __FILE__))
|
22
|
+
$:.unshift(File.expand_path('../../../chef/lib', __FILE__))
|
23
|
+
|
24
|
+
require 'chef/solr'
|
@@ -0,0 +1,569 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Thomas Bishop (<bishop.thomas@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Thomas Bishop
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'chef/solr/application/solr'
|
21
|
+
|
22
|
+
describe Chef::Solr::Application::Solr do
|
23
|
+
|
24
|
+
describe 'initialize' do
|
25
|
+
it 'should have a default config_file option' do
|
26
|
+
subject.config[:config_file].should == '/etc/chef/solr.rb'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'schema_file_path' do
|
31
|
+
it 'should return the default schema file path' do
|
32
|
+
subject.schema_file_path.should == '/var/chef/solr/conf/schema.xml'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with a custom solr home path' do
|
36
|
+
it 'should return the schema path' do
|
37
|
+
Chef::Config.stub(:[]).with(:solr_home_path).
|
38
|
+
and_return('/opt/chef/solr')
|
39
|
+
subject.schema_file_path.should == '/opt/chef/solr/conf/schema.xml'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'solr_config_file_path' do
|
46
|
+
it 'should return the default solr config path' do
|
47
|
+
subject.solr_config_file_path.should == '/var/chef/solr/conf/solrconfig.xml'
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with a custom solr home path' do
|
51
|
+
it 'should return the solr config path' do
|
52
|
+
Chef::Config.stub(:[]).with(:solr_home_path).
|
53
|
+
and_return('/opt/chef/solr')
|
54
|
+
subject.solr_config_file_path.should == '/opt/chef/solr/conf/solrconfig.xml'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'schema_document' do
|
61
|
+
before do
|
62
|
+
@schema_path = '/opt/chef/solr/conf/schema.xml'
|
63
|
+
subject.stub :schema_file_path => @schema_path
|
64
|
+
@doc_contents = '<?xml version="1.0" encoding="UTF-8" ?><foo>bar</foo>'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should read the schema file at the correct path' do
|
68
|
+
REXML::Document.stub(:new)
|
69
|
+
File.should_receive(:open).with(@schema_path, 'r').
|
70
|
+
and_yield(@doc_contents)
|
71
|
+
subject.schema_document
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return the schema' do
|
75
|
+
File.stub(:open).and_yield(@doc_contents)
|
76
|
+
subject.schema_document.should be_a REXML::Document
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'config_document' do
|
81
|
+
before do
|
82
|
+
@solr_config_path = '/opt/chef/solr/conf/solrconfig.xml'
|
83
|
+
subject.stub :solr_config_file_path => @solr_config_path
|
84
|
+
@doc_contents = '<?xml version="1.0" encoding="UTF-8" ?><foo>bar</foo>'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should read the config file at the correct path' do
|
88
|
+
REXML::Document.stub(:new)
|
89
|
+
File.should_receive(:open).with(@solr_config_path, 'r').
|
90
|
+
and_yield(@doc_contents)
|
91
|
+
subject.config_document
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return an REXML document' do
|
95
|
+
File.stub(:open).and_yield(@doc_contents)
|
96
|
+
subject.config_document.should be_a REXML::Document
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'schema_attributes' do
|
101
|
+
it 'should return the attributes of the schema element' do
|
102
|
+
schema_doc_contents = '<?xml version="1.0" encoding="UTF-8" ?>'
|
103
|
+
schema_doc_contents << '<schema name="chef" version="1.2"></schema>'
|
104
|
+
subject.stub(:schema_document).
|
105
|
+
and_return(REXML::Document.new(schema_doc_contents))
|
106
|
+
|
107
|
+
subject.schema_attributes["name"].should == 'chef'
|
108
|
+
subject.schema_attributes["version"].should == '1.2'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'solr_main_index_elements' do
|
113
|
+
before do
|
114
|
+
doc_contents = '<?xml version="1.0" encoding="UTF-8" ?>'
|
115
|
+
doc_contents << '<config><mainIndex>'
|
116
|
+
doc_contents << '<maxFieldLength>10000</maxFieldLength>'
|
117
|
+
doc_contents << '</mainIndex></config>'
|
118
|
+
subject.stub(:config_document).
|
119
|
+
and_return(REXML::Document.new(doc_contents))
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should return a collection of the REXML elements' do
|
123
|
+
subject.solr_main_index_elements.each { |e| e.should be_a REXML::Element }
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should return the correct elements' do
|
127
|
+
subject.solr_main_index_elements.first.name.should == 'maxFieldLength'
|
128
|
+
subject.solr_main_index_elements.first.text.should == '10000'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'solr_schema_name' do
|
133
|
+
it 'should return the schema name' do
|
134
|
+
subject.stub :schema_attributes => { 'name' => 'chef' }
|
135
|
+
subject.solr_schema_name.should == 'chef'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'solr_schema_version' do
|
140
|
+
it 'should return the schema version' do
|
141
|
+
subject.stub :schema_attributes => { 'version' => '1.2' }
|
142
|
+
subject.solr_schema_version.should == '1.2'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'solr_main_index_max_field_length' do
|
147
|
+
before do
|
148
|
+
@elements = [ REXML::Element.new('useCompoundFile').add_text('false'),
|
149
|
+
REXML::Element.new('ramBufferSizeMB').add_text('32'),
|
150
|
+
REXML::Element.new('maxFieldLength').add_text('10000') ]
|
151
|
+
subject.stub :solr_main_index_elements => @elements
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should return the value of maxFieldLimit as an integer' do
|
155
|
+
subject.solr_main_index_max_field_length.should == 10000
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'if unable to find the maxFieldLimit' do
|
159
|
+
before do
|
160
|
+
elements = @elements.select { |e| e.name != 'maxFieldLength' }
|
161
|
+
subject.stub :solr_main_index_elements => elements
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should return nil' do
|
165
|
+
subject.solr_main_index_max_field_length.should be_nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
describe 'valid_schema_name?' do
|
172
|
+
it 'should return true if the schema name matches' do
|
173
|
+
subject.stub :solr_schema_name => Chef::Solr::SCHEMA_NAME
|
174
|
+
subject.valid_schema_name?.should be_true
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should return false if the schema name does not match' do
|
178
|
+
subject.stub :solr_schema_name => 'foo'
|
179
|
+
subject.valid_schema_name?.should be_false
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'valid_schema_version?' do
|
184
|
+
it 'should return true if the version name matches' do
|
185
|
+
subject.stub :solr_schema_version => Chef::Solr::SCHEMA_VERSION
|
186
|
+
subject.valid_schema_version?.should be_true
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should return false if the version name does not match' do
|
190
|
+
subject.stub :solr_schema_version => '-1.0'
|
191
|
+
subject.valid_schema_version?.should be_false
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'check_value_of_main_index_max_field_length' do
|
196
|
+
it 'should log a warning if it is set to <= 10000' do
|
197
|
+
subject.stub :solr_main_index_max_field_length => 10000
|
198
|
+
pattern = /maxFieldLimit.+set to.+recommended to increase this value/
|
199
|
+
Chef::Log.should_receive(:warn).with(pattern)
|
200
|
+
subject.check_value_of_main_index_max_field_length
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should not log a warning if it is set to > 10000' do
|
204
|
+
subject.stub :solr_main_index_max_field_length => 10001
|
205
|
+
Chef::Log.should_not_receive(:warn)
|
206
|
+
subject.check_value_of_main_index_max_field_length
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'if it is not set' do
|
210
|
+
it 'should log a warning if it is not set' do
|
211
|
+
subject.stub :solr_main_index_max_field_length => nil
|
212
|
+
Chef::Log.should_receive(:warn).
|
213
|
+
with(/Unable to determine the maxFieldLimit for the mainIndex/)
|
214
|
+
subject.check_value_of_main_index_max_field_length
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
describe 'solr_home_exists?' do
|
221
|
+
before do
|
222
|
+
Chef::Config.stub(:[]).with(:solr_home_path).
|
223
|
+
and_return('/opt/chef/solr')
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should return true if the solr home exists' do
|
227
|
+
File.stub(:directory?).with('/opt/chef/solr').
|
228
|
+
and_return(true)
|
229
|
+
subject.solr_home_exist?.should be_true
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should return false if the solr home does not exist' do
|
233
|
+
File.stub(:directory?).with('/opt/chef/solr').
|
234
|
+
and_return(false)
|
235
|
+
subject.solr_home_exist?.should be_false
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'solr_data_dir_exists?' do
|
240
|
+
before do
|
241
|
+
Chef::Config.stub(:[]).with(:solr_data_path).
|
242
|
+
and_return('/opt/chef/solr')
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should return true if the solr data dir exists' do
|
246
|
+
File.stub(:directory?).with('/opt/chef/solr').
|
247
|
+
and_return(true)
|
248
|
+
subject.solr_data_dir_exist?.should be_true
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should return false if the solr data dir does not exist' do
|
252
|
+
File.stub(:directory?).with('/opt/chef/solr').
|
253
|
+
and_return(false)
|
254
|
+
subject.solr_data_dir_exist?.should be_false
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe 'solr_jetty_home_exists?' do
|
259
|
+
before do
|
260
|
+
Chef::Config.stub(:[]).with(:solr_jetty_path).
|
261
|
+
and_return('/opt/chef/solr')
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should return true if the solr jetty dir exists' do
|
265
|
+
File.stub(:directory?).with('/opt/chef/solr').
|
266
|
+
and_return(true)
|
267
|
+
subject.solr_jetty_home_exist?.should be_true
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should return false if the solr jetty dir does not exist' do
|
271
|
+
File.stub(:directory?).with('/opt/chef/solr').
|
272
|
+
and_return(false)
|
273
|
+
subject.solr_jetty_home_exist?.should be_false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe 'assert_solr_installed!' do
|
278
|
+
|
279
|
+
context 'when unsuccessful' do
|
280
|
+
before do
|
281
|
+
message = /chef solr is not installed.+home.+data.+jetty.+misconfigured/i
|
282
|
+
Chef::Log.should_receive(:fatal).with(message).and_return(true)
|
283
|
+
Chef::Log.stub(:fatal)
|
284
|
+
end
|
285
|
+
|
286
|
+
context 'because the solr home does not exist' do
|
287
|
+
before do
|
288
|
+
subject.stub :solr_home_exist? => false
|
289
|
+
subject.stub :solr_data_dir_exist => true
|
290
|
+
subject.stub :solr_jetty_home_exist => true
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'should log messages and exit' do
|
294
|
+
lambda {
|
295
|
+
subject.assert_solr_installed!
|
296
|
+
}.should raise_error SystemExit
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
context 'because the solr data dir does not exist' do
|
301
|
+
before do
|
302
|
+
subject.stub :solr_home_exist? => true
|
303
|
+
subject.stub :solr_data_dir_exist => false
|
304
|
+
subject.stub :solr_jetty_home_exist => true
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should log messages and exit' do
|
308
|
+
lambda {
|
309
|
+
subject.assert_solr_installed!
|
310
|
+
}.should raise_error SystemExit
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context 'because the solr jetty home does not exist' do
|
315
|
+
before do
|
316
|
+
subject.stub :solr_home_exist? => true
|
317
|
+
subject.stub :solr_data_dir_exist => true
|
318
|
+
subject.stub :solr_jetty_home_exist => false
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'should log messages and exit' do
|
322
|
+
lambda {
|
323
|
+
subject.assert_solr_installed!
|
324
|
+
}.should raise_error SystemExit
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'when solr home, data dir, and jetty home exist' do
|
331
|
+
before do
|
332
|
+
['home', 'data_dir', 'jetty_home'].each do |item|
|
333
|
+
subject.stub "solr_#{item}_exist?".to_sym => true
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should not exit' do
|
338
|
+
subject.assert_solr_installed!.should_not raise_error SystemExit
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
343
|
+
|
344
|
+
describe 'assert_valid_schema!' do
|
345
|
+
context 'when unsuccessful' do
|
346
|
+
before do
|
347
|
+
message = /chef solr installation.+upgraded.+/i
|
348
|
+
Chef::Log.should_receive(:fatal).with(message).and_return(true)
|
349
|
+
Chef::Log.stub(:fatal)
|
350
|
+
subject.stub :solr_schema_version => ''
|
351
|
+
end
|
352
|
+
|
353
|
+
context 'because the schema name is not valid' do
|
354
|
+
before do
|
355
|
+
subject.stub :valid_schema_name? => false
|
356
|
+
subject.stub :valid_schema_version => true
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'should log messages and exit' do
|
360
|
+
lambda {
|
361
|
+
subject.assert_valid_schema!
|
362
|
+
}.should raise_error SystemExit
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
context 'because the schema version is not valid' do
|
367
|
+
before do
|
368
|
+
subject.stub :valid_schema_name? => true
|
369
|
+
subject.stub :valid_schema_version => false
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'should log messages and exit' do
|
373
|
+
lambda {
|
374
|
+
subject.assert_valid_schema!
|
375
|
+
}.should raise_error SystemExit
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
context 'when the schema name and version are valid' do
|
382
|
+
before do
|
383
|
+
['name', 'version'].each do |item|
|
384
|
+
subject.stub "valid_schema_#{item}?".to_sym => true
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'should not exit' do
|
389
|
+
subject.assert_valid_schema!.should_not raise_error SystemExit
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
describe 'setup_application' do
|
396
|
+
before do
|
397
|
+
Chef::Daemon.should_receive :change_privilege
|
398
|
+
end
|
399
|
+
|
400
|
+
it 'should see if solr is installed' do
|
401
|
+
subject.stub :assert_valid_schema!
|
402
|
+
subject.stub :check_value_of_main_index_max_field_length
|
403
|
+
subject.should_receive :assert_solr_installed!
|
404
|
+
subject.setup_application
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should see if the schema is valid' do
|
408
|
+
subject.stub :assert_solr_installed!
|
409
|
+
subject.stub :check_value_of_main_index_max_field_length
|
410
|
+
subject.should_receive :assert_valid_schema!
|
411
|
+
subject.setup_application
|
412
|
+
end
|
413
|
+
|
414
|
+
it 'should check the maxFieldLimit setting' do
|
415
|
+
subject.stub :assert_solr_installed!
|
416
|
+
subject.stub :assert_valid_schema!
|
417
|
+
subject.should_receive :check_value_of_main_index_max_field_length
|
418
|
+
subject.setup_application
|
419
|
+
end
|
420
|
+
|
421
|
+
context 'with solr installed and a valid schema' do
|
422
|
+
before do
|
423
|
+
subject.stub :assert_solr_installed!
|
424
|
+
subject.stub :assert_valid_schema!
|
425
|
+
subject.stub :check_value_of_main_index_max_field_length
|
426
|
+
end
|
427
|
+
|
428
|
+
context 'with -L or --logfile' do
|
429
|
+
before do
|
430
|
+
@log_location = '/var/log/chef_solr.log'
|
431
|
+
Chef::Config.stub(:[]).with(:log_location).and_return(@log_location)
|
432
|
+
Chef::Config.stub(:[]).with(:log_level).and_return(:info)
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'should open the log file for appending' do
|
436
|
+
File.should_receive(:new).with(@log_location, 'a')
|
437
|
+
subject.setup_application
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
it 'should set the log level' do
|
442
|
+
Chef::Config.stub(:[]).with(:log_location).and_return(nil)
|
443
|
+
Chef::Config.stub(:[]).with(:log_level).and_return(:info)
|
444
|
+
Chef::Log.should_receive(:level=).with(:info)
|
445
|
+
subject.setup_application
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
end
|
450
|
+
|
451
|
+
describe 'run_application' do
|
452
|
+
context 'with -d or --daemonize' do
|
453
|
+
before do
|
454
|
+
Chef::Config[:daemonize] = true
|
455
|
+
Kernel.stub :exec
|
456
|
+
Dir.stub :chdir
|
457
|
+
end
|
458
|
+
|
459
|
+
it 'should daemonize' do
|
460
|
+
Chef::Daemon.should_receive(:daemonize).with('chef-solr')
|
461
|
+
subject.run_application
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'should change to the jetty home dir' do
|
466
|
+
Kernel.stub :exec
|
467
|
+
Dir.should_receive(:chdir).with(Chef::Config[:solr_jetty_path])
|
468
|
+
subject.run_application
|
469
|
+
end
|
470
|
+
|
471
|
+
context 'after changing to the jetty home dir' do
|
472
|
+
before do
|
473
|
+
Dir.should_receive(:chdir).and_yield
|
474
|
+
Chef::Daemon.stub :daemonize
|
475
|
+
Chef::Log.stub :info
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'should start the process with the default settings' do
|
479
|
+
cmd = "java -Xmx#{Chef::Config[:solr_heap_size]} "
|
480
|
+
cmd << "-Xms#{Chef::Config[:solr_heap_size]} "
|
481
|
+
cmd << "-Dsolr.data.dir=#{Chef::Config[:solr_data_path]} "
|
482
|
+
cmd << "-Dsolr.solr.home=#{Chef::Config[:solr_home_path]} "
|
483
|
+
cmd << "-jar #{File.join(Chef::Config[:solr_jetty_path], 'start.jar')}"
|
484
|
+
|
485
|
+
Kernel.should_receive(:exec).with(cmd)
|
486
|
+
subject.run_application
|
487
|
+
end
|
488
|
+
|
489
|
+
it 'should log the command that solr is started with' do
|
490
|
+
cmd = /java.+solr.+jar.+start\.jar/
|
491
|
+
Chef::Log.should_receive(:info).with(cmd)
|
492
|
+
Kernel.stub :exec
|
493
|
+
subject.run_application
|
494
|
+
end
|
495
|
+
|
496
|
+
context 'with custom heap' do
|
497
|
+
it 'should start the process with the custom setting' do
|
498
|
+
Chef::Config[:solr_heap_size] = '2048M'
|
499
|
+
cmd_fragment = /-Xmx2048M -Xms2048M/
|
500
|
+
Kernel.should_receive(:exec).with(cmd_fragment)
|
501
|
+
subject.run_application
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
context 'with custom data path' do
|
506
|
+
it 'should start the process with the custom setting' do
|
507
|
+
Chef::Config[:solr_data_path] = '/opt/chef/solr_data'
|
508
|
+
cmd_fragment = /-Dsolr\.data\.dir=\/opt\/chef\/solr_data/
|
509
|
+
Kernel.should_receive(:exec).with(cmd_fragment)
|
510
|
+
subject.run_application
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
context 'with custom home path' do
|
515
|
+
it 'should start the process with the custom setting' do
|
516
|
+
Chef::Config[:solr_home_path] = '/opt/chef/solr/'
|
517
|
+
cmd_fragment = /-Dsolr\.solr\.home=\/opt\/chef\/solr/
|
518
|
+
Kernel.should_receive(:exec).with(cmd_fragment)
|
519
|
+
subject.run_application
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
context 'with custom jetty path' do
|
524
|
+
it 'should start the process with the custom setting' do
|
525
|
+
Chef::Config[:solr_jetty_path] = '/opt/chef/solr_jetty/'
|
526
|
+
cmd_fragment = /-jar \/opt\/chef\/solr_jetty\/start.jar/
|
527
|
+
Kernel.should_receive(:exec).with(cmd_fragment)
|
528
|
+
subject.run_application
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'with custom java opts' do
|
533
|
+
it 'should start the java process with the custom setting' do
|
534
|
+
Chef::Config[:solr_java_opts] = '-XX:UseLargePages'
|
535
|
+
cmd_fragment = /-XX:UseLargePages/
|
536
|
+
Kernel.should_receive(:exec).with(cmd_fragment)
|
537
|
+
subject.run_application
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
context 'with -L or --logfile' do
|
542
|
+
it 'should close the previously opened log file and reopen it' do
|
543
|
+
Kernel.stub :exec
|
544
|
+
subject.logfile = StringIO.new
|
545
|
+
subject.should_receive(:close_and_reopen_log_file)
|
546
|
+
subject.run_application
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
end
|
551
|
+
|
552
|
+
end
|
553
|
+
|
554
|
+
describe 'close_and_reopen_log_file' do
|
555
|
+
it 'should close the log and reopen it' do
|
556
|
+
log = StringIO.new
|
557
|
+
Chef::Log.should_receive :close
|
558
|
+
STDOUT.should_receive(:reopen).with log
|
559
|
+
STDERR.should_receive(:reopen).with log
|
560
|
+
subject.logfile = log
|
561
|
+
subject.close_and_reopen_log_file
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
describe 'run' do
|
566
|
+
it { should respond_to :run}
|
567
|
+
end
|
568
|
+
|
569
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-solr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 10
|
9
|
-
- 8
|
10
|
-
version: 0.10.8
|
4
|
+
prerelease: 8
|
5
|
+
version: 0.10.10.beta.1
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Adam Jacob
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2012-04-06 00:00:00 Z
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: chef
|
@@ -25,12 +20,7 @@ dependencies:
|
|
25
20
|
requirements:
|
26
21
|
- - "="
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 10
|
32
|
-
- 8
|
33
|
-
version: 0.10.8
|
23
|
+
version: 0.10.10.beta.1
|
34
24
|
type: :runtime
|
35
25
|
version_requirements: *id001
|
36
26
|
description: |
|
@@ -54,6 +44,9 @@ files:
|
|
54
44
|
- lib/chef/solr/version.rb
|
55
45
|
- lib/chef/solr/application/solr.rb
|
56
46
|
- lib/chef/solr.rb
|
47
|
+
- spec/unit/application/solr_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/spec.opts
|
57
50
|
- solr/solr-home.tar.gz
|
58
51
|
- solr/solr-jetty.tar.gz
|
59
52
|
homepage: http://wiki.opscode.com/display/chef
|
@@ -69,19 +62,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
62
|
requirements:
|
70
63
|
- - ">="
|
71
64
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
|
-
segments:
|
74
|
-
- 0
|
75
65
|
version: "0"
|
76
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
67
|
none: false
|
78
68
|
requirements:
|
79
|
-
- - "
|
69
|
+
- - ">"
|
80
70
|
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
segments:
|
83
|
-
- 0
|
84
|
-
version: "0"
|
71
|
+
version: 1.3.1
|
85
72
|
requirements: []
|
86
73
|
|
87
74
|
rubyforge_project:
|