-/*\r
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
- *\r
- * This code is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU General Public License version 2 only, as\r
- * published by the Free Software Foundation.\r
- *\r
- * This code is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
- * version 2 for more details (a copy is included in the LICENSE file that\r
- * accompanied this code).\r
- *\r
- * You should have received a copy of the GNU General Public License version\r
- * 2 along with this work; if not, write to the Free Software Foundation,\r
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
- * or visit www.oracle.com if you need additional information or have any\r
- * questions.\r
- *\r
- */\r
-package com.github.dcevm.test.fields;\r
-\r
-import com.github.dcevm.test.TestUtil;\r
-import com.github.dcevm.test.category.Full;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.experimental.categories.Category;\r
-\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
-import static org.junit.Assert.assertEquals;\r
-\r
-/**\r
- * Tests for accessing a deleted field. In the first scenario, the field is deleted from the class.\r
- * In the second scenario, it is deleted because of a changed subtype relationship.\r
- *\r
- * @author Thomas Wuerthinger\r
- */\r
-public class AccessDeletedFieldTest {\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- __toVersion__(0);\r
- }\r
-\r
- // Version 0\r
- public static class A {\r
-\r
- public int x;\r
-\r
- int getFieldInOldCode() {\r
- \r
- __toVersion__(1);\r
-\r
- // This field does no longer exist\r
- return x;\r
- }\r
- }\r
-\r
- public static class B extends A {\r
- }\r
-\r
- // Version 1\r
- public static class A___1 {\r
- }\r
-\r
- // Version 2\r
- public static class B___2 {\r
- }\r
-\r
- // Method to enforce cast (otherwise bytecodes become invalid in version 2)\r
- public static A convertBtoA(Object b) {\r
- return (A) b;\r
- }\r
-\r
- @Test\r
- public void testOldCodeAccessesDeletedField() {\r
-\r
- assert __version__() == 0;\r
-\r
- final A a = new A();\r
- a.x = 1;\r
-\r
- TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
- @Override\r
- public void run() {\r
- assertEquals(0, a.getFieldInOldCode());\r
- }\r
- });\r
-\r
- assert __version__() == 1;\r
- __toVersion__(0);\r
- assertEquals(0, a.x);\r
- }\r
-\r
- @Test\r
- public void testAccessDeletedField() {\r
-\r
- assert __version__() == 0;\r
-\r
- final A a = new A();\r
- a.x = 1;\r
-\r
- assertEquals(1, a.x);\r
-\r
- __toVersion__(1);\r
-\r
- TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
- @Override\r
- public void run() {\r
- System.out.println(a.x);\r
- }\r
- });\r
-\r
- __toVersion__(0);\r
- assertEquals(0, a.x);\r
- }\r
-\r
- @Test\r
- @Category(Full.class)\r
- public void testAccessDeleteBaseClassFieldNormal() {\r
-\r
- __toVersion__(0);\r
- assert __version__() == 0;\r
- final B b = new B();\r
- b.x = 1;\r
- final A a = new A();\r
- a.x = 2;\r
-\r
- assertEquals(1, b.x);\r
- assertEquals(2, a.x);\r
-\r
- __toVersion__(2);\r
-\r
- TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- System.out.println(b.x);\r
- }\r
- });\r
-\r
- assertEquals(2, a.x);\r
-\r
- __toVersion__(0);\r
- assertEquals(0, b.x);\r
- }\r
-\r
- @Test\r
- @Category(Full.class)\r
- public void testAccessDeleteBaseClassFieldInvalid() {\r
-\r
- __toVersion__(0);\r
- assert __version__() == 0;\r
- final B b = new B();\r
- final A a1 = new A();\r
- a1.x = 1;\r
- b.x = 1;\r
-\r
- __toVersion__(2);\r
-\r
- TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- System.out.println(b.x);\r
- }\r
- });\r
-\r
- assertEquals(1, a1.x);\r
-\r
- __toVersion__(0);\r
- assertEquals(0, b.x);\r
- assertEquals(1, a1.x);\r
-\r
- A a = convertBtoA(b);\r
-\r
- assertEquals(0, b.x);\r
-\r
- // Must fail, because now an instance of B is in a local variable of type A!\r
- TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- __toVersion__(2);\r
- }\r
- });\r
-\r
- assertEquals(0, a.x);\r
-\r
- // Still at version 0\r
- assert __version__() == 0;\r
- }\r
-}\r
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.test.fields;
+
+import com.github.dcevm.test.TestUtil;
+import com.github.dcevm.test.category.Full;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for accessing a deleted field. In the first scenario, the field is deleted from the class.
+ * In the second scenario, it is deleted because of a changed subtype relationship.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class AccessDeletedFieldTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int x;
+
+ int getFieldInOldCode() {
+
+ __toVersion__(1);
+
+ // This field does no longer exist
+ return x;
+ }
+ }
+
+ public static class B extends A {
+ }
+
+ // Version 1
+ public static class A___1 {
+ }
+
+ // Version 2
+ public static class B___2 {
+ }
+
+ // Method to enforce cast (otherwise bytecodes become invalid in version 2)
+ public static A convertBtoA(Object b) {
+ return (A) b;
+ }
+
+ @Test
+ public void testOldCodeAccessesDeletedField() {
+
+ assert __version__() == 0;
+
+ final A a = new A();
+ a.x = 1;
+
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+ @Override
+ public void run() {
+ assertEquals(0, a.getFieldInOldCode());
+ }
+ });
+
+ assert __version__() == 1;
+ __toVersion__(0);
+ assertEquals(0, a.x);
+ }
+
+ @Test
+ public void testAccessDeletedField() {
+
+ assert __version__() == 0;
+
+ final A a = new A();
+ a.x = 1;
+
+ assertEquals(1, a.x);
+
+ __toVersion__(1);
+
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+ @Override
+ public void run() {
+ System.out.println(a.x);
+ }
+ });
+
+ __toVersion__(0);
+ assertEquals(0, a.x);
+ }
+
+ @Test
+ @Category(Full.class)
+ public void testAccessDeleteBaseClassFieldNormal() {
+
+ __toVersion__(0);
+ assert __version__() == 0;
+ final B b = new B();
+ b.x = 1;
+ final A a = new A();
+ a.x = 2;
+
+ assertEquals(1, b.x);
+ assertEquals(2, a.x);
+
+ __toVersion__(2);
+
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+
+ @Override
+ public void run() {
+ System.out.println(b.x);
+ }
+ });
+
+ assertEquals(2, a.x);
+
+ __toVersion__(0);
+ assertEquals(0, b.x);
+ }
+
+ @Test
+ @Category(Full.class)
+ public void testAccessDeleteBaseClassFieldInvalid() {
+
+ __toVersion__(0);
+ assert __version__() == 0;
+ final B b = new B();
+ final A a1 = new A();
+ a1.x = 1;
+ b.x = 1;
+
+ __toVersion__(2);
+
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+
+ @Override
+ public void run() {
+ System.out.println(b.x);
+ }
+ });
+
+ assertEquals(1, a1.x);
+
+ __toVersion__(0);
+ assertEquals(0, b.x);
+ assertEquals(1, a1.x);
+
+ A a = convertBtoA(b);
+
+ assertEquals(0, b.x);
+
+ // Must fail, because now an instance of B is in a local variable of type A!
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
+
+ @Override
+ public void run() {
+ __toVersion__(2);
+ }
+ });
+
+ assertEquals(0, a.x);
+
+ // Still at version 0
+ assert __version__() == 0;
+ }
+}
-/*\r
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
- *\r
- * This code is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU General Public License version 2 only, as\r
- * published by the Free Software Foundation.\r
- *\r
- * This code is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
- * version 2 for more details (a copy is included in the LICENSE file that\r
- * accompanied this code).\r
- *\r
- * You should have received a copy of the GNU General Public License version\r
- * 2 along with this work; if not, write to the Free Software Foundation,\r
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
- * or visit www.oracle.com if you need additional information or have any\r
- * questions.\r
- *\r
- */\r
-\r
-package com.github.dcevm.test.methods;\r
-\r
-import com.github.dcevm.MethodRedefinitionPolicy;\r
-import com.github.dcevm.RedefinitionPolicy;\r
-import com.github.dcevm.test.category.Full;\r
-import junit.framework.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.experimental.categories.Category;\r
-\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
-import static org.junit.Assert.assertEquals;\r
-\r
-/**\r
- * Test case that calls a virtual method that was deleted through class redefinition.\r
- *\r
- * @author Thomas Wuerthinger\r
- */\r
-@Category(Full.class)\r
-public class CallDeletedMethodTest {\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- __toVersion__(0);\r
- }\r
-\r
- // Version 0\r
- public static class A {\r
-\r
- public int value() {\r
- return 5;\r
- }\r
-\r
- public int oldMethod() {\r
- __toVersion__(1);\r
- return deletedMethod();\r
- }\r
-\r
- public int deletedMethod() {\r
- return 1;\r
- }\r
- }\r
-\r
- // Version 1\r
- @MethodRedefinitionPolicy(RedefinitionPolicy.AccessDeletedMembers)\r
- public static class A___1 {\r
-\r
- public int oldMethod() {\r
- return 2;\r
- }\r
- }\r
-\r
- @Test\r
- public void testOldCodeCallsDeletedMethod() {\r
-\r
- assert __version__() == 0;\r
- A a = new A();\r
-\r
- assertEquals(1, a.oldMethod());\r
- assert __version__() == 1;\r
- assertEquals(2, a.oldMethod());\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.oldMethod());\r
- assert __version__() == 1;\r
- assertEquals(2, a.oldMethod());\r
-\r
- __toVersion__(0);\r
- }\r
-\r
- @Test\r
- public void testNewCodeCallsDeletedMethod() {\r
-\r
- assert __version__() == 0;\r
-\r
- A a = new A();\r
- assertEquals(5, a.value());\r
- \r
- __toVersion__(1);\r
-\r
- try {\r
- a.value();\r
- Assert.fail("NoSuchMethodError exception must be thrown!");\r
- } catch (NoSuchMethodError e) {\r
- // Expected exception\r
- }\r
-\r
- __toVersion__(0);\r
- assertEquals(5, a.value());\r
- }\r
-}\r
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.methods;
+
+import com.github.dcevm.MethodRedefinitionPolicy;
+import com.github.dcevm.RedefinitionPolicy;
+import com.github.dcevm.test.category.Full;
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test case that calls a virtual method that was deleted through class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Category(Full.class)
+public class CallDeletedMethodTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 5;
+ }
+
+ public int oldMethod() {
+ __toVersion__(1);
+ return deletedMethod();
+ }
+
+ public int deletedMethod() {
+ return 1;
+ }
+ }
+
+ // Version 1
+ @MethodRedefinitionPolicy(RedefinitionPolicy.AccessDeletedMembers)
+ public static class A___1 {
+
+ public int oldMethod() {
+ return 2;
+ }
+ }
+
+ @Test
+ public void testOldCodeCallsDeletedMethod() {
+
+ assert __version__() == 0;
+ A a = new A();
+
+ assertEquals(1, a.oldMethod());
+ assert __version__() == 1;
+ assertEquals(2, a.oldMethod());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.oldMethod());
+ assert __version__() == 1;
+ assertEquals(2, a.oldMethod());
+
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testNewCodeCallsDeletedMethod() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+ assertEquals(5, a.value());
+
+ __toVersion__(1);
+
+ try {
+ a.value();
+ Assert.fail("NoSuchMethodError exception must be thrown!");
+ } catch (NoSuchMethodError e) {
+ // Expected exception
+ }
+
+ __toVersion__(0);
+ assertEquals(5, a.value());
+ }
+}
-/*\r
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
- *\r
- * This code is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU General Public License version 2 only, as\r
- * published by the Free Software Foundation.\r
- *\r
- * This code is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
- * version 2 for more details (a copy is included in the LICENSE file that\r
- * accompanied this code).\r
- *\r
- * You should have received a copy of the GNU General Public License version\r
- * 2 along with this work; if not, write to the Free Software Foundation,\r
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
- * or visit www.oracle.com if you need additional information or have any\r
- * questions.\r
- *\r
- */\r
-\r
-package com.github.dcevm.test.methods;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import com.github.dcevm.MethodRedefinitionPolicy;\r
-import com.github.dcevm.RedefinitionPolicy;\r
-import com.github.dcevm.test.TestUtil;\r
-import junit.framework.Assert;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
-\r
-/**\r
- * Test cases that delete a method that is currently active on the stack.\r
- *\r
- * @author Thomas Wuerthinger\r
- */\r
-public class DeleteActiveMethodTest {\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- __toVersion__(0);\r
- }\r
-\r
- // Version 0\r
- public static class A {\r
-\r
- boolean firstCall;\r
-\r
- public int value() {\r
- firstCall = true;\r
- return helperValue();\r
- }\r
-\r
- public int helperValue() {\r
-\r
- if (!firstCall) {\r
- return -1;\r
- }\r
- firstCall = false;\r
-\r
- Thread t = new Thread(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- __toVersion__(1);\r
- }\r
- });\r
- t.start();\r
-\r
- try {\r
- while (t.isAlive()) {\r
- try {\r
- this.helperValue();\r
- Thread.sleep(500);\r
- } catch (InterruptedException e) {\r
- }\r
- helperValue();\r
- }\r
- Assert.fail("Exception expected!");\r
- } catch (NoSuchMethodError e) {\r
- }\r
-\r
- try {\r
- t.join();\r
- } catch (InterruptedException e) {\r
- }\r
-\r
- return 1;\r
- }\r
- }\r
-\r
- public static class B {\r
-\r
- public int fac(int x) {\r
- if (x == 0) {\r
- __toVersion__(1);\r
- }\r
-\r
- return x * fac(x - 1);\r
- }\r
- }\r
-\r
- // Version 1\r
- @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)\r
- public static class A___1 {\r
-\r
- boolean firstCall;\r
-\r
- public int value() {\r
- __toVersion__(0);\r
- return 2;\r
- }\r
- }\r
-\r
- @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)\r
- public static class B___1 {\r
- }\r
-\r
- @Test\r
- public void testDeleteActiveMethodSimple() {\r
- assert __version__() == 0;\r
-\r
- final B b = new B();\r
- TestUtil.assertException(NoSuchMethodError.class, new Runnable() {\r
- @Override\r
- public void run() {\r
- b.fac(5);\r
- }\r
- });\r
- \r
- assert __version__() == 1;\r
- \r
- __toVersion__(0);\r
- assert __version__() == 0;\r
- }\r
-\r
- @Test\r
- public void testDeleteActiveMethod() {\r
- assert __version__() == 0;\r
-\r
- A a = new A();\r
-\r
- assertEquals(1, a.value());\r
- assert __version__() == 1;\r
-\r
- assertEquals(2, a.value());\r
- assert __version__() == 0;\r
-\r
- assertEquals(1, a.value());\r
- assert __version__() == 1;\r
-\r
- assertEquals(2, a.value());\r
- assert __version__() == 0;\r
-\r
- assertEquals(1, a.value());\r
- assert __version__() == 1;\r
-\r
- assertEquals(2, a.value());\r
- assert __version__() == 0;\r
- }\r
-}\r
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.methods;
+
+import static org.junit.Assert.assertEquals;
+
+import com.github.dcevm.MethodRedefinitionPolicy;
+import com.github.dcevm.RedefinitionPolicy;
+import com.github.dcevm.test.TestUtil;
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Test cases that delete a method that is currently active on the stack.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class DeleteActiveMethodTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ boolean firstCall;
+
+ public int value() {
+ firstCall = true;
+ return helperValue();
+ }
+
+ public int helperValue() {
+
+ if (!firstCall) {
+ return -1;
+ }
+ firstCall = false;
+
+ Thread t = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ __toVersion__(1);
+ }
+ });
+ t.start();
+
+ try {
+ while (t.isAlive()) {
+ try {
+ this.helperValue();
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+ helperValue();
+ }
+ Assert.fail("Exception expected!");
+ } catch (NoSuchMethodError e) {
+ }
+
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ }
+
+ return 1;
+ }
+ }
+
+ public static class B {
+
+ public int fac(int x) {
+ if (x == 0) {
+ __toVersion__(1);
+ }
+
+ return x * fac(x - 1);
+ }
+ }
+
+ // Version 1
+ @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)
+ public static class A___1 {
+
+ boolean firstCall;
+
+ public int value() {
+ __toVersion__(0);
+ return 2;
+ }
+ }
+
+ @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)
+ public static class B___1 {
+ }
+
+ @Test
+ public void testDeleteActiveMethodSimple() {
+ assert __version__() == 0;
+
+ final B b = new B();
+ TestUtil.assertException(NoSuchMethodError.class, new Runnable() {
+ @Override
+ public void run() {
+ b.fac(5);
+ }
+ });
+
+ assert __version__() == 1;
+
+ __toVersion__(0);
+ assert __version__() == 0;
+ }
+
+ @Test
+ public void testDeleteActiveMethod() {
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(1, a.value());
+ assert __version__() == 1;
+
+ assertEquals(2, a.value());
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assert __version__() == 1;
+
+ assertEquals(2, a.value());
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assert __version__() == 1;
+
+ assertEquals(2, a.value());
+ assert __version__() == 0;
+ }
+}
-/*\r
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
- *\r
- * This code is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU General Public License version 2 only, as\r
- * published by the Free Software Foundation.\r
- *\r
- * This code is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
- * version 2 for more details (a copy is included in the LICENSE file that\r
- * accompanied this code).\r
- *\r
- * You should have received a copy of the GNU General Public License version\r
- * 2 along with this work; if not, write to the Free Software Foundation,\r
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
- * or visit www.oracle.com if you need additional information or have any\r
- * questions.\r
- *\r
- */\r
-\r
-package com.github.dcevm.test.structural;\r
-\r
-import org.junit.Before;\r
-import org.junit.Ignore;\r
-import org.junit.Test;\r
-\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
-import static org.junit.Assert.*;\r
-\r
-/**\r
- * Smallest test case for a hierarchy swap. A<B is changed to B<A.\r
- *\r
- * @author Thomas Wuerthinger\r
- */\r
-@Ignore\r
-public class HierarchySwapTest {\r
-\r
- // Version 0\r
- public static class A {\r
-\r
- public int value() {\r
- return 1;\r
- }\r
- }\r
-\r
- public static class B extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class C {\r
-\r
- public boolean doInstanceCheckA(Object o) {\r
- return o instanceof A;\r
- }\r
-\r
- public boolean doInstanceCheckB(Object o) {\r
- return o instanceof B;\r
- }\r
- }\r
-\r
- public static class Base {\r
-\r
- public String className() {\r
- return "Base";\r
- }\r
- }\r
-\r
- public static class D extends Base {\r
-\r
- @Override\r
- public String className() {\r
- return "D";\r
- }\r
-\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class E extends Base {\r
-\r
- @Override\r
- public String className() {\r
- return "E";\r
- }\r
-\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class F extends Base {\r
-\r
- @Override\r
- public String className() {\r
- return "F";\r
- }\r
-\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- // Version 1\r
- public static class A___1 extends B___1 {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class B___1 {\r
-\r
- public int value() {\r
- return 4;\r
- }\r
- }\r
-\r
- public static class C___1 {\r
-\r
- public boolean doInstanceCheckA(Object o) {\r
- return o instanceof A;\r
- }\r
-\r
- public boolean doInstanceCheckB(Object o) {\r
- return o instanceof B;\r
- }\r
- }\r
-\r
- // Version 2\r
- public static class D___2 extends Base {\r
-\r
- @Override\r
- public String className() {\r
- return "D";\r
- }\r
-\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class E___2 extends D {\r
-\r
- @Override\r
- public String className() {\r
- return "E";\r
- }\r
-\r
- @Override\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class F___2 extends E {\r
-\r
- @Override\r
- public String className() {\r
- return "F";\r
- }\r
-\r
- @Override\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- // Version 3\r
- public static class D___3 extends E {\r
-\r
- @Override\r
- public String className() {\r
- return "D";\r
- }\r
-\r
- @Override\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class E___3 extends F {\r
-\r
- @Override\r
- public String className() {\r
- return "E";\r
- }\r
-\r
- @Override\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class F___3 extends Base {\r
-\r
- @Override\r
- public String className() {\r
- return "F";\r
- }\r
-\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- // Version 4\r
- public static class D___4 extends E {\r
-\r
- @Override\r
- public String className() {\r
- return "D";\r
- }\r
-\r
- @Override\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class E___4 extends Base {\r
-\r
- @Override\r
- public String className() {\r
- return "E";\r
- }\r
-\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- public static class F___4 extends E {\r
-\r
- @Override\r
- public String className() {\r
- return "F";\r
- }\r
-\r
- @Override\r
- public String superClassName() {\r
- return super.className();\r
- }\r
- }\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- __toVersion__(0);\r
- }\r
-\r
- @Test\r
- public void testHierarchySwap() {\r
-\r
- assert __version__() == 0;\r
-\r
- A a = new A();\r
- B b = new B();\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertTrue(b.getClass().getSuperclass().equals(A.class));\r
- assertFalse(a.getClass().getSuperclass().equals(B.class));\r
-\r
- __toVersion__(1);\r
-\r
- assertEquals(8, a.value());\r
- assertEquals(4, b.value());\r
- assertFalse(b.getClass().getSuperclass().equals(A.class));\r
- assertTrue(a.getClass().getSuperclass().equals(B.class));\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertTrue(b.getClass().getSuperclass().equals(A.class));\r
- assertFalse(a.getClass().getSuperclass().equals(B.class));\r
- }\r
-\r
- @Test\r
- public void testHierarchySwapWithInstanceOfTest() {\r
-\r
- assert __version__() == 0;\r
-\r
- A a = new A();\r
- B b = new B();\r
- C c = new C();\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertTrue(c.doInstanceCheckA(b));\r
- assertFalse(c.doInstanceCheckB(a));\r
-\r
- __toVersion__(1);\r
-\r
- assertEquals(8, a.value());\r
- assertEquals(4, b.value());\r
- assertFalse(c.doInstanceCheckA(b));\r
- assertTrue(c.doInstanceCheckB(a));\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertTrue(c.doInstanceCheckA(b));\r
- assertFalse(c.doInstanceCheckB(a));\r
- }\r
-\r
- @Test\r
- public void testHierarchySwapWithInstanceOf() {\r
-\r
- assert __version__() == 0;\r
-\r
- A a = new A();\r
- B b = new B();\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertTrue(b instanceof A);\r
- assertFalse(a instanceof B);\r
-\r
- __toVersion__(1);\r
-\r
- assertEquals(8, a.value());\r
- assertEquals(4, b.value());\r
- assertFalse(b instanceof A);\r
- assertTrue(a instanceof B);\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertTrue(b instanceof A);\r
- assertFalse(a instanceof B);\r
- }\r
-\r
- @Test\r
- public void testTripleSwap() {\r
-\r
-\r
- assert __version__() == 0;\r
-\r
- D d = new D();\r
- E e = new E();\r
- F f = new F();\r
-\r
- assertEquals(d.superClassName(), "Base");\r
- assertEquals(e.superClassName(), "Base");\r
- assertEquals(f.superClassName(), "Base");\r
-\r
- __toVersion__(2);\r
-\r
- assertEquals(d.superClassName(), "Base");\r
- assertEquals(e.superClassName(), "D");\r
- assertEquals(f.superClassName(), "E");\r
-\r
- __toVersion__(3);\r
-\r
- assertEquals(d.superClassName(), "E");\r
- assertEquals(e.superClassName(), "F");\r
- assertEquals(f.superClassName(), "Base");\r
-\r
- __toVersion__(4);\r
-\r
- assertEquals(d.superClassName(), "E");\r
- assertEquals(e.superClassName(), "Base");\r
- assertEquals(f.superClassName(), "E");\r
-\r
- __toVersion__(3);\r
-\r
- assertEquals(d.superClassName(), "E");\r
- assertEquals(e.superClassName(), "F");\r
- assertEquals(f.superClassName(), "Base");\r
-\r
- __toVersion__(2);\r
-\r
- assertEquals(d.superClassName(), "Base");\r
- assertEquals(e.superClassName(), "D");\r
- assertEquals(f.superClassName(), "E");\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(d.superClassName(), "Base");\r
- assertEquals(e.superClassName(), "Base");\r
- assertEquals(f.superClassName(), "Base");\r
- }\r
-}\r
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.structural;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.*;
+
+/**
+ * Smallest test case for a hierarchy swap. A<B is changed to B<A.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class HierarchySwapTest {
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 1;
+ }
+ }
+
+ public static class B extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class C {
+
+ public boolean doInstanceCheckA(Object o) {
+ return o instanceof A;
+ }
+
+ public boolean doInstanceCheckB(Object o) {
+ return o instanceof B;
+ }
+ }
+
+ public static class Base {
+
+ public String className() {
+ return "Base";
+ }
+ }
+
+ public static class D extends Base {
+
+ @Override
+ public String className() {
+ return "D";
+ }
+
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class E extends Base {
+
+ @Override
+ public String className() {
+ return "E";
+ }
+
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class F extends Base {
+
+ @Override
+ public String className() {
+ return "F";
+ }
+
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ // Version 1
+ public static class A___1 extends B___1 {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class B___1 {
+
+ public int value() {
+ return 4;
+ }
+ }
+
+ public static class C___1 {
+
+ public boolean doInstanceCheckA(Object o) {
+ return o instanceof A;
+ }
+
+ public boolean doInstanceCheckB(Object o) {
+ return o instanceof B;
+ }
+ }
+
+ // Version 2
+ public static class D___2 extends Base {
+
+ @Override
+ public String className() {
+ return "D";
+ }
+
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class E___2 extends D {
+
+ @Override
+ public String className() {
+ return "E";
+ }
+
+ @Override
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class F___2 extends E {
+
+ @Override
+ public String className() {
+ return "F";
+ }
+
+ @Override
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ // Version 3
+ public static class D___3 extends E {
+
+ @Override
+ public String className() {
+ return "D";
+ }
+
+ @Override
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class E___3 extends F {
+
+ @Override
+ public String className() {
+ return "E";
+ }
+
+ @Override
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class F___3 extends Base {
+
+ @Override
+ public String className() {
+ return "F";
+ }
+
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ // Version 4
+ public static class D___4 extends E {
+
+ @Override
+ public String className() {
+ return "D";
+ }
+
+ @Override
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class E___4 extends Base {
+
+ @Override
+ public String className() {
+ return "E";
+ }
+
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ public static class F___4 extends E {
+
+ @Override
+ public String className() {
+ return "F";
+ }
+
+ @Override
+ public String superClassName() {
+ return super.className();
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testHierarchySwap() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+ B b = new B();
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertTrue(b.getClass().getSuperclass().equals(A.class));
+ assertFalse(a.getClass().getSuperclass().equals(B.class));
+
+ __toVersion__(1);
+
+ assertEquals(8, a.value());
+ assertEquals(4, b.value());
+ assertFalse(b.getClass().getSuperclass().equals(A.class));
+ assertTrue(a.getClass().getSuperclass().equals(B.class));
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertTrue(b.getClass().getSuperclass().equals(A.class));
+ assertFalse(a.getClass().getSuperclass().equals(B.class));
+ }
+
+ @Test
+ public void testHierarchySwapWithInstanceOfTest() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+ B b = new B();
+ C c = new C();
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertTrue(c.doInstanceCheckA(b));
+ assertFalse(c.doInstanceCheckB(a));
+
+ __toVersion__(1);
+
+ assertEquals(8, a.value());
+ assertEquals(4, b.value());
+ assertFalse(c.doInstanceCheckA(b));
+ assertTrue(c.doInstanceCheckB(a));
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertTrue(c.doInstanceCheckA(b));
+ assertFalse(c.doInstanceCheckB(a));
+ }
+
+ @Test
+ public void testHierarchySwapWithInstanceOf() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+ B b = new B();
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertTrue(b instanceof A);
+ assertFalse(a instanceof B);
+
+ __toVersion__(1);
+
+ assertEquals(8, a.value());
+ assertEquals(4, b.value());
+ assertFalse(b instanceof A);
+ assertTrue(a instanceof B);
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertTrue(b instanceof A);
+ assertFalse(a instanceof B);
+ }
+
+ @Test
+ public void testTripleSwap() {
+
+
+ assert __version__() == 0;
+
+ D d = new D();
+ E e = new E();
+ F f = new F();
+
+ assertEquals(d.superClassName(), "Base");
+ assertEquals(e.superClassName(), "Base");
+ assertEquals(f.superClassName(), "Base");
+
+ __toVersion__(2);
+
+ assertEquals(d.superClassName(), "Base");
+ assertEquals(e.superClassName(), "D");
+ assertEquals(f.superClassName(), "E");
+
+ __toVersion__(3);
+
+ assertEquals(d.superClassName(), "E");
+ assertEquals(e.superClassName(), "F");
+ assertEquals(f.superClassName(), "Base");
+
+ __toVersion__(4);
+
+ assertEquals(d.superClassName(), "E");
+ assertEquals(e.superClassName(), "Base");
+ assertEquals(f.superClassName(), "E");
+
+ __toVersion__(3);
+
+ assertEquals(d.superClassName(), "E");
+ assertEquals(e.superClassName(), "F");
+ assertEquals(f.superClassName(), "Base");
+
+ __toVersion__(2);
+
+ assertEquals(d.superClassName(), "Base");
+ assertEquals(e.superClassName(), "D");
+ assertEquals(f.superClassName(), "E");
+
+ __toVersion__(0);
+
+ assertEquals(d.superClassName(), "Base");
+ assertEquals(e.superClassName(), "Base");
+ assertEquals(f.superClassName(), "Base");
+ }
+}
-/*\r
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
- *\r
- * This code is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU General Public License version 2 only, as\r
- * published by the Free Software Foundation.\r
- *\r
- * This code is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
- * version 2 for more details (a copy is included in the LICENSE file that\r
- * accompanied this code).\r
- *\r
- * You should have received a copy of the GNU General Public License version\r
- * 2 along with this work; if not, write to the Free Software Foundation,\r
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
- * or visit www.oracle.com if you need additional information or have any\r
- * questions.\r
- *\r
- */\r
-\r
-package com.github.dcevm.test.structural;\r
-\r
-import com.github.dcevm.test.category.Full;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.experimental.categories.Category;\r
-\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
-import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
-import static org.junit.Assert.assertEquals;\r
-\r
-/**\r
- * Tests that modify a large class hierarchy with the classes A, B, C, D, E, and F.\r
- * \r
- * @author Thomas Wuerthinger\r
- */\r
-@Category(Full.class)\r
-public class LargeHierarchyTest {\r
-\r
- private A a = new A();\r
- private B b = new B();\r
- private C c = new C();\r
- private D d = new D();\r
- private E e = new E();\r
- private F f = new F();\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- __toVersion__(0);\r
- }\r
-\r
- // Version 0\r
- public static class A {\r
-\r
- public int value() {\r
- return 1;\r
- }\r
- }\r
-\r
- public static class B extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class C extends B {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class D extends C {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class E extends D {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class F extends E {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- // Version 1\r
- public static class A___1 {\r
-\r
- public int value() {\r
- return 2;\r
- }\r
- }\r
-\r
- // Version 2\r
- // D - E - F\r
- // /\r
- // A - B - C\r
- public static class D___2 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- // Version 3\r
- // D\r
- // /\r
- // A - B - C - E - F\r
- public static class D___3 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class E___3 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- // Version 4\r
- // Completely flat\r
- public static class C___4 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class D___4 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class E___4 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- public static class F___4 extends A {\r
-\r
- @Override\r
- public int value() {\r
- return super.value() * 2;\r
- }\r
- }\r
-\r
- // Version 5\r
- public static class F___5 extends E {\r
-\r
- @Override\r
- public int value() {\r
- return 0;\r
- }\r
- }\r
-\r
- @Test\r
- public void testChangeBaseClass() {\r
-\r
- assert __version__() == 0;\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(32, f.value());\r
-\r
- __toVersion__(1);\r
-\r
- assertEquals(2, a.value());\r
- assertEquals(4, b.value());\r
- assertEquals(8, c.value());\r
- assertEquals(16, d.value());\r
- assertEquals(32, e.value());\r
- assertEquals(64, f.value());\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(32, f.value());\r
- }\r
-\r
- @Test\r
- public void testChangeSubClass() {\r
- assert __version__() == 0;\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(32, f.value());\r
-\r
- __toVersion__(5);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(0, f.value());\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(32, f.value());\r
- }\r
-\r
- @Test\r
- public void testChangeHierarchy() {\r
-\r
- assert __version__() == 0;\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(32, f.value());\r
-\r
- __toVersion__(2);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(2, d.value());\r
- assertEquals(4, e.value());\r
- assertEquals(8, f.value());\r
-\r
- __toVersion__(3);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(2, d.value());\r
- assertEquals(2, e.value());\r
- assertEquals(4, f.value());\r
-\r
- __toVersion__(4);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(2, c.value());\r
- assertEquals(2, d.value());\r
- assertEquals(2, e.value());\r
- assertEquals(2, f.value());\r
-\r
- __toVersion__(0);\r
-\r
- assertEquals(1, a.value());\r
- assertEquals(2, b.value());\r
- assertEquals(4, c.value());\r
- assertEquals(8, d.value());\r
- assertEquals(16, e.value());\r
- assertEquals(32, f.value());\r
- }\r
-}\r
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.structural;
+
+import com.github.dcevm.test.category.Full;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests that modify a large class hierarchy with the classes A, B, C, D, E, and F.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Category(Full.class)
+public class LargeHierarchyTest {
+
+ private A a = new A();
+ private B b = new B();
+ private C c = new C();
+ private D d = new D();
+ private E e = new E();
+ private F f = new F();
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 1;
+ }
+ }
+
+ public static class B extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class C extends B {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class D extends C {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class E extends D {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class F extends E {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return 2;
+ }
+ }
+
+ // Version 2
+ // D - E - F
+ // /
+ // A - B - C
+ public static class D___2 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ // Version 3
+ // D
+ // /
+ // A - B - C - E - F
+ public static class D___3 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class E___3 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ // Version 4
+ // Completely flat
+ public static class C___4 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class D___4 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class E___4 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ public static class F___4 extends A {
+
+ @Override
+ public int value() {
+ return super.value() * 2;
+ }
+ }
+
+ // Version 5
+ public static class F___5 extends E {
+
+ @Override
+ public int value() {
+ return 0;
+ }
+ }
+
+ @Test
+ public void testChangeBaseClass() {
+
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(32, f.value());
+
+ __toVersion__(1);
+
+ assertEquals(2, a.value());
+ assertEquals(4, b.value());
+ assertEquals(8, c.value());
+ assertEquals(16, d.value());
+ assertEquals(32, e.value());
+ assertEquals(64, f.value());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(32, f.value());
+ }
+
+ @Test
+ public void testChangeSubClass() {
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(32, f.value());
+
+ __toVersion__(5);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(0, f.value());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(32, f.value());
+ }
+
+ @Test
+ public void testChangeHierarchy() {
+
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(32, f.value());
+
+ __toVersion__(2);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(2, d.value());
+ assertEquals(4, e.value());
+ assertEquals(8, f.value());
+
+ __toVersion__(3);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(2, d.value());
+ assertEquals(2, e.value());
+ assertEquals(4, f.value());
+
+ __toVersion__(4);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(2, c.value());
+ assertEquals(2, d.value());
+ assertEquals(2, e.value());
+ assertEquals(2, f.value());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(4, c.value());
+ assertEquals(8, d.value());
+ assertEquals(16, e.value());
+ assertEquals(32, f.value());
+ }
+}