summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/application/ApplicationCloseTest.java
blob: e4f8552af1a0e272da210400e033b4fc31b3c914 (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
package com.vaadin.tests.application;

import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;

public class ApplicationCloseTest extends TestBase {

    private String memoryConsumer;

    @Override
    protected void setup() {
        Label applications = new Label("Applications in session: <br/>",
                ContentMode.HTML);
        if (getContext() != null) {
            applications.setValue(applications.getValue() + "App: "
                    + getContext() + "<br/>");
        }
        applications.setValue(applications.getValue() + "<br/><br/>");

        addComponent(applications);
        Label thisApp = new Label("This applications: " + this);
        Button close = new Button("Close this", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                event.getButton().getUI().getSession().close();
            }
        });

        StringBuilder sb = new StringBuilder();

        // 100 bytes
        String str = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";

        int MB = 5;
        for (int i = 0; i < MB * 10000; i++) {
            sb.append(str);
        }

        memoryConsumer = sb.toString();
        long totalUsage = Runtime.getRuntime().totalMemory();
        String totalUsageString = totalUsage / 1000 / 1000 + "MiB";
        Label memoryUsage = new Label(
                "Using about "
                        + memoryConsumer.length()
                        / 1000
                        / 1000
                        + "MiB memory for this application.<br/>Total memory usage reported as "
                        + totalUsageString + "<br/>", ContentMode.HTML);

        addComponent(thisApp);
        addComponent(memoryUsage);
        addComponent(close);
    }

    @Override
    protected String getDescription() {
        return "Click close to close the application and open a new one";
    }

    @Override
    protected Integer getTicketNumber() {
        return 3732;
    }

}