Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-01-14 16:59:27 +0000
committerXavier Coulon2016-01-19 20:46:49 +0000
commiteb1ec4580e172b3c15cb4261a707bcc248e4418e (patch)
tree2d4ed17a0be1622efc3ad51e16a6366d0bec54ef
parent7656de6fb0591b3e77553e00ea7b0502ebf46b31 (diff)
downloadorg.eclipse.linuxtools-eb1ec4580e172b3c15cb4261a707bcc248e4418e.tar.gz
org.eclipse.linuxtools-eb1ec4580e172b3c15cb4261a707bcc248e4418e.tar.xz
org.eclipse.linuxtools-eb1ec4580e172b3c15cb4261a707bcc248e4418e.zip
Bug 485735 - SWTException below DockerContainersContentProvider$1$1.run
Same fix as in https://bugs.eclipse.org/bugs/show_bug.cgi?id=485350 where the listener is removed from the connection when the view is disposed. Change-Id: Icfcdb392db398876f251fed3872e904d2eb24889 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/64328 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit d8818b3a1048d9abca5743b0365160caf9977d43) Reviewed-on: https://git.eclipse.org/r/64689
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java12
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java26
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java108
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java4
5 files changed, 142 insertions, 12 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
index 6cdd0277d2..56d774177d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 Red Hat.
+ * Copyright (c) 2015, 2016 Red Hat.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,6 +24,8 @@ import org.eclipse.linuxtools.docker.core.IDockerContainerInfo;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.mockito.Matchers;
import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerException;
@@ -161,7 +163,13 @@ public class MockDockerClientFactory {
public DockerClient build() {
try {
Mockito.when(this.dockerClient.listImages(Matchers.any())).thenReturn(this.images);
- Mockito.when(this.dockerClient.listContainers(Matchers.any())).thenReturn(this.containers);
+ Mockito.when(this.dockerClient.listContainers(Matchers.any())).thenAnswer(new Answer<List<Container>>() {
+
+ @Override
+ public List<Container> answer(InvocationOnMock invocation) {
+ return containers;
+ }
+ });
for(Entry<String, List<ImageSearchResult>> searchResult : this.searchResults.entrySet()) {
Mockito.when(this.dockerClient.searchImages(searchResult.getKey())).thenReturn(searchResult.getValue());
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java
index afd188d853..e5dea2151b 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java
@@ -17,6 +17,7 @@ import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionStorageManagerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
@@ -36,15 +37,20 @@ public class DockerConnectionManagerUtils {
final IDockerConnection... connections) {
DockerConnectionManager.getInstance()
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(connections));
- final DockerExplorerView dockerExplorerView = getDockerExplorerView(new SWTWorkbenchBot());
- if(dockerExplorerView != null) {
- SWTUtils.syncExec(() -> {
- DockerConnectionManager.getInstance().reloadConnections();
+ final SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ final DockerExplorerView dockerExplorerView = getDockerExplorerView(bot);
+ final DockerContainersView dockerContainersView = getDockerContainersView(bot);
+ SWTUtils.syncExec(() -> {
+ DockerConnectionManager.getInstance().reloadConnections();
+ if (dockerExplorerView != null) {
dockerExplorerView.getCommonViewer().refresh();
dockerExplorerView.showConnectionsOrExplanations();
- });
- SWTUtils.wait(1, TimeUnit.SECONDS);
- }
+ }
+ if (dockerContainersView != null) {
+ dockerContainersView.getViewer().refresh();
+ }
+ });
+ SWTUtils.wait(1, TimeUnit.SECONDS);
}
private static DockerExplorerView getDockerExplorerView(final SWTWorkbenchBot bot) {
@@ -53,4 +59,10 @@ public class DockerConnectionManagerUtils {
.orElse(null);
}
+ private static DockerContainersView getDockerContainersView(final SWTWorkbenchBot bot) {
+ return bot.views().stream().filter(v -> v.getReference().getId().equals(DockerContainersView.VIEW_ID))
+ .map(viewBot -> (DockerContainersView) (viewBot.getViewReference().getView(true))).findFirst()
+ .orElse(null);
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java
new file mode 100644
index 0000000000..c3d2390efe
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.views;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.DockerContainerRefreshManager;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerContainerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TestLoggerRule;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.ui.PlatformUI;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.spotify.docker.client.DockerClient;
+
+/**
+ * Testing the {@link DockerContainersView}
+ */
+public class DockerContainersViewSWTBotTest {
+
+ private SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ private SWTBotView dockerContainersViewBot;
+ private DockerContainersView dockerContainersView;
+ private SWTBotView dockerExplorerBotView;
+
+ @ClassRule
+ public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+
+ @Rule
+ public TestLoggerRule watcher = new TestLoggerRule();
+
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+
+ @Before
+ public void setup() {
+ this.bot = new SWTWorkbenchBot();
+ SWTUtils.asyncExec(() -> {try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .showView(DockerContainersView.VIEW_ID);
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail("Failed to open Docker Explorer view: " + e.getMessage());
+ }});
+ this.dockerContainersViewBot = bot.viewById(DockerContainersView.VIEW_ID);
+ this.dockerContainersView = (DockerContainersView) (dockerContainersViewBot.getViewReference().getView(true));
+ this.dockerExplorerBotView = bot.viewById(DockerExplorerView.VIEW_ID);
+ }
+
+ @Test
+ public void shouldRemoveListenersWhenClosingView() {
+ // given
+ final DockerClient client = MockDockerClientFactory
+ .container(MockDockerContainerFactory.name("angry_bar").status("Stopped").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ // remove the DockerContainerRefreshManager
+ dockerConnection.removeContainerListener(DockerContainerRefreshManager
+ .getInstance());
+ // DockerExplorerView inner classes
+ assertThat(dockerConnection.getContainerListeners()).hasSize(2);
+ // close the Docker Explorer View
+ dockerContainersViewBot.close();
+ // there should be one listener left: DockerExplorerView
+ assertThat(dockerConnection.getContainerListeners()).hasSize(1);
+ }
+
+ @Test
+ public void shouldNotRemoveListenersWhenNoSelectedConnectionBeforeClosingView() {
+ // given
+ dockerExplorerBotView.close();
+ final DockerClient client = MockDockerClientFactory
+ .container(MockDockerContainerFactory.name("angry_bar").status("Stopped").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ // remove the DockerContainerRefreshManager
+ dockerConnection.removeContainerListener(DockerContainerRefreshManager
+ .getInstance());
+ // DockerExplorerView inner classes
+ assertThat(dockerConnection.getContainerListeners()).hasSize(0);
+ // close the Docker Explorer View
+ dockerContainersViewBot.close();
+ // there should be one listener left: DockerExplorerView
+ assertThat(dockerConnection.getContainerListeners()).hasSize(0);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
index 14039b04dd..28101ffa9e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
@@ -578,10 +578,8 @@ public class DockerExplorerViewSWTBotTest {
assertThat(dockerConnection.getImageListeners()).hasSize(1);
// close the Docker Explorer View
dockerExplorerViewBot.close();
- // there should be one listener left: DockerConnectionRefreshManager
+ // there should be no listener left
assertThat(dockerConnection.getContainerListeners()).hasSize(0);
assertThat(dockerConnection.getImageListeners()).hasSize(0);
-
-
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
index da5ede59fd..69c0e785fa 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
@@ -93,6 +93,10 @@ public class DockerContainersView extends ViewPart implements
@Override
public void dispose() {
+ // remove this listener instance registered on the Docker connection
+ if (connection != null) {
+ connection.removeContainerListener(this);
+ }
// stop tracking selection changes in the Docker Explorer view (only)
getSite().getWorkbenchWindow().getSelectionService()
.removeSelectionListener(DockerExplorerView.VIEW_ID, this);

Back to the top