Skip to content

Commit

Permalink
continue script app for testing!
Browse files Browse the repository at this point in the history
  • Loading branch information
Willfrit committed Apr 17, 2019
1 parent b892108 commit c48543c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
5 changes: 3 additions & 2 deletions app_test/simple.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
--[[
Small script to test splay, just log the different neighbours during 1 minutes
Small script to test splay, just log the different neighbours, exit directly after
--]]

require("splay.base")

print("SIMPLE.LUA START")
print("I am the job "..job.position)

neighbours = job.nodes
print("I am link to :")
for _, n in pairs(neighbours) do print(" - "..n.ip..":"..n.port) end

print("Exit Discovering Job")
print("SIMPLE.LUA EXIT")
17 changes: 9 additions & 8 deletions app_test/simple_net.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rs.init(settings)
socket = rs.wrap(socket)
package.loaded['socket.core'] = socket ]]

print("SIMPLE_NET.LUA START")
print("Begin Simple network : I am "..job.me.ip..":"..job.me.port)

require("splay.base")
Expand All @@ -41,15 +42,15 @@ function receive(s)
local ip, port = s:getpeername()
while events.yield() do
local data, err = s:receive("*l")
print("I received "..data.." from "..ip..":"..port)
print("I received : "..data)
end
end

function send(s)
print("Send Stand by")
while events.yield() do
events.sleep(3)
s:send("Hello i am "..misc.dump(job.me).."\n")
events.sleep(1)
s:send("I AM "..job.position.."\n")
end
end

Expand All @@ -60,16 +61,16 @@ end

function final(s)
local ip, port = s:getpeername()
print("Closing: "..ip..":"..port.." - index ")
print("Closing: "..ip..":"..port)
end

events.run(function()
-- Accept connection from other nodes
net.server(job.me.port, {initialize = init, send = send, receive = receive, finalize = final})

-- Launch connection to each orther node (use the same function than server) (retry every 5 second)
-- Launch connection to each orther node
events.thread(function ()
events.sleep(5)
events.sleep(1)
for i, n in pairs(job.nodes) do
if n.port ~= job.me.port or n.ip ~= job.me.ip then
print("Try to begin connection to "..n.ip..":"..n.port.." - index "..i)
Expand All @@ -79,8 +80,8 @@ events.run(function()
end)

-- Stop after 20 seconds
events.sleep(20)
print("Simple Network exit")
events.sleep(4)
print("SIMPLE_NET.LUA EXIT")

events.exit()
end)
Expand Down
12 changes: 6 additions & 6 deletions app_test/simple_topo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ WITH this topology and 2 slayds
</topology>
]]--

print("TOPO TEST")

print("SIMPLE_TOPO.LUA START")
require("splay.base")

local events=require("splay.events")
Expand All @@ -41,11 +40,10 @@ u = net.udp_helper(job.me.port, print_server)

events.run(function()

print("Wait 5 seconds")
events.sleep(5)
print("Wait 2 seconds")
events.sleep(2)
print("Start send hello")


local start = misc.time()
for i, n in pairs(job.nodes) do
if i ~= job.position then
Expand All @@ -54,11 +52,13 @@ events.run(function()
end
end

events.sleep(5)
events.sleep(4)

final_time = t_end - start
print("Time to n1 -> hello -> n2 -> world -> n1 : "..final_time)
print("FINAL RTT : "..final_time.." sec")

events.kill(u.server)
end)

print("SIMPLE_TOPO.LUA EXIT")

0 comments on commit c48543c

Please sign in to comment.