question

twile avatar image
twile asked twile posted

Overriding 'close' Action

I'd like to override the 'close' Action in my session plugin for accounting internally with my own implementation of IRequestHandler.  However, as the sample doesn't have this capability, I know I'm missing some functionality.  Especially after I started getting 'OutOfMemory' errors :)

 

I would like to do the cleanup that I need to do everytime a session closes, and then execute whatever is normally executed by iTest when a session is closed.  Allowing iTest to handle normal cleanup.  Removing my 'OutOfMemroy' issues.

 

Ideas?

 

 

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.

1 Answer

·
sreenath avatar image
sreenath answered sreenath posted

Hi Twile,

 

I believe there are two ways to clean the file in iTest.

 

1. By using the -clean option while starting the iTest from command prompt as "itest -clean" command. This start the whole workspace as a fresh.

 

2. Go to > project tab > click on clean and select any particular project or all projects option in the pop-up window. This will clean all the selected projects.

 

Heap memory can also be cleaned by clicking on the garbage button at the bottom of the iTest GUI window. This will clean up all the unoccupied space from the heap. To enable this goto Window > Preferences > General and enable the option "show Heap status".

 

Attached is the screen shot for your reference.

 

Thanks,

Sreenath


Clean.JPG (120.9 KiB)
8 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.

twile avatar image twile commented ·

I'm talking about Java, using the SDK to create a plugin for a new session profile type.  The close action can be overriden with an IRequestHandler Class.  I need to know the default behavior on 'close' so I can either emulate it in my Class or just call it.  Because after overriding it, and opening the session/then closing it (while in iTest) gives OutOfMemory errors.

0 Likes 0 ·
AdamB avatar image AdamB twile commented ·

You should be able to provide a "close" handler in the plugin project extensions page.  that handler will get called when "close" is called.

 

Is that what you're hoping to do?

 

-a

0 Likes 0 ·
twile avatar image twile AdamB commented ·

Exactly, and I've already done that, and it works.

 

I first had a plugin without a UI, and the handler worked fine.

 

I added a UI and now the existence of the handler changes the behavior of the plugin such that iTest gives an 'OutOfMemory' error when closing the session.

 

However, after removing the handler from the plugin extension, that error no longer exists, and everything behaves properly in iTest.

 

I need the close handler for the plugin to work properly, but I also need whatever functionality is replaced with that handler.

0 Likes 0 ·
AdamB avatar image AdamB twile commented ·

Interesting, I wonder whether it is going into some loop when closing the session.  Does your session have any really large objects in it?  What does your close handler look like?  (btw, if you don't want to post it here, feel free to Personal Message it.)

 

-a

0 Likes 0 ·
twile avatar image twile AdamB commented ·

I don't have the exact error message.  I'll see if I can reproduce the stack trace for you.

 

I do believe it is entering a loop, but there aren't any large objects in it.

 

"What does your close handler look like?"

This is the part I want to focus on.  I don't know what it SHOULD look like.  The sample plugin doesn't have one and I can't find any documentation on what MUST be done by a close Handler.

0 Likes 0 ·
AdamB avatar image AdamB twile commented ·

So the SessionController calls the close request:

 

 @Override
    public void close(final IRequestResponse request, final IRequestContext context, IProgressMonitor monitor) throws ToolException {
        if (isTerminated() || model.getState() == SessionState.CLOSED || model.getState() == SessionState.TERMINATED) {
            return;
        }
        try {
            StateChangeResult res = model.setClosing();
            if (res.changed) {
                addRequestToModel(request.getRequestResponseMonitor(), context);
                IToolDescriptor toolDescriptor = getModel().getToolDescriptor();
                if (toolDescriptor != null) {
                    IRequestDescriptor closeDescriptor = toolDescriptor.getClose();
                    if (closeDescriptor == null) {
                        throw new ToolException(String.format("Open is not definied for tool: %s", getModel().getToolId()));
                    } else {
                        IRequestHandler closeRequestHandler = closeDescriptor.getRequestHandler();
                        if (closeRequestHandler != null) {
                            closeRequestHandler.performRequest(this, getModel(), request, context, monitor);
                        }
                    }
                }
                res = model.setClose();
                if (res.changed == false) {
                    if (res.currentState == SessionState.CLOSED || res.currentState == SessionState.TERMINATED) {
                        return;
                    }
                    throw new ToolRuntimeException("Unexpected corrupted state. Expecting state changed from closing to closed instead of " + res.previousState
                            + " to " + res.currentState);
                }
            } else {
                if (res.previousState == SessionState.NOT_STARTED || res.previousState == SessionState.OPENING) {
                    throw new ToolException("Invalid operation: close can not be performed when the session is " + res.previousState);
                } else {
                    //System.out.println("ignore the fact the session is closed or in the process of being closed");
                    return;
                }
            }
        } finally {
            // complete the request
            completeRequest(request);
        }
    }

 

 

And most of our CloseRequestHandlers simply do cleanup:

 

public class CloseRequestHandler implements IRequestHandler {

    @Override
    public void performRequest(ISessionController controller, ISessionModel model, IRequestResponse requestResponse, IRequestContext context,
            IProgressMonitor monitor) throws ToolException {
        if (!(model instanceof AvalancheSessionModel))
            return;

        AvalancheSessionModel avalancheModel = (AvalancheSessionModel) model;

        if (avalancheModel.isClearTestFolder()) {
            FileUtil.deleteDirectory(new File(avalancheModel.getTestFolder()));
        }

        requestResponse.setComplete();
    }
}

 

public class CloseRequestHandler extends VncRequestHandler {

    @Override
    public void performRequest(IRequestResponse requestResponse, IRequestContext context, IProgressMonitor monitor) throws Exception {
        model.getVncController().disconnect();
    }
}

 

 

0 Likes 0 ·
twile avatar image twile AdamB commented ·

Ok,

 

That is exactly what I use the CloseRequestHandler for.  I think I sent you on a wild goose chase, my apologies.

 

The problem was running out of PermGen memory in eclipse when running iTest.  What kind of memory allocation should I be using for eclipse when running iTest?

 

- Tom

0 Likes 0 ·
rbaswareddy avatar image rbaswareddy twile commented ·

Hi Twile,

 

Could you please attach your error log file of that PermGen memory in eclipse.

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.