question

AmeyaB avatar image
AmeyaB asked Spirent_Admin answered

How do I abort an "open" action if some validation fails?

I have an OpenHandler which performs some validation. I want to open the session only if the validation passes, otherwise I want to close the session immediately. I have the following lines of code in my OpenHandler:

 

 

// Open session only if no errors

if (valid()) {

    SessionModel sessionModel = (SessionModel) model;

    sessionModel.setOpen();

} else {

    throw new ToolException("Cannot open session; validation failed.");

}


 

However this still opens the session if the validation fails. What do I need to change?

 

 

iTestsdk
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Spirent_Admin avatar image
Spirent_Admin answered
The default behavior for all SDK Tools is that execution will continue even if the "open" step fails. More often than not, you want the execution to be aborted end as soon as the "open" step fails. To do this, follow these steps: 1. In your Session Profile, click on the Global Events page. 2. Scroll down to the "Tool" node, and select the "OnToolOpenSessionError" node. 3. Uncheck the "Inherit" checkbox; this allows you to over-ride that event. 4. Click on "Add" button, and select "AbortExecution" as the action. You can change the "AbortExecution" action to be any of the actions listed to suit your needs. You may also add additonal actions if required.
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

AdamB avatar image
AdamB answered AdamB posted

Have you stepped through the code to make sure that:

1. your open handler is getting called

2. Your valid is returning false?

 

The code (which you can see and step through) in the SessionController does the following:

 

IRequestHandler openRequestHandler = open.getRequestHandler();
                if (openRequestHandler != null) {
                    try {
                        openRequestHandler.performRequest(this, getModel(), request, context, monitor);
                        if (model.getState() != SessionState.OPENED && model.getState() != SessionState.CLOSED) {
                            // if the tool fails to set the state to OPENED, then we set it to closed.
                            setOpeningToClose();
                            throw new ToolRuntimeException("Open Request Handler did not set the state to OPEN, and did not throw an exception on failure: "
                                    + toolDescriptor.getId());
                        }
                    } catch (Exception e) {
                        setOpeningToClose();
                        if (e instanceof ToolException) {
                            throw (ToolException) e;
                        } else {
                            throw new ToolException(e);
                        }
                    }
                } else {
                

 If you fail to set the state to Open or you thrown an exception, it sets the state to "Close"

 

6 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

AmeyaB avatar image AmeyaB ♦ commented ·

Yes it's working now. For some reason I had to re-start Eclipse.

 

A follow-up question is where does the ToolException appear? It does not appear in my ErrorLog View.

0 Likes 0 ·
AdamB avatar image AdamB AmeyaB ♦ commented ·

I think that there might be some issues with interactive errors.  Does the view get a request response that is completed but has an error state?  i.e. error issues?

0 Likes 0 ·
AmeyaB avatar image AmeyaB ♦ AdamB commented ·

There are no issues in the Execution View.

0 Likes 0 ·
AdamB avatar image AdamB AmeyaB ♦ commented ·

When are there no issues in the execution view?  When you are running interactively?  Or when you are "executing"?  If the former, that is because the execution view is for execution.  If the latter, then there is a bug.  If you throw a tool exception during a step during execution, iTest should create an execution issue for that issue and put it in the execution view.

0 Likes 0 ·
AmeyaB avatar image AmeyaB ♦ AdamB commented ·

There are no issues when running interactively, and I get the correct error issue during execution. So both behaviors are as intended.

 

So the only open issue is the one you identified: How do we display the error during interactive use?

0 Likes 0 ·
AdamB avatar image AdamB AmeyaB ♦ commented ·

I believe that other tools are adding error issues to the request response and then the view is looking at the request response.  If it has issues, it displays the error.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.