diff options
author | Artur Signell <artur@vaadin.com> | 2013-04-18 01:08:55 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-04-18 11:36:36 +0300 |
commit | 5efb8f01e79bac95955b189d5999ba4ae544a137 (patch) | |
tree | 35706ba3527bdc0c0094a334e0afcd8ba148f014 /uitest/src/com/vaadin/tests/widgetset | |
parent | ff03ede4439d992371ddcbc4df510cdf85ad41db (diff) | |
download | vaadin-framework-5efb8f01e79bac95955b189d5999ba4ae544a137.tar.gz vaadin-framework-5efb8f01e79bac95955b189d5999ba4ae544a137.zip |
Simple speed test for testing roundtrips/s in various browsers
Change-Id: Id6e96e8d115b02c79038396dfada5c04e0f451ed
Diffstat (limited to 'uitest/src/com/vaadin/tests/widgetset')
3 files changed, 190 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/RoundTripTesterConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/RoundTripTesterConnector.java new file mode 100644 index 0000000000..94972d92f4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/RoundTripTesterConnector.java @@ -0,0 +1,106 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.client; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.Duration; +import com.google.gwt.user.client.ui.HTML; +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.RoundTripTester; + +@Connect(RoundTripTester.class) +public class RoundTripTesterConnector extends AbstractComponentConnector { + + private double lastPrintedTime = -1; + private int receivedPings = 0; + private List<Double> throughputData = new ArrayList<Double>(); + private int payloadSize = 0; + + @Override + protected void init() { + super.init(); + registerRpc(RoundTripTesterRpc.class, new RoundTripTesterRpc() { + + @Override + public void ping(int nr, String payload) { + getRpcProxy(RoundTripTesterRpc.class).ping(nr + 1, payload); + payloadSize = payload.length(); + + double now = Duration.currentTimeMillis(); + if (lastPrintedTime == -1) { + lastPrintedTime = now; + return; + } + receivedPings++; + + if (now - lastPrintedTime > 1000) { + double roundtripsPerSecond = receivedPings + / (now - lastPrintedTime) * 1000; + throughputData.add(roundtripsPerSecond); + getWidget().setText( + roundtripsPerSecond + " roundtrips/second"); + + lastPrintedTime = now; + receivedPings = 0; + } + + } + + @Override + public void done() { + String result = "Test results for payload of size " + + payloadSize + ":"; + double max = -1; + double min = 1239482038939.0; + double avg = 0; + + for (Double throughput : throughputData) { + if (throughput > max) { + max = throughput; + } + if (throughput < min) { + min = throughput; + } + + avg += throughput; + } + avg /= throughputData.size(); + + for (Double throughput : throughputData) { + result += "<br/>" + formatThroughput(throughput); + } + result += "<br/>Max: " + formatThroughput(max); + result += "<br/>Min: " + formatThroughput(min); + result += "<br/>Average: " + formatThroughput(avg); + getWidget().setHTML(result); + getRpcProxy(RoundTripTesterRpc.class).done(); + } + + private String formatThroughput(double throughput) { + return throughput + " roundtrips / second"; + } + }); + } + + @Override + public HTML getWidget() { + return (HTML) super.getWidget(); + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/RoundTripTesterRpc.java b/uitest/src/com/vaadin/tests/widgetset/client/RoundTripTesterRpc.java new file mode 100644 index 0000000000..24c981e0c2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/RoundTripTesterRpc.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.client; + +import com.vaadin.shared.communication.ClientRpc; +import com.vaadin.shared.communication.ServerRpc; + +public interface RoundTripTesterRpc extends ServerRpc, ClientRpc { + public void ping(int nr, String payload); + + public void done(); +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/RoundTripTester.java b/uitest/src/com/vaadin/tests/widgetset/server/RoundTripTester.java new file mode 100644 index 0000000000..d16a7a7811 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/RoundTripTester.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.server; + +import com.vaadin.tests.util.LoremIpsum; +import com.vaadin.tests.widgetset.client.RoundTripTesterRpc; +import com.vaadin.ui.AbstractComponent; + +public class RoundTripTester extends AbstractComponent { + private long testStart = 0; + private long testEnd = 0; + + public RoundTripTester() { + registerRpc(new RoundTripTesterRpc() { + @Override + public void ping(int nr, String payload) { + if (System.currentTimeMillis() < testEnd) { + getRpcProxy(RoundTripTesterRpc.class).ping(nr + 1, payload); + } else { + getRpcProxy(RoundTripTesterRpc.class).done(); + } + } + + @Override + public void done() { + } + }); + } + + public void start(long testDuration, int payloadSize) { + testStart = System.currentTimeMillis(); + testEnd = testStart + testDuration; + getRpcProxy(RoundTripTesterRpc.class).ping(1, generatePayload(payloadSize)); + } + + private String generatePayload(int payloadSize) { + StringBuilder sb = new StringBuilder(); + while (payloadSize > 10000) { + payloadSize -= 10000; + sb.append(LoremIpsum.get(10000)); + } + sb.append(LoremIpsum.get(payloadSize)); + return sb.toString(); + } + +} |