summaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-01-14 20:30:30 +0000
committerVaadin Code Review <review@vaadin.com>2013-01-14 20:30:30 +0000
commita0dfe141644d8451e7e304cbdb88c3f2dc01e141 (patch)
tree074eeaba6ed79c391d3317d32bf3c35fd5471813 /uitest/src
parent7e0a8c0e740d80dae89100a406ea9c0063b7ab41 (diff)
parent87bfc97f6fe570ca2414bb6e6c5b27d551905f03 (diff)
downloadvaadin-framework-a0dfe141644d8451e7e304cbdb88c3f2dc01e141.tar.gz
vaadin-framework-a0dfe141644d8451e7e304cbdb88c3f2dc01e141.zip
Merge "Add basic performance test (#10318)"
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java182
-rw-r--r--uitest/src/com/vaadin/tests/util/TestUtils.java21
2 files changed, 203 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java b/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java
new file mode 100644
index 0000000000..b0047d6b62
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java
@@ -0,0 +1,182 @@
+package com.vaadin.tests.performance;
+
+import java.util.Iterator;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.util.TestUtils;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.ComponentContainer;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.themes.Reindeer;
+
+public class BasicPerformanceTest extends UI {
+
+ private final VerticalLayout contentLayout = new VerticalLayout();
+
+ private int clientLimit;
+ private int serverLimit;
+ private String performanceTopic;
+ private final Button reportPerformanceButton = new Button(
+ "Report some performance", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ TestUtils.reportPerformance(performanceTopic, serverLimit,
+ clientLimit);
+ event.getButton().setEnabled(false);
+ }
+ });
+
+ @Override
+ public void init(VaadinRequest request) {
+ setContent(buildMainLayout());
+ updatePerformanceReporting("first load", 100, 100);
+ }
+
+ private void updatePerformanceReporting(String performanceTopic,
+ int serverLimit, int clientLimit) {
+ this.performanceTopic = performanceTopic;
+ this.serverLimit = serverLimit;
+ this.clientLimit = clientLimit;
+ reportPerformanceButton.setCaption("Report performance for "
+ + performanceTopic);
+ reportPerformanceButton.setEnabled(true);
+ }
+
+ private ComponentContainer buildMainLayout() {
+ contentLayout.addComponent(new Label("Content lives here"));
+
+ Panel contentScroller = new Panel(contentLayout);
+ contentScroller.setStyleName(Reindeer.PANEL_LIGHT);
+ contentScroller.setSizeFull();
+
+ TextArea performanceReportArea = new TextArea();
+ performanceReportArea.setWidth("200px");
+ TestUtils.installPerformanceReporting(performanceReportArea);
+
+ VerticalLayout leftBar = new VerticalLayout();
+ leftBar.setSizeUndefined();
+ leftBar.addComponent(new Label("This is the left bar"));
+ leftBar.addComponent(performanceReportArea);
+ leftBar.addComponent(reportPerformanceButton);
+
+ leftBar.addComponent(new Button("Set 20 panels as content",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ popupateContent(contentLayout, 20, true);
+ updatePerformanceReporting("20 panels", 100, 100);
+ }
+ }));
+ leftBar.addComponent(new Button("Set 40 panels as content",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ popupateContent(contentLayout, 40, true);
+ updatePerformanceReporting("40 panels", 100, 100);
+ }
+ }));
+ leftBar.addComponent(new Button("Set 40 layouts as content",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ popupateContent(contentLayout, 40, false);
+ updatePerformanceReporting("40 layouts", 100, 100);
+ }
+ }));
+
+ leftBar.addComponent(new Button("Update all labels",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Iterator<Component> componentIterator = contentLayout
+ .getComponentIterator();
+ while (componentIterator.hasNext()) {
+
+ Iterator<Component> columHolderIterator;
+ Component child = componentIterator.next();
+ if (child instanceof Panel) {
+ columHolderIterator = ((ComponentContainer) ((Panel) child)
+ .getContent()).getComponentIterator();
+ } else {
+ columHolderIterator = ((ComponentContainer) child)
+ .getComponentIterator();
+ }
+ while (columHolderIterator.hasNext()) {
+ VerticalLayout column = (VerticalLayout) columHolderIterator
+ .next();
+ Iterator<Component> columnIterator = column
+ .getComponentIterator();
+ while (columnIterator.hasNext()) {
+ Label label = (Label) columnIterator.next();
+ label.setValue("New value");
+ }
+ }
+ }
+ updatePerformanceReporting("Update labels", 100, 100);
+ }
+ }));
+
+ leftBar.addComponent(new Button("Clear content",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ contentLayout.removeAllComponents();
+ contentLayout.addComponent(new Label("No content"));
+ updatePerformanceReporting("No content", 100, 100);
+ }
+ }));
+
+ HorizontalLayout intermediateLayout = new HorizontalLayout();
+ intermediateLayout.setSizeFull();
+ intermediateLayout.addComponent(leftBar);
+ intermediateLayout.addComponent(contentScroller);
+ intermediateLayout.setExpandRatio(contentScroller, 1);
+
+ VerticalLayout mainLayout = new VerticalLayout();
+ mainLayout.setSizeFull();
+ mainLayout.addComponent(new Label("This is a header"));
+ mainLayout.addComponent(intermediateLayout);
+ mainLayout.setExpandRatio(intermediateLayout, 1);
+
+ return mainLayout;
+ }
+
+ private void popupateContent(VerticalLayout contentLayout, int childCount,
+ boolean wrapInPanel) {
+ contentLayout.removeAllComponents();
+ for (int i = 0; i < childCount; i++) {
+ VerticalLayout left = new VerticalLayout();
+ left.addComponent(new Label("Label 1"));
+ left.addComponent(new Label("Label 2"));
+ left.addComponent(new Label("Label 3"));
+
+ VerticalLayout right = new VerticalLayout();
+ right.addComponent(new Label("Label 4"));
+ right.addComponent(new Label("Label 5"));
+ right.addComponent(new Label("Label 6"));
+
+ HorizontalLayout columns = new HorizontalLayout();
+ columns.addComponent(left);
+ columns.addComponent(right);
+ columns.setHeight(null);
+ columns.setWidth("100%");
+
+ if (wrapInPanel) {
+ Panel panel = new Panel("Data " + i, columns);
+ panel.setWidth("100%");
+ panel.setHeight(null);
+
+ contentLayout.addComponent(panel);
+ } else {
+ contentLayout.addComponent(columns);
+ }
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/util/TestUtils.java b/uitest/src/com/vaadin/tests/util/TestUtils.java
index 62f2cc0be3..6cb6e79c1c 100644
--- a/uitest/src/com/vaadin/tests/util/TestUtils.java
+++ b/uitest/src/com/vaadin/tests/util/TestUtils.java
@@ -2,6 +2,8 @@ package com.vaadin.tests.util;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.ui.JavaScript;
+import com.vaadin.ui.TextArea;
import com.vaadin.ui.UI;
public class TestUtils {
@@ -115,6 +117,25 @@ public class TestUtils {
w.getPage().getJavaScript().execute(script);
}
+ public static void installPerformanceReporting(TextArea targetTextArea) {
+ targetTextArea.setId("performanceTestTarget");
+ JavaScript
+ .eval("window.reportVaadinPerformance = function(topic, serverLimit, clientLimit) {"
+ + "var element = document.getElementById('performanceTestTarget');"
+ + "var text = topic + ': \\n';"
+ + "for(var k in window.vaadin.clients) {"
+ + "var p = window.vaadin.clients[k].getProfilingData();"
+ + "text += ' Server time: ' + (p[3] > serverLimit?'FAIL':'OK') + ' (' + p[3] +')\\n';"
+ + "text += ' Client time: ' + (p[0] > clientLimit?'FAIL':'OK') + ' (' + p[0] +')\\n';"
+ + "}" + "element.value = text;" + "}");
+ }
+
+ public static void reportPerformance(String topic, int serverLimit,
+ int totalLimit) {
+ JavaScript.eval("window.reportVaadinPerformance(\"" + topic + "\", "
+ + serverLimit + ", " + totalLimit + ");");
+ }
+
public static IndexedContainer getISO3166Container() {
IndexedContainer c = new IndexedContainer();
fillIso3166Container(c);