Moving the GC related tests into separate classes whose name starts with GC prefix
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Mon Dec 08 15:48:51 2014 +0100
1.3 @@ -0,0 +1,111 @@
1.4 +/**
1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 + *
1.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
1.8 + *
1.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
1.10 + * Other names may be trademarks of their respective owners.
1.11 + *
1.12 + * The contents of this file are subject to the terms of either the GNU
1.13 + * General Public License Version 2 only ("GPL") or the Common
1.14 + * Development and Distribution License("CDDL") (collectively, the
1.15 + * "License"). You may not use this file except in compliance with the
1.16 + * License. You can obtain a copy of the License at
1.17 + * http://www.netbeans.org/cddl-gplv2.html
1.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.19 + * specific language governing permissions and limitations under the
1.20 + * License. When distributing the software, include this License Header
1.21 + * Notice in each file and include the License file at
1.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
1.23 + * particular file as subject to the "Classpath" exception as provided
1.24 + * by Oracle in the GPL Version 2 section of the License file that
1.25 + * accompanied this code. If applicable, add the following below the
1.26 + * License Header, with the fields enclosed by brackets [] replaced by
1.27 + * your own identifying information:
1.28 + * "Portions Copyrighted [year] [name of copyright owner]"
1.29 + *
1.30 + * Contributor(s):
1.31 + *
1.32 + * The Original Software is NetBeans. The Initial Developer of the Original
1.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
1.34 + *
1.35 + * If you wish your version of this file to be governed by only the CDDL
1.36 + * or only the GPL Version 2, indicate your decision by adding
1.37 + * "[Contributor] elects to include this software in this distribution
1.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.39 + * single choice of license, a recipient has the option to distribute
1.40 + * your version of this file under either the CDDL, the GPL Version 2 or
1.41 + * to extend the choice of license to its licensees as provided above.
1.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
1.43 + * Version 2 license, then the option applies only if the new code is
1.44 + * made subject to such option by the copyright holder.
1.45 + */
1.46 +package net.java.html.js.tests;
1.47 +
1.48 +import java.io.StringReader;
1.49 +import java.lang.ref.Reference;
1.50 +import java.lang.ref.WeakReference;
1.51 +import java.util.Arrays;
1.52 +import java.util.concurrent.Callable;
1.53 +import org.netbeans.html.boot.spi.Fn;
1.54 +import org.netbeans.html.json.tck.KOTest;
1.55 +
1.56 +/**
1.57 + *
1.58 + * @author Jaroslav Tulach
1.59 + */
1.60 +public class GCBodyTest {
1.61 + @KOTest public void callbackWithParameters() throws InterruptedException {
1.62 + Sum s = new Sum();
1.63 + int res = Bodies.sumIndirect(s);
1.64 + assert res == 42 : "Expecting 42";
1.65 + Reference<?> ref = new WeakReference<Object>(s);
1.66 + s = null;
1.67 + assertGC(ref, "Can disappear!");
1.68 + }
1.69 +
1.70 + @KOTest public void holdObjectAndReleaseObject() throws InterruptedException {
1.71 + Sum s = new Sum();
1.72 + Object obj = Bodies.instance(0);
1.73 + Bodies.setX(obj, s);
1.74 +
1.75 + Reference<?> ref = new WeakReference<Object>(s);
1.76 + s = null;
1.77 + assertNotGC(ref, "Cannot disappear!");
1.78 +
1.79 + Bodies.setX(obj, null);
1.80 +
1.81 + assertGC(ref, "Can disappear!");
1.82 + }
1.83 +
1.84 + private static void assertGC(Reference<?> ref, String msg) throws InterruptedException {
1.85 + for (int i = 0; i < 100; i++) {
1.86 + if (ref.get() == null) {
1.87 + return;
1.88 + }
1.89 + int size = Bodies.gc(Math.pow(2.0, i));
1.90 + try {
1.91 + System.gc();
1.92 + System.runFinalization();
1.93 + } catch (Error err) {
1.94 + err.printStackTrace();
1.95 + }
1.96 + }
1.97 + throw new OutOfMemoryError(msg);
1.98 + }
1.99 +
1.100 + private static void assertNotGC(Reference<?> ref, String msg) throws InterruptedException {
1.101 + for (int i = 0; i < 10; i++) {
1.102 + if (ref.get() == null) {
1.103 + throw new IllegalStateException(msg);
1.104 + }
1.105 + int size = Bodies.gc(Math.pow(2.0, i));
1.106 + try {
1.107 + System.gc();
1.108 + System.runFinalization();
1.109 + } catch (Error err) {
1.110 + err.printStackTrace();
1.111 + }
1.112 + }
1.113 + }
1.114 +}
2.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Wed Nov 12 11:35:11 2014 +0100
2.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Mon Dec 08 15:48:51 2014 +0100
2.3 @@ -217,23 +217,6 @@
2.4 Sum s = new Sum();
2.5 int res = Bodies.sumIndirect(s);
2.6 assert res == 42 : "Expecting 42";
2.7 - Reference<?> ref = new WeakReference<Object>(s);
2.8 - s = null;
2.9 - assertGC(ref, "Can disappear!");
2.10 - }
2.11 -
2.12 - @KOTest public void holdObjectAndReleaseObject() throws InterruptedException {
2.13 - Sum s = new Sum();
2.14 - Object obj = Bodies.instance(0);
2.15 - Bodies.setX(obj, s);
2.16 -
2.17 - Reference<?> ref = new WeakReference<Object>(s);
2.18 - s = null;
2.19 - assertNotGC(ref, "Cannot disappear!");
2.20 -
2.21 - Bodies.setX(obj, null);
2.22 -
2.23 - assertGC(ref, "Can disappear!");
2.24 }
2.25
2.26 @KOTest public void selectFromStringJavaArray() {
2.27 @@ -421,35 +404,4 @@
2.28 return Boolean.TRUE;
2.29 }
2.30 }
2.31 -
2.32 - private static void assertGC(Reference<?> ref, String msg) throws InterruptedException {
2.33 - for (int i = 0; i < 100; i++) {
2.34 - if (ref.get() == null) {
2.35 - return;
2.36 - }
2.37 - int size = Bodies.gc(Math.pow(2.0, i));
2.38 - try {
2.39 - System.gc();
2.40 - System.runFinalization();
2.41 - } catch (Error err) {
2.42 - err.printStackTrace();
2.43 - }
2.44 - }
2.45 - throw new OutOfMemoryError(msg);
2.46 - }
2.47 -
2.48 - private static void assertNotGC(Reference<?> ref, String msg) throws InterruptedException {
2.49 - for (int i = 0; i < 10; i++) {
2.50 - if (ref.get() == null) {
2.51 - throw new IllegalStateException(msg);
2.52 - }
2.53 - int size = Bodies.gc(Math.pow(2.0, i));
2.54 - try {
2.55 - System.gc();
2.56 - System.runFinalization();
2.57 - } catch (Error err) {
2.58 - err.printStackTrace();
2.59 - }
2.60 - }
2.61 - }
2.62 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java Mon Dec 08 15:48:51 2014 +0100
3.3 @@ -0,0 +1,138 @@
3.4 +/**
3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.6 + *
3.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
3.8 + *
3.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.10 + * Other names may be trademarks of their respective owners.
3.11 + *
3.12 + * The contents of this file are subject to the terms of either the GNU
3.13 + * General Public License Version 2 only ("GPL") or the Common
3.14 + * Development and Distribution License("CDDL") (collectively, the
3.15 + * "License"). You may not use this file except in compliance with the
3.16 + * License. You can obtain a copy of the License at
3.17 + * http://www.netbeans.org/cddl-gplv2.html
3.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.19 + * specific language governing permissions and limitations under the
3.20 + * License. When distributing the software, include this License Header
3.21 + * Notice in each file and include the License file at
3.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.23 + * particular file as subject to the "Classpath" exception as provided
3.24 + * by Oracle in the GPL Version 2 section of the License file that
3.25 + * accompanied this code. If applicable, add the following below the
3.26 + * License Header, with the fields enclosed by brackets [] replaced by
3.27 + * your own identifying information:
3.28 + * "Portions Copyrighted [year] [name of copyright owner]"
3.29 + *
3.30 + * Contributor(s):
3.31 + *
3.32 + * The Original Software is NetBeans. The Initial Developer of the Original
3.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
3.34 + *
3.35 + * If you wish your version of this file to be governed by only the CDDL
3.36 + * or only the GPL Version 2, indicate your decision by adding
3.37 + * "[Contributor] elects to include this software in this distribution
3.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
3.39 + * single choice of license, a recipient has the option to distribute
3.40 + * your version of this file under either the CDDL, the GPL Version 2 or
3.41 + * to extend the choice of license to its licensees as provided above.
3.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
3.43 + * Version 2 license, then the option applies only if the new code is
3.44 + * made subject to such option by the copyright holder.
3.45 + */
3.46 +package net.java.html.json.tests;
3.47 +
3.48 +import java.lang.ref.Reference;
3.49 +import java.lang.ref.WeakReference;
3.50 +import net.java.html.BrwsrCtx;
3.51 +import net.java.html.json.Model;
3.52 +import net.java.html.json.Models;
3.53 +import net.java.html.json.Property;
3.54 +import org.netbeans.html.json.tck.KOTest;
3.55 +
3.56 +@Model(className = "GC", properties = {
3.57 + @Property(name = "all", type = Fullname.class, array = true)
3.58 +})
3.59 +public class GCKnockoutTest {
3.60 + @Model(className = "Fullname", properties = {
3.61 + @Property(name = "firstName", type = String.class),
3.62 + @Property(name = "lastName", type = String.class)
3.63 + })
3.64 + static class FullnameCntrl {
3.65 + }
3.66 +
3.67 + @KOTest public void noLongerNeededArrayElementsCanDisappear() throws Exception {
3.68 + BrwsrCtx ctx = Utils.newContext(GCKnockoutTest.class);
3.69 + Object exp = Utils.exposeHTML(GCKnockoutTest.class,
3.70 + "<ul id='ul' data-bind='foreach: all'>\n"
3.71 + + " <li data-bind='text: firstName'/>\n"
3.72 + + "</ul>\n"
3.73 + );
3.74 + try {
3.75 + GC m = Models.bind(new GC(), ctx);
3.76 + m.getAll().add(new Fullname("Jarda", "Tulach"));
3.77 + m.applyBindings();
3.78 +
3.79 + int cnt = Utils.countChildren(GCKnockoutTest.class, "ul");
3.80 + assert cnt == 1 : "One child, but was " + cnt;
3.81 +
3.82 + m.getAll().add(new Fullname("HTML", "Java"));
3.83 +
3.84 + cnt = Utils.countChildren(GCKnockoutTest.class, "ul");
3.85 + assert cnt == 2 : "Now two " + cnt;
3.86 +
3.87 + Fullname removed = m.getAll().get(0);
3.88 + m.getAll().remove(0);
3.89 +
3.90 + cnt = Utils.countChildren(GCKnockoutTest.class, "ul");
3.91 + assert cnt == 1 : "Again One " + cnt;
3.92 +
3.93 + Reference<?> ref = new WeakReference<Object>(removed);
3.94 + removed = null;
3.95 + assertGC(ref, "Can removed object disappear?");
3.96 +
3.97 + ref = new WeakReference<Object>(m);
3.98 + m = null;
3.99 + assertNotGC(ref, "Root model cannot GC");
3.100 + } finally {
3.101 + Utils.exposeHTML(GCKnockoutTest.class, "");
3.102 + }
3.103 +
3.104 + }
3.105 +
3.106 + private void assertGC(Reference<?> ref, String msg) throws Exception {
3.107 + for (int i = 0; i < 100; i++) {
3.108 + if (ref.get() == null) {
3.109 + return;
3.110 + }
3.111 + String gc = "var max = arguments[0];\n"
3.112 + + "var arr = [];\n"
3.113 + + "for (var i = 0; i < max; i++) {\n"
3.114 + + " arr.push(i);\n"
3.115 + + "}\n"
3.116 + + "return arr.length;";
3.117 + Object cnt = Utils.executeScript(GCKnockoutTest.class, gc, Math.pow(2.0, i));
3.118 + System.gc();
3.119 + System.runFinalization();
3.120 + }
3.121 + throw new OutOfMemoryError(msg);
3.122 + }
3.123 +
3.124 + private void assertNotGC(Reference<?> ref, String msg) throws Exception {
3.125 + for (int i = 0; i < 10; i++) {
3.126 + if (ref.get() == null) {
3.127 + throw new IllegalStateException(msg);
3.128 + }
3.129 + String gc = "var max = arguments[0];\n"
3.130 + + "var arr = [];\n"
3.131 + + "for (var i = 0; i < max; i++) {\n"
3.132 + + " arr.push(i);\n"
3.133 + + "}\n"
3.134 + + "return arr.length;";
3.135 + Object cnt = Utils.executeScript(GCKnockoutTest.class, gc, Math.pow(2.0, i));
3.136 + System.gc();
3.137 + System.runFinalization();
3.138 + }
3.139 + }
3.140 +
3.141 +}
4.1 --- a/json-tck/src/main/java/net/java/html/json/tests/GCTest.java Wed Nov 12 11:35:11 2014 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,138 +0,0 @@
4.4 -/**
4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 - *
4.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
4.8 - *
4.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
4.10 - * Other names may be trademarks of their respective owners.
4.11 - *
4.12 - * The contents of this file are subject to the terms of either the GNU
4.13 - * General Public License Version 2 only ("GPL") or the Common
4.14 - * Development and Distribution License("CDDL") (collectively, the
4.15 - * "License"). You may not use this file except in compliance with the
4.16 - * License. You can obtain a copy of the License at
4.17 - * http://www.netbeans.org/cddl-gplv2.html
4.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.19 - * specific language governing permissions and limitations under the
4.20 - * License. When distributing the software, include this License Header
4.21 - * Notice in each file and include the License file at
4.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
4.23 - * particular file as subject to the "Classpath" exception as provided
4.24 - * by Oracle in the GPL Version 2 section of the License file that
4.25 - * accompanied this code. If applicable, add the following below the
4.26 - * License Header, with the fields enclosed by brackets [] replaced by
4.27 - * your own identifying information:
4.28 - * "Portions Copyrighted [year] [name of copyright owner]"
4.29 - *
4.30 - * Contributor(s):
4.31 - *
4.32 - * The Original Software is NetBeans. The Initial Developer of the Original
4.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
4.34 - *
4.35 - * If you wish your version of this file to be governed by only the CDDL
4.36 - * or only the GPL Version 2, indicate your decision by adding
4.37 - * "[Contributor] elects to include this software in this distribution
4.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.39 - * single choice of license, a recipient has the option to distribute
4.40 - * your version of this file under either the CDDL, the GPL Version 2 or
4.41 - * to extend the choice of license to its licensees as provided above.
4.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
4.43 - * Version 2 license, then the option applies only if the new code is
4.44 - * made subject to such option by the copyright holder.
4.45 - */
4.46 -package net.java.html.json.tests;
4.47 -
4.48 -import java.lang.ref.Reference;
4.49 -import java.lang.ref.WeakReference;
4.50 -import net.java.html.BrwsrCtx;
4.51 -import net.java.html.json.Model;
4.52 -import net.java.html.json.Models;
4.53 -import net.java.html.json.Property;
4.54 -import org.netbeans.html.json.tck.KOTest;
4.55 -
4.56 -@Model(className = "GC", properties = {
4.57 - @Property(name = "all", type = Fullname.class, array = true)
4.58 -})
4.59 -public class GCTest {
4.60 - @Model(className = "Fullname", properties = {
4.61 - @Property(name = "firstName", type = String.class),
4.62 - @Property(name = "lastName", type = String.class)
4.63 - })
4.64 - static class FullnameCntrl {
4.65 - }
4.66 -
4.67 - @KOTest public void noLongerNeededArrayElementsCanDisappear() throws Exception {
4.68 - BrwsrCtx ctx = Utils.newContext(GCTest.class);
4.69 - Object exp = Utils.exposeHTML(GCTest.class,
4.70 - "<ul id='ul' data-bind='foreach: all'>\n"
4.71 - + " <li data-bind='text: firstName'/>\n"
4.72 - + "</ul>\n"
4.73 - );
4.74 - try {
4.75 - GC m = Models.bind(new GC(), ctx);
4.76 - m.getAll().add(new Fullname("Jarda", "Tulach"));
4.77 - m.applyBindings();
4.78 -
4.79 - int cnt = Utils.countChildren(GCTest.class, "ul");
4.80 - assert cnt == 1 : "One child, but was " + cnt;
4.81 -
4.82 - m.getAll().add(new Fullname("HTML", "Java"));
4.83 -
4.84 - cnt = Utils.countChildren(GCTest.class, "ul");
4.85 - assert cnt == 2 : "Now two " + cnt;
4.86 -
4.87 - Fullname removed = m.getAll().get(0);
4.88 - m.getAll().remove(0);
4.89 -
4.90 - cnt = Utils.countChildren(GCTest.class, "ul");
4.91 - assert cnt == 1 : "Again One " + cnt;
4.92 -
4.93 - Reference<?> ref = new WeakReference<Object>(removed);
4.94 - removed = null;
4.95 - assertGC(ref, "Can removed object disappear?");
4.96 -
4.97 - ref = new WeakReference<Object>(m);
4.98 - m = null;
4.99 - assertNotGC(ref, "Root model cannot GC");
4.100 - } finally {
4.101 - Utils.exposeHTML(GCTest.class, "");
4.102 - }
4.103 -
4.104 - }
4.105 -
4.106 - private void assertGC(Reference<?> ref, String msg) throws Exception {
4.107 - for (int i = 0; i < 100; i++) {
4.108 - if (ref.get() == null) {
4.109 - return;
4.110 - }
4.111 - String gc = "var max = arguments[0];\n"
4.112 - + "var arr = [];\n"
4.113 - + "for (var i = 0; i < max; i++) {\n"
4.114 - + " arr.push(i);\n"
4.115 - + "}\n"
4.116 - + "return arr.length;";
4.117 - Object cnt = Utils.executeScript(GCTest.class, gc, Math.pow(2.0, i));
4.118 - System.gc();
4.119 - System.runFinalization();
4.120 - }
4.121 - throw new OutOfMemoryError(msg);
4.122 - }
4.123 -
4.124 - private void assertNotGC(Reference<?> ref, String msg) throws Exception {
4.125 - for (int i = 0; i < 10; i++) {
4.126 - if (ref.get() == null) {
4.127 - throw new IllegalStateException(msg);
4.128 - }
4.129 - String gc = "var max = arguments[0];\n"
4.130 - + "var arr = [];\n"
4.131 - + "for (var i = 0; i < max; i++) {\n"
4.132 - + " arr.push(i);\n"
4.133 - + "}\n"
4.134 - + "return arr.length;";
4.135 - Object cnt = Utils.executeScript(GCTest.class, gc, Math.pow(2.0, i));
4.136 - System.gc();
4.137 - System.runFinalization();
4.138 - }
4.139 - }
4.140 -
4.141 -}
5.1 --- a/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java Wed Nov 12 11:35:11 2014 +0100
5.2 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java Mon Dec 08 15:48:51 2014 +0100
5.3 @@ -42,6 +42,7 @@
5.4 */
5.5 package org.netbeans.html.json.tck;
5.6
5.7 +import net.java.html.js.tests.GCBodyTest;
5.8 import net.java.html.js.tests.JavaScriptBodyTest;
5.9 import org.netbeans.html.boot.spi.Fn;
5.10 import org.netbeans.html.boot.spi.Fn.Presenter;
5.11 @@ -65,7 +66,7 @@
5.12 */
5.13 protected static Class<?>[] testClasses() {
5.14 return new Class[] {
5.15 - JavaScriptBodyTest.class
5.16 + JavaScriptBodyTest.class, GCBodyTest.class
5.17 };
5.18 }
5.19
6.1 --- a/json-tck/src/main/java/org/netbeans/html/json/tck/KnockoutTCK.java Wed Nov 12 11:35:11 2014 +0100
6.2 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/KnockoutTCK.java Mon Dec 08 15:48:51 2014 +0100
6.3 @@ -46,7 +46,7 @@
6.4 import java.util.Map;
6.5 import net.java.html.BrwsrCtx;
6.6 import net.java.html.json.tests.ConvertTypesTest;
6.7 -import net.java.html.json.tests.GCTest;
6.8 +import net.java.html.json.tests.GCKnockoutTest;
6.9 import net.java.html.json.tests.JSONTest;
6.10 import net.java.html.json.tests.KnockoutTest;
6.11 import net.java.html.json.tests.MinesTest;
6.12 @@ -126,7 +126,7 @@
6.13 MinesTest.class,
6.14 OperationsTest.class,
6.15 WebSocketTest.class,
6.16 - GCTest.class
6.17 + GCKnockoutTest.class
6.18 };
6.19 }
6.20