|
| 1 | +/* |
| 2 | + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | + |
| 26 | +package test.robot.javafx.scene; |
| 27 | + |
| 28 | +import javafx.geometry.Insets; |
| 29 | +import javafx.scene.Scene; |
| 30 | +import javafx.scene.layout.HBox; |
| 31 | +import javafx.scene.layout.BorderPane; |
| 32 | +import javafx.scene.text.Text; |
| 33 | +import javafx.stage.Stage; |
| 34 | + |
| 35 | +import org.junit.Test; |
| 36 | +import test.robot.testharness.VisualTestBase; |
| 37 | +import static org.junit.Assert.assertTrue; |
| 38 | + |
| 39 | +/** |
| 40 | + * This test is based on the test case reported in JDK-8209830 |
| 41 | + * |
| 42 | + * Redundant CSS Re-application was avoided in JDK-8193445. |
| 43 | + * It results in faster application of CSS on Controls (Nodes). In turn, |
| 44 | + * resulting in improved Node creation/addition time to a Scene. |
| 45 | + * |
| 46 | + * The goal of this test is *NOT* to measure absolute performance, but to show |
| 47 | + * creating and adding 300 Nodes to a scene does not take more than a |
| 48 | + * particular threshold of time. |
| 49 | + * |
| 50 | + * The selected thresold is larger than actual observed time. |
| 51 | + * It is not a benchmark value. It is good enough to catch the regression |
| 52 | + * in performance, if any. |
| 53 | + */ |
| 54 | + |
| 55 | +public class CSSPerf_JDK8193445Test extends VisualTestBase { |
| 56 | + |
| 57 | + private Stage testStage; |
| 58 | + private Scene testScene; |
| 59 | + private BorderPane pane = new BorderPane(); |
| 60 | + private long mSec = 0; |
| 61 | + |
| 62 | + @Test(timeout = 15000) |
| 63 | + public void testTimeForAdding300NodesToScene() { |
| 64 | + runAndWait(() -> { |
| 65 | + testStage = getStage(); |
| 66 | + testScene = new Scene(pane); |
| 67 | + testStage.setScene(testScene); |
| 68 | + testStage.show(); |
| 69 | + }); |
| 70 | + |
| 71 | + waitFirstFrame(); |
| 72 | + |
| 73 | + // Measure time to create and add 300 Nodes to Scene |
| 74 | + runAndWait(() -> { |
| 75 | + long startTime = System.currentTimeMillis(); |
| 76 | + |
| 77 | + HBox hbox = new HBox(); |
| 78 | + for (int i = 0; i < 300; i++) { |
| 79 | + hbox = new HBox(new Text("y"), hbox); |
| 80 | + final HBox h = hbox; |
| 81 | + h.setPadding(new Insets(1)); |
| 82 | + } |
| 83 | + pane.setCenter(hbox); |
| 84 | + |
| 85 | + long endTime = System.currentTimeMillis(); |
| 86 | + |
| 87 | + mSec = endTime - startTime; |
| 88 | + }); |
| 89 | + |
| 90 | + System.out.println("Time to create and add 300 nodes to a Scene = " + mSec + " mSec"); |
| 91 | + |
| 92 | + // NOTE : 400 mSec is not a benchmark value |
| 93 | + // It is good enough to catch the regression in performance, if any |
| 94 | + assertTrue("Time to add 300 Nodes is more than 400 mSec", mSec < 400); |
| 95 | + } |
| 96 | +} |
0 commit comments