Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

24
Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues

Transcript of Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Page 1: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Multiple Generic Agents for XMLaw

Luiz Fernando Rodrigues

Page 2: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Agenda

• XMLaw– Using a XMLaw agent– Developing a XMLaw agent

• Scenario Simulation– Number of Stub agents analysis

• Generic Agents– Commands and Requests– Environment Variables– Stream approach

• Multiple Generic Agents– Example

• Conclusion

Page 3: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Using a XMLaw Agent

Agent Agent

MyAgent Client ClientMyAgent

Agent

Use DirectlyInheritance Delegation

Page 4: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Developing a XMLaw Agent

Agent

send(message : Message)waitForMessage() : MessagewaitForMessage(milisec : long) : Message

LawFacade

informOrganization()enterOrganization()performRole()startScece()enterScene()

Page 5: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Simulating Scenarios

• Agents– Foo– Bar

• Organization– Fubar Organization

• Foo and Bar exchange messages• Stub Agents

– FooStub– BarStub

• Test Agents– Scenario 1

• Executes Foo with BarStub and verifies the expected behavior

– Scenario 2• Executes Bar with FooStub and verifies the expected behavior

Page 6: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Scenario 1 - BarStub

... Message addLawReply = getMediatorFacade().informOrganizationToMediator(lawURL.toString()); String orgExec = addLawReply.getContentValue(MessageContentConstants.KEY_ORGANIZATION_EXECUTION_ID); Message enterOrgReply = getMediatorFacade().enterOrganization(orgExec); Message performRoleReply = getMediatorFacade().performRole(orgExec,"bar"); Message startSceneReply = getMediatorFacade().startScene("game",orgExec); String sceneExec = startSceneReply.getContentValue(MessageContentConstants.KEY_SCENE_EXECUTION_ID); Message enterSceneReply = getMediatorFacade().enterInScene(sceneExec,orgExec,"bar");

Message barStubMsg = new Message(Message.INFORM); barStubMsg.setContentValue(MessageContentConstants.KEY_ORGANIZATION_EXECUTION_ID,orgExec); barStubMsg.setContentValue(MessageContentConstants.KEY_SCENE_EXECUTION_ID,sceneExec); barStubMsg.setContentValue("hello","Hello foo, how bar you?"); barStubMsg.setReceiver(fooId,"bar"); send(barStubMsg,"bar"); Message answer = waitForMessage(); ...

System Interaction

Create, set and send the message

Page 7: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Number of Stub Agents Analysis

• Each agent may need s scenarios to be tested

• Each scenario implies in n-1 Stub Agents

• In a system with n agents, the number of Stub agents is, in the worst case:

n

kksnntsnumStubAge

1

)1(

Where Sk is the number of scenarios for the agent k

• If each agent has only 1 scenario:

nnntsnumStubAge 2

Page 8: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Generic Agents

• Is a XMLaw agent

• Make stub creation easier

• Important Features– Commands and Requests– Environment Variables– Stream approach

Page 9: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Generic Agents - Structural View

CommandResponse

Agent

AbstractCommand

execute()

CommandManager AbstractView

Page 10: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Commands and Requests

• Command– Execute an operation on the agent

• Request– Inform the command to execute– Inform arguments to the command– Example:

• performRole 171 bar• Ask the system to perform the role bar in the organization 171

• Extensions– Developer may create domain specific commands

Page 11: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Environment Variables

• Shared variables• Storage of any string value• Storage of messages

– A message is a set of variables• Example:

– the message barMsg is represented by the set:– barMsg– barMsg.sender– barMsg.senderRole– barMsg.receiver– barMsg.receiverRole– barMsg.performative– barMsg.id– barMsg.protocol

• The content of a variable is identified when the character $ is used before a String

• The variable “last”

Page 12: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

The Stream Approach

InputStream

read()

Agent

CommandManager

CommandManager(in:InputStream,out:OutputStream,ctrl:OutputStream,model:Agent)()

OutputStream

write()

output

control

input

Page 13: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

The Stream Approach

• Input Stream– Receives requests

• Output Stream– Write command responses

• Control Stream– Assert Command– Automated tests

• Several Streams Implementations available– Console– File– Socket– Stub– Composite– Piped

• The GA implementation don’t know the Stream type it is using– Flexibility

Page 14: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

GA example 1 - Command Line

...

GenericAgent agent = new GenericAgent("command line agent"); CommandManager manager = new CommandManager( System.in,

System.out, new StubOutputStream(),agent);

...

• User inputs commands in the command line• User reads responses in the command line• Control Stream is not used• Useful for a first contact with open system• Hard to repeat

Page 15: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

GA example 2– Script File

• User inputs commands in the script file• User reads responses in the output file• Control Stream is not used• Easy to repeat• User must know the commands

... FileInputStream scriptStream = new FileInputStream("script.txt"); FileOutputStream outputStream = new FileOutputStream("output.txt"); GenericAgent agent = new GenericAgent("script agent"); CommandManager manager = new CommandManager( scriptStream,

outputStream, new StubOutputStream(),agent);

...

Page 16: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

GA example 3 – Test Application

Script TestApp CommandManager output

in

out

control

• Test application uses a piped stream• Uses the control stream to assert expected behavior

Page 17: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

GA example 3 - Test Application

... FileInputStream scriptStream = new FileInputStream("script.txt"); PipedInputStream pipeInScript = new PipedInputStream(); PipedOutputStream pipeOutScript = new PipedOutputStream(pipeInScript);

PipedInputStream pipeInCtrl = new PipedInputStream(); PipedOutputStream pipeOutCtrl = new PipedOutputStream(pipeInCtrl);

TestApp app = new TestApp(scriptStream, pipeOutScript, pipeInCtrl);

FileOutputStream outputStream = new FileOutputStream("output.txt"); GenericAgent agent = new GenericAgent("tested agent"); CommandManager manager = new CommandManager( pipeInScript,

outputStream, pipeOutCtrl, agent);

...

Page 18: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Multiple Generic Agents - MuGA

• Single agent approach– Hard to create scenarios– Hard to execute

• Asynchronous execution

• Multiple agent approach– Several agents in a single script– Easy to execute

• Synchronous execution

– Easy to assert behaviors

Page 19: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Multiple Generic Agents

InputStream

read()

ScriptInterpreter

CommandManager

1..*1..*

Page 20: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Script Format

agent1 agent2

#comments

agent1:#requests for agent 1

agent2:#requests for agent 2

agent1:#requests for agent 1

Page 21: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Example – Airport Law

• Four agents– Announcer– Customer– Seller– Bank

• Four scenes– Announcement Scene– Selection Scene– Negotiation Scene– Payment Scene

Page 22: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Example

announcer customer seller bank

announcer:addLaw http://www.les.inf.puc-rio.br/xmlaw/leis/airport-law.xmlset airportOrgId $last.orgExecutionIdenterOrg $airportOrgIdperformRole $airportOrgId announcer

customer:enterOrg $airportOrgIdperformRole $airportOrgId customer

seller:enterOrg $airportOrgIdperformRole $airportOrgId seller

bank:enterOrg $airportOrgIdperformRole $airportOrgId bank

Page 23: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Example (cont)

###################################ANNOUNCEMENT SCENE##################################

customer:startScene $airportOrgId announcementset announcementSceneId $last.sceneExecutionIdenterScene $airportOrgId $announcementSceneId customermsg m1 requestset m1.hello helloset m1.orgExecutionId $airportOrgIdset m1.sceneExecutionId $announcementSceneIdset m1.receiver announcersend $m1

announcer:receive 5 rm1enterScene $airportOrgId $announcementSceneId announcermsg m2 informset m2.services movies;date;foodset m2.orgExecutionId $airportOrgIdset m2.sceneExecutionId $announcementSceneIdset m2.receiver customersend $m2

customer:receive 5 rm2assert $rm2.services movies;date;food

Page 24: Multiple Generic Agents for XMLaw Luiz Fernando Rodrigues.

Laboratório de Engenharia de Software – PUC-Rio

Conclusions

• Instead of:

n

kksnntsnumStubAge

1

)1(

• We have:

n

kksnumScripts

1

• If each agent has only 1 scenario

nnumScripts