Commit accafd17 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-1708] [LUA] Implementar testes para o SDK 2.0

[OPENBUS-1599] Criar suite de testes para o core e sdk-lua do OpenBus 2.0
- Ajustes para permitir executar todos os testes do core e SDK-Lua (básicos e interop) sem necessidade de commitar arquivos gerados tais como chaves e certificados.
- Ajustes nos testes de interop para facilitar execução com implementações em outras linguagens.
- Ajustes nos scripts de execução dos testes do core e SDK-Lua (básicos e interop).

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/openbus_v2_proto@131594 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 0d3fe6c4
local log = require "openbus.util.logger"
local server = require "openbus.util.server"
local openbus = require "openbus"
local ComponentContext = require "scs.core.ComponentContext"
local chain2str = require "chain2str"
local table = require "loop.table"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
orb:loadidlfile("messages.idl")
openbus.newthread(orb.run, orb)
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::Broadcaster")
-- customize test configuration for this case
settestcfg(iface, ...)
-- connect to the bus
local manager = orb.OpenBusConnectionManager
......@@ -17,10 +21,7 @@ local conn = manager:createConnection(bushost, busport)
manager:setDefaultConnection(conn)
-- create service implementation
Broadcaster = {
__type = orb.types:lookup("tecgraf::openbus::interop::delegation::Broadcaster"),
subscribers = {},
}
Broadcaster = { subscribers = {} }
function Broadcaster:post(message)
conn:joinChain() -- joins the current caller chain
for user in pairs(self.subscribers) do
......@@ -48,38 +49,24 @@ local component = ComponentContext(orb, {
patch_version = 0,
platform_spec = "",
})
component:addFacet("broadcaster", Broadcaster.__type.repID, Broadcaster)
local msgIface = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger")
component:addFacet(iface.name, iface.repID, Broadcaster)
-- login to the bus
conn:loginByCertificate("broadcaster", syskey)
conn:loginByCertificate(system, assert(server.readfrom(syskey)))
-- define service properties
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger")
local props = {{name="openbus.component.interface",value=iface.repID}}
-- retrieve messenger service
log:TEST(true, "retrieve messenger service")
Messenger = nil
repeat
offers = conn.offers:findServices({
{name="openbus.offer.entity",value="messenger"}, -- automatic property
{name="openbus.component.interface",value=msgIface.repID}, -- automatic property
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
for _, offer in ipairs(offers) do
local service = offer.service_ref
if not service:_non_existent() then
Messenger = orb:narrow(service:getFacet(msgIface.repID), msgIface)
break
end
end
if Messenger then break end
log:TEST("mesenger service not found yet...")
openbus.sleep(1)
until false
log:TEST(false, "messenger service found!")
log:TEST("retrieve messenger service")
for _, offer in ipairs(findoffers(conn.offers, props)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
log:TEST("found messenger service of ",entity,"!")
Messenger = orb:narrow(offer.service_ref:getFacet(iface.repID), iface)
end
-- offer broadcast service
conn.offers:registerService(component.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
conn.offers:registerService(component.IComponent, properties)
log:TEST("broadcast service ready!")
local log = require "openbus.util.logger"
local openbus = require "openbus"
local ComponentContext = require "scs.core.ComponentContext"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
orb:loadidlfile("messages.idl")
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger")
-- customize test configuration for this case
settestcfg(iface, ...)
-- connect to the bus
local manager = orb.OpenBusConnectionManager
......@@ -17,79 +19,55 @@ manager:setDefaultConnection(conn)
-- login to the bus
conn:loginByPassword(user, password)
-- find the offered services
log:TEST(true, "retrieve required services")
local tries = 10
for i = 1, tries do
offers = conn.offers:findServices({
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
for _, offer in ipairs(offers) do
local service = offer.service_ref
if not service:_non_existent() then
local name, iface
for _, prop in ipairs(offer.properties) do
if prop.name == "openbus.component.facet" then
assert(name == nil)
name = prop.value
elseif prop.name == "openbus.component.interface" then
assert(iface == nil)
iface = prop.value
end
end
_G[name] = orb:narrow(service:getFacet(iface), iface)
end
end
if messenger == nil or broadcaster == nil or forwarder == nil then
log:TEST("not all service found after ",i,(" seconds "):tag{
messenger = messenger~=nil and "OK" or nil,
broadcaster = broadcaster~=nil and "OK" or nil,
forwarder = forwarder~=nil and "OK" or nil,
})
openbus.sleep(1)
else
break
-- retrieve services
local services = {}
for _, name in ipairs{"Messenger", "Broadcaster", "Forwarder"} do
-- define service properties
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::"..name)
local props = {{name="openbus.component.interface",value=iface.repID}}
-- retrieve service
log:TEST("retrieve messenger service")
for _, offer in ipairs(findoffers(conn.offers, props)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
log:TEST("found messenger service of ",entity,"!")
services[name] = {
entity = entity,
ref = orb:narrow(offer.service_ref:getFacet(iface.repID), iface),
}
end
end
log:TEST(false, "required services found!")
-- logout from the bus
conn:logout()
conn:loginByPassword("bill", "bill")
forwarder:setForward("willian")
broadcaster:subscribe()
services.Forwarder.ref:setForward("willian")
services.Broadcaster.ref:subscribe()
conn:logout()
conn:loginByPassword("paul", "paul")
broadcaster:subscribe()
services.Broadcaster.ref:subscribe()
conn:logout()
conn:loginByPassword("mary", "mary")
broadcaster:subscribe()
services.Broadcaster.ref:subscribe()
conn:logout()
conn:loginByPassword("steve", "steve")
broadcaster:subscribe()
broadcaster:post("Testing the list!")
services.Broadcaster.ref:subscribe()
services.Broadcaster.ref:post("Testing the list!")
conn:logout()
log:TEST("waiting for messages to propagate")
for i = 1, 10 do openbus.sleep(1) end
local function showPostsOf(user, posts)
log:TEST(true, user," received ",#posts," messages:")
for index, post in ipairs(posts) do
log:TEST(index,") ",post.from,": ",post.message)
end
log:TEST(false)
end
openbus.sleep(leasetime)
local expected = {
willian = {
{
from = "forwarder",
message = "forwarded message by steve->broadcaster: Testing the list!",
from = services.Forwarder.entity,
message = "forwarded message by steve->"..services.Broadcaster.entity..": Testing the list!",
},
n = 1,
},
......@@ -98,21 +76,21 @@ local expected = {
},
paul = {
{
from = "steve->broadcaster",
from = "steve->"..services.Broadcaster.entity,
message = "Testing the list!",
},
n = 1,
},
mary = {
{
from = "steve->broadcaster",
from = "steve->"..services.Broadcaster.entity,
message = "Testing the list!",
},
n = 1,
},
steve = {
{
from = "steve->broadcaster",
from = "steve->"..services.Broadcaster.entity,
message = "Testing the list!",
},
n = 1,
......@@ -121,15 +99,14 @@ local expected = {
local actual = {}
for _, user in ipairs{"willian", "bill", "paul", "mary", "steve"} do
conn:loginByPassword(user, user)
actual[user] = messenger:receivePosts()
actual[user] = services.Messenger.ref:receivePosts()
log:TEST(user," got posts: ",actual[user])
broadcaster:unsubscribe()
services.Broadcaster.ref:unsubscribe()
conn:logout()
end
conn:loginByPassword("bill", "bill")
forwarder:cancelForward("willian")
services.Forwarder.ref:cancelForward("willian")
conn:logout()
assert(require("loop.debug.Matcher"){metatable=false}:match(actual, expected))
local log = require "openbus.util.logger"
local server = require "openbus.util.server"
local openbus = require "openbus"
local ComponentContext = require "scs.core.ComponentContext"
local table = require "loop.table"
local Timer = require "cothread.Timer"
local chain2str = require "chain2str"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
orb:loadidlfile("messages.idl")
openbus.newthread(orb.run, orb)
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::Forwarder")
-- customize test configuration for this case
settestcfg(iface, ...)
-- connect to the bus
local manager = orb.OpenBusConnectionManager
......@@ -19,10 +22,7 @@ local conn = manager:createConnection(bushost, busport)
manager:setDefaultConnection(conn)
-- create service implementation
Forwarder = {
__type = orb.types:lookup("tecgraf::openbus::interop::delegation::Forwarder"),
forwardsOf = {},
}
Forwarder = { forwardsOf = {} }
function Forwarder:setForward(to)
local chain = conn:getCallerChain()
local user = chain.caller.entity
......@@ -49,7 +49,7 @@ function Forwarder:getForward()
end
-- create timer to forward messages from time to time
timer = Timer{ rate = 5 }
timer = Timer{ rate = leasetime/2 }
function timer:action()
for user, forward in pairs(Forwarder.forwardsOf) do
log:TEST("checking messages of ",user)
......@@ -71,38 +71,24 @@ component = ComponentContext(orb, {
patch_version = 0,
platform_spec = "",
})
component:addFacet("forwarder", Forwarder.__type.repID, Forwarder)
local msgIface = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger")
component:addFacet(iface.name, iface.repID, Forwarder)
-- login to the bus
conn:loginByCertificate("forwarder", syskey)
conn:loginByCertificate(system, assert(server.readfrom(syskey)))
-- define service properties
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger")
local props = {{name="openbus.component.interface",value=iface.repID}}
-- retrieve messenger service
log:TEST(true, "retrieve messenger service")
Messenger = nil
repeat
offers = conn.offers:findServices({
{name="openbus.offer.entity",value="messenger"}, -- automatic property
{name="openbus.component.interface",value=msgIface.repID}, -- automatic property
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
for _, offer in ipairs(offers) do
local service = offer.service_ref
if not service:_non_existent() then
Messenger = orb:narrow(service:getFacet(msgIface.repID), msgIface)
break
end
end
if Messenger then break end
log:TEST("mesenger service not found yet...")
openbus.sleep(1)
until false
log:TEST(false, "messenger service found!")
log:TEST("retrieve messenger service")
for _, offer in ipairs(findoffers(conn.offers, props)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
log:TEST("found messenger service of ",entity,"!")
Messenger = orb:narrow(offer.service_ref:getFacet(iface.repID), iface)
end
-- offer broadcast service
conn.offers:registerService(component.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
conn.offers:registerService(component.IComponent, properties)
log:TEST("forwarder service ready!")
local log = require "openbus.util.logger"
local server = require "openbus.util.server"
local openbus = require "openbus"
local ComponentContext = require "scs.core.ComponentContext"
local chain2str = require "chain2str"
local table = require "loop.table"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
orb:loadidlfile("messages.idl")
openbus.newthread(orb.run, orb)
local iface = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger")
-- connect to the bus
local manager = orb.OpenBusConnectionManager
local conn = manager:createConnection(bushost, busport)
manager:setDefaultConnection(conn)
-- customize test configuration for this case
settestcfg(iface, ...)
-- create service implementation
local Messenger = {
__type = orb.types:lookup("tecgraf::openbus::interop::delegation::Messenger"),
inboxOf = table.memoize(function() return {} end),
}
local Messenger = { inboxOf = table.memoize(function() return {} end) }
function Messenger:post(to, message)
local chain = conn:getCallerChain()
local from = chain2str(chain)
......@@ -46,14 +46,12 @@ local component = ComponentContext(orb, {
patch_version = 0,
platform_spec = "",
})
component:addFacet("messenger", Messenger.__type.repID, Messenger)
component:addFacet(iface.name, iface.repID, Messenger)
-- login to the bus
conn:loginByCertificate("messenger", syskey)
conn:loginByCertificate(system, assert(server.readfrom(syskey)))
-- offer messenger service
conn.offers:registerService(component.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
conn.offers:registerService(component.IComponent, properties)
log:TEST("messenger service ready!")
#!/bin/bash
CONSOLE="${OPENBUS_HOME}/bin/busconsole -d"
SERVICES="\
messenger \
broadcaster \
forwarder \
"
pid=
for service in $SERVICES; do
echo "Starting service '$service'"
$CONSOLE $service.lua $@ &
pid="$pid $!"
trap "kill $pid > /dev/null 2> /dev/null" 0
done
echo -n "Executing test ... "
$CONSOLE client.lua $@
echo "OK"
local table = require "loop.table"
local log = require "openbus.util.logger"
local openbus = require "openbus"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
orb:loadidlfile("hello.idl")
local iface = orb.types:lookup("tecgraf::openbus::interop::simple::Hello")
-- customize test configuration for this case
settestcfg(iface, ...)
-- connect to the bus
-- obtain connection manager
local manager = orb.OpenBusConnectionManager
-- define service properties
local props = {{name="openbus.component.interface",value=iface.repID}}
for _, businfo in ipairs{
{host=bushost, port=busport, offers=3},
{host=bus2host, port=bus2port, offers=1},
......@@ -23,42 +31,27 @@ for _, businfo in ipairs{
-- login to the bus
conn:loginByPassword(user, password)
-- retrieve required services
log:TEST(true, "retrieve required services from bus ",conn.busid)
local services = {}
local tries = 10
for i = 1, tries do
local offers = conn.offers:findServices({
{name="openbus.component.facet",value="Hello"}, -- automatic property
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
local count = 0
for _, offer in ipairs(offers) do
local service = offer.service_ref
if not service:_non_existent() then
for _, prop in ipairs(offer.properties) do
if prop.name == "openbus.offer.login" then
local login = prop.value
assert(services[login] == nil)
services[login] = service:getFacetByName("Hello"):__narrow()
count = count+1
break
end
end
end
end
if count < businfo.offers then
log:TEST(count," services found after ",i," seconds, ",businfo.offers-count," missing")
openbus.sleep(1)
else
break
end
-- find the offered service
log:TEST("retrieve hello services from bus ",conn.busid,"!")
local expected = businfo.offers
local services = table.memoize(function() return {} end)
for _, offer in ipairs(findoffers(conn.offers, props, expected)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
local login = getprop(offer.properties, "openbus.offer.login")
log:TEST("found service of ",entity,"! (",login,")")
assert(services[entity][login] == nil)
services[entity][login] =
offer.service_ref:getFacetByName(iface.name):__narrow(iface)
end
log:TEST(false, "required services found at bus ",conn.busid,"!")
log:TEST("invoking ",businfo.offers," services from bus ",conn.busid,"!")
for login, hello in pairs(services) do
assert(hello:sayHello() == "Hello from "..user.."@"..conn.busid.."!")
log:TEST("invoking services from bus ",conn.busid,"!")
for entity, services in pairs(services) do
local count = 0
for login, hello in pairs(services) do
assert(hello:sayHello() == "Hello from "..user.."@"..conn.busid.."!")
count = count+1
end
assert(count == expected, entity..": found "..count.." of "..expected)
end
-- logout from the bus
......
#!/bin/bash
CONSOLE="${OPENBUS_HOME}/bin/busconsole -d"
echo "Starting service"
$CONSOLE server.lua $@ &
pid="$pid $!"
trap "kill $pid > /dev/null 2> /dev/null" 0
echo -n "Executing test ... "
$CONSOLE client.lua $@
echo "OK"
local log = require "openbus.util.logger"
local server = require "openbus.util.server"
local openbus = require "openbus"
local ComponentContext = require "scs.core.ComponentContext"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
require "openbus.test.util"
-- setup and start the ORB
local orb1 = openbus.initORB()
orb1:loadidlfile("hello.idl")
openbus.newthread(orb1.run, orb1)
local conns1 = orb1.OpenBusConnectionManager
local orb2 = openbus.initORB()
orb2:loadidlfile("hello.idl")
openbus.newthread(orb2.run, orb2)
local conns2 = orb2.OpenBusConnectionManager
local iface = orb1.types:lookup("tecgraf::openbus::interop::simple::Hello")
-- customize test configuration for this case
settestcfg(iface, ...)
-- connect to the bus
-- connect to the buses
local conns1 = orb1.OpenBusConnectionManager
local conns2 = orb2.OpenBusConnectionManager
local conn1AtBus1WithOrb1 = conns1:createConnection(bushost, busport)
local conn2AtBus1WithOrb1 = conns1:createConnection(bushost, busport)
local connAtBus2WithOrb1 = conns1:createConnection(bus2host, bus2port)
......@@ -30,24 +34,18 @@ function hello:sayHello()
return "Hello from "..chain.caller.entity.."@"..chain.busid.."!"
end
-- create service SCS component
local iface = "tecgraf::openbus::interop::simple::Hello"
local component1 = ComponentContext(orb1, {
name = "Hello",
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "",
})
component1:addFacet("Hello", orb1.types:lookup(iface).repID, hello)
local component2 = ComponentContext(orb2, {
-- create service SCS components
local compId = {
name = "Hello",
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "",
})
component2:addFacet("Hello", orb2.types:lookup(iface).repID, hello)
}
local component1 = ComponentContext(orb1, compId)
local component2 = ComponentContext(orb2, compId)
component1:addFacet(iface.name, iface.repID, hello)
component2:addFacet(iface.name, iface.repID, hello)
-- set incoming connections
conns1:setDispatcher(conn1AtBus1WithOrb1)
......@@ -58,27 +56,20 @@ conns1:setRequester(connAtBus2WithOrb1)
conns2:setDefaultConnection(connAtBus1WithOrb2)
-- login to the bus
conn1AtBus1WithOrb1:loginByCertificate(system, syskey)
conn2AtBus1WithOrb1:loginByCertificate(system, syskey)
connAtBus2WithOrb1:loginByCertificate(system, syskey)
connAtBus1WithOrb2:loginByCertificate(system, syskey)
local prvkey = assert(server.readfrom(syskey))
conn1AtBus1WithOrb1:loginByCertificate(system, prvkey)
conn2AtBus1WithOrb1:loginByCertificate(system, prvkey)
connAtBus2WithOrb1:loginByCertificate(system, prvkey)
connAtBus1WithOrb2:loginByCertificate(system, prvkey)
-- offer the service
openbus.newthread(function()
conns1:setRequester(conn1AtBus1WithOrb1)
conn1AtBus1WithOrb1.offers:registerService(component1.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
conn1AtBus1WithOrb1.offers:registerService(component1.IComponent, properties)
end)
openbus.newthread(function()
conns1:setRequester(conn2AtBus1WithOrb1)
conn2AtBus1WithOrb1.offers:registerService(component1.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
conn2AtBus1WithOrb1.offers:registerService(component1.IComponent, properties)
end)
connAtBus2WithOrb1.offers:registerService(component1.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
connAtBus1WithOrb2.offers:registerService(component2.IComponent, {
{name="offer.domain",value="Interoperability Tests"}, -- provided property
})
connAtBus2WithOrb1.offers:registerService(component1.IComponent, properties)
connAtBus1WithOrb2.offers:registerService(component2.IComponent, properties)
#!/bin/bash
CORESERV="${OPENBUS_HOME}/bin/busservices DEBUG"
echo "Starting core bus services"
if [ -d openbus.db ]; then
INITBUS=no
fi
$CORESERV -leasetime 1 \
-expirationgap .5 \
-admin admin \
-validator openbus.test.core.services.TesterUserValidator &
pid="$pid $!"
trap "kill $pid > /dev/null 2> /dev/null" 0
echo "Starting second core bus services"
if [ -d openbus2.db ]; then
INITBUS2=no
fi
$CORESERV -port 2090 \
-database openbus2.db \
-leasetime 1 \
-expirationgap .5 \
-admin admin \
-validator openbus.test.core.services.TesterUserValidator &
pid="$pid $!"
trap "kill $pid > /dev/null 2> /dev/null" 0
echo "Waiting core bus services to be accessible"
CONSOLE="${OPENBUS_HOME}/bin/busconsole -d"
$CONSOLE -l oil -e '
for _, port in ipairs{2089,2090} do
local bus = oil.init():newproxy("corbaloc::localhost:"..port.."/OpenBus_2_0",
nil, oil.corba.idl.object)
while bus:_non_existent() do
oil.sleep(1)
end
end
'
ADMINCMD="${OPENBUS_HOME}/bin/busadmin DEBUG"
if [ "$INITBUS" != "no" ]; then
echo "Setting up core bus services"
$ADMINCMD --login=admin --script=script.adm
fi
if [ "$INITBUS2" != "no" ]; then
echo "Setting up second core bus services"
$ADMINCMD --port=2090 --login=admin --script=script.adm
fi
CASES="\
simple \
delegation \
multiplexing \
sharedauth \
"
pid=
for case in $CASES; do
echo "Executing interoperation test case '$case'"
cd $case
bash runall.sh
cd ..
done
/bin/bash runtest.sh $1 simple server
/bin/bash runtest.sh $1 multiplexing server
/bin/bash runtest.sh $1 sharedauth server
/bin/bash runtest.sh $1 delegation messenger broadcaster forwarder
#!/bin/bash
CONSOLE="${OPENBUS_HOME}/bin/busconsole"
if [ "$1" == "DEBUG" ]; then
CONSOLE="$CONSOLE -d"
elif [ "$1" != "RELEASE" ]; then
echo "Usage: runtest.sh [RELEASE|DEBUG] <dir> [services]"
exit 1
fi
if [[ ${#@} > 2 ]]; then
services="${@:3:${#@}}"