Skip to content

Commit

Permalink
[sre] Avoid anyoing exceptions in event handlers.
Browse files Browse the repository at this point in the history
close #613

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 23, 2017
1 parent 8f30181 commit 9ec8d92
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 2 deletions.
Expand Up @@ -10,6 +10,7 @@ then
echo "Loading user configuration"
. "$HOME/.eclipse/eclipserc"
elif [ -r "$HOME/.eclipserc" ]
then
echo "Loading user configuration"
. "$HOME/.eclipserc"
fi
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.services.executor.ExecutorService;

import io.sarl.core.AgentTask;
Expand Down Expand Up @@ -484,6 +485,8 @@ public void run() {
} else {
mustBeCanceled = true;
}
} catch (EarlyExitException ex) {
// Be silent
} catch (Throwable ex) {
getLoggingSkill().error(Messages.SchedulesSkill_1, ex, toString(), ex.getLocalizedMessage());
mustBeCanceled = true;
Expand Down
Expand Up @@ -335,7 +335,21 @@ private void executeBehaviorMethodsInParalellWithSynchroAtTheEnd(Collection<Runn
try {
doneSignal.await();
} catch (InterruptedException ex) {
// Be silent and continue the task of the caller.
// XXX: Improve because:
// This exception occurs when one of the launched task kills the agent before all the
// submitted tasks are finished. Keep in mind that killing an agent should kill the
// launched tasks.
// Example of code that is generating this issue:
//
// on Initialize {
// in (100) [
// killMe
// ]
// }
//
// In this example, the killMe is launched before the Initialize code is finished;
// and because the Initialize event is fired through the current function, it
// causes the InterruptedException.
}

// Re-throw the run-time exception
Expand Down
Expand Up @@ -7,4 +7,4 @@ InternalEventBusSkill_3=Exception when initializing the agent.
InternalEventBusSkill_4=Exception when destroying the agent
LoggingSkill_0=AGENT-{0}
SchedulesSkill_0=Agent task is null.
SchedulesSkill_1=Error in agent's task {0}: {1}
SchedulesSkill_1=Error in agent''s task {0}: {1}
@@ -0,0 +1,87 @@
/*
* $Id$
*
* Janus platform is an open-source multiagent platform.
* More details on http://www.janusproject.io
*
* Copyright (C) 2014-2015 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* 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.janusproject.tests.bugs;

import static org.junit.Assert.*;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.junit.Test;

import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.tests.testutils.AbstractJanusRunTest;

import io.sarl.core.Destroy;
import io.sarl.core.Initialize;
import io.sarl.core.Lifecycle;
import io.sarl.core.Schedules;
import io.sarl.lang.SARLVersion;
import io.sarl.lang.annotation.PerceptGuardEvaluator;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.core.BuiltinCapacitiesProvider;
import io.sarl.lang.core.Capacity;
import io.sarl.lang.core.Skill;
import io.sarl.lang.core.UnimplementedCapacityException;
import io.sarl.lang.util.ClearableReference;

/**
* Unit test for the issue #613: Exception when destroying the agent java.lang.InterruptedException.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @see https://github.com/sarl/sarl/issues/613
*/
@SuppressWarnings("all")
public class Bug613 extends AbstractJanusRunTest {

@Test
public void killMeInInit() throws Exception {
runJanus(TAgent1.class, true);
assertEquals(0, getResults().size());
}

/**
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class TAgent1 extends TestingAgent {

public TAgent1(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
super(provider, parentID, agentID);
}

@Override
protected boolean runAgentTest() {
getSkill(Schedules.class).in(100, (it) -> forceKillMe());
return false;
}

}

}

0 comments on commit 9ec8d92

Please sign in to comment.