Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

MemoryIT.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.performance;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.junit.experimental.categories.Category;
  21. import com.vaadin.testbench.By;
  22. import com.vaadin.testcategory.MeasurementTest;
  23. import com.vaadin.tests.tb3.SingleBrowserTest;
  24. @Category(MeasurementTest.class)
  25. public class MemoryIT extends SingleBrowserTest {
  26. @Test
  27. public void measureMemory() {
  28. printTeamcityStats("grid-v8-one-item-size",
  29. getGridSize(GridMemory.PATH, 1));
  30. printTeamcityStats("grid-v7-one-item-size",
  31. getGridSize(CompatibilityGridMemory.PATH, 1));
  32. printTeamcityStats("grid-v8-100thousand-items-size",
  33. getGridSize(GridMemory.PATH, 100000));
  34. printTeamcityStats("grid-v7-100thousand-items-size",
  35. getGridSize(CompatibilityGridMemory.PATH, 100000));
  36. }
  37. @Override
  38. protected void closeApplication() {
  39. }
  40. private long getGridSize(String path, int itemsCount) {
  41. // Repeat until we get consecutive results within 0.1% of each other
  42. double lastResult = 0;
  43. int stableNumber = 0;
  44. for (int i = 0; i < 500; i++) {
  45. openUI(path, itemsCount);
  46. long currentResult = Long
  47. .parseLong(findElement(By.id("memory")).getText());
  48. close();
  49. if (approx(lastResult, currentResult, 0.001)) {
  50. stableNumber++;
  51. }
  52. lastResult = currentResult;
  53. if (stableNumber == 5) {
  54. return currentResult;
  55. }
  56. }
  57. Assert.fail("Memory size does not stabilize");
  58. return -1;
  59. }
  60. private boolean approx(double num1, double num2, double epsilon) {
  61. double delta = Math.abs(num1 - num2);
  62. double deltaLimit = num2 * epsilon;
  63. return delta < deltaLimit;
  64. }
  65. private void openUI(String path, int itemsNumber) {
  66. getDriver().get(StringUtils.strip(getBaseURL(), "/") + path + "?items="
  67. + itemsNumber);
  68. Assert.assertTrue(isElementPresent(By.className("v-grid")));
  69. }
  70. private void close() {
  71. findElement(By.id("close")).click();
  72. }
  73. private void printTeamcityStats(String key, long value) {
  74. // ##teamcity[buildStatisticValue key=&#39;&lt;valueTypeKey&gt;&#39;
  75. // value=&#39;&lt;value&gt;&#39;]
  76. System.out.println("##teamcity[buildStatisticValue key='" + key
  77. + "' value='" + value + "']");
  78. }
  79. }