primedia-endeca 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/endeca.gemspec +3 -3
- data/lib/endeca/benchmarking.rb +23 -3
- data/lib/endeca/request.rb +6 -12
- data/lib/endeca.rb +23 -2
- data/spec/endeca/benchmarking_spec.rb +13 -2
- data/spec/endeca/document_spec.rb +6 -1
- data/spec/endeca/map_spec.rb +10 -0
- data/spec/endeca_spec.rb +25 -0
- metadata +2 -2
data/endeca.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{endeca}
|
5
|
-
s.version = "1.3.
|
5
|
+
s.version = "1.3.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Rein Henrichs", "Andy Stone"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-25}
|
10
10
|
s.description = %q{An Endeca client library for Ruby.}
|
11
11
|
s.email = %q{}
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rdoc_options = ["--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{endeca}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
19
19
|
s.summary = %q{An Endeca client library for Ruby}
|
20
20
|
end
|
data/lib/endeca/benchmarking.rb
CHANGED
@@ -4,15 +4,35 @@ module Endeca
|
|
4
4
|
module Benchmarking
|
5
5
|
# Log and benchmark the workings of a single block. Will only be called if
|
6
6
|
# Endeca.debug and Endeca.benchmark are true.
|
7
|
-
def bm(
|
8
|
-
if Endeca.
|
7
|
+
def bm(metric_symbol, detail = nil)
|
8
|
+
if Endeca.analyze?
|
9
9
|
result = nil
|
10
10
|
ms = ::Benchmark.ms { result = yield }
|
11
|
-
|
11
|
+
add_bm_detail(metric_symbol,ms,detail) if detail.to_s.strip.length > 0
|
12
|
+
increase_metric(metric_symbol, ms)
|
13
|
+
Endeca.logger.debug("#{metric_symbol.to_s}: #{'%.1f' % ms}ms")
|
12
14
|
result
|
13
15
|
else
|
14
16
|
yield
|
15
17
|
end
|
16
18
|
end
|
19
|
+
|
20
|
+
def increase_metric(metric_symbol, up_value)
|
21
|
+
if Endeca.analyze?
|
22
|
+
Thread.current[:endeca] ||= {}
|
23
|
+
Thread.current[:endeca][metric_symbol] ||= 0
|
24
|
+
Thread.current[:endeca][metric_symbol] += up_value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def add_bm_detail(label,time,detail)
|
31
|
+
if Endeca.analyze?
|
32
|
+
Thread.current[:endeca] ||= {}
|
33
|
+
Thread.current[:endeca]["#{label}_detail"] ||= []
|
34
|
+
Thread.current[:endeca]["#{label}_detail"] << {:detail => detail, :time => time}
|
35
|
+
end
|
36
|
+
end
|
17
37
|
end
|
18
38
|
end
|
data/lib/endeca/request.rb
CHANGED
@@ -1,15 +1,6 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'endeca/caching'
|
3
3
|
|
4
|
-
begin
|
5
|
-
require 'system_timer'
|
6
|
-
RequestTimer = SystemTimer
|
7
|
-
rescue LoadError
|
8
|
-
require 'timeout'
|
9
|
-
RequestTimer = Timeout
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
4
|
module Endeca
|
14
5
|
class RequestError < ::StandardError; end
|
15
6
|
|
@@ -26,6 +17,7 @@ module Endeca
|
|
26
17
|
|
27
18
|
def perform
|
28
19
|
raise RequestError, endeca_error[:message] if endeca_error?
|
20
|
+
Endeca.increase_metric(:request_count, 1)
|
29
21
|
return response
|
30
22
|
end
|
31
23
|
|
@@ -63,8 +55,8 @@ module Endeca
|
|
63
55
|
Endeca.log "ENDECA ADAPTER REQUEST"
|
64
56
|
Endeca.log " parameters => " + @query.inspect
|
65
57
|
Endeca.log " uri => " + uri.to_s
|
66
|
-
Endeca.bm
|
67
|
-
|
58
|
+
Endeca.bm(:request_time, "#{@path} #{@query.inspect}") do
|
59
|
+
Endeca.timer.timeout(Endeca.timeout) do
|
68
60
|
@response = Net::HTTP.get_response(uri)
|
69
61
|
end
|
70
62
|
end
|
@@ -76,7 +68,9 @@ module Endeca
|
|
76
68
|
def handle_response(response) #:nodoc:
|
77
69
|
case response
|
78
70
|
when Net::HTTPSuccess
|
79
|
-
|
71
|
+
Endeca.bm :parse_time do
|
72
|
+
@json = JSON.parse(response.body)
|
73
|
+
end
|
80
74
|
else
|
81
75
|
response.error! # raises exception corresponding to http error Net::XXX
|
82
76
|
end
|
data/lib/endeca.rb
CHANGED
@@ -27,7 +27,7 @@ module Endeca
|
|
27
27
|
extend Logging
|
28
28
|
|
29
29
|
# :stopdoc:
|
30
|
-
VERSION = '1.3.
|
30
|
+
VERSION = '1.3.4'
|
31
31
|
# :startdoc:
|
32
32
|
|
33
33
|
# Returns the version string for the library.
|
@@ -42,15 +42,36 @@ module Endeca
|
|
42
42
|
attr_accessor :debug
|
43
43
|
attr_accessor :benchmark
|
44
44
|
attr_accessor :timeout
|
45
|
+
|
46
|
+
def analyze?
|
47
|
+
debug && logger && benchmark
|
48
|
+
end
|
49
|
+
|
50
|
+
def timer
|
51
|
+
@timer ||= get_timer
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def get_timer
|
57
|
+
require 'system_timer'
|
58
|
+
SystemTimer
|
59
|
+
rescue LoadError
|
60
|
+
require 'timeout'
|
61
|
+
Timeout
|
62
|
+
end
|
45
63
|
end
|
46
64
|
|
47
65
|
self.logger = Logger.new(STDOUT)
|
48
66
|
self.debug = false
|
49
67
|
self.benchmark = false
|
50
|
-
self.timeout =
|
68
|
+
self.timeout = 8
|
69
|
+
|
51
70
|
|
52
71
|
# Endeca URIs require colons to be escaped
|
53
72
|
def self.escape(str)
|
54
73
|
URI.escape(str, /[^-_.!~*'()a-zA-Z\d;\/?@&=+$,\[\]]/n)
|
55
74
|
end
|
56
75
|
end
|
76
|
+
|
77
|
+
puts ">> Using Endeca gem version: #{Endeca::VERSION}"
|
@@ -4,6 +4,7 @@ describe Endeca::Benchmarking do
|
|
4
4
|
class Helper
|
5
5
|
extend Endeca::Benchmarking
|
6
6
|
end
|
7
|
+
|
7
8
|
describe "#benchmark" do
|
8
9
|
before do
|
9
10
|
@logger = mock('Logger')
|
@@ -15,8 +16,18 @@ describe Endeca::Benchmarking do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should log the title and the time to the Endeca logger" do
|
18
|
-
@logger.should_receive(:debug).with("
|
19
|
-
Endeca.bm(
|
19
|
+
@logger.should_receive(:debug).with("metric: 1.0ms")
|
20
|
+
Endeca.bm(:metric){ 1 }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#add_bm_detail" do
|
25
|
+
it "should add info to the current thread" do
|
26
|
+
Endeca.stub!(:analyze?).and_return(true)
|
27
|
+
|
28
|
+
Endeca.send(:add_bm_detail, :metric, 1.1, 'query query')
|
29
|
+
|
30
|
+
Thread.current[:endeca]["metric_detail"][0].should == {:detail => "query query", :time => 1.1}
|
20
31
|
end
|
21
32
|
end
|
22
33
|
end
|
@@ -77,7 +77,7 @@ describe Endeca::Document do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe '
|
80
|
+
describe '.inspect' do
|
81
81
|
it "includes the class name" do
|
82
82
|
@document.inspect.should include(Endeca::Document.name)
|
83
83
|
end
|
@@ -370,4 +370,9 @@ describe Endeca::Document do
|
|
370
370
|
end
|
371
371
|
end
|
372
372
|
|
373
|
+
describe "#inspect" do
|
374
|
+
it "should return details of the Document class" do
|
375
|
+
Endeca::Document.inspect.should == "#<Endeca::Document>\nPath: \"http://endeca.example.com\"\nCollection Class: SubDocumentCollection\"\nMappings:\n\tfoo: {:new_foo=>nil}\n\t \nDefaultParams:\n\t \n"
|
376
|
+
end
|
377
|
+
end
|
373
378
|
end
|
data/spec/endeca/map_spec.rb
CHANGED
@@ -109,4 +109,14 @@ describe Endeca::Map do
|
|
109
109
|
should == {:F => "first_name:1|last_name:1|email:1"}
|
110
110
|
end
|
111
111
|
end
|
112
|
+
|
113
|
+
describe ".inspect" do
|
114
|
+
it "should return details of the map" do
|
115
|
+
query = {:foo => "bazz", :bizz => "somevalue"}
|
116
|
+
map = Endeca::Map.new :foo
|
117
|
+
map.into(:Ntk => :Ntt)
|
118
|
+
map.inspect.should include(":Ntk=>\"foo\"")
|
119
|
+
map.inspect.should include(":Ntt=>\"\"")
|
120
|
+
end
|
121
|
+
end
|
112
122
|
end
|
data/spec/endeca_spec.rb
CHANGED
@@ -7,6 +7,31 @@ describe Endeca do
|
|
7
7
|
Endeca.version.should == Endeca::VERSION
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
describe "#escape" do
|
12
|
+
query = 'N=5875 5922&Nf=geocode|GCLT 26.121900,-80.143600 32.18688&Nu=mgtcoid&Ns=searchonly|0||isapartment|1||sortorder|0&Ntk=showapartment|mgtcologodisplay&F=cityseopath:1|mediummgtcologo:1|mgtcodescription:1|mgtcoid:1|mgtcologo:1|mgtcologodisplay:1|mgtconame:1|msa_code:1|propertycity:1|propertystatelong:1|smallmgtcologo:1|webtollfree:1|mvtphone:1&Ntt=1|1&M=recs_per_page:99999|expand_all_dims:0'
|
13
|
+
|
14
|
+
Endeca.escape(query).should == 'N=5875%205922&Nf=geocode%7CGCLT%2026.121900,-80.143600%2032.18688&Nu=mgtcoid&Ns=searchonly%7C0%7C%7Cisapartment%7C1%7C%7Csortorder%7C0&Ntk=showapartment%7Cmgtcologodisplay&F=cityseopath%3A1%7Cmediummgtcologo%3A1%7Cmgtcodescription%3A1%7Cmgtcoid%3A1%7Cmgtcologo%3A1%7Cmgtcologodisplay%3A1%7Cmgtconame%3A1%7Cmsa_code%3A1%7Cpropertycity%3A1%7Cpropertystatelong%3A1%7Csmallmgtcologo%3A1%7Cwebtollfree%3A1%7Cmvtphone%3A1&Ntt=1%7C1&M=recs_per_page%3A99999%7Cexpand_all_dims%3A0'
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#get_timer" do
|
19
|
+
it "without system_timer available returns Timeout" do
|
20
|
+
Endeca.should_receive(:require).
|
21
|
+
with('system_timer').and_raise(LoadError)
|
22
|
+
Endeca.should_receive(:require).
|
23
|
+
with('timeout').and_return(true)
|
24
|
+
|
25
|
+
Endeca.send(:get_timer).should == Timeout
|
26
|
+
end
|
27
|
+
|
28
|
+
it "will return SystemTimer if available" do
|
29
|
+
Endeca.should_receive(:require).
|
30
|
+
with('system_timer').and_return(true)
|
31
|
+
|
32
|
+
Endeca.send(:get_timer).should == SystemTimer
|
33
|
+
end
|
34
|
+
end
|
10
35
|
end
|
11
36
|
|
12
37
|
# EOF
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: primedia-endeca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rein Henrichs
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-08-
|
13
|
+
date: 2009-08-25 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|