Skip to content

Commit

Permalink
[sre] Fixing the test for "on MemberLeft".
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 21, 2020
1 parent 7ef38c7 commit befbc5a
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ final event SpaceDestroyed {

}

/** Notifies other members the member with agentID has effectively
/** Notifies the other members that the member with the identifier agentID has effectively
* integrated the holon context.
* The event is fired within the default space of the context in which the new agent entered.
* The joining agent does not receive this event.
Expand Down Expand Up @@ -283,7 +283,7 @@ final event MemberJoined {

}

/** Notifies other members the member with agentID was
/** Notifies the other other members that the member with the identifier agentID was
* excluded (forced to leave) the holon context parentContextID.
* The event is fired within the default space of the context from which the agent was excluded.
* The excluded agent does not receive this event.
Expand Down Expand Up @@ -319,7 +319,7 @@ final event MemberExcluded {

}

/** Notifies other members the member with agentID has left the holon context.
/** Notifies the other members that the member with the identifier agentID has left the holon context.
* The event is fired within the default space of the context from which the agent has left.
* The left agent does not receive this event.
* The source of the event is the parent agent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,52 +47,93 @@ skill DefaultContextInteractionsSkill extends Skill implements DefaultContextInt


def getDefaultContext : AgentContext {
getLife(owner).defaultContext.context
val life = getLife(owner)
assert life !== null
val reference = life.defaultContext
assert reference !== null
val context = reference.context
assert context !== null
return context
}

def getDefaultSpace : EventSpace {
getLife(owner).defaultContext.defaultSpace
val life = getLife(owner)
assert life !== null
val reference = life.defaultContext
assert reference !== null
val ^space = reference.defaultSpace
assert ^space !== null
return ^space
}

def getDefaultAddress : Address {
getLife(owner).defaultContext.addressInDefaultSpace
val life = getLife(owner)
assert life !== null
val reference = life.defaultContext
assert reference !== null
val adr = reference.addressInDefaultSpace
assert adr !== null
return adr
}

def isDefaultContext(context : AgentContext) : boolean {
context.ID.isDefaultContext
assert context !== null
val id = context.ID
assert id !== null
return id.isDefaultContext
}

def isDefaultContext(contextID : UUID) : boolean {
contextID == this.defaultContext.ID
assert contextID !== null
val context = defaultContext
assert context !== null
return contextID == context.ID
}

def isDefaultSpace(^space : Space) : boolean {
^space.spaceID.isDefaultSpace
assert ^space !== null
val id = ^space.spaceID
assert id !== null
return id.isDefaultSpace
}

def isDefaultSpace(^space : SpaceID) : boolean {
^space == this.defaultSpace.spaceID
assert ^space !== null
val dspace = defaultSpace
assert dspace !== null
return ^space == dspace.spaceID
}

def isDefaultSpace(^space : UUID) : boolean {
^space == this.defaultSpace.spaceID.ID
assert ^space !== null
val dspace = defaultSpace
assert dspace !== null
val spaceid = dspace.spaceID
assert spaceid !== null
return ^space == spaceid.ID
}

def isInDefaultSpace(^event : Event) : boolean {
if (^event !== null) {
val adr = ^event.source
if (adr !== null) {
return adr.spaceID.isDefaultSpace
val spaceid = adr.spaceID
assert spaceid !== null
return spaceid.isDefaultSpace
}
}
return false
}

def emit(^event : Event, scope : Scope<Address> = null) {
^event.source = this.defaultAddress
this.defaultSpace.emit(ID, ^event, scope)
assert ^event !== null
^event.source = defaultAddress
val dspace = defaultSpace
assert dspace !== null
dspace.emit(ID, ^event, scope)
}

@Deprecated
def willReceive(receiver : UUID, ^event : Event) {
^event.emit [it.UUID == receiver]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ package io.sarl.sre.tests.runtime.internal
import io.sarl.sre.test.framework.context.SreRunContext
import io.sarl.sre.test.framework.^extension.PropertyRestoreExtension
import io.sarl.sre.test.framework.^extension.SreRunExtension
import io.sarl.sre.tests.runtime.internal.mocks.RootAgent1
import io.sarl.sre.tests.runtime.internal.mocks.Bye
import io.sarl.sre.tests.runtime.internal.mocks.MemberLeftAgent0
import io.sarl.sre.tests.runtime.internal.mocks.MemberLeftAgent1
import io.sarl.tests.api.extensions.ContextInitExtension
import io.sarl.tests.api.extensions.JavaVersionCheckExtension
import java.util.UUID
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.RepeatedTest
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.^extension.ExtendWith

import static io.sarl.tests.api.tools.TestAssertions.*
import org.junit.jupiter.api.Disabled
import static io.sarl.sre.test.framework.Constants.*

import static extension io.sarl.sre.tests.framework.SreTestUtilities.*
import static extension io.sarl.tests.api.tools.TestAssertions.*
import static extension org.junit.jupiter.api.Assertions.*

/**
* @author $Author: sgalland$
Expand All @@ -51,11 +57,74 @@ import org.junit.jupiter.api.Disabled
@Tag("run")
class OnMemberLeftTest {

@RepeatedTest(5)
@DisplayName("run")
def run(extension rc : SreRunContext) {
typeof(RootAgent1).runSre
assertContains(allResults, "ROOT:ChildAgent1", "ROOT:Child2Agent1", "CHILD1:Child2Agent1")
@RepeatedTest(10)
@DisplayName("In default context")
def inDefaultContext(extension rc : SreRunContext) {
var kern = setupTheSreKernel(null, null)

val id0 = UUID::randomUUID
waitForAgentSpawned(id0) [
kern.startAgentWithID(typeof(MemberLeftAgent0), id0, buildAgentInitializationParameters(1))
]

val id1 = UUID::randomUUID
waitForAgentSpawned(id1) [
kern.startAgentWithID(typeof(MemberLeftAgent0), id1, buildAgentInitializationParameters(2))
]

val id2 = UUID::randomUUID
waitForAgentSpawned(id2) [
kern.startAgentWithID(typeof(MemberLeftAgent0), id2, buildAgentInitializationParameters(3))
]

rootContext.defaultSpace.emit(UUID::randomUUID, new Bye)

waitForTheKernel(STANDARD_TIMEOUT)

// There is no context joint for the default context.
// Consequently, no ContextJoined event is fired
allResults.assertContains()
}

@RepeatedTest(10)
@DisplayName("In other context")
def inOtherContext(extension rc : SreRunContext) {
var kern = setupTheSreKernel(null, null)

val id0 = UUID::randomUUID
waitForAgentSpawned(id0) [
kern.startAgentWithID(typeof(MemberLeftAgent1), id0, buildAgentInitializationParameters(1, null))
]

val innerContext = rc.getInnerContextForAgent(id0)
innerContext.assertNotNull

val id1 = UUID::randomUUID
waitForAgentSpawned(id1) [
kern.startAgentWithID(typeof(MemberLeftAgent1), id1, buildAgentInitializationParameters(2, innerContext))
]

val id2 = UUID::randomUUID
waitForAgentSpawned(id2) [
kern.startAgentWithID(typeof(MemberLeftAgent1), id2, buildAgentInitializationParameters(3, innerContext))
]

// Kill the inner agents, first
waitForAgentKilled(#[id1, id2]) [
innerContext.defaultSpace.emit(UUID::randomUUID, new Bye)[it.UUID != id0]
]

// Kill the containing agent, second
rootContext.defaultSpace.emit(UUID::randomUUID, new Bye)

waitForTheKernel(STANDARD_TIMEOUT)

allResults.assertContains(
"AG1: joined MemberLeftAgent1 " + id1 + " in default space",
"AG1: joined MemberLeftAgent1 " + id1 + " in inner space",
"AG1: joined MemberLeftAgent1 " + id2 + " in default space",
"AG1: joined MemberLeftAgent1 " + id2 + " in inner space"
)
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

package io.sarl.sre.tests.runtime.internal.mocks

import io.sarl.core.Behaviors
import io.sarl.core.DefaultContextInteractions
import io.sarl.core.Initialize
import io.sarl.core.InnerContextAccess
import io.sarl.core.Lifecycle
import io.sarl.core.MemberJoined
import io.sarl.core.OpenEventSpace
import io.sarl.sre.test.framework.skills.TestingCapacity
import io.sarl.sre.test.framework.skills.TestingSkill

import static extension io.sarl.tests.api.tools.TestUtils.*
import io.sarl.core.OpenEventSpace
import io.sarl.core.Behaviors

/**
* @author $Author: sgalland$
Expand Down
Loading

0 comments on commit befbc5a

Please sign in to comment.