--- /dev/null
+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