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.

Robustness.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.robustness;
  5. import com.vaadin.automatedtests.util.Log;
  6. import com.vaadin.automatedtests.util.RandomComponents;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.ComponentContainer;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.Window;
  11. import com.vaadin.ui.Button.ClickEvent;
  12. public abstract class Robustness extends com.vaadin.Application
  13. implements Button.ClickListener {
  14. static int totalCount = 0;
  15. int count = 0;
  16. final Window main = new Window("Robustness tests by featurebrowser");
  17. Button close = new Button("Close application");
  18. Button remove = new Button("Remove all components");
  19. Button create = new Button("Create");
  20. Label label = new Label();
  21. ComponentContainer stressLayout;
  22. RandomComponents randomComponents = new RandomComponents();
  23. @Override
  24. public void init() {
  25. createNewView();
  26. }
  27. public void createNewView() {
  28. setMainWindow(main);
  29. main.setDebugId("MainWindow");
  30. main.removeAllComponents();
  31. main.addComponent(label);
  32. main.addComponent(close);
  33. main.addComponent(remove);
  34. main.addComponent(create);
  35. close.addListener(this);
  36. remove.addListener(this);
  37. create.addListener(this);
  38. remove.setDescription("After this garbage collector should"
  39. + " be able to collect every component"
  40. + " inside stressLayout.");
  41. close.setDebugId("close");
  42. remove.setDebugId("remove");
  43. create.setDebugId("create");
  44. }
  45. public void buttonClick(ClickEvent event) {
  46. if (event.getButton() == create) {
  47. create();
  48. } else if (event.getButton() == remove) {
  49. main.removeAllComponents();
  50. close.removeListener(this);
  51. remove.removeListener(this);
  52. create.removeListener(this);
  53. close = null;
  54. remove = null;
  55. create = null;
  56. label = null;
  57. stressLayout = null;
  58. System.out.println("main.getLayout()=" + main.getLayout());
  59. System.out.println(Log.getMemoryStatistics());
  60. } else if (event.getButton() == close) {
  61. System.out.println("Before close, memory statistics:");
  62. System.out.println(Log.getMemoryStatistics());
  63. close();
  64. // Still valueUnbound (session expiration) needs to occur for GC to
  65. // do its work
  66. System.out.println("After close, memory statistics:");
  67. System.out.println(Log.getMemoryStatistics());
  68. }
  69. }
  70. public abstract void create();
  71. }