summaryrefslogtreecommitdiffstats
path: root/tests/src/com/vaadin/automatedtests/robustness/Robustness.java
blob: 1e8a3766f2396b3219d46485f25ae777580c5868 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.vaadin.automatedtests.robustness;

import com.vaadin.automatedtests.util.Log;
import com.vaadin.automatedtests.util.RandomComponents;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;

public abstract class Robustness extends com.vaadin.Application implements
        Button.ClickListener {

    static int totalCount = 0;

    int count = 0;

    final Window main = new Window("Robustness tests by featurebrowser");

    Button close = new Button("Close application");

    Button remove = new Button("Remove all components");

    Button create = new Button("Create");

    Label label = new Label();

    ComponentContainer stressLayout;

    RandomComponents randomComponents = new RandomComponents();

    @Override
    public void init() {
        createNewView();
    }

    public void createNewView() {
        setMainWindow(main);
        main.setDebugId("MainWindow");
        main.removeAllComponents();

        main.addComponent(label);
        main.addComponent(close);
        main.addComponent(remove);
        main.addComponent(create);
        close.addListener(this);
        remove.addListener(this);
        create.addListener(this);

        remove.setDescription("After this garbage collector should"
                + " be able to collect every component"
                + " inside stressLayout.");

        close.setDebugId("close");
        remove.setDebugId("remove");
        create.setDebugId("create");

    }

    public void buttonClick(ClickEvent event) {
        if (event.getButton() == create) {
            create();
        } else if (event.getButton() == remove) {
            main.removeAllComponents();
            close.removeListener(this);
            remove.removeListener(this);
            create.removeListener(this);
            close = null;
            remove = null;
            create = null;
            label = null;
            stressLayout = null;
            System.out.println("main.getLayout()=" + main.getLayout());
            System.out.println(Log.getMemoryStatistics());
        } else if (event.getButton() == close) {
            System.out.println("Before close, memory statistics:");
            System.out.println(Log.getMemoryStatistics());
            close();
            // Still valueUnbound (session expiration) needs to occur for GC to
            // do its work
            System.out.println("After close, memory statistics:");
            System.out.println(Log.getMemoryStatistics());
        }
    }

    public abstract void create();
}