I do not have a sample project that I can upload. I created a sample VS model without all the tracking, learning & failover steps. In this model, the Live Invocation Step either branches to Responder or VS Image Selection.
Disregard the "if failover" assertion because this picture is taken from DevTest v10.
- Change the If environment Error to branch to VS Image Response Selection step. A connection refused exception to your Live Endpoint will be considered an environment error. This assertion fires before your Scripted Assertion. You might also see a 'red' dot next to the service in the Console view if this assertion fires - not sure.
- Then, add a Scripted Assertion to check for things that are important to you. For example, consider the Assertion logic below.
If the Assertion returns TRUE, the logic should branch to the VS Image Response Selection step.
If the Assertion returns FALSE, the Live System response is sent to the client.
I used 'false' in the logic below because when DevTest encounters an error in the script at runtime, DevTest will assume the response from the assertion is 'false'. If a scripting error occurs, the code will attempt to send the Live Response.
Switch the the true/false around and change the Assertion branching according to what makes sense to you.
import com.itko.lisa.vse.stateful.model.TransientResponse;
import com.itko.util.ParameterList;
import java.util.List;
// Get the response from the Live System
List lst = (List)testExec.getStateObject("lisa.vse.live.response");
if ( lst.size() < 1 )
return true; // noting in the response to process so go virtual
TransientResponse tr = lst.get(0);
// this is an HTTP service so the list should only have one entry
// if response is null, go virtual
if ( tr == null) {
_logger.info(" hum, response from live is NULL");
return true;
}
// Check the HTTP Return Codes
ParameterList pl = tr.getMetaData();
if ( pl.containsKey( "HTTP-Response-Code" ) ) {
if ( "200".equals( pl.get( "HTTP-Response-Code" ) ) ) {
_logger.info(" HTTP response is 200 ");
// 200 is a good response but maybe we need to check the body
// for something so do not return out of this logic
} else {
_logger.info(" HTTP response is: {} branching virtual", pl.get( "HTTP-Response-Code" ) );
return true; // all other HTTP response codes go virtual
}
} else {
// likely there is an issue if no HTTP response code is returned from Live
// so go virtual
return true;
}
// get the body and determine what to do
String theBody = tr.getBodyAsString();
// for example
int i = 0;
i = theBody.indexOf( "<head><title>404" );
if ( i > 0 )
return true;
// all checks passed must mean you want to send Live response
// Assertion is set to branch to RESPONDER Step if the return is false
return false;
I am not sure how an HTTP Timeout is trapped or what it looks like in the Live Invocation step. So that is some additional testing you will need to take care of.