• 沒有找到結果。

Resource manager

在文檔中 Agent Agent (頁 32-39)

Agent 1 . Send data to User(Include waiting user response)

3.4 Resource manager

According

Figure 3.11 A general mechanism of weaving test framework to WfMS

Figure 3.10 裡紅色的小長方形是根據 WfMS Pointcut Definition 定義所產 生,而這些執行時間點要運作的內容可能是 Execution-Collector、Agent、

Resource Manager、Validation Tool 等,我們所提出的測試平台上所有原件都 是透過此份定義所描述的時間點來與系統合作。 證這類的原件。Resource Manager 的功用就是協助開發者免於憂心實體物件在 資料庫的值是否與開發者預想的邏輯運作方式相反,以及協助開發者模擬實際資 源使用狀況,進而達到協助預期 workflow 對於實體資源使用的最大負載。

47

Resource Pool

Resource Instance Resource Manager

Figure 3.12 Resource Manager

為了提供測試時更大彈性的功能,Resource Manager 是由以下元件組成 (Figure 3.12):

1. Resource Manager:資源管理系統,本身需要控管所有由 TS-WfMS 中所 描述的實體資源,並且接收 Agent 傳來的要求,進而根據 TS-WfMS 上所 撰寫的 Rule 運行。

2. Resource Pool:對於 TS-WfMS 上所描述的各種不同實體資源,都要有他 們專屬的 Resource Pool,一個 pool 控制一種資源類別,如電子公文系 統內的交通車可能有很多種不同品牌的汽車,但是他們都是歸屬於同一 Resource Pool 所控管、模擬。

3. Resource Instance:每一個 Resource Pool 針對他們的所屬資源,全 部都必須產生一個專有的物件來模擬該實體資源真實的情況。

Resource Manager 的控制內容必須要夠彈性,以及要能兼具足夠多的功能,

才能簡易的讓開發者使用,因此 Resource manager 有三種可行的選擇可供使用 如下:

1. Script:這個實作方法是經由開發者在 TS-WfMS 中明確的表示 type =

“Script”,並寫入由我們所訂立的 Script Syntax,讓系統發展者藉

48

由撰寫簡易的 Script 來與測試系統溝通。

2. Source:除了 Script 外,也可以進一步的根據不同的程式語言,提供一 個共通介面讓他們實作,接著動態編譯程式碼,最後再呼叫使用,這個 做法可以讓開發者使用他們擅長的程式語言,撰寫相對應的模擬操作行 為,讓測試過程更加依照開發者的需求而改變。此類的方法需在 TS-WfMS 中相對應的地方使用 type = “Source”來指定。Table 3.27, Table 3.28 分別是 Spontaneous 和 Compulsory 的 Source 類型實作。

Table 3.27 SpontaneousAction Interface (implements in JAVA)

package tw.edu.ntnu.csie.iclab.ResourceManager;

import java.util.List;

import

tw.edu.ntnu.csie.iclab.ResourceManager.ResourcePool.ResourceIn stance;

public interface SpontaneousAction {

public Message action(String orig, String target, String workingAct, String workingFlow, List<ResourceInstance> resList);

}

Table 3.28 CompulsoryAction Interface (implements in JAVA)

package tw.edu.ntnu.csie.iclab.ResourceManager;

import java.util.List;

public interface CompulsoryAction {

public Message action(List<ResourcePoolInterface> poolList, String currentFlowName, String currentActName);

}

JAVA 因為有 JVM 中介動態的找尋 class 來執行,因此我們只需要保證先 動態編譯完後再使用此 class 即可,若是使用其他語言來實作則有些不 同點,如 C++可能需要透過將這個 class 編譯成 Dynamic Linking

49

Library 才能達到這樣的目的。

3. IOC:我們可以利用 IOC 的觀念將系統發展者的自定義行為藉由程式語言 的實作進一步的將其視為是一個 bean,而在執行期間動態將其呼叫使用。

此類的方法需在 TS-WfMS 中相對應的地方使用 type = “IOC”來指定。

IOC 的實作有部分需要使用 SOURCE 的方法,因為 IOC 本身不負責編譯 Source 檔案。

Agent

TS-WfMS

WfMS

1.

WfMS send data to agent

3

.Agent invoke Resource Manager According to TS-WfMS

Compulsory Action

2

.Read data form TS-WfMS

Spontaneous Action

4.

According to Resource tag

Figure 3.13 Resource Manager operation flow

簡介完 Resource Manager 的組成後,接下來簡介 Resource Manager 的運作 流程(Figure 3.13),首先由 WfMS 系統發出資訊,Agent 接收到此資訊後由 TS-WfMS 內讀取現正執行的 Activity 的資訊,接下來依照系統發展者的描述對 Resource Manager 執行 Compulsory Action(強制性動作),而在運作過程中 Resource Manager 會依照 TS-WfMS 裡的 Resource 標籤內敘述的 Spontaneous 行為運作,最 後即完成 Resource Manager 的運作流程。

我們用前述的範例,在 Figure 3.2 裡面的 A4 這個 Activity 的設定檔為例 如 Table 3.29 所示,<ParticipantAction>標籤下面有三個子標籤,他們分別也

50

有填入設定的資訊,而在這個 Activity 中,他的工作是對於顧客選定的汽車在 資料庫中的狀態做更改,因此我們可以在 before.java 寫下檢驗該車是否可以租 借 , around.java 寫 下 改 變 該 台 車 在 Resource Manager 中 的 狀 態 登 記 , After.java 中寫下驗證是否資料庫中的狀態真的已經改變,他們的程式碼大略如 下中的 Table 3.30, Table 3.31, Table 3.32 所示,藉由 Table 3.28 的介面,

開發者可以動態獲得 Resource Manager 中的所有資訊,並可在其內任意的執行 他所想要的運作,如等待資源改變狀態,或是一直存取資源,或是對於實體的資 料庫資源做確認等,開發者能夠完善的執行有關資源的所有測試或是模擬,不需 要更改 WfMS 中任何的程式碼,有效的偵測任何問題點的產生原因。

Table 3.29 Figure 3.2 中 A3 在 TS-WfMS 裡有關於 Resource manger 的範 例

<flow name="RentCar">

<Activity name="deal">

<Page seq="1">

<Presentation>

</Presentation>

<ParticipantInput>

</ParticipantInput>

<ParticipantAction type="Source">

<Before>

<SourceCode path="D:\ActionCode"

package="tw.edu.ntnu.csie.iclab.ResourceManager.Test"

classpath="D:\workspace3.2\ReachabilityTesting\src;D:\workspace3.

2\ReachabilityTesting\lib\spring\lib\jakarta-commons\commons-logg ing.jar"

bindir="D:\workspace3.2\ReachabilityTesting\bin">before.java

</SourceCode>

</Before>

<Around>

<SourceCode path="D:\ActionCode"

package="tw.edu.ntnu.csie.iclab.ResourceManager.Test"

classpath="D:\workspace3.2\ReachabilityTesting\src;D:\workspace3.

2\ReachabilityTesting\lib\spring\lib\jakarta-commons\commons-logg ing.jar"

51

bindir="D:\workspace3.2\ReachabilityTesting\bin">around.java

</SourceCode>

</Around>

<After>

<SourceCode path="D:\ActionCode"

package="tw.edu.ntnu.csie.iclab.ResourceManager.Test"

classpath="D:\workspace3.2\ReachabilityTesting\src;D:\workspace3.

2\ReachabilityTesting\lib\spring\lib\jakarta-commons\commons-logg ing.jar"

bindir="D:\workspace3.2\ReachabilityTesting\bin">after.java

</SourceCode>

</After>

</ParticipantAction>

</Page>

</Activity>

</flow>

Table 3.30 Table 3.29 裡 before 標籤的內容實作範例

package tw.edu.ntnu.csie.iclab.ResourceManager.Test;

import java.util.List;

import tw.edu.ntnu.csie.iclab.ResourceManager.CompulsoryAction;

import tw.edu.ntnu.csie.iclab.ResourceManager.Message;

import tw.edu.ntnu.csie.iclab.ResourceManager.ResourcePoolInterface;

public class before implements CompulsoryAction{

public Message action(List<ResourcePoolInterface> poolList, String currentFlowName, String currentActName) {

// write code of connecting to database and check the car state in database // return message according to the state of this resource in database

return new Message(false, "RENT FALSE");

} }

Table 3.31 Table 3.29 裡 around 標籤的內容實作範例

52

package tw.edu.ntnu.csie.iclab.ResourceManager.Test;

import java.util.List;

import tw.edu.ntnu.csie.iclab.ResourceManager.CompulsoryAction;

import tw.edu.ntnu.csie.iclab.ResourceManager.Message;

import tw.edu.ntnu.csie.iclab.ResourceManager.ResourcePoolInterface;

public class around implements CompulsoryAction{

public Message action(List<ResourcePoolInterface> poolList, String currentFlowName, String currentActName) {

for( ResourcePoolInterface respi : poolList ){

if( respi.getResourceName().equalsIgnoreCase("B.M.W") ){

return respi.stateChange("IDLE", "BUSY", 2, currentActName, currentFlowName);

} }

return new Message(false, "RENT FALSE");

} }

Table 3.32 Table 3.29 裡 after 標籤的內容實作範例

package tw.edu.ntnu.csie.iclab.ResourceManager.Test;

import java.util.List;

import tw.edu.ntnu.csie.iclab.ResourceManager.CompulsoryAction;

import tw.edu.ntnu.csie.iclab.ResourceManager.Message;

import tw.edu.ntnu.csie.iclab.ResourceManager.ResourcePoolInterface;

public class after implements CompulsoryAction{

public Message action(List<ResourcePoolInterface> poolList, String currentFlowName, String currentActName) {

// write code of connecting to database and check the car state in database // return message according to the state of this resource in database

return new Message(false, "RENT FALSE");

} }

53

Resource Manager 的運作需要仰賴與 Agent 間的搭配方能達到成果,有效 的運用 Resource Manager 所提供的功能將可進一步的對實體資源或抽象資源做 有效的監控以及模擬,提供測試平台對於偵測錯誤發生點以及判斷錯誤類型上有 更為完善的功能。

在文檔中 Agent Agent (頁 32-39)

相關文件