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.2KB

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