pantry 0.0.0 → 0.1.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.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +19 -0
- data/Gemfile +15 -0
- data/Guardfile +16 -0
- data/LICENSE +20 -0
- data/README.md +53 -0
- data/Rakefile +18 -0
- data/Vagrantfile +86 -0
- data/bin/pantry +11 -0
- data/bin/pantry-client +38 -0
- data/bin/pantry-server +33 -0
- data/dist/client.yml +79 -0
- data/dist/server.yml +56 -0
- data/dist/upstart/pantry-client.conf +12 -0
- data/dist/upstart/pantry-server.conf +12 -0
- data/doc/message_packet.dot +19 -0
- data/doc/message_packet.dot.png +0 -0
- data/doc/network_topology.dot +42 -0
- data/doc/network_topology.dot.png +0 -0
- data/lib/celluloid_zmq_patches.rb +16 -0
- data/lib/opt_parse_plus.rb +184 -0
- data/lib/pantry.rb +197 -0
- data/lib/pantry/cli.rb +154 -0
- data/lib/pantry/client.rb +131 -0
- data/lib/pantry/client_info.rb +34 -0
- data/lib/pantry/client_registry.rb +104 -0
- data/lib/pantry/command.rb +194 -0
- data/lib/pantry/command_handler.rb +53 -0
- data/lib/pantry/command_line.rb +115 -0
- data/lib/pantry/commands/create_client.rb +30 -0
- data/lib/pantry/commands/download_directory.rb +35 -0
- data/lib/pantry/commands/echo.rb +32 -0
- data/lib/pantry/commands/edit_application.rb +60 -0
- data/lib/pantry/commands/register_client.rb +38 -0
- data/lib/pantry/commands/status.rb +78 -0
- data/lib/pantry/commands/sync_directory.rb +50 -0
- data/lib/pantry/commands/update_application.rb +45 -0
- data/lib/pantry/commands/upload_file.rb +68 -0
- data/lib/pantry/communication.rb +20 -0
- data/lib/pantry/communication/client.rb +75 -0
- data/lib/pantry/communication/client_filter.rb +117 -0
- data/lib/pantry/communication/file_service.rb +125 -0
- data/lib/pantry/communication/file_service/file_progress.rb +164 -0
- data/lib/pantry/communication/file_service/receive_file.rb +97 -0
- data/lib/pantry/communication/file_service/send_file.rb +74 -0
- data/lib/pantry/communication/publish_socket.rb +20 -0
- data/lib/pantry/communication/reading_socket.rb +89 -0
- data/lib/pantry/communication/receive_socket.rb +23 -0
- data/lib/pantry/communication/security.rb +44 -0
- data/lib/pantry/communication/security/authentication.rb +98 -0
- data/lib/pantry/communication/security/curve_key_store.rb +120 -0
- data/lib/pantry/communication/security/curve_security.rb +70 -0
- data/lib/pantry/communication/security/null_security.rb +32 -0
- data/lib/pantry/communication/send_socket.rb +19 -0
- data/lib/pantry/communication/serialize_message.rb +84 -0
- data/lib/pantry/communication/server.rb +97 -0
- data/lib/pantry/communication/subscribe_socket.rb +33 -0
- data/lib/pantry/communication/wait_list.rb +45 -0
- data/lib/pantry/communication/writing_socket.rb +46 -0
- data/lib/pantry/config.rb +182 -0
- data/lib/pantry/file_editor.rb +67 -0
- data/lib/pantry/logger.rb +78 -0
- data/lib/pantry/message.rb +134 -0
- data/lib/pantry/multi_command.rb +36 -0
- data/lib/pantry/server.rb +132 -0
- data/lib/pantry/test/acceptance.rb +83 -0
- data/lib/pantry/test/support/fake_fs.rb +31 -0
- data/lib/pantry/test/support/matchers.rb +13 -0
- data/lib/pantry/test/support/minitest.rb +13 -0
- data/lib/pantry/test/support/mock_ui.rb +23 -0
- data/lib/pantry/test/unit.rb +13 -0
- data/lib/pantry/ui.rb +68 -0
- data/lib/pantry/version.rb +3 -0
- data/pantry.gemspec +40 -0
- data/test/acceptance/cli/error_handling_test.rb +7 -0
- data/test/acceptance/cli/execute_command_on_clients_test.rb +32 -0
- data/test/acceptance/cli/request_info_from_server_test.rb +44 -0
- data/test/acceptance/communication/client_requests_info_from_server_test.rb +28 -0
- data/test/acceptance/communication/heartbeat_test.rb +19 -0
- data/test/acceptance/communication/pub_sub_communication_test.rb +53 -0
- data/test/acceptance/communication/security_test.rb +117 -0
- data/test/acceptance/communication/server_requests_info_from_client_test.rb +41 -0
- data/test/acceptance/test_helper.rb +25 -0
- data/test/fixtures/config.yml +22 -0
- data/test/fixtures/empty.yml +2 -0
- data/test/fixtures/file_to_upload +3 -0
- data/test/root_dir/.gitkeep +0 -0
- data/test/unit/cli_test.rb +173 -0
- data/test/unit/client_registry_test.rb +61 -0
- data/test/unit/client_test.rb +128 -0
- data/test/unit/command_handler_test.rb +79 -0
- data/test/unit/command_line_test.rb +5 -0
- data/test/unit/command_test.rb +206 -0
- data/test/unit/commands/create_client_test.rb +25 -0
- data/test/unit/commands/download_directory_test.rb +58 -0
- data/test/unit/commands/echo_test.rb +22 -0
- data/test/unit/commands/edit_application_test.rb +84 -0
- data/test/unit/commands/register_client_test.rb +41 -0
- data/test/unit/commands/status_test.rb +81 -0
- data/test/unit/commands/sync_directory_test.rb +75 -0
- data/test/unit/commands/update_application_test.rb +35 -0
- data/test/unit/commands/upload_file_test.rb +51 -0
- data/test/unit/communication/client_filter_test.rb +262 -0
- data/test/unit/communication/client_test.rb +99 -0
- data/test/unit/communication/file_service/receive_file_test.rb +214 -0
- data/test/unit/communication/file_service/send_file_test.rb +110 -0
- data/test/unit/communication/file_service_test.rb +56 -0
- data/test/unit/communication/publish_socket_test.rb +19 -0
- data/test/unit/communication/reading_socket_test.rb +110 -0
- data/test/unit/communication/receive_socket_test.rb +20 -0
- data/test/unit/communication/security/authentication_test.rb +97 -0
- data/test/unit/communication/security/curve_key_store_test.rb +110 -0
- data/test/unit/communication/security/curve_security_test.rb +44 -0
- data/test/unit/communication/security/null_security_test.rb +15 -0
- data/test/unit/communication/security_test.rb +49 -0
- data/test/unit/communication/send_socket_test.rb +19 -0
- data/test/unit/communication/serialize_message_test.rb +128 -0
- data/test/unit/communication/server_test.rb +106 -0
- data/test/unit/communication/subscribe_socket_test.rb +46 -0
- data/test/unit/communication/wait_list_test.rb +60 -0
- data/test/unit/communication/writing_socket_test.rb +46 -0
- data/test/unit/config_test.rb +150 -0
- data/test/unit/logger_test.rb +79 -0
- data/test/unit/message_test.rb +179 -0
- data/test/unit/multi_command_test.rb +45 -0
- data/test/unit/opt_parse_plus_test.rb +218 -0
- data/test/unit/pantry_test.rb +82 -0
- data/test/unit/server_test.rb +166 -0
- data/test/unit/test_helper.rb +25 -0
- data/test/unit/ui_test.rb +58 -0
- metadata +389 -13
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::SendSocket do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Celluloid.boot
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:security) { Pantry::Communication::Security.new_client }
|
|
10
|
+
|
|
11
|
+
it "opens a ZMQ DealerSocket, bound to host / port" do
|
|
12
|
+
Celluloid::ZMQ::DealerSocket.any_instance.expects(:linger=).with(0)
|
|
13
|
+
Celluloid::ZMQ::DealerSocket.any_instance.expects(:connect).with("tcp://host:1234")
|
|
14
|
+
|
|
15
|
+
socket = Pantry::Communication::SendSocket.new("host", 1234, security)
|
|
16
|
+
socket.open
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::SerializeMessage do
|
|
4
|
+
|
|
5
|
+
describe ".to_zeromq" do
|
|
6
|
+
|
|
7
|
+
let(:pantry_message) do
|
|
8
|
+
message = Pantry::Message.new
|
|
9
|
+
message.to = "to"
|
|
10
|
+
message.from = "from"
|
|
11
|
+
message
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "builds a list of message parts containing to, metadata, and body" do
|
|
15
|
+
pantry_message << "Test Body"
|
|
16
|
+
|
|
17
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
18
|
+
|
|
19
|
+
assert_equal 3, zmq_message.length
|
|
20
|
+
assert_equal "to", zmq_message[0]
|
|
21
|
+
assert_equal "Test Body", zmq_message[2]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "ensures `to` is always a string" do
|
|
25
|
+
pantry_message.to = nil
|
|
26
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
27
|
+
|
|
28
|
+
assert_equal "", zmq_message[0]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "serializes the metadata as JSON" do
|
|
32
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
33
|
+
|
|
34
|
+
metadata = JSON.parse(zmq_message[1])
|
|
35
|
+
|
|
36
|
+
assert_equal "to", metadata["to"]
|
|
37
|
+
assert_equal "from", metadata["from"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "ensures all parts of the body are strings" do
|
|
41
|
+
pantry_message << 1
|
|
42
|
+
pantry_message << 2
|
|
43
|
+
|
|
44
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
45
|
+
|
|
46
|
+
assert_equal "1", zmq_message[2]
|
|
47
|
+
assert_equal "2", zmq_message[3]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "turns nil entries into strings" do
|
|
51
|
+
pantry_message << nil
|
|
52
|
+
pantry_message << "this"
|
|
53
|
+
|
|
54
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
55
|
+
|
|
56
|
+
assert_equal "", zmq_message[2]
|
|
57
|
+
assert_equal "this", zmq_message[3]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "converts hashes in the body to JSON" do
|
|
61
|
+
pantry_message << {:key => "value"}
|
|
62
|
+
|
|
63
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
64
|
+
|
|
65
|
+
body = JSON.parse(zmq_message[2][1..-1])
|
|
66
|
+
assert_equal "value", body["key"]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "converts arrays in the body to JSON" do
|
|
70
|
+
pantry_message << ["some", "values", 1, 2, true]
|
|
71
|
+
|
|
72
|
+
zmq_message = Pantry::Communication::SerializeMessage.to_zeromq(pantry_message)
|
|
73
|
+
|
|
74
|
+
body = JSON.parse(zmq_message[2][1..-1])
|
|
75
|
+
assert_equal ["some", "values", 1, 2, true], body
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe ".from_zeromq" do
|
|
81
|
+
|
|
82
|
+
let(:is_json) { Pantry::Communication::SerializeMessage::IS_JSON }
|
|
83
|
+
|
|
84
|
+
it "takes an array and builds a Message from the parts" do
|
|
85
|
+
parts = [ "source", {}.to_json, "body1" ]
|
|
86
|
+
|
|
87
|
+
message = Pantry::Communication::SerializeMessage.from_zeromq(parts)
|
|
88
|
+
|
|
89
|
+
assert_equal "source", message.to
|
|
90
|
+
assert_equal ["body1"], message.body
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "parses out JSON into a Hash" do
|
|
94
|
+
parts = [ "source", {:type => "command"}.to_json, "body1" ]
|
|
95
|
+
|
|
96
|
+
message = Pantry::Communication::SerializeMessage.from_zeromq(parts)
|
|
97
|
+
|
|
98
|
+
assert_equal "command", message.type
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "handles JSON based body entries" do
|
|
102
|
+
parts = [ "source", {}.to_json, is_json + {:key => "value"}.to_json ]
|
|
103
|
+
|
|
104
|
+
message = Pantry::Communication::SerializeMessage.from_zeromq(parts)
|
|
105
|
+
|
|
106
|
+
assert_equal "value", message.body[0][:key]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "handles Array based body entries" do
|
|
110
|
+
parts = [ "source", {}.to_json, is_json + [1, 2, 3, "go"].to_json ]
|
|
111
|
+
|
|
112
|
+
message = Pantry::Communication::SerializeMessage.from_zeromq(parts)
|
|
113
|
+
|
|
114
|
+
assert_equal [1, 2, 3, "go"], message.body[0]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "returns raw parts if they don't parse as JSON" do
|
|
118
|
+
parts = [ "source", {}.to_json, "{ blah blah thing", "[notreallyanarray" ]
|
|
119
|
+
|
|
120
|
+
message = Pantry::Communication::SerializeMessage.from_zeromq(parts)
|
|
121
|
+
|
|
122
|
+
assert_equal "{ blah blah thing", message.body[0]
|
|
123
|
+
assert_equal "[notreallyanarray", message.body[1]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::Server do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Pantry::Communication::PublishSocket.any_instance.stubs(:open)
|
|
7
|
+
|
|
8
|
+
Pantry::Communication::ReceiveSocket.any_instance.stubs(:add_listener)
|
|
9
|
+
Pantry::Communication::ReceiveSocket.any_instance.stubs(:open)
|
|
10
|
+
|
|
11
|
+
Pantry::Communication::FileService.any_instance.stubs(:start_server)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "opens a publish socket for communication" do
|
|
15
|
+
Pantry::Communication::PublishSocket.any_instance.expects(:open)
|
|
16
|
+
|
|
17
|
+
server = Pantry::Communication::Server.new(nil)
|
|
18
|
+
server.run
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "opens a receive socket for communication" do
|
|
22
|
+
server = Pantry::Communication::Server.new(nil)
|
|
23
|
+
|
|
24
|
+
Pantry::Communication::ReceiveSocket.any_instance.expects(:add_listener).with(server)
|
|
25
|
+
Pantry::Communication::ReceiveSocket.any_instance.expects(:open)
|
|
26
|
+
|
|
27
|
+
server.run
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "starts up a local file service" do
|
|
31
|
+
server = Pantry::Communication::Server.new(nil)
|
|
32
|
+
|
|
33
|
+
Pantry::Communication::FileService.any_instance.expects(:start_server)
|
|
34
|
+
|
|
35
|
+
server.run
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#publish_message" do
|
|
39
|
+
let(:listener) { Pantry::Server.new }
|
|
40
|
+
let(:msg) { Pantry::Message.new }
|
|
41
|
+
let(:server) { Pantry::Communication::Server.new(listener) }
|
|
42
|
+
|
|
43
|
+
before do
|
|
44
|
+
server.run
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "uses the publish socket to send messages to clients" do
|
|
48
|
+
Pantry::Communication::PublishSocket.any_instance.expects(:send_message).with(msg)
|
|
49
|
+
|
|
50
|
+
server.publish_message(msg)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "sets the from of the message to the sender" do
|
|
54
|
+
Pantry::Communication::PublishSocket.any_instance.expects(:send_message).with do |message|
|
|
55
|
+
listener.identity == message.from
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
server.publish_message(msg)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe "Message forwarding" do
|
|
63
|
+
let(:listener) { Pantry::Server.new }
|
|
64
|
+
let(:msg) {
|
|
65
|
+
m = Pantry::Message.new
|
|
66
|
+
m.from = "client427"
|
|
67
|
+
m
|
|
68
|
+
}
|
|
69
|
+
let(:server) { Pantry::Communication::Server.new(listener) }
|
|
70
|
+
|
|
71
|
+
before do
|
|
72
|
+
server.run
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "publishes the message to connected clients untouched" do
|
|
76
|
+
msg.to = "pantry"
|
|
77
|
+
|
|
78
|
+
Pantry::Communication::PublishSocket.any_instance.expects(:send_message).with(msg)
|
|
79
|
+
server.forward_message(msg)
|
|
80
|
+
|
|
81
|
+
assert msg.forwarded?, "Message should have been marked as forwarded"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "forwards off responses to forwarded messages" do
|
|
85
|
+
msg.to = "client500"
|
|
86
|
+
msg.forwarded!
|
|
87
|
+
|
|
88
|
+
Pantry::Communication::PublishSocket.any_instance.expects(:send_message).with(msg)
|
|
89
|
+
server.handle_message(msg)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "sends a message to a single client via identity, returning a future" do
|
|
94
|
+
server = Pantry::Communication::Server.new(nil)
|
|
95
|
+
server.run
|
|
96
|
+
|
|
97
|
+
message = Pantry::Message.new("message")
|
|
98
|
+
Pantry::Communication::PublishSocket.any_instance.expects(:send_message).with(message)
|
|
99
|
+
|
|
100
|
+
future = server.send_request(message)
|
|
101
|
+
|
|
102
|
+
assert_not_nil future
|
|
103
|
+
assert_not future.ready?
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::SubscribeSocket do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Celluloid.init
|
|
7
|
+
|
|
8
|
+
Celluloid::ZMQ::SubSocket.any_instance.stubs(:linger=)
|
|
9
|
+
Celluloid::ZMQ::SubSocket.any_instance.stubs(:connect)
|
|
10
|
+
Celluloid::ZMQ::SubSocket.any_instance.stubs(:subscribe)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:security) { Pantry::Communication::Security.new_client }
|
|
14
|
+
|
|
15
|
+
it "binds and subscribes to the given host and port" do
|
|
16
|
+
Celluloid::ZMQ::SubSocket.any_instance.expects(:linger=).with(0)
|
|
17
|
+
Celluloid::ZMQ::SubSocket.any_instance.expects(:connect).with("tcp://host:1235")
|
|
18
|
+
Celluloid::ZMQ::SubSocket.any_instance.expects(:subscribe).with("")
|
|
19
|
+
|
|
20
|
+
socket = Pantry::Communication::SubscribeSocket.new("host", 1235, security)
|
|
21
|
+
socket.open
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "subscription filtering" do
|
|
25
|
+
it "subscribes to the stream according to filter options given" do
|
|
26
|
+
socket = Pantry::Communication::SubscribeSocket.new("host", 1235, security)
|
|
27
|
+
socket.filter_on(Pantry::Communication::ClientFilter.new(application: "pantry"))
|
|
28
|
+
|
|
29
|
+
Celluloid::ZMQ::SubSocket.any_instance.expects(:subscribe).with("pantry")
|
|
30
|
+
|
|
31
|
+
socket.open
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "subscribes to multiple streams to support nested scoping" do
|
|
35
|
+
socket = Pantry::Communication::SubscribeSocket.new("host", 1235, security)
|
|
36
|
+
socket.filter_on(Pantry::Communication::ClientFilter.new(
|
|
37
|
+
application: "pantry", environment: "test"))
|
|
38
|
+
|
|
39
|
+
Celluloid::ZMQ::SubSocket.any_instance.expects(:subscribe).with("pantry")
|
|
40
|
+
Celluloid::ZMQ::SubSocket.any_instance.expects(:subscribe).with("pantry.test")
|
|
41
|
+
|
|
42
|
+
socket.open
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::WaitList do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Celluloid.init
|
|
7
|
+
|
|
8
|
+
@wait_list = Pantry::Communication::WaitList.new
|
|
9
|
+
@message = Pantry::Message.new("do_something")
|
|
10
|
+
|
|
11
|
+
@future = @wait_list.wait_for(@message)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "creates and returns a future waiting for a response for the given identity and message" do
|
|
15
|
+
assert !@future.ready?, "Future should not have been ready with information"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "knows if the given message matches a waiting future" do
|
|
19
|
+
assert @wait_list.waiting_for?(@message), "Wait List should be waiting for this message"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "fulfills the waiting future if a message is received matching the waiting future" do
|
|
23
|
+
@message.from = "identity"
|
|
24
|
+
@message << "The new body"
|
|
25
|
+
@wait_list.received(@message)
|
|
26
|
+
|
|
27
|
+
assert @future.ready?, "Future has not yet received information"
|
|
28
|
+
assert_equal ["The new body"], @future.value.body
|
|
29
|
+
|
|
30
|
+
assert_false @wait_list.waiting_for?(@message), "Future was not removed from the wait list"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "allows multiple entries for a given identity and message type" do
|
|
34
|
+
wait_list = Pantry::Communication::WaitList.new
|
|
35
|
+
|
|
36
|
+
m1 = Pantry::Message.new("do_something")
|
|
37
|
+
m1.from = "client"
|
|
38
|
+
|
|
39
|
+
m2 = Pantry::Message.new("do_something")
|
|
40
|
+
m2.from = "client"
|
|
41
|
+
|
|
42
|
+
m3 = Pantry::Message.new("do_something")
|
|
43
|
+
m3.from = "client"
|
|
44
|
+
|
|
45
|
+
future1 = wait_list.wait_for(m1)
|
|
46
|
+
future2 = wait_list.wait_for(m2)
|
|
47
|
+
future3 = wait_list.wait_for(m3)
|
|
48
|
+
|
|
49
|
+
assert wait_list.waiting_for?(m1)
|
|
50
|
+
|
|
51
|
+
wait_list.received(m1)
|
|
52
|
+
wait_list.received(m2)
|
|
53
|
+
wait_list.received(m3)
|
|
54
|
+
|
|
55
|
+
assert future1.ready?, "First future was not ready"
|
|
56
|
+
assert future2.ready?, "Second future was not ready"
|
|
57
|
+
assert future3.ready?, "Third future was not ready"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Communication::WritingSocket do
|
|
4
|
+
|
|
5
|
+
class TestWriter < Pantry::Communication::WritingSocket
|
|
6
|
+
attr_accessor :socket_impl
|
|
7
|
+
|
|
8
|
+
def build_socket
|
|
9
|
+
@socket_impl
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def open_socket(socket)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:security) { Pantry::Communication::Security.new_client }
|
|
17
|
+
|
|
18
|
+
it "serializes a message and sends it down the pipe" do
|
|
19
|
+
zmq_socket = Class.new do
|
|
20
|
+
attr_accessor :written, :linger
|
|
21
|
+
|
|
22
|
+
def set(*options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def write(message_body)
|
|
26
|
+
@written = message_body
|
|
27
|
+
end
|
|
28
|
+
end.new
|
|
29
|
+
|
|
30
|
+
writer = TestWriter.new("host", 1234, security)
|
|
31
|
+
writer.socket_impl = zmq_socket
|
|
32
|
+
writer.open
|
|
33
|
+
|
|
34
|
+
message = Pantry::Message.new("message_type")
|
|
35
|
+
message.to = "stream"
|
|
36
|
+
message << "message_body_1"
|
|
37
|
+
message << "message_body_2"
|
|
38
|
+
|
|
39
|
+
writer.send_message(message)
|
|
40
|
+
|
|
41
|
+
assert_equal(
|
|
42
|
+
["stream", message.metadata.to_json, "message_body_1", "message_body_2"],
|
|
43
|
+
zmq_socket.written
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
require 'unit/test_helper'
|
|
2
|
+
|
|
3
|
+
describe Pantry::Config do
|
|
4
|
+
|
|
5
|
+
let(:pantry_config) { Pantry::Config.new }
|
|
6
|
+
|
|
7
|
+
it "ensures only one Config object exists via Pantry.config" do
|
|
8
|
+
config = Pantry.config
|
|
9
|
+
assert_same config, Pantry.config
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "Global Configs" do
|
|
13
|
+
it "has an entry for logging destination" do
|
|
14
|
+
pantry_config.log_to = "stdout"
|
|
15
|
+
assert_equal "stdout", pantry_config.log_to
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "has an entry for the log level" do
|
|
19
|
+
assert_equal "info", pantry_config.log_level
|
|
20
|
+
|
|
21
|
+
pantry_config.log_level = "warn"
|
|
22
|
+
assert_equal "warn", pantry_config.log_level
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "has an entry for the syslog program name" do
|
|
26
|
+
assert_equal "pantry", pantry_config.syslog_program_name
|
|
27
|
+
|
|
28
|
+
pantry_config.syslog_program_name = "client"
|
|
29
|
+
assert_equal "client", pantry_config.syslog_program_name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "has an entry for the data dir" do
|
|
33
|
+
pantry_config.root_dir = "dir"
|
|
34
|
+
assert_equal "dir", pantry_config.root_dir
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "can load values from a given YAML file" do
|
|
38
|
+
config_file = fixture_path("config.yml")
|
|
39
|
+
pantry_config.load_file(config_file)
|
|
40
|
+
|
|
41
|
+
assert_equal "/var/log/pantry.log", pantry_config.log_to
|
|
42
|
+
assert_equal "warn", pantry_config.log_level
|
|
43
|
+
assert_equal "testing", pantry_config.syslog_program_name
|
|
44
|
+
assert_equal "/tmp/data", pantry_config.root_dir
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "does not set values to nil if not in the config" do
|
|
48
|
+
config_file = fixture_path("empty.yml")
|
|
49
|
+
pantry_config.load_file(config_file)
|
|
50
|
+
|
|
51
|
+
assert_equal "info", pantry_config.log_level
|
|
52
|
+
assert_equal "pantry", pantry_config.syslog_program_name
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "Communication Configuration" do
|
|
57
|
+
it "has an entry for the server host name" do
|
|
58
|
+
pantry_config.server_host = "127.0.0.1"
|
|
59
|
+
assert_equal "127.0.0.1", pantry_config.server_host
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "has an entry for the pub / sub port" do
|
|
63
|
+
pantry_config.pub_sub_port = 100
|
|
64
|
+
assert_equal 100, pantry_config.pub_sub_port
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "has an entry for the client-info receive port" do
|
|
68
|
+
pantry_config.receive_port = 7788
|
|
69
|
+
assert_equal 7788, pantry_config.receive_port
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "has an entry for the file service port" do
|
|
73
|
+
pantry_config.file_service_port = 1122
|
|
74
|
+
assert_equal 1122, pantry_config.file_service_port
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "has an entry for the security strategy in use" do
|
|
78
|
+
pantry_config.security = "curve"
|
|
79
|
+
assert_equal "curve", pantry_config.security
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "can load values from a given YAML file" do
|
|
83
|
+
config_file = fixture_path("config.yml")
|
|
84
|
+
pantry_config.load_file(config_file)
|
|
85
|
+
|
|
86
|
+
assert_equal "10.0.0.1", pantry_config.server_host
|
|
87
|
+
assert_equal 12345, pantry_config.pub_sub_port
|
|
88
|
+
assert_equal 54321, pantry_config.receive_port
|
|
89
|
+
assert_equal 35412, pantry_config.file_service_port
|
|
90
|
+
assert_equal "curve", pantry_config.security
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "does not set values to nil if not in the config" do
|
|
94
|
+
config_file = fixture_path("empty.yml")
|
|
95
|
+
pantry_config.load_file(config_file)
|
|
96
|
+
|
|
97
|
+
assert_equal "127.0.0.1", pantry_config.server_host
|
|
98
|
+
assert_equal 23001, pantry_config.pub_sub_port
|
|
99
|
+
assert_equal 23002, pantry_config.receive_port
|
|
100
|
+
assert_equal 23003, pantry_config.file_service_port
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "Client-side Configuration" do
|
|
105
|
+
it "has an entry for client heartbeat interval" do
|
|
106
|
+
assert_equal 300, pantry_config.client_heartbeat_interval
|
|
107
|
+
pantry_config.client_heartbeat_interval = 5
|
|
108
|
+
assert_equal 5, pantry_config.client_heartbeat_interval
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "has an entry for the client's application" do
|
|
112
|
+
pantry_config.client_application = "pantry"
|
|
113
|
+
assert_equal "pantry", pantry_config.client_application
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "has an entry for the client's environment" do
|
|
117
|
+
pantry_config.client_environment = "pantry"
|
|
118
|
+
assert_equal "pantry", pantry_config.client_environment
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "has an entry for the client's identity" do
|
|
122
|
+
pantry_config.client_identity = "pantry"
|
|
123
|
+
assert_equal "pantry", pantry_config.client_identity
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "has an entry for the client's roles" do
|
|
127
|
+
pantry_config.client_roles = ["roles"]
|
|
128
|
+
assert_equal ["roles"], pantry_config.client_roles
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "can load values from a given YAML file" do
|
|
132
|
+
config_file = fixture_path("config.yml")
|
|
133
|
+
pantry_config.load_file(config_file)
|
|
134
|
+
|
|
135
|
+
assert_equal 600, pantry_config.client_heartbeat_interval
|
|
136
|
+
assert_equal "pantry-test-1", pantry_config.client_identity
|
|
137
|
+
assert_equal "pantry", pantry_config.client_application
|
|
138
|
+
assert_equal "test", pantry_config.client_environment
|
|
139
|
+
assert_equal %w(database application), pantry_config.client_roles
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "does not clobber certain values if config has set to nil" do
|
|
143
|
+
config_file = fixture_path("empty.yml")
|
|
144
|
+
pantry_config.load_file(config_file)
|
|
145
|
+
|
|
146
|
+
assert_equal 300, pantry_config.client_heartbeat_interval
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|