文章目录
- 第二十二章 调用Callout Library函数 - 使用过程索引进行测试
- 方法 `GetGraph()`
- 使用进程索引进行测试
- 使用进程索引测试新版本的“`inputlibrary.dll`”
第二十二章 调用Callout Library函数 - 使用过程索引进行测试
方法 GetGraph()
Method GetGraph(loopsize As %Integer = 100000) As %Status
{// Get an instance of class GraphData and initialize the system indexset graphlib = ##class(User.GraphData).%New()set sc = graphlib.Init()// call functions from both libraries repeatedly// each library is loaded automatically on first callfor count=1:1:loopsize {set midvalue = graphlib.FormatData(^rawdata(count))set flatdata(count) = graphlib.RefineData(midvalue)}// plot results of the previous loopfor count=1:1:loopsize {set x = graphlib.PlotGraph(flatdata(count),0)set y = graphlib.PlotGraph(flatdata(count),x)set ^graph(x,y) = flatdata(count)}//return after unloading all libraries loaded by $ZF(-6)set status = graphlib.Unload()quit 0
}
User.GraphData
类实例化为graphlib
,并调用Init()
方法初始化系统索引。此处不一定必须调用此方法,因为只需为IRIS
实例中的所有进程初始化一次系统索引。- 第一个循环间接使用
$ZF(-6)
调用每个库中的函数,并且$ZF(-6)
在第一次需要时自动加载每个库。库 inputlibrary.dll 在第一次调用FormatData()
时加载,outputlibrary.dll
在第一次调用RefineData()
时加载。 - 第二个循环从已加载的库
outputlibrary.dll
中调用PlotGraph()
。 - 对
Unload()
的调用间接调用两个库上的$ZF(-4,4)
。
使用进程索引进行测试
如前所述,进程索引表在系统索引表之前被搜索,因此可以在进程内使用它来覆盖系统范围的定义。以下示例创建一个进程索引,用于测试上一节中使用的库之一的新版本。
使用进程索引测试新版本的“inputlibrary.dll
”
// Initialize the system index and generate output from standard libraryset testlib = ##class(User.GraphData).%New()set sc = testlib.Init()set sc = graphgen.GetGraph() // get 100000 data items by defaultmerge testgraph1 = ^graphkill ^graph// create process index and test new library with same instance of testprocset sc = $ZF(-4,4,100) // unload current copy of inputlibset sc = $ZF(-4,8) // delete existing process index, if anyset sc = $ZF(-4,7,100, "c:\testfiles\newinputlibrary.dll") // override system indexset sc = graphgen.GetGraph()merge testgraph2 = ^graph// Now compare testdata1 and testdata2
- 在前三行中,这个测试代码初始化系统索引并生成一个图形,就像前面的例子一样。该图已使用
inputlibrary.dll
的标准版本(由ID
值为100
的系统索引条目标识)绘制,并已保存到testgraph1
。 - 对
$ZF(-4,4)
的调用卸载了inputlibrary.dll
,它在系统索引表中由库ID 100
标识。 - 调用
$ZF(-4,8)
时没有指定库ID
,表示当前进程索引表中的所有条目都将被删除。 - 对
$ZF(-4,7)
的调用向进程索引表添加了一个条目,将100
设置为测试库newinputlibrary.dll
的库ID
。这将覆盖系统索引中该ID的条目。库ID
100
现在指向newinputlibrary.dll
而不是inputlibrary.dll
。 - 再次调用
GetGraph()
,使用User.GraphData
的同一个实例。除了inputlibrary.dll
的标准版本已经卸载之外,什么都没有改变,所以GetGraph()
现在将加载并使用新版本的库。测试然后比较图形testgraph1
和testgraph2
,以验证两个版本产生相同的结果。