Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-05-09 07:27:28 +0000
committerUwe Stieber2012-05-09 08:44:11 +0000
commit6fcb6c4a70f0847d4e8b584ecdfd4f218bb5e625 (patch)
tree7a7b4156381289212909b0f101c907a35084e006 /target_explorer/plugins
parent22e0d5a3cf1db36f97926012dca85204b18a59f9 (diff)
downloadorg.eclipse.tcf-6fcb6c4a70f0847d4e8b584ecdfd4f218bb5e625.tar.gz
org.eclipse.tcf-6fcb6c4a70f0847d4e8b584ecdfd4f218bb5e625.tar.xz
org.eclipse.tcf-6fcb6c4a70f0847d4e8b584ecdfd4f218bb5e625.zip
Target Explorer: Fix assertion on test case agent launch, allow framework to be used from non-UI thread
Diffstat (limited to 'target_explorer/plugins')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java18
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/CoreTestCase.java44
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/TcfTestCase.java4
3 files changed, 57 insertions, 9 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java
index 1c26f16e4..cfc145c60 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java
@@ -9,7 +9,10 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.locator.internal;
+import java.util.concurrent.atomic.AtomicReference;
+
import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.model.factory.AbstractFactoryDelegate2;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
@@ -39,13 +42,24 @@ public class ModelNodeFactoryDelegate extends AbstractFactoryDelegate2 {
*/
@SuppressWarnings("unchecked")
@Override
- public <V extends IModelNode> V newInstance(Class<V> nodeInterface, Object[] args) {
+ public <V extends IModelNode> V newInstance(final Class<V> nodeInterface, final Object[] args) {
if (args == null) return newInstance(nodeInterface);
if (IPeerModel.class.equals(nodeInterface)) {
// Peer model constructor has 2 arguments, ILocatorModel and IPeer
if (args.length == 2 && args[0] instanceof ILocatorModel && args[1] instanceof IPeer) {
- return (V) new PeerModel((ILocatorModel)args[0], (IPeer)args[1]);
+ final AtomicReference<V> node = new AtomicReference<V>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ node.set((V) new PeerModel((ILocatorModel)args[0], (IPeer)args[1]));
+ }
+ };
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ return node.get();
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/CoreTestCase.java b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/CoreTestCase.java
index 398f9b860..80347dd81 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/CoreTestCase.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/CoreTestCase.java
@@ -153,6 +153,7 @@ public class CoreTestCase extends TestCase {
setProperty(IConfigurationProperties.MAXIMIZE_VIEW, false);
setProperty(IConfigurationProperties.TARGET_PERSPECTIVE, "org.eclipse.tcf.te.ui.perspective"); //$NON-NLS-1$
+ setProperty(IConfigurationProperties.TARGET_VIEW, IUIConstants.ID_EXPLORER);
}
/**
@@ -325,7 +326,18 @@ public class CoreTestCase extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- maximizeView();
+
+ // View handling must run in the UI thread
+ if (Display.findDisplay(Thread.currentThread()) == null) {
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ maximizeView();
+ }
+ });
+ } else {
+ maximizeView();
+ }
}
/* (non-Javadoc)
@@ -333,7 +345,18 @@ public class CoreTestCase extends TestCase {
*/
@Override
protected void tearDown() throws Exception {
- restoreView();
+ // View handling must run in the UI thread
+ if (Display.findDisplay(Thread.currentThread()) == null) {
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ restoreView();
+ }
+ });
+ } else {
+ restoreView();
+ }
+
flushEventQueue();
super.tearDown();
}
@@ -397,19 +420,23 @@ public class CoreTestCase extends TestCase {
* A possibly open Eclipse Intro View will be hidden automatically.
*/
protected void maximizeView() {
+ Assert.isNotNull(Display.findDisplay(Thread.currentThread()), "Illegal Thread Access"); //$NON-NLS-1$
+
final String perspectiveId = getProperty(IConfigurationProperties.TARGET_PERSPECTIVE);
assertNotNull("Invalid null-value for test case perspective id!", perspectiveId); //$NON-NLS-1$
+ final String viewId = getProperty(IConfigurationProperties.TARGET_VIEW);
+ assertNotNull("Invalid null-value for test case view id!", perspectiveId); //$NON-NLS-1$
// Find the Eclipse Intro page and hide it.
hideView("org.eclipse.ui.internal.introview", perspectiveId); //$NON-NLS-1$
// Show the main view
setProperty(VIEW_ZOOM_STATE_CHANGED, false);
- IViewPart part = showView(IUIConstants.ID_EXPLORER, perspectiveId);
+ IViewPart part = showView(viewId, perspectiveId);
assertNotNull("Main view is not available!", part); //$NON-NLS-1$
// Get the view reference for setting the maximized state
- IViewReference reference = findView(IUIConstants.ID_EXPLORER, perspectiveId);
+ IViewReference reference = findView(viewId, perspectiveId);
assertNotNull("Failed to lookup view reference for main view!", reference); //$NON-NLS-1$
if (reference.getPage().getPartState(reference) != IWorkbenchPage.STATE_MAXIMIZED
&& isProperty(IConfigurationProperties.MAXIMIZE_VIEW, true)) {
@@ -431,12 +458,16 @@ public class CoreTestCase extends TestCase {
* Restore the main view state.
*/
protected void restoreView() {
+ Assert.isNotNull(Display.findDisplay(Thread.currentThread()), "Illegal Thread Access"); //$NON-NLS-1$
+
// restore the original view zoom state
if (isProperty(VIEW_ZOOM_STATE_CHANGED, true)) {
final String perspectiveId = getProperty(IConfigurationProperties.TARGET_PERSPECTIVE);
assertNotNull("Invalid null-value for test case perspective id!", perspectiveId); //$NON-NLS-1$
+ final String viewId = getProperty(IConfigurationProperties.TARGET_VIEW);
+ assertNotNull("Invalid null-value for test case view id!", perspectiveId); //$NON-NLS-1$
- IViewReference reference = findView(IUIConstants.ID_EXPLORER, perspectiveId);
+ IViewReference reference = findView(viewId, perspectiveId);
assertNotNull("Failed to lookup view reference for RSE Remote Systems View!", reference); //$NON-NLS-1$
if (reference.getPage().getPartState(reference) == IWorkbenchPage.STATE_MAXIMIZED
&& isProperty(IConfigurationProperties.MAXIMIZE_VIEW, true)) {
@@ -458,6 +489,7 @@ public class CoreTestCase extends TestCase {
* @return The view reference instance to the view or <code>null</code> if not available.
*/
public final IViewReference findView(String viewId, String perspectiveId) {
+ Assert.isNotNull(Display.findDisplay(Thread.currentThread()), "Illegal Thread Access"); //$NON-NLS-1$
Assert.isNotNull(viewId);
Assert.isNotNull(perspectiveId);
@@ -489,6 +521,7 @@ public class CoreTestCase extends TestCase {
* @return The view part instance to the view or <code>null</code> if it cannot be shown.
*/
public final IViewPart showView(String viewId, String perspectiveId) {
+ Assert.isNotNull(Display.findDisplay(Thread.currentThread()), "Illegal Thread Access"); //$NON-NLS-1$
Assert.isNotNull(viewId);
Assert.isNotNull(perspectiveId);
@@ -527,6 +560,7 @@ public class CoreTestCase extends TestCase {
* @param perspectiveId The perspective id. Must not be <code>null</code>.
*/
public final void hideView(String viewId, String perspectiveId) {
+ Assert.isNotNull(Display.findDisplay(Thread.currentThread()), "Illegal Thread Access"); //$NON-NLS-1$
Assert.isNotNull(viewId);
Assert.isNotNull(perspectiveId);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/TcfTestCase.java b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/TcfTestCase.java
index 5bd41aa2c..d63f60b11 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/TcfTestCase.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/TcfTestCase.java
@@ -19,13 +19,13 @@ import org.eclipse.tcf.core.TransientPeer;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.JSON;
import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.runtime.model.factory.Factory;
import org.eclipse.tcf.te.runtime.utils.Host;
import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
import org.eclipse.tcf.te.tcf.locator.model.Model;
-import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
import org.eclipse.tcf.te.tests.CoreTestCase;
/**
@@ -192,7 +192,7 @@ public class TcfTestCase extends CoreTestCase {
attrs.put(IPeer.ATTR_ID, id);
attrs.put(IPeer.ATTR_IP_HOST, ip);
peer = new TransientPeer(attrs);
- peerModel = new PeerModel(model, peer);
+ peerModel = Factory.getInstance().newInstance(IPeerModel.class, new Object[] { model, peer });
} else {
peerModel = node.get();
peer = peerModel.getPeer();

Back to the top