Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2013-05-15 09:14:27 +0000
committerMarkus Tiede2013-05-15 09:14:27 +0000
commita2522c278ca0e51f8a77b1411b20fa079e12034b (patch)
treeab1e0ca05456e8e967a82344ce31acffdab8a220
parent7b257fc0a645220a64a8dba6a351b728ccec0932 (diff)
downloadorg.eclipse.jubula.core-a2522c278ca0e51f8a77b1411b20fa079e12034b.tar.gz
org.eclipse.jubula.core-a2522c278ca0e51f8a77b1411b20fa079e12034b.tar.xz
org.eclipse.jubula.core-a2522c278ca0e51f8a77b1411b20fa079e12034b.zip
Sprint task - allow restart AUT after shutdown - part 3: minor refactoring + allow external setting via environment or JVM property of internal delays for keeping the AUT alive and waiting after the AUTs deregistration at the AUT-Agent.
-rw-r--r--org.eclipse.jubula.app.cmd/src/org/eclipse/jubula/app/cmd/batch/ExecutionController.java15
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java12
-rw-r--r--org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/commands/PrepareForShutdownCommand.java84
-rw-r--r--org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/utils/TimeUtil.java23
4 files changed, 89 insertions, 45 deletions
diff --git a/org.eclipse.jubula.app.cmd/src/org/eclipse/jubula/app/cmd/batch/ExecutionController.java b/org.eclipse.jubula.app.cmd/src/org/eclipse/jubula/app/cmd/batch/ExecutionController.java
index 0ca22eb1c..dad6eec79 100644
--- a/org.eclipse.jubula.app.cmd/src/org/eclipse/jubula/app/cmd/batch/ExecutionController.java
+++ b/org.eclipse.jubula.app.cmd/src/org/eclipse/jubula/app/cmd/batch/ExecutionController.java
@@ -52,8 +52,8 @@ import org.eclipse.jubula.client.core.businessprocess.compcheck.CompletenessGuar
import org.eclipse.jubula.client.core.businessprocess.db.TestSuiteBP;
import org.eclipse.jubula.client.core.businessprocess.problems.IProblem;
import org.eclipse.jubula.client.core.businessprocess.problems.ProblemFactory;
-import org.eclipse.jubula.client.core.communication.ConnectionException;
import org.eclipse.jubula.client.core.communication.AutAgentConnection;
+import org.eclipse.jubula.client.core.communication.ConnectionException;
import org.eclipse.jubula.client.core.model.IAUTConfigPO;
import org.eclipse.jubula.client.core.model.IAUTMainPO;
import org.eclipse.jubula.client.core.model.ICapPO;
@@ -78,7 +78,6 @@ import org.eclipse.jubula.tools.exception.JBException;
import org.eclipse.jubula.tools.i18n.I18n;
import org.eclipse.jubula.tools.messagehandling.MessageIDs;
import org.eclipse.jubula.tools.registration.AutIdentifier;
-import org.eclipse.jubula.tools.utils.EnvironmentUtils;
import org.eclipse.jubula.tools.utils.FileUtils;
import org.eclipse.jubula.tools.utils.TimeUtil;
import org.eclipse.osgi.util.NLS;
@@ -623,16 +622,8 @@ public class ExecutionController implements IAUTServerEventListener,
* this method delays the test execution start during AUT startup
*/
private void waitExternalTime() {
- int timeToWait = AUT_STARTUP_DELAY_DEFAULT;
- try {
- String value = EnvironmentUtils
- .getProcessOrSystemProperty(AUT_STARTUP_DELAY_VAR);
-
- timeToWait = Integer.valueOf(value).intValue();
- } catch (NumberFormatException e) {
- // ignore invalid formatted values and use default instead
- }
- TimeUtil.delay(timeToWait);
+ TimeUtil.delayDefaultOrExternalTime(AUT_STARTUP_DELAY_DEFAULT,
+ AUT_STARTUP_DELAY_VAR);
}
/**
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java
index 7de2f37f0..1afe3f02c 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java
@@ -54,6 +54,14 @@ import org.slf4j.LoggerFactory;
* @created Dec 1, 2009
*/
public class AutAgent {
+ /**
+ * the default value to wait after a proper AUT termination (== de-registration)
+ */
+ public static final int AUT_POST_DEREGISTRATION_DELAY_DEFAULT = 2000;
+ /**
+ * Name of the variable to override the AUTs proper AUT de-registration delay
+ */
+ public static final String AUT_POST_DEREGISTRATION_DELAY_VAR = "TEST_AUT_POST_DEREGISTRATION_DELAY"; //$NON-NLS-1$
/** property name for collection of registered AUTs */
public static final String PROP_NAME_AUTS = "auts"; //$NON-NLS-1$
@@ -594,7 +602,9 @@ public class AutAgent {
}
// The AUT has just unregistered itself - which must not be exactly
// the same as terminated - therefore we wait for another moment of time
- TimeUtil.delay(2000);
+ TimeUtil.delayDefaultOrExternalTime(
+ AUT_POST_DEREGISTRATION_DELAY_DEFAULT,
+ AUT_POST_DEREGISTRATION_DELAY_VAR);
}
}
diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/commands/PrepareForShutdownCommand.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/commands/PrepareForShutdownCommand.java
index d27fc6b45..6abaeb44c 100644
--- a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/commands/PrepareForShutdownCommand.java
+++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/commands/PrepareForShutdownCommand.java
@@ -23,7 +23,6 @@ import org.eclipse.jubula.rc.common.AUTServer;
import org.eclipse.jubula.tools.constants.AUTServerExitConstants;
import org.eclipse.jubula.tools.exception.CommunicationException;
import org.eclipse.jubula.tools.objects.ComponentIdentifier;
-import org.eclipse.jubula.tools.utils.EnvironmentUtils;
import org.eclipse.jubula.tools.utils.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +39,56 @@ public class PrepareForShutdownCommand implements ICommand {
/**
* Amount of milliseconds to delay the AUTs termination
*/
- public static final int AUT_TERMINATION_DELAY = 2000;
+ public static final int AUT_KEEP_ALIVE_DELAY_DEFAULT = 2000;
+
+ /**
+ * Name of the variable to override the AUTs termination delay
+ */
+ public static final String AUT_KEEP_ALIVE_DELAY_VAR = "TEST_AUT_KEEP_ALIVE_DELAY"; //$NON-NLS-1$
+
+ /**
+ * @author BREDEX GmbH
+ * Shutdown hook runnable to allow a proper AUT termination
+ */
+ private static class AUTProperTerminationShutdownHook implements Runnable {
+ /** {@inheritDoc} */
+ public void run() {
+ AUTServer autRC = AUTServer.getInstance();
+ // FIXME improve AUT toolkit handling
+ if (!autRC.isRcpAccessible()) {
+ // send fake message back - say last CAP execution went OK
+ // this is necessary as e.g. in Swing the AUT event thread blocks
+ // and thereby our event confirming until the AUT terminates
+ sendFakeCAPTestReponseMessage(autRC);
+ }
+
+ // keep the AUT alive to perform proper AUT termination synchronization
+ TimeUtil.delayDefaultOrExternalTime(
+ AUT_KEEP_ALIVE_DELAY_DEFAULT,
+ AUT_KEEP_ALIVE_DELAY_VAR);
+ }
+
+ /**
+ * @param autRC
+ * the AUT-Server instance to use
+ */
+ private void sendFakeCAPTestReponseMessage(AUTServer autRC) {
+ Communicator iteCom = autRC.getCommunicator();
+ CAPTestResponseMessage fakeMessage =
+ new CAPTestResponseMessage();
+ MessageCap fakeMessageCap = new MessageCap();
+ fakeMessageCap.setCi(new ComponentIdentifier());
+ fakeMessage.setMessageCap(fakeMessageCap);
+ try {
+ iteCom.send(fakeMessage);
+ } catch (CommunicationException e) {
+ // This might also occur if hook has been registered but
+ // AUT terminates without a connection to the ITE e.g.
+ // normal AUT shutdown
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ }
+ }
/** the logger */
private static final Logger LOG =
@@ -82,35 +130,8 @@ public class PrepareForShutdownCommand implements ICommand {
});
}
} else {
- Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
- public void run() {
- AUTServer autRC = AUTServer.getInstance();
- // FIXME improve AUT toolkit handling
- if (!autRC.isRcpAccessible()) {
- // send fake message back - say last CAP execution went OK
- // this is necessary as e.g. in Swing the AUT event thread blocks
- // and thereby our event confirming until the AUT terminates
- Communicator iteCom = autRC
- .getCommunicator();
- CAPTestResponseMessage fakeMessage =
- new CAPTestResponseMessage();
- MessageCap fakeMessageCap = new MessageCap();
- fakeMessageCap.setCi(new ComponentIdentifier());
- fakeMessage.setMessageCap(fakeMessageCap);
- try {
- iteCom.send(fakeMessage);
- } catch (CommunicationException e) {
- // This might also occur if hook has been registered but
- // AUT terminates without a connection to the ITE e.g.
- // normal AUT shutdown
- LOG.error(e.getLocalizedMessage(), e);
- }
- }
-
- // keep the AUT alive to perform proper AUT termination synchronization
- TimeUtil.delay(AUT_TERMINATION_DELAY);
- }
- }));
+ Runtime.getRuntime().addShutdownHook(
+ new Thread(new AUTProperTerminationShutdownHook()));
}
return null;
}
@@ -135,5 +156,4 @@ public class PrepareForShutdownCommand implements ICommand {
public void timeout() {
LOG.error(this.getClass().getName() + "timeout() called"); //$NON-NLS-1$
}
-
}
diff --git a/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/utils/TimeUtil.java b/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/utils/TimeUtil.java
index f8ca6072b..3401baf23 100644
--- a/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/utils/TimeUtil.java
+++ b/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/utils/TimeUtil.java
@@ -54,6 +54,29 @@ public abstract class TimeUtil {
}
/**
+ * Delay for a certain amount of time. Uses if set the given keys property
+ * value as a delay
+ *
+ * @param defaultDelay
+ * the delay in ms, must not be negative
+ * @param delayPropertyKey
+ * the property key; can be used to override / allow external
+ * setting of amount of delay
+ */
+ public static void delayDefaultOrExternalTime(final long defaultDelay,
+ final String delayPropertyKey) {
+ long timeToWait = defaultDelay;
+ try {
+ String value = EnvironmentUtils
+ .getProcessOrSystemProperty(delayPropertyKey);
+ timeToWait = Long.valueOf(value).longValue();
+ } catch (NumberFormatException e) {
+ // ignore invalid formatted values and use default instead
+ }
+ TimeUtil.delay(timeToWait);
+ }
+
+ /**
* @param startTime The start time.
* @param endTime The end time.
* @return a String representation of the difference between the provided

Back to the top