palta 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/lib/palta/client.rb +8 -1
- data/lib/palta/server.rb +5 -4
- data/lib/palta/version.rb +1 -1
- data/test/test_client.rb +23 -0
- data/test/test_server.rb +14 -5
- data/test/test_server_client.rb +30 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4064532eeb7881b19721d0b685be446575ee14a
|
4
|
+
data.tar.gz: 3872b4a60da1b215c106224ca8ff0d8a3a0d3699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5560f48a8de880e50c24354966c7f2a82f60c7fe77cf4152f659d5687a46914547207b956388fe778bf9be605e7d4953deafba7d368de7f455428f4bc5f8e7
|
7
|
+
data.tar.gz: bae51a0a05c61176f5315c02dd007b422fa57413d72c4ade69433cb2e8b8d7a5503c8b7bf747f4d7979e7634adb1e543e3cea0d391ca7bf6093d2cec18e3cc59
|
data/.travis.yml
ADDED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/palta/client.rb
CHANGED
@@ -6,10 +6,17 @@ module Palta
|
|
6
6
|
|
7
7
|
class Client
|
8
8
|
|
9
|
-
|
9
|
+
attr_reader :host, :port
|
10
|
+
|
11
|
+
def initialize host="localhost", port=8888
|
12
|
+
@host = host
|
13
|
+
@port = port
|
10
14
|
end
|
11
15
|
|
12
16
|
def send data
|
17
|
+
TCPSocket.open @host, @port do |s|
|
18
|
+
s.send data.to_json, 0
|
19
|
+
end
|
13
20
|
end
|
14
21
|
|
15
22
|
end
|
data/lib/palta/server.rb
CHANGED
@@ -6,7 +6,7 @@ module Palta
|
|
6
6
|
|
7
7
|
class Server
|
8
8
|
|
9
|
-
attr_reader :host, :port, :debug, :dir, :max_threads
|
9
|
+
attr_reader :host, :port, :debug, :dir, :max_threads, :msg_recv
|
10
10
|
|
11
11
|
def initialize options = {}
|
12
12
|
@host = options[:host] || "localhost"
|
@@ -15,6 +15,7 @@ module Palta
|
|
15
15
|
@dir = options[:dir] || "./.palta/data"
|
16
16
|
@max_threads = options[:max_threads] || 8
|
17
17
|
@threads = []
|
18
|
+
@msg_recv = 0
|
18
19
|
end
|
19
20
|
|
20
21
|
def actions &block
|
@@ -22,6 +23,7 @@ module Palta
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def on_msg msg
|
26
|
+
@msg_recv += 1
|
25
27
|
on_any(msg)
|
26
28
|
send("on_#{msg[:type]}", msg)
|
27
29
|
end
|
@@ -37,9 +39,8 @@ module Palta
|
|
37
39
|
loop do
|
38
40
|
client = @server.accept
|
39
41
|
data = client.recv(1024)
|
40
|
-
|
41
|
-
|
42
|
-
end
|
42
|
+
client.close
|
43
|
+
puts "[Palta::Server] thread #{i} recv: #{data}" if @debug
|
43
44
|
msg = JSON.parse(data, :symbolize_names => true)
|
44
45
|
on_msg(msg)
|
45
46
|
end
|
data/lib/palta/version.rb
CHANGED
data/test/test_client.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "./test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "palta"
|
4
|
+
|
5
|
+
class TestClient < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_default_creation_yields_no_error
|
8
|
+
c = Palta::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_creation_with_paramaters_ok
|
12
|
+
c = Palta::Client.new "192.168.0.1", 8989
|
13
|
+
assert_equal "192.168.0.1", c.host
|
14
|
+
assert_equal 8989, c.port
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_with_wrong_host_should_fail_to_send
|
18
|
+
c = Palta::Client.new "255.255.255.254"
|
19
|
+
assert_raise Errno::ENETUNREACH do
|
20
|
+
c.send({ :hola => "hi"})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/test_server.rb
CHANGED
@@ -2,16 +2,13 @@ require_relative "./test_helper"
|
|
2
2
|
require "test/unit"
|
3
3
|
require "palta"
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestServer < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def test_default_creation_yields_no_error
|
8
|
-
# Default creation should be valid in most environments
|
9
8
|
s = Palta::Server.new
|
10
9
|
end
|
11
10
|
|
12
11
|
def test_creation_with_paramaters_ok
|
13
|
-
# With (a priori) correct data, the user should be able to
|
14
|
-
# instantiate a Palta::Server object
|
15
12
|
options = {
|
16
13
|
:host => "127.0.0.1",
|
17
14
|
:port => 9898,
|
@@ -27,7 +24,7 @@ class TestBasic < Test::Unit::TestCase
|
|
27
24
|
assert_equal options[:max_threads], s.max_threads
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
27
|
+
def test_with_wrong_port_should_fail_to_start
|
31
28
|
# Without root permissions the server should fail to start in a
|
32
29
|
# port number lower than 1024
|
33
30
|
options = {
|
@@ -40,4 +37,16 @@ class TestBasic < Test::Unit::TestCase
|
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
40
|
+
def test_with_wrong_host_should_fail_to_start
|
41
|
+
# See http://stackoverflow.com/questions/10456044/what-is-a-good-invalid-ip-address-to-use-for-unit-tests
|
42
|
+
# for info about IP addresses that should not be routed anywhere
|
43
|
+
options = {
|
44
|
+
:host => "192.0.2.1"
|
45
|
+
}
|
46
|
+
s = Palta::Server.new options
|
47
|
+
assert_raise Errno::EADDRNOTAVAIL do
|
48
|
+
s.start
|
49
|
+
s.stop
|
50
|
+
end
|
51
|
+
end
|
43
52
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "./test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "palta"
|
4
|
+
|
5
|
+
class TestServerClient < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@s = Palta::Server.new
|
9
|
+
@c = Palta::Client.new
|
10
|
+
@s.actions do
|
11
|
+
def on_test
|
12
|
+
# nothing
|
13
|
+
end
|
14
|
+
end
|
15
|
+
@s.start
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_message_triggers_action
|
19
|
+
@c.send({
|
20
|
+
:type => "test",
|
21
|
+
:data => "this is a test"
|
22
|
+
})
|
23
|
+
assert_equal 1, @s.msg_recv
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
@s.stop
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: palta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Contreras Pinilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- .gitignore
|
50
|
+
- .travis.yml
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -60,8 +61,10 @@ files:
|
|
60
61
|
- lib/palta/server.rb
|
61
62
|
- lib/palta/version.rb
|
62
63
|
- palta.gemspec
|
64
|
+
- test/test_client.rb
|
63
65
|
- test/test_helper.rb
|
64
66
|
- test/test_server.rb
|
67
|
+
- test/test_server_client.rb
|
65
68
|
homepage: http://github.com/ignc/palta
|
66
69
|
licenses:
|
67
70
|
- MIT
|
@@ -88,5 +91,7 @@ specification_version: 4
|
|
88
91
|
summary: Simple Ruby server made for logging remote messages and triggering actions
|
89
92
|
according to customizable criteria
|
90
93
|
test_files:
|
94
|
+
- test/test_client.rb
|
91
95
|
- test/test_helper.rb
|
92
96
|
- test/test_server.rb
|
97
|
+
- test/test_server_client.rb
|