You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicationCloseTest.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.vaadin.tests.application;
  2. import com.vaadin.shared.ui.ContentMode;
  3. import com.vaadin.tests.components.TestBase;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.Label;
  6. import com.vaadin.ui.LegacyWindow;
  7. public class ApplicationCloseTest extends TestBase {
  8. private String memoryConsumer;
  9. @Override
  10. protected void setup() {
  11. Label applications = new Label("Applications in session: <br/>",
  12. ContentMode.HTML);
  13. if (getContext() != null) {
  14. applications.setValue(
  15. applications.getValue() + "App: " + getContext() + "<br/>");
  16. }
  17. applications.setValue(applications.getValue() + "<br/><br/>");
  18. addComponent(applications);
  19. Label thisApp = new Label("This applications: " + this);
  20. Button close = new Button("Close this", event -> {
  21. LegacyWindow ui = (LegacyWindow) event.getButton().getUI();
  22. ui.getApplication().close();
  23. });
  24. StringBuilder sb = new StringBuilder();
  25. // 100 bytes
  26. String str = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
  27. int MB = 5;
  28. for (int i = 0; i < MB * 10000; i++) {
  29. sb.append(str);
  30. }
  31. memoryConsumer = sb.toString();
  32. long totalUsage = Runtime.getRuntime().totalMemory();
  33. String totalUsageString = totalUsage / 1000 / 1000 + "MiB";
  34. Label memoryUsage = new Label(
  35. "Using about " + memoryConsumer.length() / 1000 / 1000
  36. + "MiB memory for this application.<br/>Total memory usage reported as "
  37. + totalUsageString + "<br/>",
  38. ContentMode.HTML);
  39. addComponent(thisApp);
  40. addComponent(memoryUsage);
  41. addComponent(close);
  42. }
  43. @Override
  44. protected String getDescription() {
  45. return "Click close to close the application and open a new one";
  46. }
  47. @Override
  48. protected Integer getTicketNumber() {
  49. return 3732;
  50. }
  51. }