diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl index 4cd59576b2..56441176bf 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl @@ -126,7 +126,7 @@ agent HelloChildAgent extends AbstractAgent{ } on AgentSpawned { - info("AgentSpawned, agentID:" + occurrence.agentIdentifiers + " AgentType: " + occurrence.agentType) + info("AgentSpawned, agentID:" + occurrence.agentID + " AgentType: " + occurrence.agentType) } on AgentKilled { diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-holarchy/src/main/sarl/io/sarl/demos/basic/holarchy/holarchy.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-holarchy/src/main/sarl/io/sarl/demos/basic/holarchy/holarchy.sarl index e542d74539..9895d700a8 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-holarchy/src/main/sarl/io/sarl/demos/basic/holarchy/holarchy.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-holarchy/src/main/sarl/io/sarl/demos/basic/holarchy/holarchy.sarl @@ -46,8 +46,8 @@ agent HolarchyManager { uses Lifecycle, Schedules, DefaultContextInteractions, Logging on Initialize { - /* Spawn a first holon that will in turn spawn a whole hierarchy of holons - */ + /* Spawn a first holon that will in turn spawn a whole hierarchy of holons + */ spawn(Holon, #[]) } @@ -96,12 +96,14 @@ agent Holon { info("Create the child #" + i + " at level " + count) /* spawn a new sub-holon (a holon inside his own internal context) */ - childUIDs.add(spawnInContext(Holon, innerContext, count, i)) + val aid = UUID::randomUUID + spawnInContextWithID(Holon, aid, innerContext, count, i) + childUIDs.add(aid) } /* check every seconds if he's himself the last remaining holon as member of its internal context event space - * in this case, its means that all of its members are dead, he can thus die peacefully - * TEMPORAL APPROACH TO DESTROY THE HOLARCHY not the best one, it is better to rely on event to manage the holarchy destruction see the Memberleft on clause + * in this case, its means that all of its members are dead, he can thus die peacefully + * TEMPORAL APPROACH TO DESTROY THE HOLARCHY not the best one, it is better to rely on event to manage the holarchy destruction see the Memberleft on clause * */ // task("toto").every(1000) [ // if (innerContext.defaultSpace.participants.size == 1) { diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-boids-awt/src/main/sarl/io/sarl/demos/boids/BoidsSimulation.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-boids-awt/src/main/sarl/io/sarl/demos/boids/BoidsSimulation.sarl index fc7e43be71..a80869b820 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-boids-awt/src/main/sarl/io/sarl/demos/boids/BoidsSimulation.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-boids-awt/src/main/sarl/io/sarl/demos/boids/BoidsSimulation.sarl @@ -132,7 +132,8 @@ class BoidsSimulation implements EventListener { defaultSARLContext = kernel.startWithoutAgent - environment = kernel.startAgent(typeof(Environment), height, width) + environment = UUID::randomUUID + kernel.startAgentWithID(typeof(Environment), environment, height, width) launchAllBoids ^space = defaultSARLContext.defaultSpace as OpenEventSpace @@ -160,7 +161,8 @@ class BoidsSimulation implements EventListener { var initialPosition = new Vector2d((Math::random - 0.5) * width, (Math::random - 0.5) * height) var initialVitesse = new Vector2d(Math::random - 0.5, Math::random - 0.5) - var b = kernel.startAgent(typeof(Boid), environment, p, initialPosition, initialVitesse, boidName) + var b = UUID::randomUUID + kernel.startAgentWithID(typeof(Boid), b, environment, p, initialPosition, initialVitesse, boidName) this.boidBodies.put(b, new PerceivedBoidBody(p, b, initialPosition, initialVitesse)) if (Settings::isLogActivated) { diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/src/main/sarl/io/sarl/demos/fireworks/gui/FireworksFxViewerController.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/src/main/sarl/io/sarl/demos/fireworks/gui/FireworksFxViewerController.sarl index 7fcc0cfb49..e34c7bae90 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/src/main/sarl/io/sarl/demos/fireworks/gui/FireworksFxViewerController.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/src/main/sarl/io/sarl/demos/fireworks/gui/FireworksFxViewerController.sarl @@ -109,7 +109,8 @@ class FireworksFxViewerController extends FxViewerController { var ^event = new SetupSettings(this.rocketQuantity, this.fireQuantity, this.gravity, this.draw_zone.width) if (!this.launched) { - this.launchedAgent = startAgentApplication(typeof(LaunchingArea)) [ + this.launchedAgent = UUID::randomUUID + startAgentApplication(typeof(LaunchingArea), this.launchedAgent) [ ^event.emitToAgents ] this.launch_button.disable = false diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-gameoflife/src/main/sarl/io/sarl/demos/gameoflife/game/DefaultGridManagerSkill.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-gameoflife/src/main/sarl/io/sarl/demos/gameoflife/game/DefaultGridManagerSkill.sarl index 36952a8826..0cb247a5a4 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-gameoflife/src/main/sarl/io/sarl/demos/gameoflife/game/DefaultGridManagerSkill.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-gameoflife/src/main/sarl/io/sarl/demos/gameoflife/game/DefaultGridManagerSkill.sarl @@ -21,6 +21,7 @@ package io.sarl.demos.gameoflife.game +import io.sarl.core.DefaultContextInteractions import io.sarl.core.Lifecycle import io.sarl.core.Logging import java.util.List @@ -39,7 +40,7 @@ import org.arakhne.afc.vmutil.locale.Locale */ skill DefaultGridManagerSkill implements GridManager { - uses Lifecycle, Logging + uses Lifecycle, Logging, DefaultContextInteractions val listeners = newArrayList @@ -73,7 +74,8 @@ skill DefaultGridManagerSkill implements GridManager { for (j : 0 ..< height) { // FIXME: agents created 2 times ? // FIXME: double agent spawning apparently come from: https://github.com/sarl/sarl/issues/525 - val uuid = CellAgent.spawn + val uuid = UUID::randomUUID + CellAgent.spawnInContextWithID(uuid, defaultContext) grid.set(i, j, Pair.of(uuid, false)) diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-templates-javafx/src/main/sarl/io/sarl/template/javafx/ui/MyAppFxViewerController.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-templates-javafx/src/main/sarl/io/sarl/template/javafx/ui/MyAppFxViewerController.sarl index 5c3ae704fe..5f3888541e 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-templates-javafx/src/main/sarl/io/sarl/template/javafx/ui/MyAppFxViewerController.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-templates-javafx/src/main/sarl/io/sarl/template/javafx/ui/MyAppFxViewerController.sarl @@ -20,8 +20,9 @@ class MyAppFxViewerController extends FxViewerController { def initialize { // Launching of the agent-side of the application if (!this.launched.getAndSet(true)) { - // First launch => start the agent framework with an agent of type MyAgent. - this.launchedAgent = startAgentApplication(typeof(MyAgent)) [ + // First launch => start the agent framework with an agent of type MyAgent and the computed id. + val id = UUID::randomUUID + startAgentApplication(typeof(MyAgent), id) [ // TODO: Put any action that must be done after the first agent launching ] } diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java b/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java index 5b2cb930b8..4ed4670ba8 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java +++ b/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java @@ -33,7 +33,7 @@ import static io.sarl.examples.tests.ExamplesTestUtils.isMavenProject; import static io.sarl.examples.tests.ExamplesTestUtils.readExtensionPointFromXml; import static io.sarl.examples.tests.ExamplesTestUtils.readXmlNode; -import static io.sarl.examples.tests.ExamplesTestUtils.unpackFiles; +import static io.sarl.examples.tests.ExamplesTestUtils.*; import static io.sarl.examples.tests.ExamplesTestUtils.assertFile; import static io.sarl.examples.wizard.SarlExampleLaunchConfiguration.LAUNCH_PROPERTY_FILE; import static io.sarl.examples.wizard.SarlExampleLaunchConfiguration.readLaunchConfigurationFromXml; @@ -43,8 +43,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static io.sarl.tests.api.tools.TestUtils.*; import java.io.File; +import java.io.IOException; import java.util.List; import java.util.stream.Stream; @@ -55,11 +57,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; +import org.opentest4j.TestAbortedException; import org.w3c.dom.Document; import org.w3c.dom.Node; import io.sarl.lang.compiler.batch.SarlBatchCompiler; import io.sarl.lang.util.OutParameter; +import io.sarl.tests.api.tools.TestUtils; /** Class for testing the examples. * @@ -72,6 +76,21 @@ @DisplayName("Testing all the SARL examples") public class ExamplesTest { + private static List installFiles(ExampleDescription example, File projectRoot, boolean skipIfInvalidPom) throws Exception { + // The behavior is different in Eclipse Junit and Maven surefire. + final List installedFiles; + if (isEclipseRuntimeEnvironment()) { + if (skipIfInvalidPom && isMavenProject(example.sourceFolder)) { + // Pom file is not valid because Maven has not yet applied the macro replacements into the file. + throw new TestAbortedException(); + } + installedFiles = copySourceFiles(projectRoot, example.sourceFolder); + } else { + installedFiles = unpackFiles(projectRoot, example.archive); + } + return installedFiles; + } + /** Replies the dynamics tests for the examples' paths. * * @return the dynamic tests. @@ -91,11 +110,11 @@ public Stream path() throws Exception { * @throws Exception in case of error for recovering the example descriptions. */ @TestFactory - @DisplayName("SARL Compilation") + @DisplayName("SARL compilation of archives") public Stream compilation() throws Exception { return dynamicTests(example -> { - final File projectRoot = createProject(); - final List installedFiles = unpackFiles(projectRoot, example.archive); + final File projectRoot = createProject(); + final List installedFiles = installFiles(example, projectRoot, true); assertFalse(installedFiles.isEmpty(), () -> "No installed file in " + projectRoot); if (isMavenProject(example.sourceFolder)) { // Maven compilation @@ -119,7 +138,7 @@ public Stream compilation() throws Exception { public Stream launchConfiguration() throws Exception { return dynamicTests(example -> { final File projectRoot = createProject(); - final List installedFiles = unpackFiles(projectRoot, example.archive); + final List installedFiles = installFiles(example, projectRoot, true); final File launchConfiguration = new File(projectRoot, LAUNCH_PROPERTY_FILE); assumeTrue(launchConfiguration.exists()); @@ -159,7 +178,7 @@ public Stream launchConfiguration() throws Exception { public Stream fileToOpenInEditor() throws Exception { return dynamicTests(example -> { final File projectRoot = createProject(); - final List installedFiles = unpackFiles(projectRoot, example.archive); + final List installedFiles = installFiles(example, projectRoot, false); final File pluginFile = new File(DEFAULT_RELATIVE_PATH, "plugin.xml"); final Document document = readXmlContent(pluginFile); Node node = readXmlNode(document, "plugin"); diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTestUtils.java b/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTestUtils.java index e7c06d6d3a..341f0f7497 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTestUtils.java +++ b/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTestUtils.java @@ -415,6 +415,58 @@ public static List unpackFiles(File root, File exampleZipFile) throws Exce return installedFiles; } + /** Copy the files from the given source folder into the root folder. + * + * @param root the root folder. + * @param sourceFolder the folder to copy. + * @return the list of extracted files. + * @throws Exception if cannot unpack. + * @since 0.11 + */ + public static List copySourceFiles(File root, File sourceFolder) throws Exception { + List folders = new ArrayList<>(); + if (sourceFolder.isDirectory()) { + final File absSourceFolder = sourceFolder.getAbsoluteFile().getCanonicalFile(); + folders.add(sourceFolder); + while (!folders.isEmpty()) { + final File folder = folders.remove(0); + for (final File file : folder.listFiles()) { + if (file.isDirectory()) { + folders.add(file); + } else if (file.isFile()) { + if (!isIgnorableFile(file)) { + final File absFile = file.getAbsoluteFile().getCanonicalFile(); + final File relPathFile = FileSystem.makeRelative(absFile, absSourceFolder); + final File targetFile = FileSystem.join(root, relPathFile); + targetFile.getParentFile().mkdirs(); + FileSystem.copy(file, targetFile); + } + } + } + } + } + + final List installedFiles = new ArrayList<>(); + folders = new ArrayList<>(); + folders.add(root); + while (!folders.isEmpty()) { + final File folder = folders.remove(0); + for (final File file : folder.listFiles()) { + if (file.isDirectory()) { + folders.add(file); + } else if (file.isFile()) { + if (!isIgnorableFile(file)) { + final File relPathFile = FileSystem.makeRelative(file, root); + installedFiles.add(relPathFile); + } else { + file.delete(); + } + } + } + } + return installedFiles; + } + private static boolean isIgnorableFile(File file) { final String name = file.getName(); return ".classpath".equals(name) || ".project".equals(name); diff --git a/main/externalmaven/io.sarl.javafx/src/main/sarl/io/sarl/javafx/FxViewerController.sarl b/main/externalmaven/io.sarl.javafx/src/main/sarl/io/sarl/javafx/FxViewerController.sarl index c4b3b1b485..04515a184d 100644 --- a/main/externalmaven/io.sarl.javafx/src/main/sarl/io/sarl/javafx/FxViewerController.sarl +++ b/main/externalmaven/io.sarl.javafx/src/main/sarl/io/sarl/javafx/FxViewerController.sarl @@ -101,12 +101,13 @@ abstract class FxViewerController implements EventListener { } /** Start the agent application. - * + * * @param agentType the type of the agent to launch. + * @param agentID is the identifier of the agent. * @param whenAgentLaunched the lambda that is called when the agent is really launched. + * @since 0.11 */ - def startAgentApplication(agentType : Class, - whenAgentLaunched : () => void) { + def startAgentApplication(agentType : Class, agentID : UUID = null, whenAgentLaunched : ()=>void) { var bootstrap = SRE::bootstrap if (!bootstrap.active) { throw new IllegalStateException(Messages::FxViewerController_0) @@ -115,11 +116,15 @@ abstract class FxViewerController implements EventListener { this.globalSpace = context.defaultSpace as OpenEventSpace this.UISpace = context.createSpace(typeof(OpenEventSpaceSpecification), ID) new LaunchingCallback(ID, this.globalSpace, whenAgentLaunched) - bootstrap.startAgent(agentType, this) + if (agentID !== null) { + bootstrap.startAgentWithID(agentType, agentID, this) + } else { + bootstrap.startAgent(agentType, this) + } } /** Catch exit event from JavaFX. Stop the agents and the JavaFX user interface. - * + * * @param event the JavaFx event that is the source of the exit. */ @FXML diff --git a/pom.xml b/pom.xml index 96fb2610b9..4cb5622298 100644 --- a/pom.xml +++ b/pom.xml @@ -24,29 +24,24 @@ - + 1.8 JavaSE-${sarl-dsl.min.jdk.version} 1.8 1.9 - + 1.8 JavaSE-${sarl-run.min.jdk.version} 11 12 - + 1.8 JavaSE-${user.min.jdk.version} 11 @@ -808,6 +803,25 @@ ${junit5.version} + + + false + true + true + true + + + false + + + false + true + true + + @@ -1372,26 +1386,12 @@ - - + + diff --git a/products/sarldoc/src/test/java/io/sarl/sarldoc/tests/MainTest.java b/products/sarldoc/src/test/java/io/sarl/sarldoc/tests/MainTest.java index 237b7c663a..b109a7ac4e 100644 --- a/products/sarldoc/src/test/java/io/sarl/sarldoc/tests/MainTest.java +++ b/products/sarldoc/src/test/java/io/sarl/sarldoc/tests/MainTest.java @@ -238,8 +238,8 @@ public void generateTest1() throws IOException { final int retcode = Main.run( "--encoding", "UTF-8", - "--javasource", SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT, - "--javacompiler", JavaCompiler.JAVAC.name(), + "--java-source", SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT, + "--java-compiler", JavaCompiler.JAVAC.name(), "--tempdir", this.tempFolder.getAbsolutePath(), "--directory", this.genFolder.getAbsolutePath(), "--outputdir", this.binFolder.getAbsolutePath(), @@ -280,8 +280,8 @@ public void fakeTest1() throws IOException { final int retcode = Main.run( "--fake", "--encoding", "UTF-8", - "--javasource", SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT, - "--javacompiler", JavaCompiler.JAVAC.name(), + "--java-source", SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT, + "--java-compiler", JavaCompiler.JAVAC.name(), "--tempdir", this.tempFolder.getAbsolutePath(), "--directory", this.genFolder.getAbsolutePath(), "--outputdir", this.binFolder.getAbsolutePath(), diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/BootstrapTest.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/BootstrapTest.sarl index 0fb95b432d..2641f3eeb9 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/BootstrapTest.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/BootstrapTest.sarl @@ -27,6 +27,7 @@ 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.boot.bootstrap.mocks.BootAgent1 +import io.sarl.sre.tests.runtime.boot.bootstrap.mocks.TestIdAgent0 import io.sarl.tests.api.Nullable import io.sarl.tests.api.extensions.ContextInitExtension import io.sarl.tests.api.extensions.JavaVersionCheckExtension @@ -38,7 +39,8 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.junit.jupiter.api.^extension.ExtendWith -import static org.junit.jupiter.api.Assertions.* +import static extension org.junit.jupiter.api.Assertions.* +import static io.sarl.sre.test.framework.Constants.* /** * @author $Author: sgalland$ @@ -69,6 +71,7 @@ class BootstrapTest { } @Test + @DisplayName("Default context ID") def defaultContextUUID(extension rc : SreRunContext) { System::setProperty(VariableNames::toPropertyName(BootConfig::ROOT_CONTEXT_BOOT_TYPE_NAME), RootContextType::^default.name) @@ -79,6 +82,7 @@ class BootstrapTest { } @Test + @DisplayName("Name-based context ID") def bootContextUUID(extension rc : SreRunContext) { System::setProperty(VariableNames::toPropertyName(BootConfig::ROOT_CONTEXT_BOOT_TYPE_NAME), RootContextType::BOOT_AGENT_NAME.name) @@ -90,6 +94,7 @@ class BootstrapTest { } @Test + @DisplayName("Random context ID") def randomContextUUID(extension rc : SreRunContext) { System::setProperty(VariableNames::toPropertyName(BootConfig::ROOT_CONTEXT_BOOT_TYPE_NAME), RootContextType::RANDOM.name) @@ -100,4 +105,17 @@ class BootstrapTest { assertNotEquals(bootID, id) } + @Test + @DisplayName("startAgentWithID(Class, UUID)") + def startAgentWithID(extension rc : SreRunContext) { + val kern = setupTheSreKernel(null, null) + val id = UUID::randomUUID + kern.startAgentWithID(typeof(TestIdAgent0), id, agentInitializationParameters) + waitForTheKernel(SHORT_TIMEOUT) + + var actual = getFirstResultOfType(id, typeof(UUID)) + actual.assertNotNull + id.assertEquals(actual) + } + } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/mocks/TestIdAgent0.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/mocks/TestIdAgent0.sarl new file mode 100644 index 0000000000..c2024cdb2c --- /dev/null +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/boot/bootstrap/mocks/TestIdAgent0.sarl @@ -0,0 +1,44 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2020 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.sre.tests.runtime.boot.bootstrap.mocks + +import io.sarl.core.Initialize +import io.sarl.sre.test.framework.skills.TestingCapacity +import io.sarl.sre.test.framework.skills.TestingSkill + +/** + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +agent TestIdAgent0 { + + uses TestingCapacity + + on Initialize { + setSkill(new TestingSkill(occurrence)) + addResult(ID) + killMeSoon + } + +} diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent0.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent0.sarl index 83623eb67a..62ffec6e82 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent0.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent0.sarl @@ -42,7 +42,7 @@ agent MyAgent0 { on Initialize { setSkill(new TestingSkill(occurrence)) addResult("AGENT") - new MyBehavior0(this, modifiableResults).registerBehavior + new MyBehavior0(this).registerBehavior killMe } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent1.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent1.sarl index a4cf893e4a..04f4bf8efe 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent1.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyAgent1.sarl @@ -42,7 +42,7 @@ agent MyAgent1 { on Initialize { setSkill(new TestingSkill(occurrence)) - new MyBehavior1(this, modifiableResults).registerBehavior + new MyBehavior1(this).registerBehavior killMe } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior0.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior0.sarl index 3ca9078c8a..47069cf294 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior0.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior0.sarl @@ -22,8 +22,7 @@ package io.sarl.sre.tests.runtime.internal.mocks import io.sarl.core.Initialize -import io.sarl.lang.core.Agent -import java.util.List +import io.sarl.sre.test.framework.skills.TestingCapacity /** * @author $Author: sgalland$ @@ -33,17 +32,10 @@ import java.util.List */ behavior MyBehavior0 { - val results : List + uses TestingCapacity - new (^agent : Agent, results : List) { - super(^agent) - this.results = results - } - on Initialize { - synchronized (this.results) { - this.results.add("BEHAVIOR") - } + addResult("BEHAVIOR") } } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior1.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior1.sarl index 07ee27a88e..405a4fa8d4 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior1.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/mocks/MyBehavior1.sarl @@ -22,8 +22,7 @@ package io.sarl.sre.tests.runtime.internal.mocks import io.sarl.core.Destroy -import io.sarl.lang.core.Agent -import java.util.List +import io.sarl.sre.test.framework.skills.TestingCapacity /** * @author $Author: sgalland$ @@ -33,17 +32,10 @@ import java.util.List */ behavior MyBehavior1 { - val results : List - - new (^agent : Agent, results : List) { - super(^agent) - this.results = results - } + uses TestingCapacity on Destroy { - synchronized (this.results) { - this.results.add("BEHAVIOR") - } + addResult("BEHAVIOR") } } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/AbstractExecutorServiceRunTest.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/AbstractExecutorServiceRunTest.sarl index 18150a1a7b..779385568b 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/AbstractExecutorServiceRunTest.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/AbstractExecutorServiceRunTest.sarl @@ -21,7 +21,6 @@ package io.sarl.sre.tests.runtime.services.executor -import io.sarl.lang.annotation.PrivateAPI import io.sarl.sre.test.framework.context.SreRunContext import io.sarl.sre.test.framework.^extension.PropertyRestoreExtension import io.sarl.sre.test.framework.^extension.SreRunExtension @@ -31,20 +30,18 @@ import io.sarl.sre.tests.runtime.services.executor.mocks.EveryAgent import io.sarl.sre.tests.runtime.services.executor.mocks.ExecuteAgent import io.sarl.sre.tests.runtime.services.executor.mocks.GetActiveTasksAgent import io.sarl.sre.tests.runtime.services.executor.mocks.InAgent -import io.sarl.sre.tests.runtime.services.executor.mocks.WaiterAgent import io.sarl.tests.api.extensions.ContextInitExtension import io.sarl.tests.api.extensions.JavaVersionCheckExtension import java.util.List import java.util.UUID -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.^extension.ExtendWith import static io.sarl.sre.test.framework.Constants.* import static io.sarl.tests.api.tools.TestAssertions.* -import static org.junit.jupiter.api.Assertions.* import static extension io.sarl.tests.api.tools.TestUtils.* +import static extension org.junit.jupiter.api.Assertions.* /** * @author $Author: sgalland$ @@ -81,28 +78,25 @@ abstract class AbstractExecutorServiceRunTest { @Test def every_00(extension rc : SreRunContext) { typeof(EveryAgent).runSre - // Wait two more seconds in order to give a chance to the every task to be run even if the agent is died - Thread::sleep(2000) var all = allResults - assertEquals(1, all.size) - assertEquals(2, all.get(0)) + assertEquals(2, all.size) + all.get(0).assertNotNull + assertEquals(2, all.get(1)) } /** Every task should be stopped when kill me is invoked */ @Test - @SuppressWarnings("use_reserved_sarl_annotation") - @PrivateAPI(isCallerOnly = true) - @Disabled def every_01(extension rc : SreRunContext) { - val kern = typeof(WaiterAgent).setupTheSreKernel(null, null) - kern.startAgent(typeof(EveryAgent), null, getAgentInitializationParameters) + val kern = setupTheSreKernel(null, null) + val id = UUID::randomUUID + kern.startAgentWithID(typeof(EveryAgent), id, getAgentInitializationParameters) waitForTheKernel(STANDARD_TIMEOUT) - var all = allResults - assertEquals(1, all.size) - assertEquals(2, all.get(0)) + var all = getResults(id) + id.assertEquals(all.get(0)) + 2. assertEquals(all.get(1)) } @Test diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/mocks/EveryAgent.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/mocks/EveryAgent.sarl index 956285f3d0..8a821c5b89 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/mocks/EveryAgent.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/services/executor/mocks/EveryAgent.sarl @@ -45,6 +45,7 @@ agent EveryAgent { on Initialize { setSkill(new TestingSkill(occurrence)) + addResult(ID) every(1000) [ var n = nb.incrementAndGet if (n == 2) { diff --git a/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingCapacity.sarl b/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingCapacity.sarl index 500ea2a128..eb441d857b 100644 --- a/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingCapacity.sarl +++ b/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingCapacity.sarl @@ -25,7 +25,6 @@ import io.sarl.sre.test.framework.Constants import java.util.Collection import java.util.List import java.util.UUID -import java.util.concurrent.CopyOnWriteArrayList /** * A capacity that provides the agent with testing functions. @@ -74,13 +73,6 @@ capacity TestingCapacity { @Pure def getUnmodifiableResults : List - /** - * Replies a modifiable view on the results for the current agent. - * @return the results. - */ - @Pure - def getModifiableResults : CopyOnWriteArrayList - /** Replies the initialization parameters of the agents. * * @return the initialization parameters. diff --git a/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingSkill.sarl b/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingSkill.sarl index e5be073e2f..584c06f3cb 100644 --- a/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingSkill.sarl +++ b/tests/io.sarl.sre.test.framework/src/main/sarl/io/sarl/sre/test/framework/skills/TestingSkill.sarl @@ -21,16 +21,16 @@ package io.sarl.sre.test.framework.skills +import io.sarl.core.Initialize import io.sarl.core.Lifecycle import io.sarl.core.Schedules import io.sarl.sre.test.framework.Constants import io.sarl.sre.test.framework.context.SreRunContext +import java.util.ArrayList import java.util.Collection import java.util.List import java.util.UUID -import java.util.concurrent.CopyOnWriteArrayList import org.eclipse.xtend.lib.annotations.Accessors -import io.sarl.core.Initialize /** * A skill that provides the agent with testing functions. @@ -45,7 +45,7 @@ skill TestingSkill implements TestingCapacity { uses Schedules, Lifecycle - val results = new CopyOnWriteArrayList + val results = new ArrayList val context : SreRunContext @@ -72,16 +72,22 @@ skill TestingSkill implements TestingCapacity { } override addResult(result : Object) { - getModifiableResults.add(result) + synchronized (this) { + getModifiableResults.add(result) + } } @Pure override getNumberOfResults : int { - return getModifiableResults.size + synchronized (this) { + return getModifiableResults.size + } } override addResults(results : Collection) { - getModifiableResults.addAll(results) + synchronized (this) { + getModifiableResults.addAll(results) + } } @Pure @@ -90,8 +96,10 @@ skill TestingSkill implements TestingCapacity { } @Pure - override getModifiableResults : CopyOnWriteArrayList { - return this.results + def getModifiableResults : List { + synchronized (this) { + return this.results + } } @Pure