Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to test collaboration/concurrency between two RCP application instances ?
How to test collaboration/concurrency between two RCP application instances ? [message #1386805] Fri, 20 June 2014 15:43 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi all,

I wrote an application to work in a collaborative way. And now, I need to test - for exemple - that when a first user modifies a diagram, a second one won't be allowed to. In other words, I want to check that my underlying locking mechanism is working fine.

I considered three scenarios based on SWTBot and I would appreciate any tips or recommendations.

Scenario 1 : Two SWTBot instances running in parallel. Theoretically simple to launch and distribute the tests but how to synchronise the execution between the two instances to make sure the tests are executed in the correct order ?

Scenario 2 : Two nested SWTBot instances. The first one should launch the second one and handle it during the whole tests execution, that is, keep it alive and provide the tests to be executed when appropriate.

Scenario 3 : One SWTBot instance coupled with "headless" junit tests.
The JUnit tests would programmatically achieve the same actions that would have been performed using the HMI.

At the first glance, scenario 3 looks easier to set up than the second one.

But scenario 2 seems to be the more appealing. Writing SWTBot test could mean less code writing than for headless junit tests. And this scenario is closer to reality than the third one.

Therefore, is the 2nd scenario the best one and a feasible strategy ? If yes, how to programmatically create the second nested SWTBot instance ? How to keep it alive and pass it along the whole execution ? And, how to provide it with its own tests to be executed when appropriate ?

Kind regards,

Laurent
Re: How to test collaboration/concurrency between two RCP application instances ? [message #1386973 is a reply to message #1386805] Mon, 23 June 2014 10:52 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

On 06/20/2014 05:43 PM, Laurent Le Moux wrote:
> I wrote an application to work in a collaborative way. And now, I need
> to test - for exemple - that when a first user modifies a diagram, a
> second one won't be allowed to. In other words, I want to check that my
> underlying locking mechanism is working fine.

SWTBot by itself doesn't provide much more than the finder APIs when in
comes to test execution, so there is nothing magic to help you there.
AFAIK, there is no generic Eclipse project or technology to deal with
collaboration/orchestration between multiple RCP applications. I guess
you'll have to do it more or less manually.

> Scenario 1 : Two SWTBot instances running in parallel. Theoretically
> simple to launch and distribute the tests but how to synchronise the
> execution between the two instances to make sure the tests are executed
> in the correct order ?

That's the solution I'd go for in that case:
Both application could connect to a remote notification service (you
could think of using any protocol you like such as simple TCP or UDP,
RMI, MQTT or even just a shared file) and would send event when they
finished a piece of action and listen to incoming events and react when
it's ready.

Depending on the protocol, in order to make an application test pause
while the other is processing, you could either just use a synchronous
method "protocol.receive()"-like, or for example if you go for
filesystem, implement an ICondition and use it in bot.waitUntil or
bot.waitWhile method.

Eg
bot.waitUntil(new ICondition() {
File f = new File("collaborationStatusFile");

@Override public boolean test() {
return someGetFileContentAsStringMethod(f).contains("other
application notify job is done");
}
}


> Scenario 2 : Two nested SWTBot instances. The first one should launch
> the second one and handle it during the whole tests execution, that is,
> keep it alive and provide the tests to be executed when appropriate.

Even if you do that, it will be 2 separate processes so you can't
orchestrate them without a synchronization mechanism as discussed above.
IMO, this is too complex and doesn't provide anything helpful for your case.

> Scenario 3 : One SWTBot instance coupled with "headless" junit tests.
> The JUnit tests would programmatically achieve the same actions that
> would have been performed using the HMI.

In general, being able to do thing headlessly is a big plus. If that's
something you achieved and that still make your test relevant, it's
definitely something interesting to do as it will make everything a bit
easier.


> But scenario 2 seems to be the more appealing. Writing SWTBot test could
> mean less code writing than for headless junit tests. And this scenario
> is closer to reality than the third one.
>
> Therefore, is the 2nd scenario the best one and a feasible strategy ? If
> yes, how to programmatically create the second nested SWTBot instance ?
> How to keep it alive and pass it along the whole execution ? And, how to
> provide it with its own tests to be executed when appropriate ?

Scenario 2 is a superset of Scenario 1.
If I were to do this kind of work, I would go for scenario 1, relying on
a simple synchronous notification protocol to wait for n-way
notification between applications.

HTH,
--
Mickael Istria
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Re: How to test collaboration/concurrency between two RCP application instances ? [message #1389228 is a reply to message #1386973] Fri, 27 June 2014 14:11 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Mickael,

Thank you for your detailed answer. I followed your recommendation and I now have two instances running in parallel and relying on a basic synchronization service and protocol.

Just one more thing if I may... Wink

My first instance successfully runs four tests when executed alone.
Then, in "collaboration mode" :
1. It runs successfully the three first tests.
2. I launch from my Eclipse IDE the second instance.
3. From the synchronization service, the second instance "knows" it can run its single test and exit.
4. Finally the first instance regains control to execute the last test.
But this one fails with a SWTBot WidgetNotFoundException.

There is no exception anymore if, just after launching the second instance and before it actually starts, I minimize my Eclipse IDE...

So the problem appears to be that when the second instance is closed, the IDE becomes the active window instead of the first instance.

So my question is, how can I make my first instance be the active window again ?

Regards,

Laurent
Re: How to test collaboration/concurrency between two RCP application instances ? [message #1389350 is a reply to message #1389228] Fri, 27 June 2014 17:25 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

I tried to "force" somehow the first instance to appear on top of my desktop (and on top of the IDE) by adding the following code :

Display.getDefault().syncExec(new Runnable() {
  @Override
  public void run() {
    bot.getDisplay().getFocusControl().setFocus();
  }
});


But I now get a "SWTException : Failed to execute runnable" Sad.

Regards,

Laurent
Re: How to test collaboration/concurrency between two RCP application instances ? [message #1390568 is a reply to message #1389350] Sun, 29 June 2014 17:26 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

After reading some other posts, I tried :
Display.getDefault().syncExec(new Runnable() {
  @Override
  public void run() {
   bot.shells()[0].widget.forceActive();
  }
});
SWTBotMenu openMenu = bot.menu("Menu");

and
Display.getDefault().syncExec(new Runnable() {
  @Override
  public void run() {
   bot.shells()[0].widget.forceFocus();
  }
});
SWTBotMenu openMenu = bot.menu("Menu");


But I'm then back to my initial problem.
Opening the menu fails with the WidgetNotFoundException and I still can not get my first instance to be brought on top of my desktop.

Regards,

Laurent
Re: How to test collaboration/concurrency between two RCP application instances ? [message #1390966 is a reply to message #1390568] Mon, 30 June 2014 08:44 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

I finally found a solution :
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();

or
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceFocus();

or
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();

in the runnable does the job...

Kind regards,

Laurent
Previous Topic:SWTBot cannot copy/paste on tree items using keyboard shortcuts
Next Topic:Getting a move instead of a resize...
Goto Forum:
  


Current Time: Fri Apr 19 03:15:07 GMT 2024

Powered by FUDForum. Page generated in 0.01502 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top