Commit 89af9974 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2476] [Lua] Assistente não pode aceitar tempo de espera entre tentativas igual a ZERO

- Incorporação de forma não-oficial de um novo assistente (módulo 'openbus.assistant2')
- Diversas correções no assistente oficial.
- Novos testes para o assistente.



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/02_00_00@155715 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 3eaf4481
This diff is collapsed.
This diff is collapsed.
......@@ -14,7 +14,7 @@ local insert = array.insert
local function checktype(funcname, index, typenames, value)
local function checktype(funcname, valname, typenames, value)
local luatype = type(value)
for typename in typenames:gmatch("[^|]+") do
if typename == "string" and luatype == "number" then
......@@ -26,29 +26,51 @@ local function checktype(funcname, index, typenames, value)
return value
end
end
error("bad argument #"..index.." to '"..funcname.."' (expected "..typenames
error("bad "..valname.." to '"..funcname.."' (expected "..typenames
..", got "..luatype..")", 3)
end
local function checkmeta(funcname, index, expected, value)
local function checkmeta(funcname, valname, expected, value)
local actual = getmetatable(value)
if actual == expected then
return value
end
error("bad argument #"..index.." to '"..funcname
error("bad "..valname.." to '"..funcname
.."' (expected object, got "..type(value)..")", 3)
end
local function convertconstructor(constructor, typedef)
assert(type(constructor) == "function", "constructor was not a function (got "..type(constructor)..")")
return function(fields, ...)
for name, typename in pairs(typedef) do
local checker = (type(typename)=="string") and checktype or checkmeta
checker(name, "field '"..name.."'", typename, fields[name])
return constructor(fiedls, ...)
end
end
end
local function convertmodule(module, typedefs)
for name, typedef in pairs(typedefs) do
local func = module[name]
assert(type(func) == "function", name.." was not a function (got "..type(func)..")")
module[name] = function(...)
for index, typename in ipairs(typedef) do
local checker = (type(typename)=="string") and checktype or checkmeta
checker(name, index, typename, select(index, ...))
--assert(type(func) == "function", name.." was not a function (got "..type(func)..")")
if next(typedef) ~= nil and #typedef == 0 then
module[name] = function(fields, ...)
checktype(name, "fields", "table", fields)
for field, typename in pairs(typedef) do
local checker = (type(typename)=="string") and checktype or checkmeta
checker(name, "field '"..field.."'", typename, fields[field])
end
return func(fields, ...)
end
else
module[name] = function(...)
for index, typename in ipairs(typedef) do
local checker = (type(typename)=="string") and checktype or checkmeta
checker(name, "argument #"..index, typename, select(index, ...))
end
return func(...)
end
return func(...)
end
end
end
......
......@@ -11,6 +11,7 @@ OPENBUSLIBIDL= ${SDK_IDL_SOURCE_HOME}/src
LUADIR= ../lua
LUASRC= \
$(LUADIR)/openbus/assistant.lua \
$(LUADIR)/openbus/assistant2.lua \
$(LUADIR)/openbus/core/Access.lua \
$(LUADIR)/openbus/core/idl/makeaux.lua \
$(LUADIR)/openbus/core/idl/parsed.lua \
......
This diff is collapsed.
local _G = require "_G"
local assert = _G.assert
local error = _G.error
local ipairs = _G.ipairs
local pairs = _G.pairs
local pcall = _G.pcall
local type = _G.type
local coroutine = require "coroutine"
local string = require "string"
local io = require "io"
local uuid = require "uuid"
local giop = require "oil.corba.giop"
local cothread = require "cothread"
local openbus = require "openbus"
local assistant = require "openbus.assistant2"
local libidl = require "openbus.idl"
local idl = require "openbus.core.idl"
local msg = require "openbus.util.messages"
local log = require "openbus.util.logger"
local sysex = giop.SystemExceptionIDs
bushost, busport, verbose = ...
require "openbus.test.configs"
--cothread.verbose:flag("threads", true)
--cothread.verbose:flag("state", true)
local smalltime = .1
local accesskey = openbus.newKey()
-- login as admin and provide additional functionality for the test
local invalidate, shutdown do
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
local conn = OpenBusContext:createConnection(bushost, busport)
conn:loginByPassword(admin, admpsw)
OpenBusContext:setDefaultConnection(conn)
function invalidate(loginId)
OpenBusContext:getLoginRegistry():invalidateLogin(loginId)
end
function shutdown()
conn:logout()
orb:shutdown()
end
end
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)
do log:TEST("Two threads logging in")
local conn = assistant.create{
orb = orb,
bushost = bushost,
busport = busport,
accesskey = accesskey,
}
local failures = 0
local threads = 2
local function trylogin()
local ok, ex = pcall(conn.loginByPassword, conn, user, password)
threads = threads-1
if not ok then
failures = failures+1
assert(ex._repid == libidl.types.AlreadyLoggedIn)
end
end
for i = 1, threads do
cothread.schedule(coroutine.create(trylogin))
end
repeat cothread.delay(smalltime) until threads == 0
assert(conn.login ~= nil)
assert(uuid.isvalid(conn.login.id))
assert(conn.login.entity == user)
assert(failures == 1)
assert(conn:logout() == true)
end
do log:TEST("Two threads getting invalid login and trying to relog")
local conn = assistant.create{
orb = orb,
bushost = bushost,
busport = busport,
accesskey = accesskey,
}
conn:loginByPassword(user, password)
OpenBusContext:setDefaultConnection(conn.connection)
local mylogin = conn.login
local failures = 0
local threads = 2
local function callop()
conn:getAllServices()
threads = threads-1
end
-- invalidate login
invalidate(mylogin.id)
-- perform calls with an invalid login
for i = 1, threads do cothread.schedule(coroutine.create(callop)) end
repeat cothread.delay(smalltime) until threads == 0
-- check connection after execution of callbacks
assert(conn.login ~= nil)
assert(conn.login ~= mylogin)
conn:logout()
OpenBusContext:setDefaultConnection(nil)
end
orb:shutdown()
shutdown()
This diff is collapsed.
local _G = require "_G"
local assert = _G.assert
local error = _G.error
local ipairs = _G.ipairs
local pairs = _G.pairs
local pcall = _G.pcall
local type = _G.type
local coroutine = require "coroutine"
local string = require "string"
local io = require "io"
local uuid = require "uuid"
local giop = require "oil.corba.giop"
local cothread = require "cothread"
local openbus = require "openbus"
local assistant = require "openbus.assistant2"
local libidl = require "openbus.idl"
local idl = require "openbus.core.idl"
local msg = require "openbus.util.messages"
local log = require "openbus.util.logger"
local sysex = giop.SystemExceptionIDs
local LoginObserverRepId = idl.types.services.access_control.LoginObserver
bushost, busport, verbose = ...
require "openbus.test.configs"
local accesskey = openbus.newKey()
-- login as admin and provide additional functionality for the test
local invalidate, shutdown do
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
local conn = OpenBusContext:createConnection(bushost, busport)
conn:loginByPassword(admin, admpsw)
OpenBusContext:setDefaultConnection(conn)
function invalidate(loginId)
OpenBusContext:getLoginRegistry():invalidateLogin(loginId)
end
function newproxy(...)
return orb:newproxy(...)
end
function servant(func)
if func == nil then func = function() end end
return tostring(orb:newservant({entityLogout=func}, nil,
LoginObserverRepId)),
nil,
LoginObserverRepId
end
function shutdown()
conn:logout()
orb:shutdown()
end
end
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)
do log:TEST("Relog while performing a call")
local conn = assistant.create{
orb = orb,
bushost = bushost,
busport = busport,
accesskey = accesskey,
}
conn:loginByPassword(user, password)
OpenBusContext:setDefaultConnection(conn.connection)
invalidate(conn.login.id)
local prx = orb:newproxy(servant())
prx:entityLogout{id="???",entity="???"}
OpenBusContext:setDefaultConnection(nil)
assert(conn:logout())
end
do log:TEST("Relog while dispathing a call")
local conn = assistant.create{
orb = orb,
bushost = bushost,
busport = busport,
accesskey = accesskey,
}
conn:loginByPassword(user, password)
OpenBusContext:setDefaultConnection(conn.connection)
local ior = tostring(orb:newservant({}, nil, "CORBA::InterfaceDef"))
local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")
invalidate(conn.login.id)
local res = pxy:_non_existent()
assert(res == false)
OpenBusContext:setDefaultConnection(nil)
assert(conn:logout())
end
orb:shutdown()
shutdown()
......@@ -15,6 +15,10 @@ openbus/test/util/database \
openbus/test/LoginLogout \
openbus/test/Concurrency \
openbus/test/NoLoginIceptorCalls \
openbus/test/assistant/LoginLogout \
openbus/test/assistant/Concurrency \
openbus/test/assistant/NoLoginIceptorCalls \
openbus/test/assistant/AssistantLoginLogout \
"
for case in ${LUACASES}; do
echo -n "Test '${case}' ... "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment