propono 1.7.0 → 2.0.0.rc1
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/.travis.yml +2 -9
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -2
- data/README.md +35 -91
- data/lib/propono.rb +4 -144
- data/lib/propono/components/aws_client.rb +78 -0
- data/lib/propono/components/aws_config.rb +4 -9
- data/lib/propono/components/client.rb +93 -0
- data/lib/propono/components/queue.rb +4 -6
- data/lib/propono/components/queue_subscription.rb +32 -22
- data/lib/propono/components/sqs_message.rb +3 -6
- data/lib/propono/components/topic.rb +6 -5
- data/lib/propono/configuration.rb +0 -2
- data/lib/propono/services/publisher.rb +21 -44
- data/lib/propono/services/queue_listener.rb +54 -57
- data/lib/propono/version.rb +1 -1
- data/propono.gemspec +3 -2
- data/test/components/aws_config_test.rb +4 -4
- data/test/components/client_test.rb +68 -0
- data/test/components/queue_subscription_test.rb +68 -70
- data/test/components/queue_test.rb +6 -3
- data/test/components/topic_test.rb +4 -2
- data/test/configuration_test.rb +27 -55
- data/test/integration/integration_test.rb +4 -7
- data/test/integration/slow_queue_test.rb +11 -8
- data/test/integration/sns_to_sqs_test.rb +17 -17
- data/test/services/publisher_test.rb +59 -156
- data/test/services/queue_listener_test.rb +96 -103
- data/test/test_helper.rb +21 -48
- metadata +26 -39
- data/lib/propono/components/post_subscription.rb +0 -19
- data/lib/propono/components/sns.rb +0 -11
- data/lib/propono/components/sqs.rb +0 -12
- data/lib/propono/services/queue_creator.rb +0 -29
- data/lib/propono/services/subscriber.rb +0 -12
- data/lib/propono/services/tcp_listener.rb +0 -48
- data/lib/propono/services/topic_creator.rb +0 -23
- data/lib/propono/services/udp_listener.rb +0 -52
- data/test/components/post_subscription_test.rb +0 -29
- data/test/components/sns_test.rb +0 -25
- data/test/components/sqs_test.rb +0 -26
- data/test/integration/tcp_to_sqs_test.rb +0 -53
- data/test/integration/udp_proxy_test.rb +0 -50
- data/test/integration/udp_to_sqs_test.rb +0 -53
- data/test/propono_test.rb +0 -83
- data/test/services/queue_creator_test.rb +0 -61
- data/test/services/subscriber_test.rb +0 -21
- data/test/services/tcp_listener_test.rb +0 -76
- data/test/services/topic_creator_test.rb +0 -40
- data/test/services/udp_listener_test.rb +0 -73
data/lib/propono/version.rb
CHANGED
data/propono.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "propono"
|
8
8
|
spec.version = Propono::VERSION
|
9
9
|
spec.authors = ["MalcyL", "iHiD"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["jez.walker@gmail.com", "c.p.care@gmail.com", "malcolm@landonsonline.me.uk"]
|
11
11
|
spec.description = %q{Pub / Sub Library using Amazon Web Services}
|
12
12
|
spec.summary = %q{General purpose pub/sub library built on top of AWS SNS and SQS}
|
13
13
|
spec.homepage = ""
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "aws-sdk-sns"
|
22
|
+
spec.add_dependency "aws-sdk-sqs"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "rake"
|
@@ -15,11 +15,11 @@ module Propono
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_access_key
|
18
|
-
assert_equal "test-access-key", @aws_config.aws_options[:
|
18
|
+
assert_equal "test-access-key", @aws_config.aws_options[:access_key_id]
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_secret_key
|
22
|
-
assert_equal "test-secret-key", @aws_config.aws_options[:
|
22
|
+
assert_equal "test-secret-key", @aws_config.aws_options[:secret_access_key]
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_region
|
@@ -37,12 +37,12 @@ module Propono
|
|
37
37
|
|
38
38
|
def test_selecting_use_iam_profile_results_in_no_access_key
|
39
39
|
@config.use_iam_profile = true
|
40
|
-
assert ! @aws_config.aws_options.has_key?(:
|
40
|
+
assert ! @aws_config.aws_options.has_key?(:access_key_id)
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_selecting_use_iam_profile_results_in_no_secret_key
|
44
44
|
@config.use_iam_profile = true
|
45
|
-
assert ! @aws_config.aws_options.has_key?(:
|
45
|
+
assert ! @aws_config.aws_options.has_key?(:secret_access_key)
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_region_when_using_iam_profile
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Propono
|
4
|
+
class ClientTest < Minitest::Test
|
5
|
+
|
6
|
+
def test_publish_calls_publisher_publish
|
7
|
+
topic, message = "Foo", "Bar"
|
8
|
+
client = Propono::Client.new
|
9
|
+
Publisher.expects(:publish).with(
|
10
|
+
client.aws_client,
|
11
|
+
client.config,
|
12
|
+
topic,
|
13
|
+
message,
|
14
|
+
{}
|
15
|
+
)
|
16
|
+
client.publish(topic, message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_publish_sets_suffix_publish
|
20
|
+
queue_suffix = "-bar"
|
21
|
+
topic = "foo"
|
22
|
+
message = "asdasdasda"
|
23
|
+
|
24
|
+
client = Propono::Client.new
|
25
|
+
client.config.queue_suffix = queue_suffix
|
26
|
+
Publisher.expects(:publish).with(
|
27
|
+
client.aws_client,
|
28
|
+
client.config,
|
29
|
+
"#{topic}#{queue_suffix}",
|
30
|
+
message,
|
31
|
+
{}
|
32
|
+
)
|
33
|
+
client.publish(topic, message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_listen_calls_queue_listener
|
37
|
+
topic = 'foobar'
|
38
|
+
|
39
|
+
client = Propono::Client.new
|
40
|
+
QueueListener.expects(:listen).with(
|
41
|
+
client.aws_client,
|
42
|
+
client.config,
|
43
|
+
topic
|
44
|
+
)
|
45
|
+
client.listen(topic)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_drain_queue_calls_queue_listener
|
49
|
+
topic = 'foobar'
|
50
|
+
|
51
|
+
client = Propono::Client.new
|
52
|
+
QueueListener.expects(:drain).with(
|
53
|
+
client.aws_client,
|
54
|
+
client.config,
|
55
|
+
topic
|
56
|
+
)
|
57
|
+
client.drain_queue(topic)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_block_configuration_syntax
|
61
|
+
test_key = "foobar-123-access"
|
62
|
+
client = Propono::Client.new do |config|
|
63
|
+
config.access_key = test_key
|
64
|
+
end
|
65
|
+
assert_equal test_key, client.config.access_key
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -5,108 +5,106 @@ module Propono
|
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
@suffix = "-suf"
|
8
|
-
|
8
|
+
propono_config.queue_suffix = @suffix
|
9
9
|
end
|
10
10
|
|
11
11
|
def teardown
|
12
12
|
super
|
13
|
-
|
13
|
+
propono_config.queue_suffix = ""
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
TopicCreator.expects(:find_or_create).with("#{topic_id}#{@suffix}-slow").returns(slow_topic)
|
23
|
-
QueueSubscription.create(topic_id)
|
16
|
+
def test_create_calls_submethods
|
17
|
+
subscription = QueueSubscription.new(aws_client, propono_config, "foobar")
|
18
|
+
subscription.expects(:create_and_subscribe_main_queue)
|
19
|
+
subscription.expects(:create_and_subscribe_slow_queue)
|
20
|
+
subscription.expects(:create_misc_queues)
|
21
|
+
subscription.create
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
TopicCreator.stubs(find_or_create: Topic.new("1123"))
|
24
|
+
def test_create_main_queue
|
25
|
+
policy = "Some policy"
|
26
|
+
topic_name = "SomeName"
|
31
27
|
|
28
|
+
subscription = QueueSubscription.new(aws_client, propono_config, topic_name)
|
29
|
+
subscription.stubs(:create_and_subscribe_slow_queue)
|
30
|
+
subscription.stubs(:create_misc_queues)
|
31
|
+
subscription.stubs(generate_policy: policy)
|
32
32
|
queue_name = subscription.send(:queue_name)
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
topic = mock
|
35
|
+
queue = mock
|
36
|
+
aws_client.expects(:create_topic).with("#{topic_name}#{@suffix}").returns(topic)
|
37
|
+
aws_client.expects(:create_queue).with(queue_name).returns(queue)
|
38
|
+
aws_client.expects(:subscribe_sqs_to_sns).with(queue, topic)
|
39
|
+
aws_client.expects(:set_sqs_policy).with(queue, policy)
|
40
40
|
|
41
41
|
subscription.create
|
42
|
+
assert_equal queue, subscription.queue
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
subscription = QueueSubscription.new(topic_id)
|
49
|
-
|
50
|
-
assert_equal "MyApp-Foobar#{@suffix}", subscription.send(:queue_name)
|
51
|
-
end
|
45
|
+
def test_create_slow_queue
|
46
|
+
policy = "Some policy"
|
47
|
+
topic_name = "SomeName"
|
48
|
+
slow_queue = mock
|
52
49
|
|
53
|
-
|
54
|
-
|
50
|
+
subscription = QueueSubscription.new(aws_client, propono_config, topic_name)
|
51
|
+
subscription.stubs(:create_and_subscribe_main_queue)
|
52
|
+
subscription.stubs(:create_misc_queues)
|
53
|
+
subscription.stubs(generate_policy: policy)
|
54
|
+
queue_name = subscription.send(:queue_name)
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
topic = mock
|
57
|
+
slow_queue = mock
|
58
|
+
aws_client.expects(:create_topic).with("#{topic_name}#{@suffix}-slow").returns(topic)
|
59
|
+
aws_client.expects(:create_queue).with("#{queue_name}-slow").returns(slow_queue)
|
60
|
+
aws_client.expects(:subscribe_sqs_to_sns).with(slow_queue, topic)
|
61
|
+
aws_client.expects(:set_sqs_policy).with(slow_queue, policy)
|
58
62
|
|
59
|
-
|
63
|
+
subscription.create
|
64
|
+
assert_equal slow_queue, subscription.slow_queue
|
60
65
|
end
|
61
66
|
|
62
|
-
def
|
63
|
-
|
67
|
+
def test_create_misc_queues
|
68
|
+
policy = "Some policy"
|
69
|
+
topic_name = "SomeName"
|
70
|
+
failed_queue = mock
|
71
|
+
corrupt_queue = mock
|
64
72
|
|
65
|
-
|
66
|
-
|
73
|
+
subscription = QueueSubscription.new(aws_client, propono_config, topic_name)
|
74
|
+
subscription.stubs(:create_and_subscribe_main_queue)
|
75
|
+
subscription.stubs(:create_and_subscribe_slow_queue)
|
76
|
+
subscription.stubs(generate_policy: policy)
|
77
|
+
queue_name = subscription.send(:queue_name)
|
78
|
+
|
79
|
+
aws_client.expects(:create_queue).with("#{queue_name}-failed").returns(failed_queue)
|
80
|
+
aws_client.expects(:create_queue).with("#{queue_name}-corrupt").returns(corrupt_queue)
|
67
81
|
|
68
|
-
sns = mock()
|
69
|
-
sns.expects(:subscribe).with(arn, Fog::AWS::SQS::Mock::QueueArn, 'sqs').twice
|
70
|
-
subscription = QueueSubscription.new("Some topic")
|
71
|
-
subscription.stubs(sns: sns)
|
72
82
|
subscription.create
|
83
|
+
|
84
|
+
assert_equal failed_queue, subscription.failed_queue
|
85
|
+
assert_equal corrupt_queue, subscription.corrupt_queue
|
73
86
|
end
|
74
87
|
|
75
|
-
def
|
76
|
-
|
77
|
-
policy = "{foobar: 123}"
|
88
|
+
def test_subscription_queue_name
|
89
|
+
propono_config.application_name = "MyApp"
|
78
90
|
|
79
|
-
|
80
|
-
|
91
|
+
topic_name = "Foobar"
|
92
|
+
subscription = QueueSubscription.new(aws_client, propono_config, topic_name)
|
81
93
|
|
82
|
-
|
83
|
-
sqs.expects(:set_queue_attributes).with(Fog::AWS::SQS::Mock::QueueUrl, "Policy", policy).twice
|
84
|
-
subscription = QueueSubscription.new("Some topic")
|
85
|
-
subscription.stubs(sqs: sqs)
|
86
|
-
subscription.stubs(generate_policy: policy)
|
87
|
-
subscription.create
|
94
|
+
assert_equal "MyApp-Foobar#{@suffix}", subscription.send(:queue_name)
|
88
95
|
end
|
89
96
|
|
90
|
-
def
|
91
|
-
|
92
|
-
failed_queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl)
|
93
|
-
corrupt_queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl)
|
94
|
-
slow_queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl)
|
95
|
-
|
96
|
-
QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf').returns(queue)
|
97
|
-
QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf-failed').returns(failed_queue)
|
98
|
-
QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf-corrupt').returns(corrupt_queue)
|
99
|
-
QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf-slow').returns(slow_queue)
|
100
|
-
subscription = QueueSubscription.new("SomeTopic")
|
101
|
-
subscription.create
|
97
|
+
def test_subscription_queue_name_with_spaces
|
98
|
+
propono_config.application_name = "My App"
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
100
|
+
topic_name = "Foobar"
|
101
|
+
subscription = QueueSubscription.new(aws_client, propono_config, topic_name)
|
102
|
+
|
103
|
+
assert_equal "My_App-Foobar#{@suffix}", subscription.send(:queue_name)
|
106
104
|
end
|
107
105
|
|
108
106
|
def test_create_raises_with_nil_topic
|
109
|
-
subscription = QueueSubscription.new(nil)
|
107
|
+
subscription = QueueSubscription.new(aws_client, propono_config, nil)
|
110
108
|
assert_raises ProponoError do
|
111
109
|
subscription.create
|
112
110
|
end
|
@@ -141,7 +139,7 @@ module Propono
|
|
141
139
|
}
|
142
140
|
EOS
|
143
141
|
|
144
|
-
assert_equal policy, QueueSubscription.new(nil).send(:generate_policy, queue, topic)
|
142
|
+
assert_equal policy, QueueSubscription.new(aws_client, propono_config, nil).send(:generate_policy, queue, topic)
|
145
143
|
end
|
146
144
|
end
|
147
145
|
end
|
@@ -2,14 +2,17 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Propono
|
4
4
|
class QueueTest < Minitest::Test
|
5
|
-
def
|
5
|
+
def test_url
|
6
6
|
url = 'foobar'
|
7
|
-
queue = Queue.new(url)
|
7
|
+
queue = Queue.new(url, nil)
|
8
8
|
assert url, queue.url
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_arn
|
12
|
-
|
12
|
+
arn = 'foobar'
|
13
|
+
attributes = {"QueueArn" => arn}
|
14
|
+
queue = Queue.new(nil, attributes)
|
15
|
+
assert arn, queue.arn
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -2,9 +2,11 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Propono
|
4
4
|
class TopicTest < Minitest::Test
|
5
|
-
def
|
5
|
+
def test_arn
|
6
6
|
arn = 'foobar'
|
7
|
-
|
7
|
+
aws_topic = mock
|
8
|
+
aws_topic.expects(:topic_arn).returns(arn)
|
9
|
+
topic = Topic.new(aws_topic)
|
8
10
|
assert arn, topic.arn
|
9
11
|
end
|
10
12
|
end
|
data/test/configuration_test.rb
CHANGED
@@ -9,118 +9,90 @@ module Propono
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_obtaining_singletion
|
12
|
-
refute
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_block_syntax
|
16
|
-
test_key = "foobar-123-access"
|
17
|
-
Propono.config do |config|
|
18
|
-
config.access_key = test_key
|
19
|
-
end
|
20
|
-
assert_equal test_key, Propono.config.access_key
|
12
|
+
refute propono_config.nil?
|
21
13
|
end
|
22
14
|
|
23
15
|
def test_use_iam_profile_defaults_false
|
24
|
-
assert !
|
16
|
+
assert ! propono_config.use_iam_profile
|
25
17
|
end
|
26
18
|
|
27
19
|
def test_use_iam_profile
|
28
|
-
|
29
|
-
assert
|
20
|
+
propono_config.use_iam_profile = true
|
21
|
+
assert propono_config.use_iam_profile
|
30
22
|
end
|
31
23
|
|
32
24
|
def test_access_key
|
33
25
|
access_key = "test-access-key"
|
34
|
-
|
35
|
-
assert_equal access_key,
|
26
|
+
propono_config.access_key = access_key
|
27
|
+
assert_equal access_key, propono_config.access_key
|
36
28
|
end
|
37
29
|
|
38
30
|
def test_secret_key
|
39
31
|
secret_key = "test-secret-key"
|
40
|
-
|
41
|
-
assert_equal secret_key,
|
32
|
+
propono_config.secret_key = secret_key
|
33
|
+
assert_equal secret_key, propono_config.secret_key
|
42
34
|
end
|
43
35
|
|
44
36
|
def test_queue_region
|
45
37
|
queue_region = "test-queue-region"
|
46
|
-
|
47
|
-
assert_equal queue_region,
|
38
|
+
propono_config.queue_region = queue_region
|
39
|
+
assert_equal queue_region, propono_config.queue_region
|
48
40
|
end
|
49
41
|
|
50
42
|
def test_application_name
|
51
43
|
application_name = "test-application-name"
|
52
|
-
|
53
|
-
assert_equal application_name,
|
44
|
+
propono_config.application_name = application_name
|
45
|
+
assert_equal application_name, propono_config.application_name
|
54
46
|
end
|
55
47
|
|
56
48
|
def test_queue_suffix
|
57
49
|
queue_suffix = "test-application-name"
|
58
|
-
|
59
|
-
assert_equal queue_suffix,
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_udp_host
|
63
|
-
val = "test-application-name"
|
64
|
-
Propono.config.udp_host = val
|
65
|
-
assert_equal val, Propono.config.udp_host
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_udp_port
|
69
|
-
val = 10000
|
70
|
-
Propono.config.udp_port = val
|
71
|
-
assert_equal val, Propono.config.udp_port
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_tcp_host
|
75
|
-
val = "test-application-name"
|
76
|
-
Propono.config.tcp_host = val
|
77
|
-
assert_equal val, Propono.config.tcp_host
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_tcp_port
|
81
|
-
val = 9382
|
82
|
-
Propono.config.tcp_port = val
|
83
|
-
assert_equal val, Propono.config.tcp_port
|
50
|
+
propono_config.queue_suffix = queue_suffix
|
51
|
+
assert_equal queue_suffix, propono_config.queue_suffix
|
84
52
|
end
|
85
53
|
|
86
54
|
def test_num_messages_per_poll
|
87
55
|
val = 3
|
88
|
-
|
89
|
-
assert_equal val,
|
56
|
+
propono_config.num_messages_per_poll = val
|
57
|
+
assert_equal val, propono_config.num_messages_per_poll
|
90
58
|
end
|
91
59
|
|
92
60
|
def test_missing_access_key_throws_exception
|
93
61
|
assert_raises(ProponoConfigurationError) do
|
94
|
-
|
62
|
+
propono_config.access_key
|
95
63
|
end
|
96
64
|
end
|
97
65
|
|
98
66
|
def test_missing_secret_key_throws_exception
|
99
67
|
assert_raises(ProponoConfigurationError) do
|
100
|
-
|
68
|
+
propono_config.secret_key
|
101
69
|
end
|
102
70
|
end
|
103
71
|
|
104
72
|
def test_missing_queue_region_throws_exception
|
105
73
|
assert_raises(ProponoConfigurationError) do
|
106
|
-
|
74
|
+
propono_config.queue_region
|
107
75
|
end
|
108
76
|
end
|
109
77
|
|
110
78
|
def test_missing_application_name_throws_exception
|
111
79
|
assert_raises(ProponoConfigurationError) do
|
112
|
-
|
80
|
+
propono_config.application_name
|
113
81
|
end
|
114
82
|
end
|
115
83
|
|
116
84
|
def test_default_max_retries
|
117
|
-
assert_equal 0,
|
85
|
+
assert_equal 0, propono_config.max_retries
|
118
86
|
end
|
119
87
|
|
120
88
|
def test_max_retries
|
121
89
|
val = 5
|
122
|
-
|
123
|
-
assert_equal 5,
|
90
|
+
propono_config.max_retries = val
|
91
|
+
assert_equal 5, propono_config.max_retries
|
92
|
+
end
|
93
|
+
|
94
|
+
def propono_config
|
95
|
+
@propono_config ||= Propono::Configuration.new
|
124
96
|
end
|
125
97
|
end
|
126
98
|
end
|