Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add REST stages that run in background
* useful for resilience tests where we need to kill some servers from stages running in foreground
- Loading branch information
Showing
6 changed files
with
219 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/radargun/stages/test/legacy/StressorsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.radargun.stages.test.legacy; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
/** | ||
* A class that holds additional information about stressors and makes is possible to | ||
* pass stressors together with this information between stages. An arbitrary stage can wait | ||
* for the stressors to finish and track their execution time. | ||
* | ||
* @author Martin Gencur | ||
*/ | ||
public class StressorsManager { | ||
|
||
private CountDownLatch finishCountDown; | ||
private long startTime; | ||
private List<LegacyStressor> stressors; | ||
|
||
public StressorsManager(List<LegacyStressor> stressors, long startTime, CountDownLatch finishCountDown) { | ||
this.stressors = stressors; | ||
this.startTime = startTime; | ||
this.finishCountDown = finishCountDown; | ||
} | ||
|
||
public long getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public List<LegacyStressor> getStressors() { | ||
return stressors; | ||
} | ||
|
||
public CountDownLatch getFinishCountDown() { | ||
return finishCountDown; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
extensions/rest/src/main/java/org/radargun/stages/BackgroundRESTOperationsStartStage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.radargun.stages; | ||
|
||
import java.util.List; | ||
import org.radargun.DistStageAck; | ||
import org.radargun.StageResult; | ||
import org.radargun.config.Namespace; | ||
import org.radargun.config.Stage; | ||
import org.radargun.stages.test.legacy.Completion; | ||
import org.radargun.stages.test.legacy.LegacyTestStage; | ||
import org.radargun.stages.test.legacy.TimeStressorCompletion; | ||
|
||
/** | ||
* A stage for REST operations running in background. | ||
* | ||
* @author Martin Gencur | ||
*/ | ||
@Namespace(LegacyTestStage.NAMESPACE) | ||
@Stage(doc = "Stage for starting REST operations in the background") | ||
public class BackgroundRESTOperationsStartStage extends RESTOperationsTestStage { | ||
|
||
//Override Init method from BaseTestStage in order to handle duration specifically | ||
@Override | ||
public void check() { | ||
if (duration > 0 || duration < 0) { | ||
duration = 0; | ||
log.warn("Parameter duration ignored in background stage. Stage will run indefinitely until " + | ||
"it is manually stopped from " + BackgroundRESTOperationsStopStage.class.getSimpleName()); | ||
} | ||
if (numOperations > 0) { | ||
numOperations = 0; | ||
log.warn("Parameter numOperations ignored in background stage."); | ||
} | ||
if (timeout > 0 || timeout < 0) { | ||
timeout = 0; | ||
log.warn("Parameter timeout ignored in background stage."); | ||
} | ||
} | ||
|
||
@Override | ||
protected Completion createCompletion() { | ||
return new TimeStressorCompletion(duration); | ||
} | ||
|
||
@Override | ||
public DistStageAck executeOnSlave() { | ||
if (!isServiceRunning()) { | ||
log.info("Not running test on this slave as service is not running."); | ||
return successfulResponse(); | ||
} | ||
try { | ||
log.info("Starting test " + testName + " in the background."); | ||
stressorsManager = setUpAndStartStressors(); | ||
slaveState.put(testName, this); | ||
return successfulResponse(); | ||
} catch (Exception e) { | ||
return errorResponse("Exception while initializing the test", e); | ||
} | ||
} | ||
|
||
@Override | ||
public StageResult processAckOnMaster(List<DistStageAck> acks) { | ||
StageResult result = StageResult.SUCCESS; | ||
logDurationInfo(acks); | ||
for (DistStageAck ack : acks) { | ||
if (ack.isError()) { | ||
log.warn("Received error ack " + ack); | ||
result = errorResult(); | ||
} else { | ||
if (log.isTraceEnabled()) { | ||
log.trace("Received success ack " + ack); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
extensions/rest/src/main/java/org/radargun/stages/BackgroundRESTOperationsStopStage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.radargun.stages; | ||
|
||
import java.util.List; | ||
import org.radargun.DistStageAck; | ||
import org.radargun.StageResult; | ||
import org.radargun.config.Namespace; | ||
import org.radargun.config.Property; | ||
import org.radargun.config.Stage; | ||
import org.radargun.stages.test.legacy.LegacyTestStage; | ||
import org.radargun.utils.TimeService; | ||
import org.radargun.utils.Utils; | ||
|
||
/** | ||
* A test stage for stopping REST operations background stage. | ||
* | ||
* @author Martin Gencur | ||
*/ | ||
@Namespace(LegacyTestStage.NAMESPACE) | ||
@Stage(doc = "Stage for stopping REST operations running in the background") | ||
public class BackgroundRESTOperationsStopStage extends RESTOperationsTestStage { | ||
|
||
@Property(doc = "Name of the background operations to be stopped. Default is 'Test'.") | ||
protected String testNameToStop = "Test"; | ||
|
||
@Override | ||
public void check() { | ||
if (duration > 0 || duration < 0) { | ||
duration = 0; | ||
log.warn("Parameter duration ignored in background stage."); | ||
} | ||
if (numOperations > 0) { | ||
numOperations = 0; | ||
log.warn("Parameter numOperations ignored in background stage."); | ||
} | ||
if (timeout > 0 || timeout < 0) { | ||
timeout = 0; | ||
log.warn("Parameter timeout ignored in background stage."); | ||
} | ||
} | ||
|
||
@Override | ||
public void init() { | ||
//do not check any parameters | ||
} | ||
|
||
@Override | ||
public DistStageAck executeOnSlave() { | ||
if (!isServiceRunning()) { | ||
log.info("Not running test on this slave as service is not running."); | ||
return successfulResponse(); | ||
} | ||
try { | ||
BackgroundRESTOperationsStartStage startedStage = (BackgroundRESTOperationsStartStage) slaveState.get(testNameToStop); | ||
if (startedStage == null) { | ||
throw new RuntimeException("Unable to find the test in slaveState: " + testNameToStop); | ||
} | ||
log.info("Stopping test " + startedStage.testName + " running in the background."); | ||
|
||
startedStage.setTerminated(); | ||
|
||
waitForStressorsToFinish(startedStage.getStressorsManager()); | ||
log.info("Finished test. Test duration is: " + Utils.getMillisDurationString(TimeService.currentTimeMillis() - startedStage.getStressorsManager().getStartTime())); | ||
return newStatisticsAck(startedStage.getStressorsManager().getStressors()); | ||
} catch (Exception e) { | ||
return errorResponse("Exception while initializing the test", e); | ||
} | ||
} | ||
|
||
@Override | ||
public StageResult processAckOnMaster(List<DistStageAck> acks) { | ||
return processAckOnMaster(acks, testNameToStop); | ||
} | ||
} |