project BLF > class tLogger > method LogUnitTest
Internal usage
BLF
program code (program1/tlogger.p)
if viLogBusinessCodeDataCount > 0
and vcLogBusinessCodeFile <> ""
then do:
if (viLoggerDebugLevel mod 4) > 1
then for each tStack by tStack.tiSequence descending:
viLogBusinessCodeDataCount = viLogBusinessCodeDataCount + 1.
create tLogBusinessCodeData.
assign tLogBusinessCodeData.tiCount = viLogBusinessCodeDataCount
tLogBusinessCodeData.tcMethod = "<BusCode>" + chr(10)
+ "time=" + string(now) + chr(10)
+ "method=" + tStack.tcMethod + chr(10)
+ "parent=" + tStack.tcParent + chr(10)
+ "duration=0" + chr(10)
+ "END" + chr(10)
+ "</BusCode>" + chr(10).
release tLogBusinessCodeData.
delete tStack.
end.
/* Lock the ct-log file for other processes (multi-threading support).
If the file is locked, wait for release.
If no release occurs, ignore the lock.
*/
do while search(vcLogBusinessCodeFile + ".lock") <> ?:
if viLockCount > 3 then leave.
viLockCount = viLockCount + 1.
pause 1 no-message.
end.
output stream sLug to value (vcLogBusinessCodeFile + ".lock").
put stream sLug unformatted "locked" skip.
output stream sLug close.
/* write data, 'clean up' carriage-returns first */
output stream sLug to value (vcLogBusinessCodeFile) append.
for each tLogBusinessCodeData:
vcOutput = replace (tLogBusinessCodeData.tcMethod,chr(13),"").
vcOutput = replace (vcOutput,chr(10),chr(13) + chr(10)).
put stream sLug unformatted vcOutput skip.
end.
output stream sLug close.
empty temp-table tLogBusinessCodeData.
viLogBusinessCodeDataCount = 0.
/* release lock */
os-delete value (vcLogBusinessCodeFile + ".lock").
end.
if vcLogUnitTestFile = ""
then return.
if (viLoggerDebugLevel mod 64) > 31
then do:
empty temp-table tCompList.
output stream sLug to value (vcLogUnitTestFile) append.
/* ================================================================= */
/* Get a list of business components that are still in memory */
/* legally (this list does not include technical components). */
/* ================================================================= */
run GetComponentPool (output dataset tBusCompPool) no-error.
for each tBusCompPool where tBusCompPool.tlIsInMemory:
do viFcCount1 = num-entries(tBusCompPool.thProc:super-procedures) to 1 by -1:
create bbusComp.
assign bbusComp.tcName = tBusCompPool.tcName
bbusComp.thProc = widget-handle(entry(viFcCount1,tBusCompPool.thProc:super-procedures))
bbusComp.tlIsInMemory = no.
end.
find first tCompList where tCompList.tcCompName = "component-" + tBusCompPool.tcName no-error.
if not available tCompList then create tCompList.
assign tCompList.tcCompName = "component-" + tBusCompPool.tcName
tCompList.tiCount = tCompList.tiCount + 1.
end.
/* ================================================================= */
/* Go through all persistent procedures. */
/* List all components and report all other procedures. */
/* ================================================================= */
vhFcComponent = session:first-procedure.
do while vhFcComponent <> ?:
vcProc = vhFcComponent:file-name.
if vcProc begins "program/"
or vcProc begins "query/"
then vcProcList = vcProcList + ","
+ entry(1,entry(2,vcProc,"/"),".").
if not (vcProc begins "api/"
or vcProc begins "appinfo/"
or vcProc begins "ins/"
or vcProc begins "query/"
or vcProc begins "ref_int/"
or (vcProc begins "program" and
not (vcProc begins "program/")))
then do:
if not can-find (first tBusCompPool where tBusCompPool.thProc = vhFcComponent)
then do:
find first tCompList where tCompList.tcCompName = vcProc no-error.
if not available tCompList then create tCompList.
assign tCompList.tcCompName = vcProc
tCompList.tiCount = tCompList.tiCount + 1.
end.
end.
vhFcComponent = vhFcComponent:next-sibling.
end.
vhFcComponent = session:first-procedure.
do while vhFcComponent <> ?:
vcProc = vhFcComponent:file-name.
if vcProc begins "api/"
or vcProc begins "appinfo/"
or vcProc begins "query/"
or vcProc begins "ref_int/"
or (vcProc begins "ins/" and
not (vhFcComponent:unique-id = viLogUnitTestIgnoreSessionUID))
or (vcProc begins "program" and
not (vcProc begins "program/") and
not (can-do (vcProcList,entry(1,entry(2,vcProc,"/"),"."))))
then do:
vhIP = ?.
vhIP = vhFcComponent:instantiating-procedure no-error.
/* ignore the queries started from the cacher and the componentpool components */
if not (vhIP <> ? and
(vhIP:file-name = "program1/cacher.p" or
vhIP:file-name = "program1/componentpool.p") and
vhFcComponent:file-name begins "query")
then
put stream sLug unformatted
"Error : program not closed properly (" vcProc
(if vhIP = ?
then ""
else ") (started from " + vhIP:file-name)
") (ID=" vhFcComponent:unique-id ")" skip.
end.
vhFcComponent = vhFcComponent:next-sibling.
end.
for each tCompList where tCompList.tiCount > 1:
put stream sLug unformatted
"Error : " tCompList.tcCompName " has " tCompList.tiCount " occurrences in memory." skip.
end.
/* ================================================================= */
/* Report forgotten dynamic queries + datasets + buffers. */
/* ================================================================= */
vhFcComponent = session:first-query.
do while vhFcComponent <> ?:
vcTables = "".
do viFcCount1 = 1 to vhFcComponent:num-buffers:
vhBuffer = ?.
vhBuffer = vhFcComponent:get-buffer-handle(viFcCount1) no-error.
if valid-handle(vhBuffer)
then do:
vcReportedBuffers = vcReportedBuffers + "," + string(vhBuffer).
vcTables = vcTables + "," + vhBuffer:table.
end.
end.
viFcCount4 = vhFcComponent:unique-id.
if vhFcComponent:private-data <> "Persistent"
then do:
vhIP = ?.
vhIP = vhFcComponent:instantiating-procedure no-error.
put stream sLug unformatted
"Error : dynamic query not closed properly (ID="
viFcCount4
(if vhFcComponent:name = ""
or vhFcComponent:name = ?
then ""
else ") (name=" + vhFcComponent:name)
(if vcTables = ""
then ""
else ") (tables=" + substring(vcTables,2,-1,"CHARACTER"))
(if vhIP = ?
then ""
else ") (created from " + vhIP:file-name)
(if vhFcComponent:private-data = ""
or vhFcComponent:private-data = ?
then ""
else ") (private-data=" + vhFcComponent:private-data)
")" skip.
end.
vhFcComponent = vhFcComponent:next-sibling.
end.
vhFcComponent = session:first-dataset.
do while vhFcComponent <> ?:
vcTables = "".
do viFcCount1 = 1 to vhFcComponent:num-buffers:
vhBuffer = ?.
vhBuffer = vhFcComponent:get-buffer-handle(viFcCount1) no-error.
if valid-handle(vhBuffer)
then do:
vcReportedBuffers = vcReportedBuffers
+ "," + string(vhBuffer)
+ "," + string(vhBuffer:table-handle).
vcTables = vcTables + "," + vhBuffer:table.
end.
end.
viFcCount4 = vhFcComponent:unique-id.
if vhFcComponent:private-data <> "Persistent"
then do:
vhIP = ?.
vhIP = vhFcComponent:instantiating-procedure no-error.
put stream sLug unformatted
"Error : dynamic dataset not closed properly (ID="
viFcCount4
(if vhFcComponent:name = ""
or vhFcComponent:name = ?
then ""
else ") (name=" + vhFcComponent:name)
(if vcTables = ""
then ""
else ") (tables=" + substring(vcTables,2,-1,"CHARACTER"))
(if vhIP = ?
then ""
else ") (created from " + vhIP:file-name)
(if vhFcComponent:private-data = ""
or vhFcComponent:private-data = ?
then ""
else ") (private-data=" + vhFcComponent:private-data)
")" skip.
end.
vhFcComponent = vhFcComponent:next-sibling.
end.
vhFcComponent = session:first-buffer.
do while vhFcComponent <> ?:
if vhFcComponent:private-data <> "Persistent"
and not can-do (vcReportedBuffers,string(vhFcComponent))
then do:
vhIP = ?.
vhIP = vhFcComponent:instantiating-procedure no-error.
put stream sLug unformatted
"Error : dynamic "
vhFcComponent:type
" not closed properly (ID="
vhFcComponent:unique-id ") (name="
vhFcComponent:name ""
(if vhIP = ?
then ""
else ") (created from " + vhIP:file-name)
(if vhFcComponent:private-data = ""
or vhFcComponent:private-data = ?
then ""
else ") (private-data=" + vhFcComponent:private-data)
")" skip.
end.
vhFcComponent = vhFcComponent:next-sibling.
end.
/* ================================================================= */
/* Report non-closed connections to other appservers. */
/* ================================================================= */
vhFcComponent = session:first-server.
do while vhFcComponent <> ?:
vhFcQuery = vhFcComponent:first-procedure.
do while vhFcQuery <> ?:
vhIP = ?.
vhIP = vhFcQuery:instantiating-procedure no-error.
put stream sLug unformatted
"Error : procedure "
vhFcQuery:file-name
" is still running on appserver " vhFcComponent:name ""
(if vhIP = ?
then ""
else " (started from " + vhIP:file-name + ")")
skip.
vhFcQuery = vhFcQuery:next-sibling.
end.
vhFcComponent = vhFcComponent:next-sibling.
end.
/* ================================================================= */
/* Report non-closed sockets. */
/* ================================================================= */
vhFcComponent = session:first-server-socket.
do while vhFcComponent <> ?:
vhIP = ?.
vhIP = vhFcComponent:instantiating-procedure no-error.
put stream sLug unformatted
"Error : server-socket is still open (" vhFcComponent:name ""
(if vhIP = ?
then ""
else ") (created from " + vhIP:file-name)
")" skip.
vhFcComponent = vhFcComponent:next-sibling.
end.
vhFcComponent = session:first-socket.
do while vhFcComponent <> ?:
vhIP = ?.
vhIP = vhFcComponent:instantiating-procedure no-error.
put stream sLug unformatted
"Error : socket is still open (" vhFcComponent:name ""
(if vhIP = ?
then ""
else ") (created from " + vhIP:file-name)
")" skip.
vhFcComponent = vhFcComponent:next-sibling.
end.
output stream sLug close.
output stream sLug to value (vcLogUTIntermediateFile) append.
put stream sLug unformatted "ACTIVATE " skip. /* count client-server calls */
for each tCompList by tCompList.tcCompName:
put stream sLug unformatted
"PROCEDURE 0 " tCompList.tcCompName skip.
end.
output stream sLug close.
empty temp-table tCompList.
empty temp-table tBusCompPool.
end.