diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-02-17 17:25:57 +0000 |
---|---|---|
committer | <> | 2015-03-17 16:26:24 +0000 |
commit | 780b92ada9afcf1d58085a83a0b9e6bc982203d1 (patch) | |
tree | 598f8b9fa431b228d29897e798de4ac0c1d3d970 /test/java/compat/src | |
parent | 7a2660ba9cc2dc03a69ddfcfd95369395cc87444 (diff) | |
download | berkeleydb-master.tar.gz |
Diffstat (limited to 'test/java/compat/src')
61 files changed, 1254 insertions, 1074 deletions
diff --git a/test/java/compat/src/com/sleepycat/bind/serial/test/MarshalledObject.java b/test/java/compat/src/com/sleepycat/bind/serial/test/MarshalledObject.java index 57a44c99..93a87324 100644 --- a/test/java/compat/src/com/sleepycat/bind/serial/test/MarshalledObject.java +++ b/test/java/compat/src/com/sleepycat/bind/serial/test/MarshalledObject.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/bind/serial/test/NullClassCatalog.java b/test/java/compat/src/com/sleepycat/bind/serial/test/NullClassCatalog.java index fceeca02..b78eb21b 100644 --- a/test/java/compat/src/com/sleepycat/bind/serial/test/NullClassCatalog.java +++ b/test/java/compat/src/com/sleepycat/bind/serial/test/NullClassCatalog.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/bind/serial/test/SerialBindingTest.java b/test/java/compat/src/com/sleepycat/bind/serial/test/SerialBindingTest.java index 8d843156..91d2cf6d 100644 --- a/test/java/compat/src/com/sleepycat/bind/serial/test/SerialBindingTest.java +++ b/test/java/compat/src/com/sleepycat/bind/serial/test/SerialBindingTest.java @@ -1,17 +1,22 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.bind.serial.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.Serializable; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.EntityBinding; import com.sleepycat.bind.serial.ClassCatalog; @@ -19,50 +24,27 @@ import com.sleepycat.bind.serial.SerialBinding; import com.sleepycat.bind.serial.SerialSerialBinding; import com.sleepycat.bind.serial.TupleSerialMarshalledBinding; import com.sleepycat.db.DatabaseEntry; -import com.sleepycat.util.ExceptionUnwrapper; import com.sleepycat.util.FastOutputStream; -import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; /** * @author Mark Hayes */ -public class SerialBindingTest extends TestCase { +public class SerialBindingTest extends TestBase { private ClassCatalog catalog; private DatabaseEntry buffer; private DatabaseEntry keyBuffer; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(SerialBindingTest.class); - return suite; - } - - public SerialBindingTest(String name) { - - super(name); - } - - @Override + @Before public void setUp() { - SharedTestUtils.printTestName("SerialBindingTest." + getName()); catalog = new TestClassCatalog(); buffer = new DatabaseEntry(); keyBuffer = new DatabaseEntry(); } - @Override + @After public void tearDown() { /* Ensure that GC can cleanup. */ @@ -71,17 +53,6 @@ public class SerialBindingTest extends TestCase { keyBuffer = null; } - @Override - public void runTest() - throws Throwable { - - try { - super.runTest(); - } catch (Exception e) { - throw ExceptionUnwrapper.unwrap(e); - } - } - private void primitiveBindingTest(Object val) { Class cls = val.getClass(); @@ -101,6 +72,7 @@ public class SerialBindingTest extends TestCase { } catch (IllegalArgumentException expected) {} } + @Test public void testPrimitiveBindings() { primitiveBindingTest("abc"); @@ -114,6 +86,7 @@ public class SerialBindingTest extends TestCase { primitiveBindingTest(new Double(123.123)); } + @Test public void testNullObjects() { SerialBinding binding = new SerialBinding(catalog, null); @@ -123,6 +96,7 @@ public class SerialBindingTest extends TestCase { assertEquals(null, binding.entryToObject(buffer)); } + @Test public void testSerialSerialBinding() { SerialBinding keyBinding = new SerialBinding(catalog, String.class); @@ -142,6 +116,7 @@ public class SerialBindingTest extends TestCase { // also tests TupleSerialBinding since TupleSerialMarshalledBinding extends // it + @Test public void testTupleSerialMarshalledBinding() { SerialBinding valueBinding = new SerialBinding(catalog, @@ -165,6 +140,7 @@ public class SerialBindingTest extends TestCase { assertEquals("index2", val.getIndexKey2()); } + @Test public void testBufferSize() { CaptureSizeBinding binding = @@ -196,6 +172,7 @@ public class SerialBindingTest extends TestCase { } } + @Test public void testBufferOverride() { FastOutputStream out = new FastOutputStream(10); @@ -282,6 +259,7 @@ public class SerialBindingTest extends TestCase { * a crude test because to create a truly working class loader is a large * undertaking. */ + @Test public void testClassloaderOverride() { DatabaseEntry entry = new DatabaseEntry(); diff --git a/test/java/compat/src/com/sleepycat/bind/serial/test/TestClassCatalog.java b/test/java/compat/src/com/sleepycat/bind/serial/test/TestClassCatalog.java index 2490d658..be457f77 100644 --- a/test/java/compat/src/com/sleepycat/bind/serial/test/TestClassCatalog.java +++ b/test/java/compat/src/com/sleepycat/bind/serial/test/TestClassCatalog.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/bind/test/BindingSpeedTest.java b/test/java/compat/src/com/sleepycat/bind/test/BindingSpeedTest.java index 6dc24246..1bdbc657 100644 --- a/test/java/compat/src/com/sleepycat/bind/test/BindingSpeedTest.java +++ b/test/java/compat/src/com/sleepycat/bind/test/BindingSpeedTest.java @@ -1,15 +1,17 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.bind.test; +import static org.junit.Assert.assertTrue; + import java.io.Externalizable; -import java.io.InputStreamReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; @@ -19,13 +21,16 @@ import java.io.Serializable; import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; import javax.xml.parsers.SAXParserFactory; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; @@ -37,11 +42,13 @@ import com.sleepycat.bind.tuple.TupleOutput; import com.sleepycat.util.FastInputStream; import com.sleepycat.util.FastOutputStream; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; /** * @author Mark Hayes */ -public class BindingSpeedTest extends TestCase { +@RunWith(Parameterized.class) +public class BindingSpeedTest extends TestBase { static final String JAVA_UNSHARED = "java-unshared".intern(); static final String JAVA_SHARED = "java-shared".intern(); @@ -54,28 +61,13 @@ public class BindingSpeedTest extends TestCase { static final int RUN_COUNT = 1000; static final boolean VERBOSE = false; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - - TestSuite suite = new TestSuite(); - suite.addTest(new BindingSpeedTest(JAVA_UNSHARED)); - suite.addTest(new BindingSpeedTest(JAVA_SHARED)); - suite.addTest(new BindingSpeedTest(JAVA_EXTERNALIZABLE)); - suite.addTest(new BindingSpeedTest(XML_SAX)); - suite.addTest(new BindingSpeedTest(TUPLE)); - suite.addTest(new BindingSpeedTest(REFLECT_METHOD)); - suite.addTest(new BindingSpeedTest(REFLECT_FIELD)); - return suite; + @Parameters + public static List<Object[]> genParams(){ + + return Arrays.asList(new Object[][]{{JAVA_UNSHARED}, {JAVA_SHARED}, + {JAVA_EXTERNALIZABLE}, {XML_SAX}, + {TUPLE}, {REFLECT_METHOD}, + {REFLECT_FIELD}}); } private String command; @@ -90,16 +82,15 @@ public class BindingSpeedTest extends TestCase { public BindingSpeedTest(String name) { - super("BindingSpeedTest." + name); command = name; + customName = "BindingSpeedTest." + name; } - @Override + @Test public void runTest() throws Exception { - SharedTestUtils.printTestName(getName()); - + SharedTestUtils.printTestName(customName); boolean isTuple = false; boolean isReflectMethod = false; boolean isReflectField = false; @@ -211,7 +202,7 @@ public class BindingSpeedTest extends TestCase { } } - @Override + @After public void tearDown() { /* Ensure that GC can cleanup. */ diff --git a/test/java/compat/src/com/sleepycat/bind/tuple/test/MarshalledObject.java b/test/java/compat/src/com/sleepycat/bind/tuple/test/MarshalledObject.java index 3ea7b40a..87346823 100644 --- a/test/java/compat/src/com/sleepycat/bind/tuple/test/MarshalledObject.java +++ b/test/java/compat/src/com/sleepycat/bind/tuple/test/MarshalledObject.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleBindingTest.java b/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleBindingTest.java index 3feeb3bc..a5601879 100644 --- a/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleBindingTest.java +++ b/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleBindingTest.java @@ -1,18 +1,22 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.bind.tuple.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import java.math.BigDecimal; import java.math.BigInteger; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.EntityBinding; import com.sleepycat.bind.EntryBinding; @@ -41,48 +45,24 @@ import com.sleepycat.bind.tuple.TupleMarshalledBinding; import com.sleepycat.bind.tuple.TupleOutput; import com.sleepycat.bind.tuple.TupleTupleMarshalledBinding; import com.sleepycat.db.DatabaseEntry; -import com.sleepycat.util.ExceptionUnwrapper; import com.sleepycat.util.FastOutputStream; -import com.sleepycat.util.test.SharedTestUtils; /** * @author Mark Hayes */ -public class TupleBindingTest extends TestCase { +public class TupleBindingTest { private DatabaseEntry buffer; private DatabaseEntry keyBuffer; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(TupleBindingTest.class); - return suite; - } - - public TupleBindingTest(String name) { - - super(name); - } - - @Override + @Before public void setUp() { - SharedTestUtils.printTestName("TupleBindingTest." + getName()); buffer = new DatabaseEntry(); keyBuffer = new DatabaseEntry(); } - @Override + @After public void tearDown() { /* Ensure that GC can cleanup. */ @@ -90,16 +70,6 @@ public class TupleBindingTest extends TestCase { keyBuffer = null; } - @Override - public void runTest() - throws Throwable { - - try { - super.runTest(); - } catch (Exception e) { - throw ExceptionUnwrapper.unwrap(e); - } - } private void primitiveBindingTest(Class primitiveCls, Class compareCls, Object val, int byteSize) { @@ -143,6 +113,7 @@ public class TupleBindingTest extends TestCase { assertEquals(val2, val3); } + @Test public void testPrimitiveBindings() { primitiveBindingTest(String.class, String.class, @@ -356,6 +327,7 @@ public class TupleBindingTest extends TestCase { new BigDecimal("123456789.123456")); } + @Test public void testTupleInputBinding() { EntryBinding binding = new TupleInputBinding(); @@ -373,6 +345,7 @@ public class TupleBindingTest extends TestCase { } // also tests TupleBinding since TupleMarshalledBinding extends it + @Test public void testTupleMarshalledBinding() { EntryBinding binding = @@ -390,6 +363,7 @@ public class TupleBindingTest extends TestCase { // also tests TupleTupleBinding since TupleTupleMarshalledBinding extends // it + @Test public void testTupleTupleMarshalledBinding() { EntityBinding binding = @@ -411,6 +385,7 @@ public class TupleBindingTest extends TestCase { assertEquals("index2", val.getIndexKey2()); } + @Test public void testBufferSize() { CaptureSizeBinding binding = new CaptureSizeBinding(); @@ -452,6 +427,7 @@ public class TupleBindingTest extends TestCase { } } + @Test public void testBufferOverride() { TupleOutput out = new TupleOutput(new byte[10]); diff --git a/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleFormatTest.java b/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleFormatTest.java index 823ecaaa..3480abba 100644 --- a/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleFormatTest.java +++ b/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleFormatTest.java @@ -1,65 +1,45 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.bind.tuple.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.tuple.TupleBinding; import com.sleepycat.bind.tuple.TupleInput; import com.sleepycat.bind.tuple.TupleOutput; import com.sleepycat.db.DatabaseEntry; -import com.sleepycat.util.test.SharedTestUtils; /** * @author Mark Hayes */ -public class TupleFormatTest extends TestCase { +public class TupleFormatTest { private TupleInput in; private TupleOutput out; private DatabaseEntry buffer; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(TupleFormatTest.class); - return suite; - } - - public TupleFormatTest(String name) { - - super(name); - } - - @Override + @Before public void setUp() { - SharedTestUtils.printTestName("TupleFormatTest." + getName()); buffer = new DatabaseEntry(); out = new TupleOutput(); } - @Override + @After public void tearDown() { /* Ensure that GC can cleanup. */ @@ -87,6 +67,7 @@ public class TupleFormatTest extends TestCase { assertEquals(0, in.available()); } + @Test public void testString() { stringTest(""); @@ -130,6 +111,7 @@ public class TupleFormatTest extends TestCase { assertEquals(0, in.available()); } + @Test public void testFixedString() { fixedStringTest(new char[0]); @@ -157,6 +139,7 @@ public class TupleFormatTest extends TestCase { assertEquals(0, in.available()); } + @Test public void testNullString() { out.reset(); @@ -229,6 +212,7 @@ public class TupleFormatTest extends TestCase { } } + @Test public void testChars() { charsTest(new char[0]); @@ -282,6 +266,7 @@ public class TupleFormatTest extends TestCase { } } + @Test public void testBytes() { bytesTest(new char[0]); @@ -320,6 +305,7 @@ public class TupleFormatTest extends TestCase { assertEquals(0, in.available()); } + @Test public void testBoolean() { booleanTest(true); @@ -360,6 +346,7 @@ public class TupleFormatTest extends TestCase { assertEquals(expected, in.readUnsignedByte()); } + @Test public void testUnsignedByte() { unsignedByteTest(0); @@ -397,6 +384,7 @@ public class TupleFormatTest extends TestCase { assertEquals(expected, in.readUnsignedShort()); } + @Test public void testUnsignedShort() { unsignedShortTest(0); @@ -442,6 +430,7 @@ public class TupleFormatTest extends TestCase { assertEquals(expected, in.readUnsignedInt()); } + @Test public void testUnsignedInt() { unsignedIntTest(0L); @@ -485,6 +474,7 @@ public class TupleFormatTest extends TestCase { assertEquals((byte) val, in.readByte()); } + @Test public void testByte() { byteTest(0); @@ -524,6 +514,7 @@ public class TupleFormatTest extends TestCase { assertEquals((short) val, in.readShort()); } + @Test public void testShort() { shortTest(0); @@ -563,6 +554,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readInt()); } + @Test public void testInt() { intTest(0); @@ -602,6 +594,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readLong()); } + @Test public void testLong() { longTest(0); @@ -647,6 +640,7 @@ public class TupleFormatTest extends TestCase { } } + @Test public void testFloat() { floatTest(0); @@ -704,6 +698,7 @@ public class TupleFormatTest extends TestCase { } } + @Test public void testDouble() { doubleTest(0); @@ -764,6 +759,7 @@ public class TupleFormatTest extends TestCase { } } + @Test public void testSortedFloat() { sortedFloatTest(0); @@ -821,6 +817,7 @@ public class TupleFormatTest extends TestCase { } } + @Test public void testSortedDouble() { sortedDoubleTest(0); @@ -878,6 +875,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readPackedInt()); } + @Test public void testPackedInt() { /* Exhaustive value testing is in PackedIntTest. */ @@ -907,6 +905,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readPackedLong()); } + @Test public void testPackedLong() { /* Exhaustive value testing is in PackedIntTest. */ @@ -936,6 +935,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readSortedPackedInt()); } + @Test public void testSortedPackedInt() { /* Exhaustive value testing is in sortedPackedIntTest. */ @@ -987,6 +987,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readSortedPackedLong()); } + @Test public void testSortedPackedLong() { /* Exhaustive value testing is in sortedPackedLongTest. */ @@ -1053,6 +1054,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readBigInteger()); } + @Test public void testBigInteger() { /* Exhaustive value testing is in bigIntegerTest. */ @@ -1094,6 +1096,7 @@ public class TupleFormatTest extends TestCase { assertEquals(val, in.readBigDecimal()); } + @Test public void testBigDecimal() { /* Exhaustive value testing is in BigDecimal. */ @@ -1145,6 +1148,7 @@ public class TupleFormatTest extends TestCase { assertEquals(0, val.compareTo(in.readSortedBigDecimal())); } + @Test public void testSortedBigDecimal() { /* Exhaustive value testing is in BigDecimal. */ diff --git a/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleOrderingTest.java b/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleOrderingTest.java index 5beec774..b29bd257 100644 --- a/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleOrderingTest.java +++ b/test/java/compat/src/com/sleepycat/bind/tuple/test/TupleOrderingTest.java @@ -1,60 +1,39 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.bind.tuple.test; -import java.math.BigInteger; +import static org.junit.Assert.fail; + import java.math.BigDecimal; +import java.math.BigInteger; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.tuple.TupleOutput; -import com.sleepycat.util.test.SharedTestUtils; /** * @author Mark Hayes */ -public class TupleOrderingTest extends TestCase { +public class TupleOrderingTest { private TupleOutput out; private byte[] prevBuf; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(TupleOrderingTest.class); - return suite; - } - - public TupleOrderingTest(String name) { - - super(name); - } - - @Override + @Before public void setUp() { - SharedTestUtils.printTestName("TupleOrderingTest." + getName()); out = new TupleOutput(); prevBuf = null; } - @Override + @After public void tearDown() { /* Ensure that GC can cleanup. */ @@ -143,6 +122,7 @@ public class TupleOrderingTest extends TestCase { out.reset(); } + @Test public void testString() { final String[] DATA = { @@ -177,6 +157,7 @@ public class TupleOrderingTest extends TestCase { check(); } + @Test public void testFixedString() { final char[][] DATA = { @@ -188,6 +169,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testChars() { final char[][] DATA = { @@ -200,6 +182,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testBytes() { final char[][] DATA = { @@ -212,6 +195,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testBoolean() { final boolean[] DATA = { @@ -223,6 +207,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testUnsignedByte() { final int[] DATA = { @@ -234,6 +219,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testUnsignedShort() { final int[] DATA = { @@ -245,6 +231,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testUnsignedInt() { final long[] DATA = { @@ -257,6 +244,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testByte() { final byte[] DATA = { @@ -270,6 +258,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testShort() { final short[] DATA = { @@ -285,6 +274,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testInt() { final int[] DATA = { @@ -302,6 +292,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testLong() { final long[] DATA = { @@ -321,6 +312,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testFloat() { // Only positive floats and doubles are ordered deterministically @@ -343,6 +335,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testDouble() { // Only positive floats and doubles are ordered deterministically @@ -365,6 +358,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testSortedFloat() { final float[] DATA = { @@ -413,6 +407,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testSortedDouble() { final double[] DATA = { @@ -464,6 +459,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testPackedIntAndLong() { /* Only packed int/long values from 0 to 630 are ordered correctly */ for (int i = 0; i <= 630; i += 1) { @@ -477,6 +473,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testSortedPackedInt() { final int[] DATA = { Integer.MIN_VALUE, Integer.MIN_VALUE + 1, @@ -493,6 +490,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testSortedPackedLong() { final long[] DATA = { Long.MIN_VALUE, Long.MIN_VALUE + 1, @@ -511,6 +509,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testBigInteger() { final BigInteger[] DATA = { new BigInteger("-1111111111111111111111111"), @@ -542,6 +541,7 @@ public class TupleOrderingTest extends TestCase { } } + @Test public void testSortedBigDecimal() { final BigDecimal[] DATA = { new BigDecimal(BigInteger.valueOf(Long.MIN_VALUE), diff --git a/test/java/compat/src/com/sleepycat/collections/KeyRangeTest.java b/test/java/compat/src/com/sleepycat/collections/KeyRangeTest.java index c02f6b75..b0af3432 100644 --- a/test/java/compat/src/com/sleepycat/collections/KeyRangeTest.java +++ b/test/java/compat/src/com/sleepycat/collections/KeyRangeTest.java @@ -1,20 +1,23 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + import java.io.File; import java.io.Serializable; import java.util.Arrays; import java.util.Comparator; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Test; import com.sleepycat.bind.ByteArrayBinding; import com.sleepycat.compat.DbCompat; @@ -28,11 +31,12 @@ import com.sleepycat.db.OperationStatus; import com.sleepycat.util.keyrange.KeyRange; import com.sleepycat.util.keyrange.KeyRangeException; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; /** * @author Mark Hayes */ -public class KeyRangeTest extends TestCase { +public class KeyRangeTest extends TestBase { private static boolean VERBOSE = false; @@ -58,32 +62,6 @@ public class KeyRangeTest extends TestCase { private DataView view; private DataCursor cursor; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - - return new TestSuite(KeyRangeTest.class); - } - - public KeyRangeTest(String name) { - - super(name); - } - - @Override - public void setUp() { - SharedTestUtils.printTestName(SharedTestUtils.qualifiedTestName(this)); - } - private void openDb(Comparator<byte []> comparator) throws Exception { @@ -113,7 +91,7 @@ public class KeyRangeTest extends TestCase { env = null; } - @Override + @After public void tearDown() { try { if (store != null) { @@ -136,12 +114,14 @@ public class KeyRangeTest extends TestCase { cursor = null; } + @Test public void testScan() throws Exception { openDb(null); doScan(false); closeDb(); } + @Test public void testScanComparator() throws Exception { openDb(new ReverseComparator()); doScan(true); @@ -361,6 +341,7 @@ public class KeyRangeTest extends TestCase { System.out.println(); } + @Test public void testSubRanges() { DatabaseEntry begin = new DatabaseEntry(); diff --git a/test/java/compat/src/com/sleepycat/collections/test/CollectionTest.java b/test/java/compat/src/com/sleepycat/collections/test/CollectionTest.java index 5a3963d2..e7edc67a 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/CollectionTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/CollectionTest.java @@ -1,16 +1,22 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -22,9 +28,10 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.concurrent.ConcurrentMap; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.bind.EntityBinding; import com.sleepycat.bind.EntryBinding; @@ -50,12 +57,14 @@ import com.sleepycat.db.DatabaseException; import com.sleepycat.db.Environment; import com.sleepycat.util.ExceptionUnwrapper; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class CollectionTest extends TestCase { +@RunWith(Parameterized.class) +public class CollectionTest extends TestBase { private static final int NONE = 0; private static final int SUB = 1; @@ -69,13 +78,13 @@ public class CollectionTest extends TestCase { * test below the block size (6), at the block size (10), and above it (14 * and 22). */ - private static final int DEFAULT_MAX_KEY = 6; + protected static final int DEFAULT_MAX_KEY = 6; private static final int[] MAX_KEYS = {6, 10, 14, 22}; private boolean testStoredIterator; - private int maxKey; /* Must be a multiple of 2. */ - private int beginKey = 1; - private int endKey; + private static int maxKey; /* Must be a multiple of 2. */ + protected static int beginKey = 1; + private static int endKey; private Environment env; private Database store; @@ -104,121 +113,49 @@ public class CollectionTest extends TestCase { private StoredKeySet keySet; private StoredValueSet valueSet; - /** - * Runs a command line collection test. - * @see #usage - */ - public static void main(String[] args) { - if (args.length == 1 && - (args[0].equals("-h") || args[0].equals("-help"))) { - usage(); - } else { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite(args)); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - } - - private static void usage() { - - System.out.println( - "Usage: java com.sleepycat.collections.test.CollectionTest\n" + - " -h | -help\n" + - " [testName]...\n" + - " where testName has the format:\n" + - " <env>-<store>-{entity|value}\n" + - " <env> is:\n" + - " bdb | cdb | txn\n" + - " <store> is:\n" + - " btree-uniq | btree-dup | btree-dupsort | btree-recnum |\n" + - " hash-uniq | hash-dup | hash-dupsort |\n" + - " queue | recno | recno-renum\n" + - " For example: bdb-btree-uniq-entity\n" + - " If no arguments are given then all tests are run."); - System.exit(2); - } - - public static Test suite() { - return suite(null); - } - - static Test suite(String[] args) { - if (SharedTestUtils.runLongTests()) { - TestSuite suite = new TestSuite(); - - /* StoredIterator tests. */ - permuteTests(args, suite, true, DEFAULT_MAX_KEY); - - /* BlockIterator tests with different maxKey values. */ - for (int i = 0; i < MAX_KEYS.length; i += 1) { - permuteTests(args, suite, false, MAX_KEYS[i]); - } - - return suite; - } else { - return baseSuite(args); - } - } - - private static void permuteTests(String[] args, - TestSuite suite, - boolean storedIter, - int maxKey) { - TestSuite baseTests = baseSuite(args); - Enumeration e = baseTests.tests(); - while (e.hasMoreElements()) { - CollectionTest t = (CollectionTest) e.nextElement(); - t.setParams(storedIter, maxKey); - suite.addTest(t); - } - } - - private static TestSuite baseSuite(String[] args) { - TestSuite suite = new TestSuite(); + @Parameters + public static List<Object[]> genParams() { + if (SharedTestUtils.runLongTests()){ + List<Object[]> list = baseParams(true, DEFAULT_MAX_KEY); + + for (int i : MAX_KEYS) + list.addAll(baseParams(false, i)); + + return list; + } + return baseParams(false, 6); + } + + private static List<Object[]> baseParams(boolean storedIter, + int maximumKey){ + + List <Object[]> list = new ArrayList<Object[]>(); for (int i = 0; i < TestEnv.ALL.length; i += 1) { for (int j = 0; j < TestStore.ALL.length; j += 1) { for (int k = 0; k < 2; k += 1) { boolean entityBinding = (k != 0); - - addTest(args, suite, new CollectionTest( - TestEnv.ALL[i], TestStore.ALL[j], - entityBinding, false)); - + + list.add(new Object[] {TestEnv.ALL[i], TestStore.ALL[j], + entityBinding, false, storedIter, maximumKey}); + if (TestEnv.ALL[i].isTxnMode()) { - addTest(args, suite, new CollectionTest( - TestEnv.ALL[i], TestStore.ALL[j], - entityBinding, true)); + list.add(new Object[] + {TestEnv.ALL[i], TestStore.ALL[j], entityBinding, + true, storedIter, maximumKey}); } } } } - return suite; + + return list; } - private static void addTest(String[] args, TestSuite suite, - CollectionTest test) { - - if (args == null || args.length == 0) { - suite.addTest(test); - } else { - for (int t = 0; t < args.length; t += 1) { - if (args[t].equals(test.testName)) { - suite.addTest(test); - break; - } - } - } - } - - public CollectionTest(TestEnv testEnv, TestStore testStore, - boolean isEntityBinding, boolean isAutoCommit) { - - super(null); + public CollectionTest(TestEnv testEnv, + TestStore testStore, + boolean isEntityBinding, + boolean isAutoCommit, + boolean storedIter, + int maxKey) { this.testEnv = testEnv; this.testStore = testStore; @@ -229,14 +166,15 @@ public class CollectionTest extends TestCase { valueBinding = testStore.getValueBinding(); entityBinding = testStore.getEntityBinding(); - setParams(false, DEFAULT_MAX_KEY); + setParams(storedIter, maxKey); + customName = testName; } - private void setParams(boolean storedIter, int maxKey) { + private void setParams(boolean storedIter, int maximumKey) { - this.testStoredIterator = storedIter; - this.maxKey = maxKey; - this.endKey = maxKey; + testStoredIterator = storedIter; + maxKey = maximumKey; + endKey = maximumKey; testName = testEnv.getName() + '-' + testStore.getName() + (isEntityBinding ? "-entity" : "-value") + @@ -245,19 +183,13 @@ public class CollectionTest extends TestCase { ((maxKey != DEFAULT_MAX_KEY) ? ("-maxKey-" + maxKey) : ""); } - @Override - public void tearDown() { - setName(testName); - } - @Override + @Test public void runTest() throws Exception { - SharedTestUtils.printTestName(SharedTestUtils.qualifiedTestName(this)); try { env = testEnv.open(testName); - // For testing auto-commit, use a normal (transactional) runner for // all reading and for writing via an iterator, and a do-nothing // runner for writing via collections; if auto-commit is tested, diff --git a/test/java/compat/src/com/sleepycat/collections/test/DbTestUtil.java b/test/java/compat/src/com/sleepycat/collections/test/DbTestUtil.java index de92d03f..69ba23d9 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/DbTestUtil.java +++ b/test/java/compat/src/com/sleepycat/collections/test/DbTestUtil.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * * $Id: DbTestUtil.java,v 0f73af5ae3da 2010/05/10 05:38:40 alexander $ */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/ForeignKeyTest.java b/test/java/compat/src/com/sleepycat/collections/test/ForeignKeyTest.java index ef540994..60d196b6 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/ForeignKeyTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/ForeignKeyTest.java @@ -1,17 +1,29 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.bind.serial.StoredClassCatalog; import com.sleepycat.bind.serial.TupleSerialMarshalledKeyCreator; @@ -29,12 +41,14 @@ import com.sleepycat.db.SecondaryDatabase; import com.sleepycat.util.ExceptionUnwrapper; import com.sleepycat.util.RuntimeExceptionWrapper; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class ForeignKeyTest extends TestCase { +@RunWith(Parameterized.class) +public class ForeignKeyTest extends TestBase { private static final ForeignKeyDeleteAction[] ACTIONS = { ForeignKeyDeleteAction.ABORT, @@ -47,29 +61,20 @@ public class ForeignKeyTest extends TestCase { "CASCADE", }; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(); - for (int i = 0; i < TestEnv.ALL.length; i += 1) { - for (int j = 0; j < ACTIONS.length; j += 1) { - suite.addTest(new ForeignKeyTest(TestEnv.ALL[i], - ACTIONS[j], - ACTION_LABELS[j])); + @Parameters + public static List<Object[]> genParams() { + List<Object[]> params = new ArrayList<Object[]>(); + for (TestEnv testEnv : TestEnv.ALL) { + int i = 0; + for (ForeignKeyDeleteAction action : ACTIONS) { + params.add(new Object[]{testEnv, action, ACTION_LABELS[i]}); + i ++; } } - return suite; + + return params; } - + private TestEnv testEnv; private Environment env; private StoredClassCatalog catalog; @@ -87,23 +92,24 @@ public class ForeignKeyTest extends TestCase { public ForeignKeyTest(TestEnv testEnv, ForeignKeyDeleteAction onDelete, String onDeleteLabel) { - super("ForeignKeyTest-" + testEnv.getName() + '-' + onDeleteLabel); + customName = + "ForeignKeyTest-" + testEnv.getName() + '-' + onDeleteLabel; this.testEnv = testEnv; this.onDelete = onDelete; } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(getName()); - env = testEnv.open(getName()); - + super.setUp(); + SharedTestUtils.printTestName(customName); + env = testEnv.open(customName); createDatabase(); } - @Override + @After public void tearDown() { try { @@ -144,7 +150,7 @@ public class ForeignKeyTest extends TestCase { } } - @Override + @Test public void runTest() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/IterDeadlockTest.java b/test/java/compat/src/com/sleepycat/collections/test/IterDeadlockTest.java index 1a8dcc4d..9492ffe3 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/IterDeadlockTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/IterDeadlockTest.java @@ -1,18 +1,22 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.Iterator; import java.util.ListIterator; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.ByteArrayBinding; import com.sleepycat.collections.StoredIterator; @@ -24,6 +28,7 @@ import com.sleepycat.db.Database; import com.sleepycat.db.DatabaseConfig; import com.sleepycat.db.Environment; import com.sleepycat.db.DeadlockException; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** @@ -33,26 +38,10 @@ import com.sleepycat.util.test.TestEnv; * the first element. * @author Mark Hayes */ -public class IterDeadlockTest extends TestCase { +public class IterDeadlockTest extends TestBase { private static final byte[] ONE = { 1 }; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(IterDeadlockTest.class); - return suite; - } - private Environment env; private Database store1; private Database store2; @@ -60,12 +49,7 @@ public class IterDeadlockTest extends TestCase { private StoredSortedMap map2; private final ByteArrayBinding binding = new ByteArrayBinding(); - public IterDeadlockTest(String name) { - - super(name); - } - - @Override + @Before public void setUp() throws Exception { @@ -76,7 +60,7 @@ public class IterDeadlockTest extends TestCase { map2 = new StoredSortedMap(store2, binding, binding, true); } - @Override + @After public void tearDown() { if (store1 != null) { @@ -119,6 +103,7 @@ public class IterDeadlockTest extends TestCase { return DbCompat.testOpenDatabase(env, null, file, null, config); } + @Test public void testIterDeadlock() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/JoinTest.java b/test/java/compat/src/com/sleepycat/collections/test/JoinTest.java index d2bf4152..9157a6cc 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/JoinTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/JoinTest.java @@ -1,16 +1,24 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.serial.StoredClassCatalog; import com.sleepycat.bind.serial.test.MarshalledObject; @@ -28,33 +36,19 @@ import com.sleepycat.db.Environment; import com.sleepycat.db.SecondaryConfig; import com.sleepycat.db.SecondaryDatabase; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class JoinTest extends TestCase +public class JoinTest extends TestBase implements TransactionWorker { private static final String MATCH_DATA = "d4"; // matches both keys = "yes" private static final String MATCH_KEY = "k4"; // matches both keys = "yes" private static final String[] VALUES = {"yes", "yes"}; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - return new JoinTest(); - } - private Environment env; private TransactionRunner runner; private StoredClassCatalog catalog; @@ -67,21 +61,20 @@ public class JoinTest extends TestCase private StoredMap indexMap2; public JoinTest() { - - super("JoinTest"); + customName = "JoinTest"; } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(getName()); - env = TestEnv.TXN.open(getName()); + SharedTestUtils.printTestName(customName); + env = TestEnv.TXN.open(customName); runner = new TransactionRunner(env); createDatabase(); } - @Override + @After public void tearDown() { try { @@ -117,7 +110,7 @@ public class JoinTest extends TestCase } } - @Override + @Test public void runTest() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/NullTransactionRunner.java b/test/java/compat/src/com/sleepycat/collections/test/NullTransactionRunner.java index 96d56dc6..20ce2e2a 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/NullTransactionRunner.java +++ b/test/java/compat/src/com/sleepycat/collections/test/NullTransactionRunner.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/NullValueTest.java b/test/java/compat/src/com/sleepycat/collections/test/NullValueTest.java index 238855c4..59929598 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/NullValueTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/NullValueTest.java @@ -1,15 +1,21 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.EntityBinding; import com.sleepycat.bind.EntryBinding; @@ -29,30 +35,16 @@ import com.sleepycat.db.DatabaseConfig; import com.sleepycat.db.DatabaseException; import com.sleepycat.db.Environment; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * Unit test for [#19085]. The collections API supports storing and retrieving * null values, as long as the value binding supports null values. */ -public class NullValueTest extends TestCase +public class NullValueTest extends TestBase implements TransactionWorker { - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - return new NullValueTest(); - } - private Environment env; private ClassCatalog catalog; private Database db; @@ -60,20 +52,20 @@ public class NullValueTest extends TestCase public NullValueTest() { - super("NullValueTest"); + customName = "NullValueTest"; } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(getName()); - env = TestEnv.TXN.open(getName()); + SharedTestUtils.printTestName(customName); + env = TestEnv.TXN.open(customName); runner = new TransactionRunner(env); open(); } - @Override + @After public void tearDown() { if (catalog != null) { try { @@ -116,7 +108,7 @@ public class NullValueTest extends TestCase db = DbCompat.testOpenDatabase(env, null, "test", null, dbConfig); } - @Override + @Test public void runTest() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/SecondaryDeadlockTest.java b/test/java/compat/src/com/sleepycat/collections/test/SecondaryDeadlockTest.java index 2b122a72..c3f54ea3 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/SecondaryDeadlockTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/SecondaryDeadlockTest.java @@ -1,15 +1,19 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.collections.StoredSortedMap; import com.sleepycat.collections.TransactionRunner; @@ -19,6 +23,7 @@ import com.sleepycat.db.Environment; import com.sleepycat.db.DeadlockException; import com.sleepycat.db.TransactionConfig; import com.sleepycat.util.ExceptionUnwrapper; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** @@ -30,29 +35,13 @@ import com.sleepycat.util.test.TestEnv; * * @author Mark Hayes */ -public class SecondaryDeadlockTest extends TestCase { +public class SecondaryDeadlockTest extends TestBase { private static final Long N_ONE = new Long(1); private static final Long N_101 = new Long(101); private static final int N_ITERS = 20; private static final int MAX_RETRIES = 1000; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(SecondaryDeadlockTest.class); - return suite; - } - private Environment env; private Database store; private Database index; @@ -60,15 +49,16 @@ public class SecondaryDeadlockTest extends TestCase { private StoredSortedMap indexMap; private Exception exception; - public SecondaryDeadlockTest(String name) { + public SecondaryDeadlockTest() { - super(name); + customName = "SecondaryDeadlockTest"; } - @Override + @Before public void setUp() throws Exception { + super.setUp(); env = TestEnv.TXN.open("SecondaryDeadlockTest"); store = TestStore.BTREE_UNIQ.open(env, "store.db"); index = TestStore.BTREE_UNIQ.openIndex(store, "index.db"); @@ -82,7 +72,7 @@ public class SecondaryDeadlockTest extends TestCase { true); } - @Override + @After public void tearDown() { if (index != null) { @@ -114,6 +104,7 @@ public class SecondaryDeadlockTest extends TestCase { indexMap = null; } + @Test public void testSecondaryDeadlock() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestDataBinding.java b/test/java/compat/src/com/sleepycat/collections/test/TestDataBinding.java index 76626ada..bbd4b006 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestDataBinding.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestDataBinding.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestEntity.java b/test/java/compat/src/com/sleepycat/collections/test/TestEntity.java index a1a53b46..29d4cde9 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestEntity.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestEntity.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestEntityBinding.java b/test/java/compat/src/com/sleepycat/collections/test/TestEntityBinding.java index 791ac276..e5b78d43 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestEntityBinding.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestEntityBinding.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestEnv.java b/test/java/compat/src/com/sleepycat/collections/test/TestEnv.java index 72345325..76f59ce1 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestEnv.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestEnv.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * * $Id: TestEnv.java,v 0f73af5ae3da 2010/05/10 05:38:40 alexander $ */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestKeyAssigner.java b/test/java/compat/src/com/sleepycat/collections/test/TestKeyAssigner.java index dddd19ba..7f19e871 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestKeyAssigner.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestKeyAssigner.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestKeyCreator.java b/test/java/compat/src/com/sleepycat/collections/test/TestKeyCreator.java index 867622ad..15347b64 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestKeyCreator.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestKeyCreator.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestSR15721.java b/test/java/compat/src/com/sleepycat/collections/test/TestSR15721.java index 8caf58c1..0fd7c433 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestSR15721.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestSR15721.java @@ -1,62 +1,34 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.collections.CurrentTransaction; import com.sleepycat.db.Environment; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Chao Huang */ -public class TestSR15721 extends TestCase { - - /** - * Runs a command line collection test. - * @see #usage - */ - public static void main(String[] args) { - if (args.length == 1 && - (args[0].equals("-h") || args[0].equals("-help"))) { - usage(); - } else { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - } - - private static void usage() { - - System.out.println( - "Usage: java com.sleepycat.collections.test.TestSR15721" - + " [-h | -help]\n"); - System.exit(2); - } - - public static Test suite() { - TestSuite suite = new TestSuite(TestSR15721.class); - return suite; - } +public class TestSR15721 extends TestBase { private Environment env; private CurrentTransaction currentTxn; - @Override + @Before public void setUp() throws Exception { @@ -64,7 +36,7 @@ public class TestSR15721 extends TestCase { currentTxn = CurrentTransaction.getInstance(env); } - @Override + @After public void tearDown() { try { if (env != null) { @@ -83,6 +55,7 @@ public class TestSR15721 extends TestCase { * Tests that the CurrentTransaction instance doesn't indeed allow GC to * reclaim while attached environment is open. [#15721] */ + @Test public void testSR15721Fix() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/TestStore.java b/test/java/compat/src/com/sleepycat/collections/test/TestStore.java index 265ec886..54f9ffd8 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TestStore.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TestStore.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/collections/test/TransactionTest.java b/test/java/compat/src/com/sleepycat/collections/test/TransactionTest.java index 1244174e..c091c403 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/TransactionTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/TransactionTest.java @@ -1,12 +1,19 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileNotFoundException; import java.util.Iterator; @@ -14,9 +21,9 @@ import java.util.List; import java.util.SortedSet; import java.util.concurrent.atomic.AtomicInteger; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.collections.CurrentTransaction; import com.sleepycat.collections.StoredCollections; @@ -41,49 +48,18 @@ import com.sleepycat.db.Transaction; import com.sleepycat.db.TransactionConfig; import com.sleepycat.util.RuntimeExceptionWrapper; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class TransactionTest extends TestCase { +public class TransactionTest extends TestBase { private static final Long ONE = new Long(1); private static final Long TWO = new Long(2); private static final Long THREE = new Long(3); - /** - * Runs a command line collection test. - * @see #usage - */ - public static void main(String[] args) { - if (args.length == 1 && - (args[0].equals("-h") || args[0].equals("-help"))) { - usage(); - } else { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - } - - private static void usage() { - - System.out.println( - "Usage: java com.sleepycat.collections.test.TransactionTest" - + " [-h | -help]\n"); - System.exit(2); - } - - public static Test suite() { - TestSuite suite = new TestSuite(TransactionTest.class); - return suite; - } private Environment env; private CurrentTransaction currentTxn; @@ -91,16 +67,16 @@ public class TransactionTest extends TestCase { private StoredSortedMap map; private TestStore testStore = TestStore.BTREE_UNIQ; - public TransactionTest(String name) { + public TransactionTest() { - super(name); + customName = "TransactionTest"; } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(SharedTestUtils.qualifiedTestName(this)); + super.setUp(); env = TestEnv.TXN.open("TransactionTests"); currentTxn = CurrentTransaction.getInstance(env); store = testStore.open(env, dbName(0)); @@ -108,7 +84,7 @@ public class TransactionTest extends TestCase { testStore.getValueBinding(), true); } - @Override + @After public void tearDown() { try { @@ -132,9 +108,10 @@ public class TransactionTest extends TestCase { private String dbName(int i) { - return "txn-test-" + getName() + '-' + i; + return "txn-test-" + i; } + @Test public void testGetters() throws Exception { @@ -191,6 +168,7 @@ public class TransactionTest extends TestCase { assertTrue(!isReadCommitted(map.entrySet())); } + @Test public void testTransactional() throws Exception { @@ -232,6 +210,7 @@ public class TransactionTest extends TestCase { db.close(); } + @Test public void testExceptions() throws Exception { @@ -246,6 +225,7 @@ public class TransactionTest extends TestCase { } catch (IllegalStateException expected) {} } + @Test public void testNested() throws Exception { @@ -317,12 +297,14 @@ public class TransactionTest extends TestCase { assertEquals(ONE, map.get(ONE)); } + @Test public void testRunnerCommit() throws Exception { commitTest(false); } + @Test public void testExplicitCommit() throws Exception { @@ -373,12 +355,14 @@ public class TransactionTest extends TestCase { assertNull(currentTxn.getTransaction()); } + @Test public void testRunnerAbort() throws Exception { abortTest(false); } + @Test public void testExplicitAbort() throws Exception { @@ -436,6 +420,7 @@ public class TransactionTest extends TestCase { assertNull(currentTxn.getTransaction()); } + @Test public void testReadCommittedCollection() throws Exception { @@ -484,6 +469,7 @@ public class TransactionTest extends TestCase { storedContainer.getCursorConfig().getReadCommitted(); } + @Test public void testReadCommittedTransaction() throws Exception { @@ -524,6 +510,7 @@ public class TransactionTest extends TestCase { assertNull(currentTxn.getTransaction()); } + @Test public void testReadUncommittedCollection() throws Exception { @@ -569,6 +556,7 @@ public class TransactionTest extends TestCase { storedContainer.getCursorConfig().getReadUncommitted(); } + @Test public void testReadUncommittedTransaction() throws Exception { @@ -596,6 +584,7 @@ public class TransactionTest extends TestCase { * This test only succeeds intermittently, probably due to its reliance * on the GC call. */ + @Test public void testCurrentTransactionGC() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/serial/CatalogCornerCaseTest.java b/test/java/compat/src/com/sleepycat/collections/test/serial/CatalogCornerCaseTest.java index e620371b..d8d8b296 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/serial/CatalogCornerCaseTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/serial/CatalogCornerCaseTest.java @@ -1,14 +1,16 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test.serial; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.bind.serial.StoredClassCatalog; import com.sleepycat.compat.DbCompat; @@ -16,44 +18,31 @@ import com.sleepycat.db.Database; import com.sleepycat.db.DatabaseConfig; import com.sleepycat.db.Environment; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class CatalogCornerCaseTest extends TestCase { - - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - return new TestSuite(CatalogCornerCaseTest.class); - } +public class CatalogCornerCaseTest extends TestBase { private Environment env; - public CatalogCornerCaseTest(String name) { + public CatalogCornerCaseTest() { - super(name); + customName = "CatalogCornerCaseTest"; } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(getName()); - env = TestEnv.BDB.open(getName()); + super.setUp(); + SharedTestUtils.printTestName(customName); + env = TestEnv.BDB.open(customName); } - @Override + @After public void tearDown() { try { @@ -68,6 +57,7 @@ public class CatalogCornerCaseTest extends TestCase { } } + @Test public void testReadOnlyEmptyCatalog() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java b/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java index b9fd4750..9e7954bc 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java @@ -1,17 +1,27 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test.serial; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.File; import java.io.ObjectStreamClass; +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.bind.serial.SerialBinding; import com.sleepycat.bind.serial.StoredClassCatalog; @@ -23,6 +33,7 @@ import com.sleepycat.db.Database; import com.sleepycat.db.DatabaseConfig; import com.sleepycat.db.Environment; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** @@ -34,29 +45,20 @@ import com.sleepycat.util.test.TestEnv; * * @author Mark Hayes */ -public class StoredClassCatalogTest extends TestCase +@RunWith(Parameterized.class) +public class StoredClassCatalogTest extends TestBase implements TransactionWorker { static final String CATALOG_FILE = "catalogtest-catalog.db"; static final String STORE_FILE = "catalogtest-store.db"; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(); - for (int i = 0; i < TestEnv.ALL.length; i += 1) { - suite.addTest(new StoredClassCatalogTest(TestEnv.ALL[i])); - } - return suite; + @Parameters + public static List<Object[]> genParams() { + List<Object[]> params = new ArrayList<Object[]>(); + for (TestEnv testEnv : TestEnv.ALL) + params.add(new Object[]{testEnv}); + + return params; } private TestEnv testEnv; @@ -69,20 +71,29 @@ public class StoredClassCatalogTest extends TestCase public StoredClassCatalogTest(TestEnv testEnv) { - super(makeTestName(testEnv)); this.testEnv = testEnv; + customName = makeTestName(testEnv); } static String makeTestName(TestEnv testEnv) { return "StoredClassCatalogTest-" + testEnv.getName(); } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(getName()); - env = testEnv.open(makeTestName(testEnv), false); + SharedTestUtils.printTestName(customName); + + /* + * Copy the environment generated by StoredClassCatalogTestInit in + * test dest dir, which is required to perform this test. + */ + SharedTestUtils.copyDir( + new File(SharedTestUtils.getDestDir(), customName), + new File(SharedTestUtils.getTestDir(), customName)); + + env = testEnv.open(customName, false); runner = new TransactionRunner(env); catalog = new StoredClassCatalog(openDb(CATALOG_FILE, false)); @@ -108,7 +119,7 @@ public class StoredClassCatalogTest extends TestCase return DbCompat.testOpenDatabase(env, null, file, null, config); } - @Override + @After public void tearDown() { try { @@ -139,8 +150,8 @@ public class StoredClassCatalogTest extends TestCase runner = null; } } - - @Override + + @Test public void runTest() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java b/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java index 6fde045d..80117289 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java +++ b/test/java/compat/src/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java @@ -1,16 +1,25 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test.serial; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.bind.serial.SerialBinding; import com.sleepycat.bind.serial.StoredClassCatalog; @@ -22,6 +31,7 @@ import com.sleepycat.db.Database; import com.sleepycat.db.DatabaseConfig; import com.sleepycat.db.Environment; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** @@ -33,29 +43,20 @@ import com.sleepycat.util.test.TestEnv; * * @author Mark Hayes */ -public class StoredClassCatalogTestInit extends TestCase +@RunWith(Parameterized.class) +public class StoredClassCatalogTestInit extends TestBase implements TransactionWorker { static final String CATALOG_FILE = StoredClassCatalogTest.CATALOG_FILE; static final String STORE_FILE = StoredClassCatalogTest.STORE_FILE; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(); - for (int i = 0; i < TestEnv.ALL.length; i += 1) { - suite.addTest(new StoredClassCatalogTestInit(TestEnv.ALL[i])); - } - return suite; + @Parameters + public static List<Object[]> genParams() { + List<Object[]> params = new ArrayList<Object[]>(); + for (TestEnv testEnv : TestEnv.ALL) + params.add(new Object[]{testEnv}); + + return params; } private TestEnv testEnv; @@ -67,16 +68,16 @@ public class StoredClassCatalogTestInit extends TestCase public StoredClassCatalogTestInit(TestEnv testEnv) { - super("StoredClassCatalogTestInit-" + testEnv.getName()); this.testEnv = testEnv; + customName = StoredClassCatalogTest.makeTestName(testEnv); } - @Override + @Before public void setUp() throws Exception { - - SharedTestUtils.printTestName(getName()); - env = testEnv.open(StoredClassCatalogTest.makeTestName(testEnv)); + + SharedTestUtils.printTestName(customName); + env = testEnv.open(customName); runner = new TransactionRunner(env); catalog = new StoredClassCatalog(openDb(CATALOG_FILE)); @@ -100,8 +101,9 @@ public class StoredClassCatalogTestInit extends TestCase return DbCompat.testOpenDatabase(env, null, file, null, config); } - @Override - public void tearDown() { + @After + public void tearDown() + throws Exception { try { if (catalog != null) { @@ -114,6 +116,14 @@ public class StoredClassCatalogTestInit extends TestCase if (env != null) { env.close(); } + + /* + * Copy environment generated by this test to test dest dir. + * Since the environment is necessary for StoreClassCatalogTest. + */ + SharedTestUtils.copyDir(testEnv.getDirectory(customName, false), + new File(SharedTestUtils.getDestDir(), customName)); + } catch (Exception e) { System.err.println("Ignored exception during tearDown: "); e.printStackTrace(); @@ -128,13 +138,13 @@ public class StoredClassCatalogTestInit extends TestCase } } - @Override + @Test public void runTest() throws Exception { - + runner.run(this); } - + public void doWork() { TestSerial one = new TestSerial(null); TestSerial two = new TestSerial(one); diff --git a/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java b/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java index 23261e59..700dc9d4 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java +++ b/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test.serial; diff --git a/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java.original b/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java.original index 55d9e9a3..51dd91f3 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java.original +++ b/test/java/compat/src/com/sleepycat/collections/test/serial/TestSerial.java.original @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle. All rights reserved. * */ package com.sleepycat.collections.test.serial; diff --git a/test/java/compat/src/com/sleepycat/collections/test/serial/TupleSerialFactoryTest.java b/test/java/compat/src/com/sleepycat/collections/test/serial/TupleSerialFactoryTest.java index 27002bec..5eb5fc30 100644 --- a/test/java/compat/src/com/sleepycat/collections/test/serial/TupleSerialFactoryTest.java +++ b/test/java/compat/src/com/sleepycat/collections/test/serial/TupleSerialFactoryTest.java @@ -1,16 +1,25 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.collections.test.serial; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.bind.serial.StoredClassCatalog; import com.sleepycat.bind.serial.test.MarshalledObject; @@ -25,34 +34,27 @@ import com.sleepycat.db.ForeignKeyDeleteAction; import com.sleepycat.db.SecondaryConfig; import com.sleepycat.db.SecondaryDatabase; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class TupleSerialFactoryTest extends TestCase - implements TransactionWorker { - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } +@RunWith(Parameterized.class) +public class TupleSerialFactoryTest extends TestBase + implements TransactionWorker { - public static Test suite() { - TestSuite suite = new TestSuite(); - for (int i = 0; i < TestEnv.ALL.length; i += 1) { + @Parameters + public static List<Object[]> genParams() { + List<Object[]> params = new ArrayList<Object[]>(); + for (TestEnv testEnv : TestEnv.ALL) { for (int sorted = 0; sorted < 2; sorted += 1) { - suite.addTest(new TupleSerialFactoryTest(TestEnv.ALL[i], - sorted != 0)); + params.add(new Object[]{testEnv, sorted != 0 }); } } - return suite; + + return params; } private TestEnv testEnv; @@ -72,28 +74,28 @@ public class TupleSerialFactoryTest extends TestCase public TupleSerialFactoryTest(TestEnv testEnv, boolean isSorted) { - super(null); this.testEnv = testEnv; this.isSorted = isSorted; String name = "TupleSerialFactoryTest-" + testEnv.getName(); name += isSorted ? "-sorted" : "-unsorted"; - setName(name); + customName = name; } - @Override + @Before public void setUp() throws Exception { - SharedTestUtils.printTestName(getName()); - env = testEnv.open(getName()); + super.setUp(); + SharedTestUtils.printTestName(customName); + env = testEnv.open(customName); runner = new TransactionRunner(env); createDatabase(); } - @Override + @After public void tearDown() { try { @@ -135,7 +137,7 @@ public class TupleSerialFactoryTest extends TestCase } } - @Override + @Test public void runTest() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/db/util/DualTestCase.java b/test/java/compat/src/com/sleepycat/db/util/DualTestCase.java index a109a4d0..8e34fcc8 100644 --- a/test/java/compat/src/com/sleepycat/db/util/DualTestCase.java +++ b/test/java/compat/src/com/sleepycat/db/util/DualTestCase.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * * $Id$ */ @@ -11,27 +11,22 @@ package com.sleepycat.db.util; import java.io.File; import java.io.FileNotFoundException; -import junit.framework.TestCase; +import com.sleepycat.util.test.TestBase; import com.sleepycat.db.DatabaseException; import com.sleepycat.db.Environment; import com.sleepycat.db.EnvironmentConfig; -public class DualTestCase extends TestCase { +public class DualTestCase extends TestBase { - private Environment env; private boolean setUpInvoked = false; public DualTestCase() { super(); } - protected DualTestCase(String name) { - super(name); - } - @Override - protected void setUp() + public void setUp() throws Exception { setUpInvoked = true; @@ -39,20 +34,20 @@ public class DualTestCase extends TestCase { } @Override - protected void tearDown() + public void tearDown() throws Exception { if (!setUpInvoked) { throw new IllegalStateException ("tearDown was invoked without a corresponding setUp() call"); } - destroy(); super.tearDown(); } protected Environment create(File envHome, EnvironmentConfig envConfig) throws DatabaseException { + Environment env = null; try { env = new Environment(envHome, envConfig); } catch (FileNotFoundException e) { @@ -61,25 +56,10 @@ public class DualTestCase extends TestCase { return env; } - protected void close(Environment environment) + protected void close(Environment env) throws DatabaseException { env.close(); - env = null; - } - - protected void destroy() - throws Exception { - - if (env != null) { - try { - /* Close in case we hit an exception and didn't close */ - env.close(); - } catch (RuntimeException e) { - /* OK if already closed */ - } - env = null; - } } public static boolean isReplicatedTest(Class<?> testCaseClass) { diff --git a/test/java/compat/src/com/sleepycat/persist/test/BindingTest.java b/test/java/compat/src/com/sleepycat/persist/test/BindingTest.java index 88ac6683..17e87ba5 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/BindingTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/BindingTest.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ @@ -10,6 +10,12 @@ package com.sleepycat.persist.test; import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; import static com.sleepycat.persist.model.Relationship.ONE_TO_MANY; import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.FileNotFoundException; @@ -36,6 +42,10 @@ import java.util.TreeSet; import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import com.sleepycat.bind.EntryBinding; import com.sleepycat.compat.DbCompat; import com.sleepycat.db.DatabaseConfig; @@ -68,12 +78,13 @@ import com.sleepycat.persist.raw.RawField; import com.sleepycat.persist.raw.RawObject; import com.sleepycat.persist.raw.RawType; import com.sleepycat.util.test.SharedTestUtils; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** * @author Mark Hayes */ -public class BindingTest extends TestCase { +public class BindingTest extends TestBase { private static final String STORE_PREFIX = "persist#foo#"; @@ -84,15 +95,18 @@ public class BindingTest extends TestCase { private DatabaseEntry keyEntry; private DatabaseEntry dataEntry; - @Override - public void setUp() { - envHome = new File(System.getProperty(SharedTestUtils.DEST_DIR)); - SharedTestUtils.emptyDir(envHome); + @Before + public void setUp() + throws Exception { + + envHome = SharedTestUtils.getTestDir(); + super.setUp(); + keyEntry = new DatabaseEntry(); dataEntry = new DatabaseEntry(); } - @Override + @After public void tearDown() { if (env != null) { try { @@ -153,6 +167,7 @@ public class BindingTest extends TestCase { env = null; } + @Test public void testBasic() throws FileNotFoundException, DatabaseException { @@ -216,6 +231,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSimpleTypes() throws FileNotFoundException, DatabaseException { @@ -309,6 +325,7 @@ public class BindingTest extends TestCase { } } + @Test public void testArrayTypes() throws FileNotFoundException, DatabaseException { @@ -404,6 +421,7 @@ public class BindingTest extends TestCase { } } + @Test public void testEnumTypes() throws FileNotFoundException, DatabaseException { @@ -481,6 +499,7 @@ public class BindingTest extends TestCase { } } + @Test public void testEnumObjectTypes() throws FileNotFoundException, DatabaseException { @@ -520,6 +539,7 @@ public class BindingTest extends TestCase { } } + @Test public void testProxyTypes() throws FileNotFoundException, DatabaseException { @@ -664,6 +684,7 @@ public class BindingTest extends TestCase { } } + @Test public void testEmbedded() throws FileNotFoundException, DatabaseException { @@ -786,6 +807,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSubclass() throws FileNotFoundException, DatabaseException { @@ -835,6 +857,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSuperclass() throws FileNotFoundException, DatabaseException { @@ -890,6 +913,7 @@ public class BindingTest extends TestCase { } } + @Test public void testAbstract() throws FileNotFoundException, DatabaseException { @@ -1059,6 +1083,7 @@ public class BindingTest extends TestCase { } } + @Test public void testCompositeKey() throws FileNotFoundException, DatabaseException { @@ -1189,6 +1214,7 @@ public class BindingTest extends TestCase { } } + @Test public void testComparableKey() throws FileNotFoundException, DatabaseException { @@ -1316,6 +1342,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSecKeys() throws FileNotFoundException, DatabaseException { @@ -1785,6 +1812,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSecKeyRefToPriKey() throws FileNotFoundException, DatabaseException { @@ -1843,6 +1871,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSecKeyInSuperclass() throws FileNotFoundException, DatabaseException { @@ -1908,6 +1937,7 @@ public class BindingTest extends TestCase { } } + @Test public void testSecKeyInSubclass() throws FileNotFoundException, DatabaseException { diff --git a/test/java/compat/src/com/sleepycat/persist/test/Enhanced0.java b/test/java/compat/src/com/sleepycat/persist/test/Enhanced0.java index 90ca6700..e42ca46b 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/Enhanced0.java +++ b/test/java/compat/src/com/sleepycat/persist/test/Enhanced0.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/persist/test/Enhanced1.java b/test/java/compat/src/com/sleepycat/persist/test/Enhanced1.java index 638c82a1..062aa968 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/Enhanced1.java +++ b/test/java/compat/src/com/sleepycat/persist/test/Enhanced1.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/persist/test/Enhanced2.java b/test/java/compat/src/com/sleepycat/persist/test/Enhanced2.java index b29a5501..8032a553 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/Enhanced2.java +++ b/test/java/compat/src/com/sleepycat/persist/test/Enhanced2.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/persist/test/Enhanced3.java b/test/java/compat/src/com/sleepycat/persist/test/Enhanced3.java index 32a14b8b..9c413a51 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/Enhanced3.java +++ b/test/java/compat/src/com/sleepycat/persist/test/Enhanced3.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/persist/test/EvolveCase.java b/test/java/compat/src/com/sleepycat/persist/test/EvolveCase.java index d8c13b4d..0f00265a 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/EvolveCase.java +++ b/test/java/compat/src/com/sleepycat/persist/test/EvolveCase.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; diff --git a/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java b/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java index f4a5c93e..5b96d8a9 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java +++ b/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; @@ -7965,4 +7965,96 @@ class EvolveClasses { return new ProxiedClass(((IntegerClass)data[0]).data); } } + + @Persistent(version=1) + static class MultipleSelfRefsEmbed { + MultipleSelfRefs ref; + MultipleSelfRefsEmbed embed; + /* ref2 is a new field. */ + MultipleSelfRefs ref2; + } + + /** + * Test multiple refs in an attempt to reproduce a bug where an assertion + * fired in Evolver.evolveInternal. This did not reproduce the bug, + * apparently because a very specific sequence of nested references is + * needed. But the test is included in case it is useful for other + * reasons. [#21869] + */ + @Entity(version=1) + static class MultipleSelfRefs + extends EvolveCase { + + private static final String NAME = PREFIX + "MultipleSelfRefs"; + + @PrimaryKey + int key; + + MultipleSelfRefs ref; + MultipleSelfRefsEmbed embed; + /* ref2 is a new field. */ + MultipleSelfRefs ref2; + + @Override + void checkEvolvedModel(EntityModel model, + Environment env, + boolean oldTypesExist) { + checkEntity(true, model, env, NAME, 1, null); + if (oldTypesExist) { + checkVersions(model, NAME, 1, NAME, 0); + } else { + checkVersions(model, NAME, 1); + } + } + + @Override + void readObjects(EntityStore store, boolean doUpdate) + throws DatabaseException { + + PrimaryIndex<Integer, MultipleSelfRefs> + index = store.getPrimaryIndex + (Integer.class, + MultipleSelfRefs.class); + MultipleSelfRefs obj = index.get(99); + TestCase.assertNotNull(obj); + TestCase.assertEquals(99, obj.key); + + if (doUpdate) { + index.put(obj); + } + } + + @Override + void copyRawObjects(RawStore rawStore, EntityStore newStore) + throws DatabaseException { + + PrimaryIndex<Integer, MultipleSelfRefs> + index = newStore.getPrimaryIndex + (Integer.class, + MultipleSelfRefs.class); + RawObject raw = rawStore.getPrimaryIndex(NAME).get(99); + index.put((MultipleSelfRefs) + newStore.getModel().convertRawObject(raw)); + } + + @Override + void readRawObjects(RawStore store, + boolean expectEvolved, + boolean expectUpdated) + throws DatabaseException { + + RawObject obj; + if (expectEvolved) { + obj = readRaw(store, 99, NAME, 1, CASECLS, 0); + } else { + obj = readRaw(store, 99, NAME, 0, CASECLS, 0); + } + if (expectEvolved && expectUpdated) { + checkRawFields(obj, "key", 99, "ref", ref, "embed", embed, + "ref2", ref2); + } else { + checkRawFields(obj, "key", 99, "ref", ref, "embed", embed); + } + } + } } diff --git a/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java.original b/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java.original index 3fdba6aa..244ba60c 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java.original +++ b/test/java/compat/src/com/sleepycat/persist/test/EvolveClasses.java.original @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle. All rights reserved. + * Copyright (c) 2000, 2015 Oracle. All rights reserved. * */ package com.sleepycat.persist.test; @@ -3144,4 +3144,33 @@ class EvolveClasses { return new ProxiedClass(data[0]); } } + + /* [#21869] */ + @Persistent + static class MultipleSelfRefsEmbed { + MultipleSelfRefs ref; + MultipleSelfRefsEmbed embed; + } + + @Entity + static class MultipleSelfRefs + extends EvolveCase { + + @PrimaryKey + int key; + + MultipleSelfRefs ref; + MultipleSelfRefsEmbed embed; + + @Override + void writeObjects(EntityStore store) + throws DatabaseException { + + PrimaryIndex<Integer, MultipleSelfRefs> + index = store.getPrimaryIndex + (Integer.class, MultipleSelfRefs.class); + key = 99; + index.put(this); + } + } } diff --git a/test/java/compat/src/com/sleepycat/persist/test/EvolveTest.java b/test/java/compat/src/com/sleepycat/persist/test/EvolveTest.java index d2a5f4a0..89b10e4c 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/EvolveTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/EvolveTest.java @@ -1,14 +1,17 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; -import java.io.IOException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.Test; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import com.sleepycat.persist.evolve.EvolveConfig; import com.sleepycat.persist.evolve.EvolveEvent; @@ -28,15 +31,14 @@ import com.sleepycat.util.test.SharedTestUtils; */ public class EvolveTest extends EvolveTestBase { + public EvolveTest(String originalClsName, String evolvedClsName) + throws Exception { + super(originalClsName, evolvedClsName); + } + /* Toggle to use listener every other test case. */ private static boolean useEvolveListener; - public static Test suite() - throws Exception { - - return getSuite(EvolveTest.class); - } - private int evolveNRead; private int evolveNConverted; @@ -44,22 +46,25 @@ public class EvolveTest extends EvolveTestBase { return true; } - @Override - public void tearDown() { - try { super.tearDown(); } catch (Throwable e) { } - } - - @Override + @Before public void setUp() - throws IOException { + throws Exception { + super.setUp(); + /* Copy the log files created by EvolveTestInit. */ envHome = getTestInitHome(true /*evolved*/); envHome.mkdirs(); SharedTestUtils.emptyDir(envHome); SharedTestUtils.copyFiles(getTestInitHome(false /*evolved*/), envHome); } + + @After + public void tearDown() { + try { super.tearDown(); } catch (Throwable e) { } + } + @Test public void testLazyEvolve() throws Exception { @@ -151,6 +156,7 @@ public class EvolveTest extends EvolveTestBase { closeAll(); } + @Test public void testEagerEvolve() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/persist/test/EvolveTestBase.java b/test/java/compat/src/com/sleepycat/persist/test/EvolveTestBase.java index 651f26b0..c1e2f77a 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/EvolveTestBase.java +++ b/test/java/compat/src/com/sleepycat/persist/test/EvolveTestBase.java @@ -1,17 +1,22 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileNotFoundException; -import java.util.Enumeration; +import java.util.ArrayList; +import java.util.List; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.db.DatabaseException; import com.sleepycat.db.Environment; @@ -22,6 +27,7 @@ import com.sleepycat.persist.evolve.IncompatibleClassException; import com.sleepycat.persist.model.AnnotationModel; import com.sleepycat.persist.model.EntityModel; import com.sleepycat.persist.raw.RawStore; +import com.sleepycat.util.test.TestBase; import com.sleepycat.util.test.TestEnv; /** @@ -29,7 +35,8 @@ import com.sleepycat.util.test.TestEnv; * * @author Mark Hayes */ -public abstract class EvolveTestBase extends TestCase { +@RunWith(Parameterized.class) +public abstract class EvolveTestBase extends TestBase { /* * When adding a evolve test class, three places need to be changed: @@ -242,6 +249,8 @@ public abstract class EvolveTestBase extends TestCase { null, "ProxyClassObjectArrayFieldChanged", null, + "MultipleSelfRefs", + null, //*/ }; @@ -255,40 +264,35 @@ public abstract class EvolveTestBase extends TestCase { EvolveCase caseObj; String caseLabel; - static TestSuite getSuite(Class testClass) - throws Exception { - - TestSuite suite = new TestSuite(); + @Parameters + public static List<Object[]> genParams() { + return paramsHelper(); + } + + protected static List<Object[]> paramsHelper() { + List<Object[]> list = new ArrayList<Object[]>(); for (int i = 0; i < ALL.length; i += 2) { - String originalClsName = ALL[i]; - String evolvedClsName = ALL[i + 1]; - if (evolvedClsName == null) { - evolvedClsName = originalClsName; - } - TestSuite baseSuite = new TestSuite(testClass); - Enumeration e = baseSuite.tests(); - while (e.hasMoreElements()) { - EvolveTestBase test = (EvolveTestBase) e.nextElement(); - test.init(originalClsName, evolvedClsName); - suite.addTest(test); + if (ALL[i+1] == null) { + list.add(new Object[]{ALL[i], ALL[i]}); + } else { + list.add(new Object[]{ALL[i], ALL[i+1]}); } } - return suite; - } - - private void init(String originalClsName, - String evolvedClsName) - throws Exception { - - String caseClsName = useEvolvedClass() ? - evolvedClsName : originalClsName; - caseClsName = "com.sleepycat.persist.test.EvolveClasses$" + - caseClsName; + + return list; + } + + public EvolveTestBase(String originalClsName, String evolvedClsName) + throws Exception{ + String caseClsName = useEvolvedClass() ? evolvedClsName + : originalClsName; + caseClsName = "com.sleepycat.persist.test.EvolveClasses$" + caseClsName; this.caseClsName = caseClsName; this.caseCls = Class.forName(caseClsName); this.caseObj = (EvolveCase) caseCls.newInstance(); this.caseLabel = evolvedClsName; + customName = "-" + caseLabel; } abstract boolean useEvolvedClass(); @@ -299,12 +303,9 @@ public abstract class EvolveTestBase extends TestCase { (evolved ? "evolved" : "original") + '/' + caseLabel); } - @Override + @After public void tearDown() { - /* Set test name for reporting; cannot be done in the ctor or setUp. */ - setName(caseLabel + '-' + getName()); - if (env != null) { try { closeAll(); diff --git a/test/java/compat/src/com/sleepycat/persist/test/EvolveTestInit.java b/test/java/compat/src/com/sleepycat/persist/test/EvolveTestInit.java index 80b44a52..33f35d86 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/EvolveTestInit.java +++ b/test/java/compat/src/com/sleepycat/persist/test/EvolveTestInit.java @@ -1,12 +1,15 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; -import junit.framework.Test; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Test; import com.sleepycat.util.test.SharedTestUtils; @@ -20,10 +23,9 @@ import com.sleepycat.util.test.SharedTestUtils; */ public class EvolveTestInit extends EvolveTestBase { - public static Test suite() - throws Exception { - - return getSuite(EvolveTestInit.class); + public EvolveTestInit(String originalClsName, String evolvedClsName) + throws Exception { + super(originalClsName, evolvedClsName); } @Override @@ -31,13 +33,15 @@ public class EvolveTestInit extends EvolveTestBase { return false; } - @Override + @Before public void setUp() { + envHome = getTestInitHome(false /*evolved*/); envHome.mkdirs(); SharedTestUtils.emptyDir(envHome); } + @Test public void testInit() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/persist/test/ForeignKeyTest.java b/test/java/compat/src/com/sleepycat/persist/test/ForeignKeyTest.java index 1ef8ac3f..5e68cd08 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/ForeignKeyTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/ForeignKeyTest.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ @@ -11,11 +11,19 @@ import static com.sleepycat.persist.model.DeleteAction.ABORT; import static com.sleepycat.persist.model.DeleteAction.CASCADE; import static com.sleepycat.persist.model.DeleteAction.NULLIFY; import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import java.util.Enumeration; +import java.util.ArrayList; +import java.util.List; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.compat.DbCompat; import com.sleepycat.db.DatabaseException; @@ -34,39 +42,53 @@ import com.sleepycat.util.test.TxnTestCase; /** * @author Mark Hayes */ +@RunWith(Parameterized.class) public class ForeignKeyTest extends TxnTestCase { - private static final DeleteAction[] ACTIONS = { + protected static final DeleteAction[] ACTIONS = { ABORT, NULLIFY, CASCADE, }; - private static final String[] ACTION_LABELS = { + protected static final String[] ACTION_LABELS = { "ABORT", "NULLIFY", "CASCADE", }; - public static Test suite() { - testClass = ForeignKeyTest.class; - TestSuite suite = new TestSuite(); - for (int i = 0; i < ACTIONS.length; i += 1) { - for (int j = 0; j < 2; j++) { - TestSuite txnSuite = txnTestSuite(null, null); - Enumeration e = txnSuite.tests(); - while (e.hasMoreElements()) { - ForeignKeyTest test = (ForeignKeyTest) e.nextElement(); - test.onDelete = ACTIONS[i]; - test.onDeleteLabel = ACTION_LABELS[i]; - test.useSubclass = (j == 0); - test.useSubclassLabel = - (j == 0) ? "UseSubclass" : "UseBaseclass"; - suite.addTest(test); - } + @Parameters + public static List<Object[]> genParams() { + return paramsHelper(false); + } + + protected static List<Object[]> paramsHelper(boolean rep) { + final String[] txnTypes = getTxnTypes(null, rep); + final List<Object[]> newParams = new ArrayList<Object[]>(); + int i = 0; + for (final DeleteAction action : ACTIONS) { + for (final String type : txnTypes) { + newParams.add(new Object[] + {type, action, ACTION_LABELS[i], "UseSubclass"}); + newParams.add(new Object[] + {type, action, ACTION_LABELS[i], "UseBaseclass"}); } + i++; } - return suite; + return newParams; + } + + public ForeignKeyTest(String type, + DeleteAction action, + String label, + String useClassLabel){ + initEnvConfig(); + txnType = type; + isTransactional = (txnType != TXN_NULL); + onDelete = action; + onDeleteLabel = label; + useSubclassLabel = useClassLabel; + customName = txnType + '-' + onDeleteLabel + "-" + useSubclassLabel; } private EntityStore store; @@ -74,18 +96,10 @@ public class ForeignKeyTest extends TxnTestCase { private PrimaryIndex<String, Entity2> pri2; private SecondaryIndex<String, String, Entity1> sec1; private SecondaryIndex<String, String, Entity2> sec2; - private DeleteAction onDelete; - private String onDeleteLabel; + private final DeleteAction onDelete; + private final String onDeleteLabel; private boolean useSubclass; - private String useSubclassLabel; - - @Override - public void tearDown() - throws Exception { - - super.tearDown(); - setName(getName() + '-' + onDeleteLabel + "-" + useSubclassLabel); - } + private final String useSubclassLabel; private void open() throws DatabaseException { @@ -109,6 +123,7 @@ public class ForeignKeyTest extends TxnTestCase { store.close(); } + @Test public void testForeignKeys() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/persist/test/IndexTest.java b/test/java/compat/src/com/sleepycat/persist/test/IndexTest.java index a1063f57..ebe86ca7 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/IndexTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/IndexTest.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ @@ -11,6 +11,10 @@ import static com.sleepycat.persist.model.Relationship.MANY_TO_MANY; import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; import static com.sleepycat.persist.model.Relationship.ONE_TO_MANY; import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Collection; @@ -23,7 +27,11 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import junit.framework.Test; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.collections.MapEntryParameter; import com.sleepycat.db.DatabaseException; @@ -47,14 +55,22 @@ import com.sleepycat.util.test.TxnTestCase; * * @author Mark Hayes */ +@RunWith(Parameterized.class) public class IndexTest extends TxnTestCase { private static final int N_RECORDS = 5; private static final int THREE_TO_ONE = 3; - public static Test suite() { - testClass = IndexTest.class; - return txnTestSuite(null, null); + @Parameters + public static List<Object[]> genParams() { + return getTxnParams(null, false); + } + + public IndexTest(String type){ + initEnvConfig(); + txnType = type; + isTransactional = (txnType != TXN_NULL); + customName = txnType; } private EntityStore store; @@ -129,17 +145,10 @@ public class IndexTest extends TxnTestCase { rawStore = null; } - @Override - public void setUp() - throws Exception { - - super.setUp(); - } - /** * The store must be closed before closing the environment. */ - @Override + @After public void tearDown() throws Exception { @@ -165,6 +174,7 @@ public class IndexTest extends TxnTestCase { /** * Primary keys: {0, 1, 2, 3, 4} */ + @Test public void testPrimary() throws DatabaseException { @@ -228,6 +238,7 @@ public class IndexTest extends TxnTestCase { /** * { 0:0, 1:-1, 2:-2, 3:-3, 4:-4 } */ + @Test public void testOneToOne() throws DatabaseException { @@ -251,6 +262,7 @@ public class IndexTest extends TxnTestCase { /** * { 0:0, 1:1, 2:2, 3:0, 4:1 } */ + @Test public void testManyToOne() throws DatabaseException { @@ -277,6 +289,7 @@ public class IndexTest extends TxnTestCase { /** * { 0:{}, 1:{10}, 2:{20,21}, 3:{30,31,32}, 4:{40,41,42,43} */ + @Test public void testOneToMany() throws DatabaseException { @@ -305,6 +318,7 @@ public class IndexTest extends TxnTestCase { /** * { 0:{}, 1:{0}, 2:{0,1}, 3:{0,1,2}, 4:{0,1,2,3} */ + @Test public void testManyToMany() throws DatabaseException { @@ -836,10 +850,10 @@ public class IndexTest extends TxnTestCase { private int manyToOne; @SecondaryKey(relate=ONE_TO_MANY) - private Set<Integer> oneToMany = new TreeSet<Integer>(); + private final Set<Integer> oneToMany = new TreeSet<Integer>(); @SecondaryKey(relate=MANY_TO_MANY) - private Set<Integer> manyToMany = new TreeSet<Integer>(); + private final Set<Integer> manyToMany = new TreeSet<Integer>(); private MyEntity() {} diff --git a/test/java/compat/src/com/sleepycat/persist/test/JoinTest.java b/test/java/compat/src/com/sleepycat/persist/test/JoinTest.java index 6ffb6c5a..774c72fa 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/JoinTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/JoinTest.java @@ -1,18 +1,23 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; -import junit.framework.Test; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.db.DatabaseException; import com.sleepycat.db.Transaction; @@ -30,13 +35,21 @@ import com.sleepycat.util.test.TxnTestCase; /** * @author Mark Hayes */ +@RunWith(Parameterized.class) public class JoinTest extends TxnTestCase { private static final int N_RECORDS = 5; - public static Test suite() { - testClass = JoinTest.class; - return txnTestSuite(null, null); + @Parameters + public static List<Object[]> genParams() { + return getTxnParams(null, false); + } + + public JoinTest(String type){ + initEnvConfig(); + txnType = type; + isTransactional = (txnType != TXN_NULL); + customName = txnType; } private EntityStore store; @@ -72,6 +85,7 @@ public class JoinTest extends TxnTestCase { store.close(); } + @Test public void testJoin() throws DatabaseException { diff --git a/test/java/compat/src/com/sleepycat/persist/test/NegativeTest.java b/test/java/compat/src/com/sleepycat/persist/test/NegativeTest.java index 8810eded..aba7e7c9 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/NegativeTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/NegativeTest.java @@ -1,21 +1,30 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; +import static com.sleepycat.persist.model.DeleteAction.NULLIFY; import static com.sleepycat.persist.model.Relationship.ONE_TO_MANY; import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE; -import static com.sleepycat.persist.model.DeleteAction.NULLIFY; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Locale; -import junit.framework.Test; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.db.DatabaseConfig; import com.sleepycat.db.DatabaseException; @@ -39,11 +48,19 @@ import com.sleepycat.util.test.TxnTestCase; * * @author Mark Hayes */ +@RunWith(Parameterized.class) public class NegativeTest extends TxnTestCase { - public static Test suite() { - testClass = NegativeTest.class; - return txnTestSuite(null, null); + @Parameters + public static List<Object[]> genParams() { + return getTxnParams(null, false); + } + + public NegativeTest(String type){ + initEnvConfig(); + txnType = type; + isTransactional = (txnType != TXN_NULL); + customName = txnType; } private EntityStore store; @@ -77,14 +94,7 @@ public class NegativeTest extends TxnTestCase { store = null; } - @Override - public void setUp() - throws Exception { - - super.setUp(); - } - - @Override + @After public void tearDown() throws Exception { @@ -99,6 +109,7 @@ public class NegativeTest extends TxnTestCase { super.tearDown(); } + @Test public void testBadKeyClass1() throws DatabaseException { @@ -123,12 +134,13 @@ public class NegativeTest extends TxnTestCase { static class UseBadKeyClass1 { @PrimaryKey - private BadKeyClass1 f1 = new BadKeyClass1(); + private final BadKeyClass1 f1 = new BadKeyClass1(); @SecondaryKey(relate=ONE_TO_ONE) - private BadKeyClass1 f2 = new BadKeyClass1(); + private final BadKeyClass1 f2 = new BadKeyClass1(); } + @Test public void testBadSequenceKeys() throws DatabaseException { @@ -202,6 +214,7 @@ public class NegativeTest extends TxnTestCase { * A proxied object may not current contain a field that references the * parent proxy. [#15815] */ + @Test public void testProxyNestedRef() throws DatabaseException { @@ -232,6 +245,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow primary keys on entity subclasses. [#15757] */ + @Test public void testEntitySubclassWithPrimaryKey() throws DatabaseException { @@ -321,6 +335,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow storing null entities. [#19085] */ + @Test public void testNullEntity() throws DatabaseException { @@ -343,6 +358,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow embedded entity classes and subclasses. [#16077] */ + @Test public void testEmbeddedEntity() throws DatabaseException { @@ -448,6 +464,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow SecondaryKey collection with no type parameter. [#15950] */ + @Test public void testTypelessKeyCollection() throws DatabaseException { @@ -472,7 +489,7 @@ public class NegativeTest extends TxnTestCase { private int x; @SecondaryKey(relate=ONE_TO_MANY) - private Collection keys = new ArrayList(); + private final Collection keys = new ArrayList(); TypelessKeyCollectionEntity(int x) { this.x = x; @@ -484,6 +501,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow a persistent proxy that extends an entity. [#15950] */ + @Test public void testProxyEntity() throws DatabaseException { @@ -519,6 +537,7 @@ public class NegativeTest extends TxnTestCase { /** * Wrapper type not allowed for nullified foreign key. */ + @Test public void testBadNullifyKey() throws DatabaseException { @@ -555,6 +574,7 @@ public class NegativeTest extends TxnTestCase { /** * @Persistent not allowed on an enum. */ + @Test public void testPersistentEnum() throws DatabaseException { @@ -584,6 +604,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow a reference to an interface marked @Persistent. */ + @Test public void testPersistentInterface() throws DatabaseException { @@ -617,6 +638,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow reference to @Persistent inner class. */ + @Test public void testPersistentInnerClass() throws DatabaseException { @@ -651,6 +673,7 @@ public class NegativeTest extends TxnTestCase { /** * Disallow @Entity inner class. */ + @Test public void testSetConfigAfterOpen() throws DatabaseException { diff --git a/test/java/compat/src/com/sleepycat/persist/test/OperationTest.java b/test/java/compat/src/com/sleepycat/persist/test/OperationTest.java index 137bb6cb..014cdbbc 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/OperationTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/OperationTest.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ @@ -13,6 +13,12 @@ import static com.sleepycat.persist.model.Relationship.MANY_TO_MANY; import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; import static com.sleepycat.persist.model.Relationship.ONE_TO_MANY; import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.EnumSet; @@ -22,7 +28,11 @@ import java.util.List; import java.util.Map; import java.util.Set; -import junit.framework.Test; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.sleepycat.compat.DbCompat; import com.sleepycat.db.Database; @@ -52,13 +62,21 @@ import com.sleepycat.util.test.TxnTestCase; * * @author Mark Hayes */ +@RunWith(Parameterized.class) public class OperationTest extends TxnTestCase { private static final String STORE_NAME = "test"; - public static Test suite() { - testClass = OperationTest.class; - return txnTestSuite(null, null); + @Parameters + public static List<Object[]> genParams() { + return getTxnParams(null, false); + } + + public OperationTest(String type){ + initEnvConfig(); + txnType = type; + isTransactional = (txnType != TXN_NULL); + customName = txnType; } private EntityStore store; @@ -105,17 +123,10 @@ public class OperationTest extends TxnTestCase { store = null; } - @Override - public void setUp() - throws Exception { - - super.setUp(); - } - /** * The store must be closed before closing the environment. */ - @Override + @After public void tearDown() throws Exception { @@ -130,6 +141,7 @@ public class OperationTest extends TxnTestCase { super.tearDown(); } + @Test public void testReadOnly() throws DatabaseException { @@ -157,6 +169,7 @@ public class OperationTest extends TxnTestCase { + @Test public void testUninitializedCursor() throws DatabaseException { @@ -204,6 +217,7 @@ public class OperationTest extends TxnTestCase { close(); } + @Test public void testCursorCount() throws DatabaseException { @@ -238,6 +252,7 @@ public class OperationTest extends TxnTestCase { close(); } + @Test public void testCursorUpdate() throws DatabaseException { @@ -321,6 +336,7 @@ public class OperationTest extends TxnTestCase { close(); } + @Test public void testCursorDelete() throws DatabaseException { @@ -426,6 +442,7 @@ public class OperationTest extends TxnTestCase { close(); } + @Test public void testDeleteFromSubIndex() throws DatabaseException { @@ -503,6 +520,7 @@ public class OperationTest extends TxnTestCase { private MyEntity() {} } + @Test public void testSharedSequence() throws DatabaseException { @@ -546,6 +564,7 @@ public class OperationTest extends TxnTestCase { private Integer key; } + @Test public void testSeparateSequence() throws DatabaseException { @@ -591,6 +610,7 @@ public class OperationTest extends TxnTestCase { private Integer key; } + @Test public void testCompositeSequence() throws DatabaseException { @@ -699,6 +719,7 @@ public class OperationTest extends TxnTestCase { * NullPointerException in JE 3.0.12. No SR was created because the use * case is very obscure and was discovered by code inspection. */ + @Test public void testOpenRawStoreReadOnly() throws DatabaseException { @@ -723,6 +744,7 @@ public class OperationTest extends TxnTestCase { * referenced when getSecondaryIndex was called. This was a bug in JE * 3.0.12, reported on OTN. [#15103] */ + @Test public void testToManyKeyClass() throws DatabaseException { @@ -744,6 +766,7 @@ public class OperationTest extends TxnTestCase { * fail with "IllegalArgumentException: Wrong secondary key class: ..." * when the store was opened read-only. [#15156] */ + @Test public void testToManyReadOnly() throws DatabaseException { @@ -790,6 +813,7 @@ public class OperationTest extends TxnTestCase { * be opened automatically. If X is not opened, foreign key constraints * will not be enforced. [#15358] */ + @Test public void testAutoOpenRelatedEntity() throws DatabaseException { @@ -854,12 +878,14 @@ public class OperationTest extends TxnTestCase { } } + @Test public void testSecondaryBulkLoad1() throws DatabaseException { doSecondaryBulkLoad(true); } + @Test public void testSecondaryBulkLoad2() throws DatabaseException { @@ -945,6 +971,7 @@ public class OperationTest extends TxnTestCase { close(); } + @Test public void testPersistentFields() throws DatabaseException { @@ -1004,6 +1031,7 @@ public class OperationTest extends TxnTestCase { * getSecondaryConfig. This was a bug in JE 3.3.69, reported on OTN. * [#16407] */ + @Test public void testKeyClassInitialization() throws DatabaseException { @@ -1012,6 +1040,7 @@ public class OperationTest extends TxnTestCase { close(); } + @Test public void testKeyName() throws DatabaseException { @@ -1063,6 +1092,7 @@ public class OperationTest extends TxnTestCase { * subclass instance, which contains a secondary key, without registering * the subclass up front. [#16399] */ + @Test public void testPutEntitySubclassWithoutRegisterClass() throws DatabaseException { @@ -1092,6 +1122,7 @@ public class OperationTest extends TxnTestCase { * Checks that registerClass avoids an exception when storing an entity * subclass instance, which defines a secondary key. [#16399] */ + @Test public void testPutEntitySubclassWithRegisterClass() throws DatabaseException { @@ -1123,6 +1154,7 @@ public class OperationTest extends TxnTestCase { * registerClass is sufficient and subsequent use of the store does not * require it. [#16399] */ + @Test public void testPutEntitySubclassWithRegisterClass2() throws DatabaseException { @@ -1160,6 +1192,7 @@ public class OperationTest extends TxnTestCase { * avoid an exception when storing an entity subclass instance, which * defines a secondary key. [#16399] */ + @Test public void testPutEntitySubclassWithGetSubclassIndex() throws DatabaseException { @@ -1191,6 +1224,7 @@ public class OperationTest extends TxnTestCase { * getSubclassIndex is sufficient and subsequent use of the store does not * require it. [#16399] */ + @Test public void testPutEntitySubclassWithGetSubclassIndex2() throws DatabaseException { @@ -1260,6 +1294,7 @@ public class OperationTest extends TxnTestCase { private ExtendedStatement() {} } + @Test public void testCustomCompare() throws DatabaseException { @@ -1329,7 +1364,7 @@ public class OperationTest extends TxnTestCase { private ReverseIntKey secKey1; @SecondaryKey(relate=ONE_TO_MANY) - private Set<ReverseIntKey> secKey2 = new HashSet<ReverseIntKey>(); + private final Set<ReverseIntKey> secKey2 = new HashSet<ReverseIntKey>(); private CustomCompareEntity() {} @@ -1390,6 +1425,7 @@ public class OperationTest extends TxnTestCase { * comparator. The comparator is initialized on its first use, just as if * recovery were run. */ + @Test public void testStoredComparators() throws DatabaseException { @@ -1562,6 +1598,7 @@ public class OperationTest extends TxnTestCase { } } + @Test public void testEmbeddedMapTypes() throws DatabaseException { open(); diff --git a/test/java/compat/src/com/sleepycat/persist/test/PersistTestUtils.java b/test/java/compat/src/com/sleepycat/persist/test/PersistTestUtils.java index 76fd96cd..0b564a4f 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/PersistTestUtils.java +++ b/test/java/compat/src/com/sleepycat/persist/test/PersistTestUtils.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; diff --git a/test/java/compat/src/com/sleepycat/persist/test/SequenceTest.java b/test/java/compat/src/com/sleepycat/persist/test/SequenceTest.java index b7c751ed..b6c3aacc 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/SequenceTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/SequenceTest.java @@ -1,14 +1,20 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; +import static org.junit.Assert.assertEquals; + import java.io.File; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import com.sleepycat.db.Environment; import com.sleepycat.db.EnvironmentConfig; import com.sleepycat.db.util.DualTestCase; @@ -30,26 +36,24 @@ public class SequenceTest extends DualTestCase { private File envHome; private Environment env; - @Override + @Before public void setUp() throws Exception { super.setUp(); - - envHome = new File(System.getProperty(SharedTestUtils.DEST_DIR)); - SharedTestUtils.emptyDir(envHome); + envHome = SharedTestUtils.getTestDir(); } - @Override + @After public void tearDown() throws Exception { super.tearDown(); - envHome = null; env = null; } + @Test public void testSequenceKeys() throws Exception { diff --git a/test/java/compat/src/com/sleepycat/persist/test/SubclassIndexTest.java b/test/java/compat/src/com/sleepycat/persist/test/SubclassIndexTest.java index b7715fb3..31c1e4bc 100644 --- a/test/java/compat/src/com/sleepycat/persist/test/SubclassIndexTest.java +++ b/test/java/compat/src/com/sleepycat/persist/test/SubclassIndexTest.java @@ -1,16 +1,25 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.persist.test; import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import com.sleepycat.db.DatabaseException; import com.sleepycat.db.Environment; import com.sleepycat.db.EnvironmentConfig; @@ -36,22 +45,19 @@ public class SubclassIndexTest extends DualTestCase { private Environment env; private EntityStore store; - @Override + @Before public void setUp() throws Exception { + envHome = SharedTestUtils.getTestDir(); super.setUp(); - - envHome = new File(System.getProperty(SharedTestUtils.DEST_DIR)); - SharedTestUtils.emptyDir(envHome); } - @Override + @After public void tearDown() throws Exception { super.tearDown(); - envHome = null; env = null; } @@ -83,6 +89,7 @@ public class SubclassIndexTest extends DualTestCase { env = null; } + @Test public void testSubclassIndex() throws DatabaseException { @@ -161,6 +168,7 @@ public class SubclassIndexTest extends DualTestCase { * created up front also. So this test is somewhat less useful, but still * nice to have around. [#16399] */ + @Test public void testAddSecKey() throws DatabaseException { diff --git a/test/java/compat/src/com/sleepycat/util/test/ExceptionWrapperTest.java b/test/java/compat/src/com/sleepycat/util/test/ExceptionWrapperTest.java index 233690d2..47763af5 100644 --- a/test/java/compat/src/com/sleepycat/util/test/ExceptionWrapperTest.java +++ b/test/java/compat/src/com/sleepycat/util/test/ExceptionWrapperTest.java @@ -1,19 +1,21 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.util.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.Test; import com.sleepycat.util.ExceptionUnwrapper; import com.sleepycat.util.IOExceptionWrapper; @@ -22,35 +24,9 @@ import com.sleepycat.util.RuntimeExceptionWrapper; /** * @author Mark Hayes */ -public class ExceptionWrapperTest extends TestCase { - - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(ExceptionWrapperTest.class); - return suite; - } - - public ExceptionWrapperTest(String name) { - - super(name); - } - - @Override - public void setUp() { - - SharedTestUtils.printTestName("ExceptionWrapperTest." + getName()); - } +public class ExceptionWrapperTest extends TestBase { + @Test public void testIOWrapper() { try { throw new IOExceptionWrapper(new RuntimeException("msg")); @@ -65,6 +41,7 @@ public class ExceptionWrapperTest extends TestCase { } } + @Test public void testRuntimeWrapper() { try { throw new RuntimeExceptionWrapper(new IOException("msg")); @@ -79,6 +56,7 @@ public class ExceptionWrapperTest extends TestCase { } } + @Test public void testErrorWrapper() { try { throw new RuntimeExceptionWrapper(new Error("msg")); @@ -101,6 +79,7 @@ public class ExceptionWrapperTest extends TestCase { * Generates a stack trace for a nested exception and checks the output * for the nested exception. */ + @Test public void testStackTrace() { /* Nested stack traces are not avilable in Java 1.3. */ diff --git a/test/java/compat/src/com/sleepycat/util/test/FastOutputStreamTest.java b/test/java/compat/src/com/sleepycat/util/test/FastOutputStreamTest.java index 3d103e9f..c20e896e 100644 --- a/test/java/compat/src/com/sleepycat/util/test/FastOutputStreamTest.java +++ b/test/java/compat/src/com/sleepycat/util/test/FastOutputStreamTest.java @@ -1,50 +1,24 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.util.test; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; import com.sleepycat.util.FastOutputStream; /** * @author Mark Hayes */ -public class FastOutputStreamTest extends TestCase { - - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(FastOutputStreamTest.class); - return suite; - } - - public FastOutputStreamTest(String name) { - - super(name); - } - - @Override - public void setUp() { - - SharedTestUtils.printTestName("FastOutputStreamTest." + getName()); - } +public class FastOutputStreamTest extends TestBase { + @Test public void testBufferSizing() { FastOutputStream fos = new FastOutputStream(); assertEquals diff --git a/test/java/compat/src/com/sleepycat/util/test/PackedIntegerTest.java b/test/java/compat/src/com/sleepycat/util/test/PackedIntegerTest.java index 33ab22f4..8baa607e 100644 --- a/test/java/compat/src/com/sleepycat/util/test/PackedIntegerTest.java +++ b/test/java/compat/src/com/sleepycat/util/test/PackedIntegerTest.java @@ -1,18 +1,19 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.util.test; -import junit.framework.Test; -import junit.framework.TestCase; +import static org.junit.Assert.fail; + +import org.junit.Test; import com.sleepycat.util.PackedInteger; -public class PackedIntegerTest extends TestCase { +public class PackedIntegerTest extends TestBase { static final long V119 = 119L; static final long MAX_1 = 0xFFL; static final long MAX_2 = 0xFFFFL; @@ -22,28 +23,7 @@ public class PackedIntegerTest extends TestCase { static final long MAX_6 = 0xFFFFFFFFFFFFL; static final long MAX_7 = 0xFFFFFFFFFFFFFFL; - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - - return new PackedIntegerTest(); - } - - public PackedIntegerTest() { - - super("PackedIntegerTest"); - } - - @Override + @Test public void runTest() { /* Packed int tests. */ diff --git a/test/java/compat/src/com/sleepycat/util/test/SharedTestUtils.java b/test/java/compat/src/com/sleepycat/util/test/SharedTestUtils.java index 38f1aa68..d992d3f6 100644 --- a/test/java/compat/src/com/sleepycat/util/test/SharedTestUtils.java +++ b/test/java/compat/src/com/sleepycat/util/test/SharedTestUtils.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ @@ -15,6 +15,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.channels.FileChannel; import junit.framework.TestCase; @@ -28,22 +29,66 @@ public class SharedTestUtils { /* Common system properties for running tests */ public static String DEST_DIR = "testdestdir"; + public static String TEST_ENV_DIR = "testenvdirroot"; + public static String FAILURE_DIR = "failurecopydir"; + public static String DEFAULT_DEST_DIR = "build/test/classes"; + public static String DEFAULT_TEST_DIR_ROOT = "build/test/envdata"; + public static String DEFAULT_FAIL_DIR = "build/test/failures"; public static String NO_SYNC = "txnnosync"; public static String LONG_TEST = "longtest"; + public static String COPY_LIMIT = "copylimit"; public static final DatabaseConfig DBCONFIG_CREATE = new DatabaseConfig(); static { DBCONFIG_CREATE.setAllowCreate(true); } + + /** + * The environment store compiled class files and generated environment by + * test that is distinctive with test environment. + */ + public static File getDestDir() { + String dir = System.getProperty(DEST_DIR, DEFAULT_DEST_DIR); + File file = new File(dir); + if (!file.isDirectory()) + file.mkdir(); + + return file; + } - private static File getTestDir() { - String dir = System.getProperty(DEST_DIR); - if (dir == null || dir.length() == 0) { - throw new IllegalArgumentException - ("System property must be set to test data directory: " + - DEST_DIR); - } - return new File(dir); + /** + * If not define system property "testenvdirroot", use build/test/envdata + * as test environment root directory. + */ + public static File getTestDir() { + String dir = System.getProperty(TEST_ENV_DIR, DEFAULT_TEST_DIR_ROOT); + File file = new File(dir); + if (!file.isDirectory()) + file.mkdir(); + + return file; + } + + /** + * Allow to set up self defined directory store failure copy. + */ + public static File getFailureCopyDir() { + String dir = System.getProperty(FAILURE_DIR, DEFAULT_FAIL_DIR); + File file = new File(dir); + if (!file.isDirectory()) + file.mkdir(); + + return file; + } + + /** + * If test failed, copy its environment to other location. The default + * limit is 10, but our test support the value via system property. + */ + public static int getCopyLimit() { + String limit = System.getProperty(COPY_LIMIT, "10"); + + return Integer.parseInt(limit); } /** @@ -91,13 +136,16 @@ public class SharedTestUtils { dir.mkdirs(); } } - + + /** + * @return A sub-directory of current test destination directory. + */ public static File getNewDir(String name) { File dir = new File(getTestDir(), name); emptyDir(dir); return dir; } - + public static File getNewFile() { return getNewFile("test-file"); } @@ -174,4 +222,95 @@ public class SharedTestUtils { } } } + + /** + * Copy everything in test destination directory to another place for + * future evaluation when test failed. + */ + public static void copyDir(File fromDir, File toDir) + throws Exception { + + if (fromDir == null || toDir == null) + throw new NullPointerException("File location error"); + + if (!fromDir.isDirectory()) + throw new IllegalStateException + (fromDir + " should be a directory"); + + if (!toDir.exists() && !toDir.mkdirs()) + throw new IllegalStateException("Unable to create copy dest dir:" + + toDir); + + String[] list = fromDir.list(); + if (list != null) { + + for (String fileName : list) { + File file = new File(fromDir, fileName); + if (file.isDirectory()) + copyDir(file, new File(toDir, fileName)); + else + copyFile(file, new File(toDir, fileName)); + } + } + } + + /** + * Copy file to specified location. + */ + private static void copyFile(File from, File to) + throws Exception { + + if (to.isDirectory()) + to = new File(to, from.getName()); + + FileInputStream fis = null; + FileOutputStream fos = null; + FileChannel fcin = null; + FileChannel fcout = null; + + try { + fis = new FileInputStream(from); + fos = new FileOutputStream(to); + fcin = fis.getChannel(); + fcout = fos.getChannel(); + fcin.transferTo(0, fcin.size(), fcout); + } finally { + if (fis != null) { + fis.close(); + } + if (fos != null) { + fos.close(); + } + } + } + + /** + * Clean up everything in JE test destination directory including all kind + * files and sub directories generated by last test except je.properties. + */ + public static void cleanUpTestDir(File dir) { + if (!dir.isDirectory() || !dir.exists()) + throw new IllegalStateException( + "Not an existing directory: " + dir); + File[] files = dir.listFiles(); + if (files == null) + return; + + for (File file : files) { + if ("je.properties".equals(file.getName())) + continue; + + if (file.isDirectory()) { + cleanUpTestDir(file); + + if (file.list().length == 0 && !file.delete()) + throw new IllegalStateException( + "Unable to delete" + file); + } else { + if(!file.delete()) + throw new IllegalStateException( + "Unable to delete " + file); + } + } + } } diff --git a/test/java/compat/src/com/sleepycat/util/test/TestBase.java b/test/java/compat/src/com/sleepycat/util/test/TestBase.java new file mode 100644 index 00000000..d7d0f46e --- /dev/null +++ b/test/java/compat/src/com/sleepycat/util/test/TestBase.java @@ -0,0 +1,96 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. + * + */ + +package com.sleepycat.util.test; + +import java.io.File; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +/** + * The base class for all JE unit tests. + */ +public abstract class TestBase { + + /* + * Need to provide a customized name suffix for those tests which are + * Parameterized. + * + * This is because we need to provide a unique directory name for those + * failed tests. Parameterized class would reuse test cases, so class name + * plus the test method is not unique. User should set the customName + * in the constructor of a Parameterized test. + */ + protected String customName; + + /** + * The rule we use to control every test case, the core of this rule is + * copy the testing environment, files, sub directories to another place + * for future investigation, if any of test failed. But we do have a limit + * to control how many times we copy because of disk space. So once the + * failure counter exceed limit, it won't copy the environment any more. + */ + @Rule + public TestRule watchman = new TestWatcher() { + + /* Copy Environments when the test failed. */ + @Override + protected void failed(Throwable t, Description desc) { + String dirName = makeFileName(desc); + try { + copyEnvironments(dirName); + } catch (Exception e) { + throw new RuntimeException + ("can't copy env dir to " + dirName + " after failure", e); + } + } + + @Override + protected void succeeded(Description desc){ + } + }; + + @Before + public void setUp() + throws Exception { + + SharedTestUtils.cleanUpTestDir(SharedTestUtils.getTestDir()); + } + + @After + public void tearDown() throws Exception { + // Provision for future use + } + + /** + * Copy the testing directory to other place. + */ + private void copyEnvironments(String path) throws Exception{ + + File failureDir = SharedTestUtils.getFailureCopyDir(); + if (failureDir.list().length < SharedTestUtils.getCopyLimit()) { + SharedTestUtils.copyDir(SharedTestUtils.getTestDir(), + new File(failureDir, path)); + } + } + + /** + * Get failure copy directory name. + */ + private String makeFileName(Description desc) { + String name = desc.getClassName() + "-" + desc.getMethodName(); + if (customName != null) { + name = name + "-" + customName; + } + return name; + } +} diff --git a/test/java/compat/src/com/sleepycat/util/test/TestEnv.java b/test/java/compat/src/com/sleepycat/util/test/TestEnv.java index 9bbdc576..80bf691d 100644 --- a/test/java/compat/src/com/sleepycat/util/test/TestEnv.java +++ b/test/java/compat/src/com/sleepycat/util/test/TestEnv.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ diff --git a/test/java/compat/src/com/sleepycat/util/test/TxnTestCase.java b/test/java/compat/src/com/sleepycat/util/test/TxnTestCase.java index 69aef341..0fada37f 100644 --- a/test/java/compat/src/com/sleepycat/util/test/TxnTestCase.java +++ b/test/java/compat/src/com/sleepycat/util/test/TxnTestCase.java @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ @@ -10,10 +10,10 @@ package com.sleepycat.util.test; import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.Enumeration; +import java.util.List; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; import com.sleepycat.compat.DbCompat; import com.sleepycat.db.CursorConfig; @@ -45,7 +45,6 @@ public abstract class TxnTestCase extends DualTestCase { public static final String TXN_AUTO = "txn-auto"; public static final String TXN_USER = "txn-user"; public static final String TXN_CDB = "txn-cdb"; - protected static Class<? extends TestCase> testClass; protected File envHome; protected Environment env; @@ -53,13 +52,17 @@ public abstract class TxnTestCase extends DualTestCase { protected String txnType; protected boolean isTransactional; - /** - * Returns a txn test suite. If txnTypes is null, all three types are run. - */ - public static TestSuite txnTestSuite(EnvironmentConfig envConfig, - String[] txnTypes) { + public static List<Object[]> getTxnParams(String[] txnTypes, boolean rep) { + final List<Object[]> list = new ArrayList<Object[]>(); + for (final String type : getTxnTypes(txnTypes, rep)) { + list.add(new Object[] {type}); + } + return list; + } + + public static String[] getTxnTypes(String[] txnTypes, boolean rep) { if (txnTypes == null) { - if (isReplicatedTest(testClass)) { + if (rep) { txnTypes = new String[] { // Skip non-transactional tests TxnTestCase.TXN_USER, TxnTestCase.TXN_AUTO }; @@ -76,68 +79,43 @@ public abstract class TxnTestCase extends DualTestCase { } else { if (!DbCompat.CDB) { /* Remove TxnTestCase.TXN_CDB, if there is any. */ - ArrayList<String> tmp = new ArrayList<String> - (Arrays.asList(txnTypes)); + final ArrayList<String> tmp = + new ArrayList<String>(Arrays.asList(txnTypes)); tmp.remove(TxnTestCase.TXN_CDB); txnTypes = new String[tmp.size()]; tmp.toArray(txnTypes); } } - if (envConfig == null) { - envConfig = new EnvironmentConfig(); - envConfig.setAllowCreate(true); - } - TestSuite suite = new TestSuite(); - for (int i = 0; i < txnTypes.length; i += 1) { - TestSuite baseSuite = new TestSuite(testClass); - Enumeration e = baseSuite.tests(); - while (e.hasMoreElements()) { - TxnTestCase test = (TxnTestCase) e.nextElement(); - test.txnInit(envConfig, txnTypes[i]); - suite.addTest(test); - } - } - return suite; + return txnTypes; } - private void txnInit(EnvironmentConfig envConfig, String txnType) { - - this.envConfig = envConfig; - this.txnType = txnType; - isTransactional = (txnType != TXN_NULL); - } - - @Override + @Before public void setUp() throws Exception { super.setUp(); envHome = SharedTestUtils.getNewDir(); - } - - @Override - public void runTest() - throws Throwable { - openEnv(); - super.runTest(); - closeEnv(); } - @Override + @After public void tearDown() throws Exception { - /* Set test name for reporting; cannot be done in the ctor or setUp. */ - setName(txnType + ':' + getName()); - super.tearDown(); + closeEnv(); env = null; - - try { - SharedTestUtils.emptyDir(envHome); - } catch (Throwable e) { - System.out.println("tearDown: " + e); + } + + protected void initEnvConfig() { + if (envConfig == null) { + envConfig = new EnvironmentConfig(); + envConfig.setAllowCreate(true); + + /* Always use write-no-sync (by default) to speed up tests. */ + if (!envConfig.getTxnNoSync() && !envConfig.getTxnWriteNoSync()) { + envConfig.setTxnWriteNoSync(true); + } } } @@ -196,9 +174,8 @@ public abstract class TxnTestCase extends DualTestCase { if (txnType == TXN_USER) { return env.beginTransaction(parentTxn, config); - } else { - return null; } + return null; } /** diff --git a/test/java/compat/src/com/sleepycat/util/test/UtfTest.java b/test/java/compat/src/com/sleepycat/util/test/UtfTest.java index 8d1c4aa2..fec9137e 100644 --- a/test/java/compat/src/com/sleepycat/util/test/UtfTest.java +++ b/test/java/compat/src/com/sleepycat/util/test/UtfTest.java @@ -1,18 +1,18 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.util.test; +import static org.junit.Assert.fail; + import java.io.DataOutputStream; import java.util.Arrays; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.Test; import com.sleepycat.util.FastOutputStream; import com.sleepycat.util.UtfOps; @@ -20,40 +20,14 @@ import com.sleepycat.util.UtfOps; /** * @author Mark Hayes */ -public class UtfTest extends TestCase { - - public static void main(String[] args) { - junit.framework.TestResult tr = - junit.textui.TestRunner.run(suite()); - if (tr.errorCount() > 0 || - tr.failureCount() > 0) { - System.exit(1); - } else { - System.exit(0); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(UtfTest.class); - return suite; - } - - public UtfTest(String name) { - - super(name); - } - - @Override - public void setUp() { - - SharedTestUtils.printTestName("UtfTest." + getName()); - } +public class UtfTest extends TestBase { /** * Compares the UtfOps implementation to the java.util.DataOutputStream * (and by implication DataInputStream) implementation, character for * character in the full Unicode set. */ + @Test public void testMultibyte() throws Exception { |