第二十二章 调用Callout Library函数 - 使用过程索引进行测试

发布时间:2024年01月13日

第二十二章 调用Callout Library函数 - 使用过程索引进行测试

方法 GetGraph()

Method GetGraph(loopsize As %Integer = 100000) As %Status
{
   // Get an instance of class GraphData and initialize the system index
   set graphlib = ##class(User.GraphData).%New()
   set sc = graphlib.Init()

   // call functions from both libraries repeatedly
   // each library is loaded automatically on first call
   for count=1:1:loopsize {
      set midvalue = graphlib.FormatData(^rawdata(count))
      set flatdata(count) = graphlib.RefineData(midvalue)
   }

   // plot results of the previous loop
   for 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 library
   set testlib = ##class(User.GraphData).%New()
   set sc = testlib.Init()
   set sc = graphgen.GetGraph()   // get 100000 data items by default
   merge testgraph1 = ^graph
   kill ^graph

   // create process index and test new library with same instance of testproc
   set sc = $ZF(-4,4,100)   // unload current copy of inputlib
   set sc = $ZF(-4,8)   // delete existing process index, if any
   set sc = $ZF(-4,7,100, "c:\testfiles\newinputlibrary.dll")  // override system index
   set 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()现在将加载并使用新版本的库。测试然后比较图形testgraph1testgraph2,以验证两个版本产生相同的结果。
文章来源:https://blog.csdn.net/yaoxin521123/article/details/135566839
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。