]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged test case and fix for #3732 - "Programmatically closed applications remain...
authorArtur Signell <artur.signell@itmill.com>
Thu, 19 Nov 2009 08:11:20 +0000 (08:11 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 19 Nov 2009 08:11:20 +0000 (08:11 +0000)
svn changeset:9888/svn branch:6.2

src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/WebApplicationContext.java
tests/src/com/vaadin/tests/application/ApplicationCloseTest.java [new file with mode: 0644]

index 0300e26a9439b3448082ba892ce612e2d18a55ed..692f30dc92b1282565933207d7186ae7cf40b216 100644 (file)
@@ -1928,8 +1928,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
         if (session != null) {
             WebApplicationContext context = WebApplicationContext
                     .getApplicationContext(session);
-            context.applicationToAjaxAppMgrMap.remove(application);
-            // FIXME: Move to WebApplicationContext
             context.removeApplication(application);
         }
     }
index e49c95d905b751db1288b55bdddd8837cf6a83ed..2e114a38dc8a327dfa8e7cb7cc11a7beae2faaa2 100644 (file)
@@ -193,6 +193,7 @@ public class WebApplicationContext implements ApplicationContext,
 
     protected void removeApplication(Application application) {
         applications.remove(application);
+        applicationToAjaxAppMgrMap.remove(application);
     }
 
     protected void addApplication(Application application) {
@@ -216,7 +217,6 @@ public class WebApplicationContext implements ApplicationContext,
             while (!applications.isEmpty()) {
                 final Application app = applications.iterator().next();
                 app.close();
-                applicationToAjaxAppMgrMap.remove(app);
                 removeApplication(app);
             }
         } catch (Exception e) {
diff --git a/tests/src/com/vaadin/tests/application/ApplicationCloseTest.java b/tests/src/com/vaadin/tests/application/ApplicationCloseTest.java
new file mode 100644 (file)
index 0000000..0777f68
--- /dev/null
@@ -0,0 +1,70 @@
+package com.vaadin.tests.application;\r
+\r
+import com.vaadin.Application;\r
+import com.vaadin.terminal.gwt.server.WebApplicationContext;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+\r
+public class ApplicationCloseTest extends TestBase {\r
+\r
+    private String memoryConsumer;\r
+\r
+    @Override\r
+    protected void setup() {\r
+        Label applications = new Label("Applications in session: <br/>",\r
+                Label.CONTENT_XHTML);\r
+        for (Application a : ((WebApplicationContext) getContext())\r
+                .getApplications()) {\r
+            applications.setValue(applications.getValue() + "App: " + a\r
+                    + "<br/>");\r
+        }\r
+        applications.setValue(applications.getValue() + "<br/><br/>");\r
+\r
+        addComponent(applications);\r
+        Label thisApp = new Label("This applications: " + this);\r
+        Button close = new Button("Close this", new Button.ClickListener() {\r
+\r
+            public void buttonClick(ClickEvent event) {\r
+                event.getButton().getApplication().close();\r
+            }\r
+        });\r
+\r
+        StringBuilder sb = new StringBuilder();\r
+\r
+        // 100 bytes\r
+        String str = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";\r
+\r
+        int MB = 5;\r
+        for (int i = 0; i < MB * 10000; i++) {\r
+            sb.append(str);\r
+        }\r
+\r
+        memoryConsumer = sb.toString();\r
+        long totalUsage = Runtime.getRuntime().totalMemory();\r
+        String totalUsageString = totalUsage / 1000 / 1000 + "MiB";\r
+        Label memoryUsage = new Label(\r
+                "Using about "\r
+                        + memoryConsumer.length()\r
+                        / 1000\r
+                        / 1000\r
+                        + "MiB memory for this application.<br/>Total memory usage reported as "\r
+                        + totalUsageString + "<br/>", Label.CONTENT_XHTML);\r
+\r
+        addComponent(thisApp);\r
+        addComponent(memoryUsage);\r
+        addComponent(close);\r
+    }\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "Click close to close the application and open a new one";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return 3732;\r
+    }\r
+\r
+}\r