alephant 0.0.9.9.1-java → 0.1.1-java
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/.gitignore +1 -0
- data/alephant.gemspec +8 -2
- data/lib/alephant.rb +40 -56
- data/lib/alephant/models/jsonpath_lookup.rb +16 -0
- data/lib/alephant/models/parser.rb +20 -2
- data/lib/alephant/models/queue.rb +6 -5
- data/lib/alephant/models/render_mapper.rb +56 -0
- data/lib/alephant/models/writer.rb +44 -0
- data/lib/alephant/version.rb +1 -1
- data/lib/env.rb +0 -2
- data/spec/alephant_spec.rb +51 -197
- data/spec/fixtures/components/foo/models/bar.rb +7 -0
- data/spec/fixtures/components/foo/models/foo.rb +1 -1
- data/spec/parser_spec.rb +17 -9
- data/spec/render_mapper_spec.rb +63 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/writer_spec.rb +52 -0
- metadata +97 -34
- data/bin/alephant +0 -37
- data/lib/alephant/errors.rb +0 -6
- data/lib/alephant/errors/invalid_view_path.rb +0 -6
- data/lib/alephant/errors/view_model_not_found.rb +0 -6
- data/lib/alephant/errors/view_template_not_found.rb +0 -6
- data/lib/alephant/models/cache.rb +0 -28
- data/lib/alephant/models/logger.rb +0 -22
- data/lib/alephant/models/multi_renderer.rb +0 -84
- data/lib/alephant/models/renderer.rb +0 -34
- data/lib/alephant/models/sequence_table.rb +0 -99
- data/lib/alephant/models/sequencer.rb +0 -61
- data/lib/alephant/preview/server.rb +0 -75
- data/lib/alephant/preview/template.rb +0 -63
- data/lib/alephant/tasks.rb +0 -8
- data/lib/alephant/util/string.rb +0 -9
- data/lib/alephant/views.rb +0 -15
- data/lib/alephant/views/base.rb +0 -16
- data/lib/alephant/views/preview.rb +0 -44
- data/lib/tasks/preview.rake +0 -16
- data/spec/cache_spec.rb +0 -63
- data/spec/logger_spec.rb +0 -40
- data/spec/multi_renderer_spec.rb +0 -92
- data/spec/renderer_spec.rb +0 -62
- data/spec/sequencer_spec.rb +0 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e380898fbfc1de04d24909fbd8cc82f82c338c4d
|
4
|
+
data.tar.gz: 8d82eb8ad5ec19279c9547092e74d04aabc61ac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ca79920b31f43796118ff510eea1735ff2fdfc396357dd867e5711ddc918b70de9d9774dd9380c320476f70ad373d8ad0ac58b7a548e3f14b4f874dec1af91a
|
7
|
+
data.tar.gz: 5d48de598a04829e0ed2a1fbddd909cad847cf79fc10fc2f9846ffcdd0a5521139ee5be51d2dc072531cb1aa19f473c10d109543f1dadc5ca46003d850d26003
|
data/.gitignore
CHANGED
data/alephant.gemspec
CHANGED
@@ -8,14 +8,13 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.name = 'alephant'
|
9
9
|
s.version = Alephant::VERSION
|
10
10
|
s.date = Time.now.strftime "%Y-%m-%d"
|
11
|
-
s.summary = "Static
|
11
|
+
s.summary = "Static publishing in the cloud"
|
12
12
|
s.description = "Static publishing to S3 based on SQS messages"
|
13
13
|
s.authors = ["Robert Kenny"]
|
14
14
|
s.email = 'kenoir@gmail.com'
|
15
15
|
s.license = 'GPLv3'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split($/)
|
18
|
-
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
18
|
s.platform = "java"
|
20
19
|
s.homepage = 'https://github.com/BBC-News/alephant'
|
21
20
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -36,5 +35,12 @@ Gem::Specification.new do |s|
|
|
36
35
|
s.add_runtime_dependency 'aws-sdk', '~> 1.0'
|
37
36
|
s.add_runtime_dependency 'mustache', '>= 0.99.5'
|
38
37
|
s.add_runtime_dependency 'jsonpath'
|
38
|
+
|
39
|
+
s.add_runtime_dependency 'alephant-sequencer'
|
40
|
+
s.add_runtime_dependency 'alephant-logger'
|
41
|
+
s.add_runtime_dependency 'alephant-cache'
|
42
|
+
s.add_runtime_dependency 'alephant-renderer'
|
43
|
+
s.add_runtime_dependency 'alephant-lookup'
|
44
|
+
s.add_runtime_dependency 'alephant-preview'
|
39
45
|
end
|
40
46
|
|
data/lib/alephant.rb
CHANGED
@@ -1,63 +1,48 @@
|
|
1
1
|
require_relative 'env'
|
2
2
|
|
3
|
-
require 'alephant/models/
|
4
|
-
require 'alephant/models/queue'
|
5
|
-
require 'alephant/models/cache'
|
6
|
-
require 'alephant/models/renderer'
|
7
|
-
require 'alephant/models/multi_renderer'
|
8
|
-
require 'alephant/models/sequence_table'
|
9
|
-
require 'alephant/models/sequencer'
|
3
|
+
require 'alephant/models/render_mapper'
|
10
4
|
require 'alephant/models/parser'
|
5
|
+
require 'alephant/models/writer'
|
6
|
+
require 'alephant/models/queue'
|
11
7
|
|
12
|
-
require 'alephant/
|
8
|
+
require 'alephant/sequencer'
|
9
|
+
require 'alephant/cache'
|
10
|
+
require 'alephant/logger'
|
13
11
|
require 'alephant/views'
|
12
|
+
require 'alephant/renderer'
|
13
|
+
require 'alephant/lookup'
|
14
14
|
|
15
15
|
module Alephant
|
16
16
|
class Alephant
|
17
|
-
|
17
|
+
include ::Alephant::Logger
|
18
18
|
|
19
|
-
|
20
|
-
:s3_bucket_id,
|
21
|
-
:s3_object_path,
|
22
|
-
:s3_object_id,
|
23
|
-
:table_name,
|
24
|
-
:sqs_queue_id,
|
25
|
-
:view_path,
|
26
|
-
:component_id,
|
27
|
-
:sequence_id
|
28
|
-
]
|
19
|
+
attr_reader :sequencer, :queue, :writer, :parser
|
29
20
|
|
30
21
|
def initialize(opts = {}, logger = nil)
|
31
|
-
set_logger(logger)
|
32
|
-
set_opts(opts)
|
33
|
-
|
34
|
-
@logger = ::Alephant.logger
|
35
|
-
@sequencer = Sequencer.create(@table_name, @sqs_queue_id, @sequence_id)
|
36
|
-
@queue = Queue.new(@sqs_queue_id)
|
37
|
-
@cache = Cache.new(@s3_bucket_id, @s3_object_path)
|
38
|
-
@multi_renderer = MultiRenderer.new(@component_id, @view_path)
|
39
|
-
@parser = Parser.new
|
40
|
-
end
|
41
|
-
|
42
|
-
def set_logger(logger)
|
43
|
-
::Alephant.logger = logger
|
44
|
-
end
|
45
|
-
|
46
|
-
def write(data)
|
47
|
-
@multi_renderer.render(data).each do |id, item|
|
48
|
-
@cache.put(id, item)
|
49
|
-
end
|
50
|
-
end
|
22
|
+
::Alephant::Logger.set_logger(logger) unless logger.nil?
|
51
23
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
24
|
+
@parser = Parser.new(
|
25
|
+
opts[:msg_vary_id_path]
|
26
|
+
)
|
27
|
+
@sequencer = Sequencer.create(
|
28
|
+
opts[:sequencer_table_name],
|
29
|
+
opts[:sqs_queue_url],
|
30
|
+
opts[:sequence_id_path]
|
31
|
+
)
|
32
|
+
@queue = Queue.new(
|
33
|
+
opts[:sqs_queue_url]
|
34
|
+
)
|
35
|
+
@writer = Writer.new(
|
36
|
+
opts.select do |k,v|
|
37
|
+
[
|
38
|
+
:renderer_id,
|
39
|
+
:s3_bucket_id,
|
40
|
+
:s3_object_path,
|
41
|
+
:view_path,
|
42
|
+
:lookup_table_name
|
43
|
+
].include? k
|
44
|
+
end
|
45
|
+
)
|
61
46
|
end
|
62
47
|
|
63
48
|
def run!
|
@@ -66,15 +51,14 @@ module Alephant
|
|
66
51
|
end
|
67
52
|
end
|
68
53
|
|
54
|
+
def receive(msg)
|
55
|
+
write msg if sequencer.sequential?(msg)
|
56
|
+
end
|
57
|
+
|
69
58
|
private
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
singleton_class.class_eval do
|
74
|
-
attr_accessor k
|
75
|
-
end
|
76
|
-
send("#{k}=", v)
|
77
|
-
end
|
59
|
+
def write(msg)
|
60
|
+
writer.write(parser.parse(msg), sequencer.sequence_id_from(msg))
|
61
|
+
sequencer.set_last_seen(msg)
|
78
62
|
end
|
79
63
|
|
80
64
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'jsonpath'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Alephant
|
5
|
+
class JsonPathLookup
|
6
|
+
attr_reader :path
|
7
|
+
def initialize(path)
|
8
|
+
@path = path
|
9
|
+
@jsonpath = JsonPath.new(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def lookup(msg)
|
13
|
+
@jsonpath.on(JSON.parse(msg)).first
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,8 +2,26 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Alephant
|
4
4
|
class Parser
|
5
|
-
|
5
|
+
attr_reader :vary_lookup
|
6
|
+
|
7
|
+
def initialize(vary_jsonpath = nil)
|
8
|
+
@vary_lookup = vary_jsonpath ? JsonPathLookup.new(vary_jsonpath) : nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(msg)
|
12
|
+
symbolize(msg.body).tap { |o| o[:options] = options_for msg }
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def symbolize(data)
|
6
17
|
JSON.parse(data, :symbolize_names => true)
|
7
18
|
end
|
19
|
+
|
20
|
+
def options_for(msg)
|
21
|
+
{}.tap do |o|
|
22
|
+
o[:variant] = vary_lookup.lookup(msg.body) if not vary_lookup.nil?
|
23
|
+
end
|
24
|
+
end
|
8
25
|
end
|
9
|
-
end
|
26
|
+
end
|
27
|
+
|
@@ -1,22 +1,23 @@
|
|
1
1
|
require 'aws-sdk'
|
2
|
+
require 'alephant/logger'
|
2
3
|
|
3
4
|
module Alephant
|
4
5
|
class Queue
|
6
|
+
include ::Alephant::Logger
|
7
|
+
|
5
8
|
attr_accessor :q
|
6
9
|
|
7
10
|
def initialize(id)
|
8
|
-
@logger = ::Alephant.logger
|
9
|
-
|
10
11
|
@sqs = AWS::SQS.new
|
11
12
|
@q = @sqs.queues[id]
|
12
13
|
|
13
14
|
unless @q.exists?
|
14
15
|
@q = @sqs.queues.create(id)
|
15
16
|
sleep_until_queue_exists
|
16
|
-
|
17
|
+
logger.info("Queue.initialize: created queue with id #{id}")
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
+
logger.info("Queue.initialize: ended with id #{id}")
|
20
21
|
end
|
21
22
|
|
22
23
|
def sleep_until_queue_exists
|
@@ -24,7 +25,7 @@ module Alephant
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def poll(*args, &block)
|
27
|
-
|
28
|
+
logger.info("Queue.poll: polling with arguments #{args}")
|
28
29
|
@q.poll(*args, &block)
|
29
30
|
end
|
30
31
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'alephant/logger'
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
class RenderMapper
|
5
|
+
include ::Alephant::Logger
|
6
|
+
DEFAULT_LOCATION = 'components'
|
7
|
+
|
8
|
+
def initialize(component_id, view_base_path=nil)
|
9
|
+
self.base_path = "#{view_base_path}/#{component_id}" unless view_base_path.nil?
|
10
|
+
@component_id = component_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def base_path
|
14
|
+
@base_path || DEFAULT_LOCATION
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_path=(path)
|
18
|
+
@base_path = File.directory?(path) ? path : (raise "Invalid path")
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate(data)
|
22
|
+
template_locations.reduce({}) do |obj, file|
|
23
|
+
template_id = template_id_for file
|
24
|
+
obj.tap { |o| o[template_id] = create_renderer(template_id, data) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_renderer(template_file, data)
|
29
|
+
model = instantiate_model(template_file, data)
|
30
|
+
Renderer.create(template_file, base_path, model)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def instantiate_model(view_id, data)
|
35
|
+
require model_location_for view_id
|
36
|
+
Views.get_registered_class(view_id).new(data)
|
37
|
+
end
|
38
|
+
|
39
|
+
def model_location_for(template_file)
|
40
|
+
File.join(base_path, 'models', "#{template_file}.rb")
|
41
|
+
end
|
42
|
+
|
43
|
+
def template_locations
|
44
|
+
Dir[template_base_path]
|
45
|
+
end
|
46
|
+
|
47
|
+
def template_base_path
|
48
|
+
"#{base_path}/templates/*"
|
49
|
+
end
|
50
|
+
|
51
|
+
def template_id_for(template_location)
|
52
|
+
template_location.split('/').last.sub(/\.mustache/, '')
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'alephant/models/jsonpath_lookup'
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
class Writer
|
5
|
+
attr_reader :mapper, :cache
|
6
|
+
|
7
|
+
def initialize(opts)
|
8
|
+
@renderer_id =
|
9
|
+
opts[:renderer_id]
|
10
|
+
@cache = Cache.new(
|
11
|
+
opts[:s3_bucket_id],
|
12
|
+
opts[:s3_object_path]
|
13
|
+
)
|
14
|
+
@mapper = RenderMapper.new(
|
15
|
+
opts[:renderer_id],
|
16
|
+
opts[:view_path]
|
17
|
+
)
|
18
|
+
@lookup_table_name =
|
19
|
+
opts[:lookup_table_name]
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(data, version = nil)
|
23
|
+
mapper.generate(data).each do |id, r|
|
24
|
+
store(id, r.render, location_for(id, version), data[:options])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def store(id, content, location, options)
|
30
|
+
cache.put(location, content)
|
31
|
+
lookup(id).write(options, location)
|
32
|
+
end
|
33
|
+
|
34
|
+
def lookup(component_id)
|
35
|
+
Lookup.create(@lookup_table_name, component_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def location_for(component_id, version = nil)
|
39
|
+
base_name = "#{@renderer_id}_#{component_id}"
|
40
|
+
version ? "#{base_name}_#{version}" : base_name
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/alephant/version.rb
CHANGED
data/lib/env.rb
CHANGED
data/spec/alephant_spec.rb
CHANGED
@@ -1,229 +1,83 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Alephant::Alephant do
|
4
|
-
subject { Alephant::Alephant }
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
multi_renderer = double()
|
12
|
-
|
13
|
-
Alephant::Sequencer.stub(:create).and_return(sequencer)
|
14
|
-
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
15
|
-
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
16
|
-
Alephant::MultiRenderer.any_instance.stub(:initialize).and_return(multi_renderer)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets specified options" do
|
20
|
-
instance = subject.new({
|
21
|
-
:s3_bucket_id => :s3_bucket_id,
|
22
|
-
:s3_object_path => :s3_object_path,
|
23
|
-
:s3_object_id => :s3_object_id,
|
24
|
-
:table_name => :table_name,
|
25
|
-
:sqs_queue_id => :sqs_queue_id,
|
26
|
-
:component_id => :component_id,
|
27
|
-
:sequence_id => :sequence_id
|
28
|
-
})
|
29
|
-
|
30
|
-
expect(instance.s3_bucket_id).to eq(:s3_bucket_id);
|
31
|
-
expect(instance.s3_object_path).to eq(:s3_object_path);
|
32
|
-
expect(instance.s3_object_id).to eq(:s3_object_id);
|
33
|
-
expect(instance.table_name).to eq(:table_name);
|
34
|
-
expect(instance.sqs_queue_id).to eq(:sqs_queue_id);
|
35
|
-
expect(instance.component_id).to eq(:component_id);
|
36
|
-
expect(instance.sequence_id).to eq(:sequence_id);
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets unspecified options to nil" do
|
40
|
-
instance = subject.new
|
41
|
-
|
42
|
-
expect(instance.s3_bucket_id).to eq(nil);
|
43
|
-
expect(instance.s3_object_path).to eq(nil);
|
44
|
-
expect(instance.s3_object_id).to eq(nil);
|
45
|
-
expect(instance.table_name).to eq(nil);
|
46
|
-
expect(instance.sqs_queue_id).to eq(nil);
|
47
|
-
expect(instance.component_id).to eq(nil);
|
48
|
-
expect(instance.sequence_id).to eq(nil);
|
49
|
-
end
|
50
|
-
|
51
|
-
context "initializes @sequencer" do
|
52
|
-
it "with Sequencer.create(:table_name, @sqs_queue_id)" do
|
53
|
-
Alephant::Sequencer
|
54
|
-
.should_receive(:create)
|
55
|
-
.with(:table_name, :sqs_queue_id, :sequence_id)
|
56
|
-
|
57
|
-
instance = subject.new({
|
58
|
-
:table_name => :table_name,
|
59
|
-
:sqs_queue_id => :sqs_queue_id,
|
60
|
-
:sequence_id => :sequence_id
|
61
|
-
})
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "initializes @queue" do
|
66
|
-
it "with Queue.new(@sqs_queue_id)" do
|
67
|
-
Alephant::Queue
|
68
|
-
.should_receive(:new)
|
69
|
-
.with(:sqs_queue_id)
|
70
|
-
|
71
|
-
instance = subject.new({
|
72
|
-
:sqs_queue_id => :sqs_queue_id
|
73
|
-
})
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "initializes @cache" do
|
78
|
-
it "with Cache.new(@s3_bucket_id, @s3_object_path)" do
|
79
|
-
Alephant::Cache
|
80
|
-
.should_receive(:new)
|
81
|
-
.with(:s3_bucket_id, :s3_object_path)
|
82
|
-
|
83
|
-
instance = subject.new({
|
84
|
-
:s3_bucket_id => :s3_bucket_id,
|
85
|
-
:s3_object_path => :s3_object_path
|
86
|
-
})
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "initializes @multi_renderer" do
|
91
|
-
it "MultiRenderer class to be initialized" do
|
92
|
-
Alephant::MultiRenderer
|
93
|
-
.should_receive(:new)
|
94
|
-
.with('foo', 'components')
|
95
|
-
|
96
|
-
instance = subject.new({
|
97
|
-
:view_path => 'components',
|
98
|
-
:component_id => 'foo'
|
99
|
-
})
|
100
|
-
end
|
101
|
-
end
|
5
|
+
before(:each) do
|
6
|
+
Alephant::Writer.any_instance.stub(:initialize)
|
7
|
+
Alephant::Queue.any_instance.stub(:initialize)
|
8
|
+
Alephant::Parser.any_instance.stub(:initialize)
|
9
|
+
Alephant::Sequencer::Sequencer.any_instance.stub(:initialize)
|
102
10
|
end
|
103
11
|
|
104
|
-
describe "
|
105
|
-
|
106
|
-
|
107
|
-
queue
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
Alephant::Sequencer.stub(:create).and_return(sequencer)
|
112
|
-
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
113
|
-
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
114
|
-
Alephant::MultiRenderer.any_instance.stub(:initialize).and_return(multi_renderer)
|
12
|
+
describe "#initialize(opts = {}, logger)" do
|
13
|
+
it "sets parser, sequencer, queue and writer" do
|
14
|
+
expect(subject.writer).to be_a Alephant::Writer
|
15
|
+
expect(subject.queue).to be_a Alephant::Queue
|
16
|
+
expect(subject.parser).to be_a Alephant::Parser
|
17
|
+
expect(subject.sequencer).to be_a Alephant::Sequencer::Sequencer
|
115
18
|
end
|
19
|
+
end
|
116
20
|
|
21
|
+
describe "#run!" do
|
117
22
|
it "returns a Thread" do
|
118
|
-
|
119
|
-
:sqs_queue_id => :sqs_queue_id
|
120
|
-
})
|
121
|
-
|
122
|
-
expect(instance.run!).to be_a(Thread)
|
23
|
+
expect(subject.run!).to be_a(Thread)
|
123
24
|
end
|
124
25
|
|
125
26
|
it "calls @queue.poll" do
|
126
|
-
|
127
|
-
:sqs_queue_id => :sqs_queue_id
|
128
|
-
})
|
129
|
-
|
130
|
-
instance.should_receive(:receive).with(:msg)
|
27
|
+
subject.should_receive(:receive).with(:msg)
|
131
28
|
|
132
29
|
expect_any_instance_of(Alephant::Queue)
|
133
|
-
|
134
|
-
|
30
|
+
.to receive(:poll)
|
31
|
+
.and_yield(:msg)
|
135
32
|
|
136
|
-
t =
|
33
|
+
t = subject.run!
|
137
34
|
t.join
|
138
35
|
end
|
139
36
|
end
|
140
37
|
|
141
|
-
describe "receive(msg)" do
|
142
|
-
|
143
|
-
sequencer = double()
|
144
|
-
queue = double()
|
145
|
-
cache = double()
|
146
|
-
multi_renderer = double()
|
147
|
-
|
148
|
-
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
149
|
-
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
150
|
-
Alephant::MultiRenderer.any_instance.stub(:initialize).and_return(multi_renderer)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "writes data to cache if sequential order is true" do
|
154
|
-
data = "{ \"foo\":\"bar\" }"
|
155
|
-
|
156
|
-
msg = double()
|
157
|
-
msg.stub(:id).and_return(:id)
|
158
|
-
msg.stub(:md5).and_return(:md5)
|
159
|
-
msg.stub(:body).and_return(data)
|
160
|
-
|
161
|
-
|
162
|
-
Alephant::Sequencer::Sequencer
|
163
|
-
.any_instance
|
164
|
-
.stub(:sequential?)
|
165
|
-
.and_return(true)
|
166
|
-
|
167
|
-
Alephant::Sequencer::SequenceTable
|
168
|
-
.any_instance
|
169
|
-
.stub(:create)
|
170
|
-
|
171
|
-
Alephant::Sequencer::Sequencer
|
172
|
-
.any_instance
|
173
|
-
.stub(:set_last_seen)
|
174
|
-
|
175
|
-
instance = subject.new
|
38
|
+
describe "#receive(msg)" do
|
39
|
+
subject { Alephant::Alephant.new }
|
176
40
|
|
177
|
-
instance
|
178
|
-
.should_receive(:write)
|
179
|
-
.with(JSON.parse(data, :symbolize_names => true))
|
180
|
-
|
181
|
-
instance.receive(msg)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe "write(data)" do
|
186
41
|
before(:each) do
|
187
|
-
|
188
|
-
|
189
|
-
|
42
|
+
Alephant::Parser.any_instance
|
43
|
+
.stub(:parse)
|
44
|
+
.and_return(:parsed_msg)
|
45
|
+
Alephant::Sequencer::Sequencer
|
46
|
+
.any_instance.stub(:sequence_id_from)
|
47
|
+
.and_return(:sequence_id)
|
190
48
|
Alephant::Sequencer::Sequencer
|
191
|
-
.any_instance
|
192
|
-
.stub(:initialize)
|
193
|
-
.and_return(sequencer)
|
194
|
-
|
195
|
-
Alephant::Queue
|
196
|
-
.any_instance
|
197
|
-
.stub(:initialize)
|
198
|
-
.and_return(queue)
|
49
|
+
.any_instance.stub(:set_last_seen)
|
199
50
|
end
|
200
51
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
52
|
+
context "message is nonsequential" do
|
53
|
+
before(:each) do
|
54
|
+
Alephant::Sequencer::Sequencer
|
55
|
+
.any_instance.stub(:sequential?)
|
56
|
+
.and_return(false)
|
57
|
+
end
|
206
58
|
|
207
|
-
|
208
|
-
.any_instance
|
209
|
-
|
210
|
-
.with(:foo, templates[:foo])
|
59
|
+
it "should not call write" do
|
60
|
+
Alephant::Writer.any_instance
|
61
|
+
.should_not_receive(:write)
|
211
62
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
.with(:bar, templates[:bar])
|
63
|
+
subject.receive(:msg)
|
64
|
+
end
|
65
|
+
end
|
216
66
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
67
|
+
context "message is sequential" do
|
68
|
+
before(:each) do
|
69
|
+
Alephant::Sequencer::Sequencer
|
70
|
+
.any_instance.stub(:sequential?)
|
71
|
+
.and_return(true)
|
72
|
+
end
|
221
73
|
|
222
|
-
|
223
|
-
|
224
|
-
|
74
|
+
it "calls writer with a parsed message and sequence_id" do
|
75
|
+
Alephant::Writer.any_instance
|
76
|
+
.should_receive(:write).with(:parsed_msg, :sequence_id)
|
225
77
|
|
226
|
-
|
78
|
+
subject.receive(:msg)
|
79
|
+
end
|
227
80
|
end
|
228
81
|
end
|
82
|
+
|
229
83
|
end
|