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.

PerformanceTestBasicComponentRendering.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests;
  17. import java.util.Date;
  18. import java.util.Map;
  19. import com.vaadin.server.UserError;
  20. import com.vaadin.shared.ui.ContentMode;
  21. import com.vaadin.tests.components.TestDateField;
  22. import com.vaadin.ui.Button;
  23. import com.vaadin.ui.CustomComponent;
  24. import com.vaadin.ui.Label;
  25. import com.vaadin.ui.TabSheet;
  26. import com.vaadin.ui.VerticalLayout;
  27. import com.vaadin.v7.ui.ComboBox;
  28. import com.vaadin.v7.ui.Table;
  29. import com.vaadin.v7.ui.TextField;
  30. public class PerformanceTestBasicComponentRendering extends CustomComponent {
  31. private final VerticalLayout main;
  32. private final VerticalLayout testContainer;
  33. private Date startTime;
  34. private final Label result;
  35. private static final String DESCRIPTION = "Rendering lots of differend components to stress rendering performance. Visits server after render (due table cache row fetch) and prints client round trip time to a label. More exact render time can be checked from clients debug dialog.";
  36. private static final int INITIAL_COMPONENTS = 10;
  37. public PerformanceTestBasicComponentRendering() {
  38. main = new VerticalLayout();
  39. setCompositionRoot(main);
  40. addInfo();
  41. result = new Label();
  42. main.addComponent(result);
  43. testContainer = new VerticalLayout();
  44. final Table t = TestForTablesInitialColumnWidthLogicRendering
  45. .getTestTable(5, 200);
  46. Table t2 = new Table("Test Table with 199 rows rendered initially") {
  47. @Override
  48. public void changeVariables(Object source,
  49. Map<String, Object> variables) {
  50. super.changeVariables(source, variables);
  51. // end timing on cache row request
  52. endTest();
  53. }
  54. };
  55. t2.setPageLength(199); // render almost all rows at once
  56. t2.setContainerDataSource(t.getContainerDataSource());
  57. testContainer.addComponent(t2);
  58. for (int i = 0; i < INITIAL_COMPONENTS; i++) {
  59. ComboBox cb = new ComboBox("Combobox " + i);
  60. for (int j = 0; j < INITIAL_COMPONENTS; j++) {
  61. cb.addItem("option " + i + " " + j);
  62. }
  63. testContainer.addComponent(cb);
  64. TextField tf = new TextField("TextField " + i);
  65. tf.setDescription("DESC SDKJSDF");
  66. tf.setComponentError(new UserError("dsfjklsdf"));
  67. testContainer.addComponent(tf);
  68. testContainer.addComponent(new TestDateField("DateField" + i));
  69. testContainer.addComponent(new Button("Button" + i));
  70. TabSheet ts = new TabSheet();
  71. for (int j = 0; j < INITIAL_COMPONENTS; j++) {
  72. Label tab = new Label("Tab content " + i + " " + j);
  73. tab.setCaption("Tab " + i + " " + j);
  74. ts.addTab(tab);
  75. }
  76. testContainer.addComponent(ts);
  77. }
  78. main.addComponent(testContainer);
  79. startTest();
  80. }
  81. public void startTest() {
  82. startTime = new Date();
  83. }
  84. public void endTest() {
  85. final long millis = (new Date()).getTime() - startTime.getTime();
  86. final Float f = new Float(millis / 1000.0);
  87. result.setValue("Test completed in " + f + " seconds");
  88. }
  89. private void addInfo() {
  90. main.addComponent(new Label(DESCRIPTION, ContentMode.HTML));
  91. }
  92. }