vayacondios-server 0.2.11 → 0.3.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.
- data/.gitignore +3 -1
- data/.travis.yml +2 -0
- data/Gemfile +15 -9
- data/LICENSE.md +2 -6
- data/Procfile +1 -1
- data/README.md +656 -111
- data/Rakefile +89 -6
- data/bin/vcd +10 -0
- data/bin/vcd-server +8 -0
- data/config/database.yml +6 -0
- data/config/spec.example.yml +18 -0
- data/config/vayacondios.example.yml +15 -0
- data/config/vcd-server.rb +37 -0
- data/examples/configuration.rb +56 -0
- data/examples/event_stream.rb +19 -0
- data/examples/simple.rb +61 -0
- data/features/event.feature +319 -0
- data/features/events.feature +208 -0
- data/features/stash.feature +840 -0
- data/features/stashes.feature +492 -0
- data/features/step_definitions/stash_steps.rb +113 -0
- data/features/stream.feature +30 -0
- data/features/support/em.rb +14 -0
- data/features/support/env.rb +13 -0
- data/lib/vayacondios/configuration.rb +63 -0
- data/lib/vayacondios/server/api.rb +126 -0
- data/lib/vayacondios/server/api_options.rb +56 -0
- data/lib/vayacondios/server/configuration.rb +23 -0
- data/lib/vayacondios/server/driver.rb +71 -0
- data/lib/vayacondios/server/drivers/mongo.rb +126 -0
- data/lib/vayacondios/server/handlers/document_handler.rb +81 -0
- data/lib/vayacondios/server/handlers/event_handler.rb +31 -26
- data/lib/vayacondios/server/handlers/events_handler.rb +31 -0
- data/lib/vayacondios/server/handlers/stash_handler.rb +69 -0
- data/lib/vayacondios/server/handlers/stashes_handler.rb +49 -0
- data/lib/vayacondios/server/handlers/stream_handler.rb +39 -0
- data/lib/vayacondios/server/models/document.rb +87 -0
- data/lib/vayacondios/server/models/event.rb +198 -0
- data/lib/vayacondios/server/models/stash.rb +100 -0
- data/lib/vayacondios/server.rb +35 -0
- data/lib/vayacondios-server.rb +19 -13
- data/lib/vayacondios.rb +22 -0
- data/pom.xml +124 -4
- data/spec/configuration_spec.rb +41 -0
- data/spec/server/api_options_spec.rb +32 -0
- data/spec/server/api_spec.rb +279 -0
- data/spec/server/configuration_spec.rb +27 -0
- data/spec/server/drivers/mongo_spec.rb +107 -0
- data/spec/server/handlers/event_handler_spec.rb +62 -0
- data/spec/server/handlers/events_handler_spec.rb +51 -0
- data/spec/server/handlers/stash_handler_spec.rb +68 -0
- data/spec/server/handlers/stashes_handler_spec.rb +50 -0
- data/spec/server/handlers/stream_handler_spec.rb +5 -0
- data/spec/server/models/document_spec.rb +9 -0
- data/spec/server/models/event_spec.rb +185 -0
- data/spec/server/models/stash_spec.rb +95 -0
- data/spec/spec_helper.rb +23 -3
- data/spec/support/database_helper.rb +42 -0
- data/spec/support/log_helper.rb +19 -0
- data/spec/support/shared_context_for_events.rb +22 -0
- data/spec/support/shared_context_for_stashes.rb +24 -0
- data/spec/support/shared_examples_for_handlers.rb +32 -0
- data/src/main/java/com/infochimps/vayacondios/BaseClient.java +342 -0
- data/src/main/java/com/infochimps/vayacondios/HTTPClient.java +426 -0
- data/src/main/java/com/infochimps/vayacondios/VayacondiosClient.java +487 -65
- data/src/main/java/com/infochimps/vayacondios/test/IntegrationTest.java +3 -0
- data/src/test/java/com/infochimps/vayacondios/BaseClientTest.java +50 -0
- data/src/test/java/com/infochimps/vayacondios/HTTPClientIT.java +267 -0
- data/vayacondios-server.gemspec +9 -9
- metadata +127 -122
- checksums.yaml +0 -15
- data/.rspec +0 -2
- data/.yardopts +0 -10
- data/Guardfile +0 -41
- data/app/http_shim.rb +0 -71
- data/bin/vcd.sh +0 -27
- data/config/http_shim.rb +0 -43
- data/config/vayacondios.example.yaml +0 -7
- data/config/vayacondios.yaml +0 -7
- data/examples/java/ItemSetTest.java +0 -76
- data/lib/tasks/publish.rake +0 -23
- data/lib/tasks/spec.rake +0 -11
- data/lib/tasks/yard.rake +0 -2
- data/lib/vayacondios/client/config.rb +0 -7
- data/lib/vayacondios/client/configliere.rb +0 -38
- data/lib/vayacondios/client/cube_client.rb +0 -39
- data/lib/vayacondios/client/http_client.rb +0 -49
- data/lib/vayacondios/client/itemset.rb +0 -130
- data/lib/vayacondios/client/legacy_switch.rb +0 -43
- data/lib/vayacondios/client/notifier.rb +0 -123
- data/lib/vayacondios/client/zabbix_client.rb +0 -148
- data/lib/vayacondios/legacy_switch.rb +0 -43
- data/lib/vayacondios/server/errors/bad_request.rb +0 -6
- data/lib/vayacondios/server/errors/not_found.rb +0 -6
- data/lib/vayacondios/server/handlers/config_handler.rb +0 -32
- data/lib/vayacondios/server/handlers/itemset_handler.rb +0 -60
- data/lib/vayacondios/server/legacy_switch.rb +0 -43
- data/lib/vayacondios/server/model/config_document.rb +0 -89
- data/lib/vayacondios/server/model/document.rb +0 -25
- data/lib/vayacondios/server/model/event_document.rb +0 -94
- data/lib/vayacondios/server/model/itemset_document.rb +0 -126
- data/lib/vayacondios/server/rack/extract_methods.rb +0 -35
- data/lib/vayacondios/server/rack/jsonize.rb +0 -43
- data/lib/vayacondios/server/rack/params.rb +0 -50
- data/lib/vayacondios/server/rack/path.rb +0 -23
- data/lib/vayacondios/server/rack/path_validation.rb +0 -22
- data/lib/vayacondios/version.rb +0 -3
- data/lib/vayacondios-client.rb +0 -22
- data/scripts/hadoop_monitor/configurable.rb +0 -66
- data/scripts/hadoop_monitor/hadoop_attempt_scraper.rb +0 -45
- data/scripts/hadoop_monitor/hadoop_client.rb +0 -273
- data/scripts/hadoop_monitor/hadoop_monitor.rb +0 -101
- data/scripts/hadoop_monitor/hadoopable.rb +0 -65
- data/scripts/hadoop_monitor/machine_monitor.rb +0 -115
- data/scripts/s3_cataloger/buckets +0 -33
- data/scripts/s3_cataloger/foreach_bucket +0 -88
- data/scripts/s3_cataloger/parse_ls.py +0 -391
- data/spec/client/itemset_legacy_spec.rb +0 -55
- data/spec/client/itemset_spec.rb +0 -60
- data/spec/client/notifier_spec.rb +0 -120
- data/spec/server/config_spec.rb +0 -113
- data/spec/server/event_spec.rb +0 -103
- data/spec/server/itemset_legacy_spec.rb +0 -320
- data/spec/server/itemset_spec.rb +0 -317
- data/spec/server/rack/extract_methods_spec.rb +0 -60
- data/spec/server/rack/path_spec.rb +0 -36
- data/spec/server/rack/path_validation_spec.rb +0 -22
- data/spec/server/server_spec.rb +0 -20
- data/spec/support/mongo_cleaner.rb +0 -32
- data/src/main/java/ItemSetTest.java +0 -76
- data/src/main/java/com/infochimps/util/CurrentClass.java +0 -26
- data/src/main/java/com/infochimps/util/DebugUtil.java +0 -38
- data/src/main/java/com/infochimps/util/HttpHelper.java +0 -181
- data/src/main/java/com/infochimps/vayacondios/ItemSets.java +0 -373
- data/src/main/java/com/infochimps/vayacondios/LinkToVCD.java +0 -18
- data/src/main/java/com/infochimps/vayacondios/MemoryVCDShim.java +0 -84
- data/src/main/java/com/infochimps/vayacondios/Organization.java +0 -62
- data/src/main/java/com/infochimps/vayacondios/PathBuilder.java +0 -13
- data/src/main/java/com/infochimps/vayacondios/StandardVCDLink.java +0 -218
- data/src/main/java/com/infochimps/vayacondios/VCDIntegrationTest.java +0 -108
- data/src/test/java/com/infochimps/vayacondios/TestVayacondiosInMemory.java +0 -78
- data/vayacondios-client.gemspec +0 -25
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vayacondios::Server::EventsHandler, behaves_like: 'handler' do
|
4
|
+
|
5
|
+
let(:params) { { organization: 'organization', topic: 'topic' } }
|
6
|
+
let(:query) { { foo: 'bar' } }
|
7
|
+
let(:model_class){ Vayacondios::Server::Event }
|
8
|
+
|
9
|
+
context '#create' do
|
10
|
+
it 'raises a validation error' do
|
11
|
+
expect{ handler.create(params, query) }.to raise_error(validation_error, /create/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context '#search', 'when events are found' do
|
16
|
+
it 'returns an array of events' do
|
17
|
+
model_class.should_receive(:search).with(params, query).and_call_original
|
18
|
+
driver.should_receive(:search).and_return([{ _id: 'abc123', _t: '2013-01-01T08:12:23.328Z', _d: { foo: 'bar' } }])
|
19
|
+
handler.search(params, query).should eq([
|
20
|
+
{
|
21
|
+
id: 'abc123',
|
22
|
+
time: '2013-01-01T08:12:23.328Z',
|
23
|
+
foo: 'bar'
|
24
|
+
}
|
25
|
+
])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#search', 'when no events are found' do
|
30
|
+
it 'returns an empty array' do
|
31
|
+
model_class.should_receive(:search).with(params, query).and_call_original
|
32
|
+
driver.should_receive(:search).and_return([])
|
33
|
+
handler.search(params, query).should eq([])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context '#update' do
|
38
|
+
it 'raises a validation error' do
|
39
|
+
expect{ handler.update(params, query) }.to raise_error(validation_error, /update/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#delete' do
|
44
|
+
it 'returns a success response' do
|
45
|
+
model_class.should_receive(:destroy).with(params, query).and_call_original
|
46
|
+
driver.should_receive(:remove).and_return(true)
|
47
|
+
handler.delete(params, query).should eq(success_response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vayacondios::Server::StashHandler, behaves_like: 'handler' do
|
4
|
+
|
5
|
+
let(:params) { { organization: 'organization', topic: 'topic' } }
|
6
|
+
let(:document) { { foo: 'bar' } }
|
7
|
+
let(:model_class){ Vayacondios::Server::Stash }
|
8
|
+
|
9
|
+
context '#create' do
|
10
|
+
it 'returns the created stash' do
|
11
|
+
model_class.should_receive(:create).with(params, document).and_call_original
|
12
|
+
driver.should_receive(:insert).and_return(_id: 'topic', foo: 'bar')
|
13
|
+
handler.create(params, document).should eq(foo: 'bar')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context '#retrieve', 'when not found' do
|
18
|
+
it 'raises a validation error' do
|
19
|
+
driver.should_receive(:retrieve).and_return(nil)
|
20
|
+
expect{ handler.retrieve(params, {}) }.to raise_error(validation_error, /not found/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#retrieve', 'when params have no id' do
|
25
|
+
it 'returns the selected record' do
|
26
|
+
model_class.should_receive(:find).with(params).and_call_original
|
27
|
+
driver.should_receive(:retrieve).and_return(_id: 'topic', id: { foo: 'bar' })
|
28
|
+
handler.retrieve(params, {}).should eq(id: { foo: 'bar' })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#retrieve', 'when params have an id' do
|
33
|
+
let(:params){ { organization: 'organization', topic: 'topic', id: 'id' } }
|
34
|
+
|
35
|
+
it 'returns the selected record sliced by id' do
|
36
|
+
model_class.should_receive(:find).with(params).and_call_original
|
37
|
+
driver.should_receive(:retrieve).and_return(_id: 'topic', id: { foo: 'bar' })
|
38
|
+
handler.retrieve(params, {}).should eq(foo: 'bar')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'raises a validation error when retrieved record does not have id as a key' do
|
42
|
+
driver.should_receive(:retrieve).and_return(_id: 'topic', id2: { foo: 'bar' })
|
43
|
+
expect{ handler.retrieve(params, {}) }.to raise_error(validation_error, /contain id/i)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context '#update' do
|
48
|
+
it 'raises a validation error' do
|
49
|
+
expect{ handler.update(params, document) }.to raise_error(validation_error, /update/)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#delete', 'when params have an id' do
|
54
|
+
let(:params){ { organization: 'organization', topic: 'topic', id: 'id' } }
|
55
|
+
|
56
|
+
it 'raises a validation error' do
|
57
|
+
expect{ handler.delete(params, {}) }.to raise_error(validation_error, /not supported/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context '#delete', 'when params do not have an id' do
|
62
|
+
it 'returns a success response' do
|
63
|
+
model_class.should_receive(:destroy).with(params, {}).and_call_original
|
64
|
+
driver.should_receive(:remove).and_return(true)
|
65
|
+
handler.delete(params, {}).should eq(success_response)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vayacondios::Server::StashesHandler, behaves_like: 'handler' do
|
4
|
+
|
5
|
+
let(:params) { { organization: 'organization', topic: 'topic' } }
|
6
|
+
let(:query) { { foo: 'bar' } }
|
7
|
+
let(:model_class){ Vayacondios::Server::Stash }
|
8
|
+
|
9
|
+
context '#create' do
|
10
|
+
it 'raises a validation error' do
|
11
|
+
expect{ handler.create(params, query) }.to raise_error(validation_error, /create not allowed/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context '#retrieve', 'when no stashes are found' do
|
16
|
+
it 'returns an empty array' do
|
17
|
+
model_class.should_receive(:search).with(params, query).and_call_original
|
18
|
+
driver.should_receive(:search).and_return([])
|
19
|
+
handler.retrieve(params, query).should eq([])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#retrieve', 'when stashes are found' do
|
24
|
+
it "returns the record found by the Stash model it delegates to" do
|
25
|
+
model_class.should_receive(:search).with(params, query).and_call_original
|
26
|
+
driver.should_receive(:search).and_return([{ _id: 'topic', foo: 'bar' }])
|
27
|
+
handler.retrieve(params, query).should eq([{ topic: 'topic', foo: 'bar' }])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#update' do
|
32
|
+
it 'raises a validation error' do
|
33
|
+
expect{ handler.update(params, query) }.to raise_error(validation_error, /update not allowed/)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context '#delete', 'with an empty query', focus: true do
|
38
|
+
it 'raises a validation error' do
|
39
|
+
expect{ handler.delete(params, {}) }.to raise_error(validation_error, /empty/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#delete', 'with a query', focus: true do
|
44
|
+
it 'returns a success response' do
|
45
|
+
model_class.should_receive(:destroy).with(params, query).and_call_original
|
46
|
+
driver.should_receive(:remove).and_return(true)
|
47
|
+
handler.delete(params, query).should eq(success_response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vayacondios::Server::Event do
|
4
|
+
|
5
|
+
let(:params) { { topic: 'topic', organization: 'organization', id: 'id' } }
|
6
|
+
let(:now) { event.format_time Time.now }
|
7
|
+
let(:document_error){ Vayacondios::Server::Document::Error }
|
8
|
+
|
9
|
+
subject(:event){ described_class.receive params }
|
10
|
+
|
11
|
+
its(:location){ should eq('organization.topic.events') }
|
12
|
+
|
13
|
+
context '#receive_topic' do
|
14
|
+
it 'sanitizes the topic' do
|
15
|
+
event.receive_topic '.foo$bar'
|
16
|
+
event.topic.should eq('_foo_bar')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#receive_time' do
|
21
|
+
it 'formats the time' do
|
22
|
+
event.receive_time '2014-01-23T15:29:19.412412-06:00'
|
23
|
+
event.time.should be_a(Time)
|
24
|
+
event.time.should be_utc
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context '#to_timestamp', 'when argument is a string' do
|
29
|
+
it 'returns a time' do
|
30
|
+
event.to_timestamp('Aug 31').should be_a(Time)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the default when there is parse error' do
|
34
|
+
default = now
|
35
|
+
event.to_timestamp('foobar', default).should be(default)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context '#to_timestamp', 'when argument is a date' do
|
40
|
+
it 'returns a time' do
|
41
|
+
event.to_timestamp(Date.today).should be_a(Time)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context '#to_timestamp', 'when argument is a time' do
|
46
|
+
it 'returns the time argument' do
|
47
|
+
t = now
|
48
|
+
event.to_timestamp(t).should be(t)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context '#to_timestamp', 'when argument is numeric' do
|
53
|
+
it 'returns a time' do
|
54
|
+
event.to_timestamp(1390513812).should be_a(Time)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context '#to_timestamp', 'when argument is anything else' do
|
59
|
+
it 'returns the default' do
|
60
|
+
default = now
|
61
|
+
event.to_timestamp(Object.new, default).should be(default)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context '#format_time' do
|
66
|
+
it 'converts all time to UTC' do
|
67
|
+
tokyo_time = now.getlocal('+09:00')
|
68
|
+
event.format_time(tokyo_time).should be_utc
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'rounds all time to milliseconds' do
|
72
|
+
precise_time = Time.at(1390514371.671_238_912)
|
73
|
+
event.format_time(precise_time).nsec.should eq(671_000_000)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context '#document' do
|
78
|
+
it 'returns the internal representation of this Event' do
|
79
|
+
event.receive!(time: now, body: { foo: 'bar' })
|
80
|
+
event.document.should eq(_id: 'id',
|
81
|
+
_t: now,
|
82
|
+
_d: { foo: 'bar' })
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context '#from_document' do
|
87
|
+
it 'updates the Event with the document' do
|
88
|
+
updated = event.from_document(_t: now, _d: { foo: 'bar' })
|
89
|
+
updated.id.should eq('id')
|
90
|
+
updated.time.should eq(now)
|
91
|
+
updated.body.should eq(foo: 'bar')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context '#external_document' do
|
96
|
+
it 'returns the external representation of this Event' do
|
97
|
+
event.receive!(time: now, body: { foo: 'bar' })
|
98
|
+
event.external_document.should eq(id: 'id',
|
99
|
+
time: now.iso8601(3),
|
100
|
+
foo: 'bar')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context '#event_filter' do
|
105
|
+
it 'handles :after as greater than' do
|
106
|
+
event.event_filter(after: now).should eq(_t: { gt: now })
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'handles :from as greater than or equal to' do
|
110
|
+
event.event_filter(from: now).should eq(_t: { gte: now })
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'prioritizes :after over :from' do
|
114
|
+
event.event_filter(after: now, from: now).should eq(_t: { gt: now })
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'handles :before as less than' do
|
118
|
+
event.event_filter(before: now).should eq(_t: { lt: now })
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'handles :upto as less than or equal to' do
|
122
|
+
event.event_filter(upto: now).should eq(_t: { lte: now })
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'prioritizes :before over :upto' do
|
126
|
+
event.event_filter(before: now, upto: now).should eq(_t: { lt: now })
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'merges extra keys as data matchers' do
|
130
|
+
event.event_filter(foo: 'bar', before: now).should eq(_t: { lt: now }, _d: { foo: 'bar' })
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context '#prepare_search', focus: true do
|
135
|
+
it 'returns self for chaining' do
|
136
|
+
event.prepare_search({}).should be(event)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'creates a filter based on the query' do
|
140
|
+
prepared = event.prepare_search(foo: 'bar', before: now)
|
141
|
+
prepared.filter.should eq(_t: { lt: now }, _d: { foo: 'bar' })
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context '#prepare_find', focus: true do
|
146
|
+
it 'returns self for chaining' do
|
147
|
+
event.prepare_find.should be(event)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'raises an error if it was not created with an id' do
|
151
|
+
event.write_attribute(:id, nil)
|
152
|
+
expect{ event.prepare_find }.to raise_error(document_error, /id/i)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'returns itself' do
|
156
|
+
event.prepare_find.document.should eq(_id: 'id')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context '#prepare_create', focus: true do
|
161
|
+
it 'returns self for chaining' do
|
162
|
+
event.prepare_create({}).should be(event)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'raises an error when given a non-Hash' do
|
166
|
+
expect{ subject.prepare_create([]) }.to raise_error(document_error, /Hash/)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'sets the time and body of the event' do
|
170
|
+
prepared = event.prepare_create(time: now, foo: 'bar')
|
171
|
+
prepared.document.should eq(_id: 'id', _t: now, _d: { foo: 'bar' })
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context '#prepare_destroy', focus: true do
|
176
|
+
it 'returns self for chaining' do
|
177
|
+
event.prepare_destroy({}).should be(event)
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'creates a filter based on the query' do
|
181
|
+
prepared = event.prepare_destroy(foo: 'bar', before: now)
|
182
|
+
prepared.filter.should eq(_t: { lt: now }, _d: { foo: 'bar' })
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vayacondios::Server::Stash, stashes: true do
|
4
|
+
|
5
|
+
let(:params) { { topic: 'topic', organization: 'organization', id: 'id' } }
|
6
|
+
let(:document_error){ Vayacondios::Server::Document::Error }
|
7
|
+
|
8
|
+
subject(:stash){ described_class.receive params }
|
9
|
+
|
10
|
+
its(:location){ should eq('organization.stash') }
|
11
|
+
|
12
|
+
context '#document' do
|
13
|
+
it 'returns the internal representation of this stash' do
|
14
|
+
stash.receive!(body: { foo: 'bar' })
|
15
|
+
stash.document.should eq(_id: 'topic', foo: 'bar')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#from_document' do
|
20
|
+
it 'updates the stash with the document' do
|
21
|
+
updated = stash.from_document(_id: 'qix', foo: 'bar')
|
22
|
+
updated.document.should eq(_id: 'qix', foo: 'bar')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#external_document' do
|
27
|
+
it 'returns the external representation of this stash' do
|
28
|
+
stash.receive!(body: { foo: 'bar' })
|
29
|
+
stash.external_document.should eq(topic: 'topic', foo: 'bar')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#prepare_search' do
|
34
|
+
it 'returns itself for chaining' do
|
35
|
+
stash.prepare_search({}).should be(stash)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'prepares a search filter' do
|
39
|
+
prepared = stash.prepare_search(foo: 'bar')
|
40
|
+
prepared.filter.should eq(_id: 'topic', foo: 'bar')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context '#prepare_create' do
|
45
|
+
it 'returns itself for chaining' do
|
46
|
+
stash.prepare_create({}).should be(stash)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '#prepare_create', 'without an id' do
|
51
|
+
before(:each){ stash.write_attribute(:id, nil) }
|
52
|
+
|
53
|
+
it 'raises an error if document is not a Hash' do
|
54
|
+
expect{ stash.prepare_create([]) }.to raise_error(document_error, /hash/i)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'sets :body to be the document' do
|
58
|
+
prepared = stash.prepare_create(foo: 'bar')
|
59
|
+
prepared.body.should eq(foo: 'bar')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context '#prepare_create', 'with an id' do
|
64
|
+
it 'sets :body to be the document' do
|
65
|
+
prepared = stash.prepare_create(foo: 'bar')
|
66
|
+
prepared.body.should eq('id' => { foo: 'bar' })
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context '#prepare_find' do
|
71
|
+
it 'returns itself for chaining' do
|
72
|
+
stash.prepare_find.should be(stash)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'raises an error if there is no topic' do
|
76
|
+
stash.write_attribute(:topic, nil)
|
77
|
+
expect{ stash.prepare_find }.to raise_error(document_error, /topic/)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns itself' do
|
81
|
+
stash.prepare_find.document.should eq(_id: 'topic')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context '#prepare_destroy' do
|
86
|
+
it 'returns itself for chaining' do
|
87
|
+
stash.prepare_destroy({}).should be(stash)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'prepares a delete filter' do
|
91
|
+
prepared = stash.prepare_destroy(foo: 'bar')
|
92
|
+
prepared.filter.should eq(_id: 'topic', foo: 'bar')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
-
require 'bundler/setup' ; Bundler.require
|
2
|
-
|
3
|
-
Dir["spec/support/**/*.rb"].each {|f| require File.join(File.dirname(__FILE__), '..', f) }
|
1
|
+
require 'bundler/setup' ; Bundler.require(:test)
|
4
2
|
|
5
3
|
require 'goliath/test_helper'
|
4
|
+
require 'mongo'
|
5
|
+
|
6
|
+
if ENV['VAYACONDIOS_COV']
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start do
|
9
|
+
add_group 'Library', 'lib/'
|
10
|
+
add_group 'Test', '(spec|features)/'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
WITH_MONGO = ENV['WITH_MONGO']
|
15
|
+
|
16
|
+
require 'vayacondios-server'
|
17
|
+
require 'vayacondios-client'
|
18
|
+
|
19
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each{ |f| require f }
|
6
20
|
|
7
21
|
Goliath.env = :test
|
22
|
+
|
23
|
+
require 'vayacondios/server/api'
|
24
|
+
|
25
|
+
RSpec.configure do |c|
|
26
|
+
c.include Goliath::TestHelper
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module DatabaseHelper
|
2
|
+
|
3
|
+
def insert_record(index, document)
|
4
|
+
# mongo only
|
5
|
+
db_query(index){ |db| db.connection.insert(document) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def database_count index
|
9
|
+
# mongo only
|
10
|
+
db_query(index){ |db| db.connection.count }
|
11
|
+
end
|
12
|
+
|
13
|
+
def retrieve_record(index, filter = {})
|
14
|
+
# mongo only
|
15
|
+
db_query(index){ |db| db.connection.find_one(filter) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def db_connection
|
19
|
+
return @db_connection if @db_connection
|
20
|
+
settings = Vayacondios::Server::DbConfig.env :test
|
21
|
+
driver = Vayacondios::Server::Driver.retrieve settings[:driver]
|
22
|
+
@db_connection = driver.connect settings.merge(log: log)
|
23
|
+
end
|
24
|
+
|
25
|
+
def db_locations
|
26
|
+
@locations ||= [ "organization.topic.events", "organization.stash" ]
|
27
|
+
end
|
28
|
+
|
29
|
+
def db_query(location, &blk)
|
30
|
+
db_connection.set_location location
|
31
|
+
db_locations << location
|
32
|
+
result = blk.call db_connection
|
33
|
+
db_connection.unset_location
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def db_reset!
|
38
|
+
db_locations.uniq.each do |location|
|
39
|
+
db_query(location){ |db| EM::Synchrony.sync db.reset! }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
shared_context 'events', events: true do
|
2
|
+
let(:nil_event) { nil }
|
3
|
+
let(:json_nil_event) { 'null' }
|
4
|
+
let(:hash_event) { { 'foo' => 'bar'} }
|
5
|
+
let(:json_hash_event) { '{"foo":"bar"}' }
|
6
|
+
let(:array_event) { [1, 2, 3] }
|
7
|
+
let(:json_array_event) { '[1,2,3]' }
|
8
|
+
let(:string_event) { 'HELLO' }
|
9
|
+
let(:json_string_event) { '"HELLO"' }
|
10
|
+
let(:numeric_event) { 1 }
|
11
|
+
let(:json_numeric_event) { '1' }
|
12
|
+
let(:nested_event) { { 'A' => 1, 'B' => { 'c' => 2, 'd' => 3 } } }
|
13
|
+
let(:json_nested_event) { MultiJson.dump(nested_event) }
|
14
|
+
let(:event_query) { { 'foo' => 'bar' } }
|
15
|
+
let(:json_event_query) { MultiJson.dump(event_query) }
|
16
|
+
let(:event_query_with_sort) { { 'foo' => 'bar', 'sort' => %w[ bing descending ] } }
|
17
|
+
let(:event_query_with_limit) { { 'foo' => 'bar', 'limit' => 10 } }
|
18
|
+
let(:event_query_with_fields) { { 'foo' => 'bar', 'fields' => %w[ bing bam ] } }
|
19
|
+
let(:event_query_with_string_time) { { 'foo' => 'bar', 'from' => '2013-06-08 01:19:15 -0500' } }
|
20
|
+
let(:event_query_with_int_time) { { 'foo' => 'bar', 'from' => 1370672418 } }
|
21
|
+
let(:event_query_with_id) { { 'foo' => 'bar', 'id' => 'baz' } }
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
shared_context 'stashes', stashes: true do
|
2
|
+
let(:nil_stash) { nil }
|
3
|
+
let(:json_nil_stash) { 'null' }
|
4
|
+
let(:hash_stash) { { 'foo' => 'bar' } }
|
5
|
+
let(:json_hash_stash) { '{"foo":"bar"}' }
|
6
|
+
let(:array_stash) { [1, 2, 3] }
|
7
|
+
let(:json_array_stash) { '[1,2,3]' }
|
8
|
+
let(:string_stash) { 'HELLO' }
|
9
|
+
let(:json_string_stash) { '"HELLO"' }
|
10
|
+
let(:numeric_stash) { 1 }
|
11
|
+
let(:json_numeric_stash) { '1' }
|
12
|
+
let(:nested_stash) { { 'root' => { 'b' => 2, 'c' => { 'x' => 3 }, 'a' => 1 } } }
|
13
|
+
let(:stash_query) { { 'foo' => 'bar' } }
|
14
|
+
let(:json_stash_query) { MultiJson.dump(stash_query) }
|
15
|
+
let(:nested_stash_query) { { 'root.b' => 2 } }
|
16
|
+
let(:json_nested_stash_query) { MultiJson.dump(nested_stash_query) }
|
17
|
+
let(:stash_query_with_limit) { { 'foo' => 'bar', 'limit' => 10 } }
|
18
|
+
let(:stash_query_with_sort) { { 'foo' => 'bar', 'sort' => %w[ bar ascending ] } }
|
19
|
+
let(:stash_query_with_topic) { { 'foo' => 'bar', 'topic' => 'baz' } }
|
20
|
+
let(:stash_replacement) { { 'foo' => 'baz' } }
|
21
|
+
let(:json_stash_replacement) { '{"foo":"baz"}' }
|
22
|
+
let(:stash_update) { { 'counter' => 1 } }
|
23
|
+
let(:json_stash_update) { '{"counter":1}' }
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
shared_examples 'handlers', behaves_like: 'handler' do
|
2
|
+
include LogHelper
|
3
|
+
|
4
|
+
let!(:driver) do
|
5
|
+
db = Class.new{ include Vayacondios::Server::Driver }.new
|
6
|
+
db.set_log log
|
7
|
+
db
|
8
|
+
end
|
9
|
+
|
10
|
+
def validation_error
|
11
|
+
Goliath::Validation::Error
|
12
|
+
end
|
13
|
+
|
14
|
+
def success_response
|
15
|
+
handler.action_successful
|
16
|
+
end
|
17
|
+
|
18
|
+
subject(:handler){ described_class.new(log, driver) }
|
19
|
+
|
20
|
+
it{ should respond_to(:log) }
|
21
|
+
it{ should respond_to(:database) }
|
22
|
+
|
23
|
+
its(:action_successful){ should eq(ok: true) }
|
24
|
+
|
25
|
+
context '#call' do
|
26
|
+
it 'calls base methods for logging before delegating' do
|
27
|
+
handler.log.should_receive(:debug).at_least(1).times
|
28
|
+
handler.should_receive(:create).with({}, {})
|
29
|
+
handler.call(:create, {}, {})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|