forked from celluloid/floss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
51 lines (37 loc) · 909 Bytes
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$: << File.expand_path('../lib', __FILE__)
require 'floss/node'
CLUSTER_SIZE = 5
nodes = CLUSTER_SIZE.times.map do |i|
port = 50000 + i
"tcp://127.0.0.1:#{port}"
end
supervisor = Celluloid::SupervisionGroup.run!
CLUSTER_SIZE.times.map do |i|
combination = nodes.rotate(i)
options = {id: combination.first, peers: combination[1..-1]}
supervisor.supervise(Floss::Node, options)
end
sleep 1
begin
leader = supervisor.actors.find(&:leader?)
puts "The leader is #{leader.id}"
leader.execute("Hello World!")
rescue => e
puts "Couldn't execute my command!"
p e
end
sleep 1
begin
leader = supervisor.actors.find(&:leader?)
puts "The leader is #{leader.id}"
leader.execute("Hello Again!")
rescue => e
puts "Couldn't execute my command!"
p e
end
sleep 0.5
supervisor.actors.each do |actor|
Celluloid.logger.info("Log of #{actor.id}: #{actor.log.entries}")
end
sleep 1
exit