diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-10-14 16:47:22 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-10-14 16:47:22 +0000 |
commit | b044b17b7c455d6f23b0a4f8da7550d997036caa (patch) | |
tree | 2ca110f70551636d2522f4c86049df89b12c3bfc /src/test/java/com/amazon/carbonado/spi | |
parent | 2fd7b3fd77c8141f7fb21d2bd86eb839fa55ef6f (diff) |
Moved tests to separate project.
Diffstat (limited to 'src/test/java/com/amazon/carbonado/spi')
5 files changed, 0 insertions, 1110 deletions
diff --git a/src/test/java/com/amazon/carbonado/spi/TestConversionComparator.java b/src/test/java/com/amazon/carbonado/spi/TestConversionComparator.java deleted file mode 100644 index 5cd7caa..0000000 --- a/src/test/java/com/amazon/carbonado/spi/TestConversionComparator.java +++ /dev/null @@ -1,179 +0,0 @@ -/*
- * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
- * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
- * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.amazon.carbonado.spi;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import com.amazon.carbonado.spi.ConversionComparator;
-
-/**
- * Test cases for {@link ConversionComparator}.
- *
- * @author Brian S O'Neill
- */
-public class TestConversionComparator extends TestCase {
- private static final int BOOLEAN_CODE = 0;
- private static final int BYTE_CODE = 1;
- private static final int SHORT_CODE = 2;
- private static final int CHAR_CODE = 3;
- private static final int INT_CODE = 4;
- private static final int FLOAT_CODE = 5;
- private static final int LONG_CODE = 6;
- private static final int DOUBLE_CODE = 7;
-
- private static final Class[] PRIMITIVE_CLASSES = {
- boolean.class, byte.class, short.class, char.class,
- int.class, float.class, long.class, double.class
- };
-
- private static final Class[] BOXED_PRIMITIVE_CLASSES = {
- Boolean.class, Byte.class, Short.class, Character.class,
- Integer.class, Float.class, Long.class, Double.class
- };
-
- // States which primitive conversions are allowed.
- private static final boolean[][] PRIMITIVE_MATRIX = {
- // from...
- // boolean byte short char int float long double
- { true, false, false, false, false, false, false, false }, // to boolean
- { false, true, false, false, false, false, false, false }, // to byte
- { false, true, true, false, false, false, false, false }, // to short
- { false, false, false, true, false, false, false, false }, // to char
- { false, true, true, false, true, false, false, false }, // to int
- { false, true, true, false, false, true, false, false }, // to float
- { false, true, true, false, true, false, true, false }, // to long
- { false, true, true, false, true, true, false, true }, // to double
- };
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static TestSuite suite() {
- return new TestSuite(TestConversionComparator.class);
- }
-
- public TestConversionComparator(String name) {
- super(name);
- }
-
- public void test_isConversionPossible_basics() {
- ConversionComparator cc = new ConversionComparator(Object.class);
- assertEquals(true, cc.isConversionPossible(Object.class));
- assertEquals(false, cc.isConversionPossible(String.class));
- assertEquals(false, cc.isConversionPossible(boolean.class));
- assertEquals(false, cc.isConversionPossible(Integer.class));
- assertEquals(false, cc.isConversionPossible(int.class));
-
- cc = new ConversionComparator(String.class);
- assertEquals(true, cc.isConversionPossible(Object.class));
- assertEquals(true, cc.isConversionPossible(String.class));
- assertEquals(false, cc.isConversionPossible(boolean.class));
- assertEquals(false, cc.isConversionPossible(Integer.class));
- assertEquals(false, cc.isConversionPossible(int.class));
-
- cc = new ConversionComparator(boolean.class);
- assertEquals(true, cc.isConversionPossible(Object.class));
- assertEquals(false, cc.isConversionPossible(String.class));
- assertEquals(true, cc.isConversionPossible(boolean.class));
- assertEquals(false, cc.isConversionPossible(Integer.class));
- assertEquals(false, cc.isConversionPossible(int.class));
-
- cc = new ConversionComparator(Integer.class);
- assertEquals(true, cc.isConversionPossible(Object.class));
- assertEquals(false, cc.isConversionPossible(String.class));
- assertEquals(false, cc.isConversionPossible(boolean.class));
- assertEquals(true, cc.isConversionPossible(Integer.class));
- assertEquals(true, cc.isConversionPossible(int.class));
-
- cc = new ConversionComparator(int.class);
- assertEquals(true, cc.isConversionPossible(Object.class));
- assertEquals(false, cc.isConversionPossible(String.class));
- assertEquals(false, cc.isConversionPossible(boolean.class));
- assertEquals(true, cc.isConversionPossible(Integer.class));
- assertEquals(true, cc.isConversionPossible(int.class));
- }
-
- public void test_isConversionPossible_primitives() {
- test_isConversionPossible_primitives(false, false);
- test_isConversionPossible_primitives(false, true);
- test_isConversionPossible_primitives(true, false);
- test_isConversionPossible_primitives(true, true);
- }
-
- private void test_isConversionPossible_primitives(boolean fromBoxed, boolean toBoxed) {
- for (int fromCode = BOOLEAN_CODE; fromCode <= DOUBLE_CODE; fromCode++) {
- ConversionComparator cc = new ConversionComparator
- (fromBoxed ? BOXED_PRIMITIVE_CLASSES[fromCode] : PRIMITIVE_CLASSES[fromCode]);
- for (int toCode = BOOLEAN_CODE; toCode <= DOUBLE_CODE; toCode++) {
- boolean expected = PRIMITIVE_MATRIX[toCode][fromCode];
- Class toType = toBoxed ? BOXED_PRIMITIVE_CLASSES[toCode] : PRIMITIVE_CLASSES[toCode];
- assertEquals(expected, cc.isConversionPossible(toType));
- }
- }
- }
-
- public void test_compare() {
- ConversionComparator cc = new ConversionComparator(Object.class);
- assertEquals(true, cc.compare(Object.class, String.class) < 0);
- assertEquals(true, cc.compare(String.class, Object.class) > 0);
- assertEquals(0, cc.compare(Object.class, Object.class));
- assertEquals(0, cc.compare(String.class, String.class));
- assertEquals(0, cc.compare(String.class, String.class));
- assertEquals(0, cc.compare(int.class, Number.class));
-
- cc = new ConversionComparator(String.class);
- assertEquals(true, cc.compare(String.class, Object.class) < 0);
- assertEquals(true, cc.compare(Object.class, String.class) > 0);
- assertEquals(0, cc.compare(String.class, String.class));
- assertEquals(true, cc.compare(int.class, String.class) > 0);
-
- cc = new ConversionComparator(Integer.class);
- assertEquals(true, cc.compare(String.class, Object.class) > 0);
- assertEquals(true, cc.compare(Object.class, String.class) < 0);
- assertEquals(true, cc.compare(Object.class, Number.class) > 0);
- assertEquals(true, cc.compare(Integer.class, Number.class) < 0);
- assertEquals(true, cc.compare(int.class, Number.class) > 0);
- assertEquals(true, cc.compare(long.class, Number.class) > 0);
- assertEquals(true, cc.compare(long.class, Long.class) < 0);
-
- cc = new ConversionComparator(int.class);
- assertEquals(true, cc.compare(String.class, Object.class) > 0);
- assertEquals(true, cc.compare(Object.class, String.class) < 0);
- assertEquals(true, cc.compare(Object.class, Number.class) > 0);
- assertEquals(true, cc.compare(Integer.class, Number.class) < 0);
- assertEquals(true, cc.compare(int.class, Number.class) < 0);
- assertEquals(true, cc.compare(long.class, Number.class) < 0);
- assertEquals(true, cc.compare(long.class, Long.class) < 0);
-
- cc = new ConversionComparator(Byte.class);
- assertEquals(true, cc.compare(int.class, Number.class) > 0);
- assertEquals(true, cc.compare(long.class, Number.class) > 0);
- assertEquals(true, cc.compare(long.class, Integer.class) < 0);
-
- cc = new ConversionComparator(byte.class);
- assertEquals(true, cc.compare(short.class, int.class) < 0);
- assertEquals(true, cc.compare(long.class, int.class) > 0);
-
- cc = new ConversionComparator(java.util.Date.class);
- assertEquals(true, cc.compare(Object.class, Comparable.class) > 0);
- assertEquals(0, cc.compare(java.io.Serializable.class, Comparable.class));
- }
-}
diff --git a/src/test/java/com/amazon/carbonado/spi/TestCursorList.java b/src/test/java/com/amazon/carbonado/spi/TestCursorList.java deleted file mode 100644 index 605e981..0000000 --- a/src/test/java/com/amazon/carbonado/spi/TestCursorList.java +++ /dev/null @@ -1,224 +0,0 @@ -/*
- * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
- * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
- * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.amazon.carbonado.spi;
-
-import com.amazon.carbonado.Cursor;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import com.amazon.carbonado.cursor.EmptyCursorFactory;
-
-/**
- * Test case for TransactionManager.CursorList.
- *
- * @author Brian S O'Neill
- */
-public class TestCursorList extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static TestSuite suite() {
- return new TestSuite(TestCursorList.class);
- }
-
- TransactionManager.CursorList mList;
-
- public TestCursorList(String name) {
- super(name);
- }
-
- protected void setUp() {
- mList = new TransactionManager.CursorList();
- }
-
- public void testRegisterFew() {
- assertEquals(0, mList.size());
-
- {
- Cursor cursor = EmptyCursorFactory.newEmptyCursor();
- mList.register(cursor, null);
- assertEquals(1, mList.size());
- assertEquals(cursor, mList.getCursor(0));
- assertEquals(null, mList.getValue(0));
- Object value = mList.unregister(cursor);
- assertEquals(0, mList.size());
- assertEquals(null, value);
- }
-
- {
- Cursor cursor_1 = EmptyCursorFactory.newEmptyCursor();
- Cursor cursor_2 = EmptyCursorFactory.newEmptyCursor();
- mList.register(cursor_1, null);
- assertEquals(1, mList.size());
- mList.register(cursor_2, null);
- assertEquals(2, mList.size());
- assertEquals(cursor_1, mList.getCursor(0));
- assertEquals(cursor_2, mList.getCursor(1));
- assertEquals(null, mList.getValue(0));
- assertEquals(null, mList.getValue(1));
-
- Object value = mList.unregister(cursor_2);
- assertEquals(1, mList.size());
- assertEquals(cursor_1, mList.getCursor(0));
- assertEquals(null, value);
- mList.unregister(cursor_2);
- assertEquals(1, mList.size());
- mList.unregister(cursor_1);
- assertEquals(0, mList.size());
- }
-
- // unregister in reverse
- {
- Cursor cursor_1 = EmptyCursorFactory.newEmptyCursor();
- Cursor cursor_2 = EmptyCursorFactory.newEmptyCursor();
- mList.register(cursor_1, null);
- mList.register(cursor_2, null);
-
- mList.unregister(cursor_1);
- assertEquals(1, mList.size());
- assertEquals(cursor_2, mList.getCursor(0));
-
- mList.unregister(cursor_1);
- assertEquals(1, mList.size());
- mList.unregister(cursor_2);
- assertEquals(0, mList.size());
- }
- }
-
- public void testRegisterFewValue() {
- Cursor cursor_1 = EmptyCursorFactory.newEmptyCursor();
- Cursor cursor_2 = EmptyCursorFactory.newEmptyCursor();
- String value_1 = "1";
- String value_2 = "2";
-
- mList.register(cursor_1, value_1);
- assertEquals(1, mList.size());
- assertEquals(cursor_1, mList.getCursor(0));
- assertEquals(value_1, mList.getValue(0));
-
- mList.register(cursor_2, value_2);
- assertEquals(2, mList.size());
- assertEquals(cursor_1, mList.getCursor(0));
- assertEquals(value_1, mList.getValue(0));
- assertEquals(cursor_2, mList.getCursor(1));
- assertEquals(value_2, mList.getValue(1));
-
- Object value = mList.unregister(cursor_2);
- assertEquals(1, mList.size());
- assertEquals(cursor_1, mList.getCursor(0));
- assertEquals(value_1, mList.getValue(0));
- assertEquals(value_2, value);
-
- value = mList.unregister(cursor_2);
- assertEquals(1, mList.size());
- assertEquals(null, value);
- value = mList.unregister(cursor_1);
- assertEquals(0, mList.size());
- assertEquals(value_1, value);
- }
-
- // Tests that the array expands properly.
- public void testRegisterMany() {
- final int count = 50;
- Cursor[] cursors = new Cursor[count];
- for (int i=0; i<count; i++) {
- cursors[i] = EmptyCursorFactory.newEmptyCursor();
- mList.register(cursors[i], null);
- assertEquals(i + 1, mList.size());
- }
-
- for (int i=0; i<count; i++) {
- assertEquals(cursors[i], mList.getCursor(i));
- assertEquals(null, mList.getValue(i));
- }
-
- for (int i=0; i<count; i++) {
- mList.unregister(cursors[i]);
- assertEquals(count - i - 1, mList.size());
- }
- }
-
- // Tests that the arrays expand properly and store values.
- public void testRegisterManyValues() {
- final int count = 50;
- Cursor[] cursors = new Cursor[count];
- Integer[] values = new Integer[count];
- for (int i=0; i<count; i++) {
- cursors[i] = EmptyCursorFactory.newEmptyCursor();
- values[i] = i;
- mList.register(cursors[i], values[i]);
- assertEquals(i + 1, mList.size());
- }
-
- for (int i=0; i<count; i++) {
- assertEquals(cursors[i], mList.getCursor(i));
- assertEquals(values[i], mList.getValue(i));
- }
-
- for (int i=0; i<count; i++) {
- Object value = mList.unregister(cursors[i]);
- assertEquals(count - i - 1, mList.size());
- assertEquals(values[i], value);
- }
- }
-
- public void testCloseCursors() throws Exception {
- final int count = 50;
-
- // Without values
- {
- Cursor[] cursors = new Cursor[count];
- for (int i=0; i<count; i++) {
- cursors[i] = EmptyCursorFactory.newEmptyCursor();
- mList.register(cursors[i], null);
- }
-
- mList.closeCursors();
- assertEquals(0, mList.size());
-
- /*
- for (int i=0; i<count; i++) {
- assertEquals(true, cursors[i].isClosed());
- }
- */
- }
-
- // With values
- {
- Cursor[] cursors = new Cursor[count];
- Integer[] values = new Integer[count];
- for (int i=0; i<count; i++) {
- cursors[i] = EmptyCursorFactory.newEmptyCursor();
- values[i] = i;
- mList.register(cursors[i], values[i]);
- }
-
- mList.closeCursors();
- assertEquals(0, mList.size());
-
- /*
- for (int i=0; i<count; i++) {
- assertEquals(true, cursors[i].isClosed());
- }
- */
- }
- }
-}
diff --git a/src/test/java/com/amazon/carbonado/spi/TestSequenceValueGenerator.java b/src/test/java/com/amazon/carbonado/spi/TestSequenceValueGenerator.java deleted file mode 100644 index ae17e5d..0000000 --- a/src/test/java/com/amazon/carbonado/spi/TestSequenceValueGenerator.java +++ /dev/null @@ -1,258 +0,0 @@ -/*
- * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
- * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
- * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.amazon.carbonado.spi;
-
-import java.util.Random;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import com.amazon.carbonado.PersistException;
-import com.amazon.carbonado.Repository;
-import com.amazon.carbonado.Storage;
-
-import com.amazon.carbonado.repo.toy.ToyRepository;
-
-import com.amazon.carbonado.stored.StorableTestBasic;
-
-/**
- *
- *
- * @author Brian S O'Neill
- */
-public class TestSequenceValueGenerator extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static TestSuite suite() {
- return new TestSuite(TestSequenceValueGenerator.class);
- }
-
- private Repository mRepository;
-
- public TestSequenceValueGenerator(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- mRepository = new ToyRepository();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void test_basics() throws Exception {
- SequenceValueGenerator generator = new SequenceValueGenerator(mRepository, "foo");
-
- for (int i=1; i<=950; i++) {
- assertEquals(i, generator.nextLongValue());
- }
-
- generator.reset(1);
-
- for (int i=1; i<=950; i++) {
- assertEquals(i, generator.nextIntValue());
- }
-
- generator.reset(1);
-
- for (int i=1; i<=950; i++) {
- assertEquals(String.valueOf(i), generator.nextDecimalValue());
- }
-
- // Make sure data is persisted
-
- generator = new SequenceValueGenerator(mRepository, "foo");
-
- assertTrue(generator.nextLongValue() > 950);
-
- // Make sure data is isolated
-
- generator = new SequenceValueGenerator(mRepository, "another");
-
- for (int i=1; i<=1050; i++) {
- assertEquals(i, generator.nextLongValue());
- }
-
- // Make sure reserved values can be returned
-
- generator.returnReservedValues();
- generator = new SequenceValueGenerator(mRepository, "another");
-
- assertEquals(1051, generator.nextLongValue());
- }
-
- public void test_highIncrement() throws Exception {
- SequenceValueGenerator generator =
- new SequenceValueGenerator(mRepository, "foo", 1, 125);
-
- for (int i=0; i<950; i++) {
- assertEquals(i * 125 + 1, generator.nextLongValue());
- }
- }
-
- public void test_highInitialAndHighIncrement() throws Exception {
- SequenceValueGenerator generator =
- new SequenceValueGenerator(mRepository, "foo", 0x500000000L, 125);
-
- for (int i=0; i<950; i++) {
- assertEquals(i * 125 + 0x500000000L, generator.nextLongValue());
- }
-
- try {
- // Doesn't fit in an int.
- generator.nextIntValue();
- fail();
- } catch (PersistException e) {
- }
- }
-
- public void test_lowReserve() throws Exception {
- SequenceValueGenerator generator =
- new SequenceValueGenerator(mRepository, "goo", 1, 1, 1);
-
- for (int i=1; i<=950; i++) {
- assertEquals(i, generator.nextLongValue());
- }
- }
-
- public void test_overflow() throws Exception {
- Storage<StoredSequence> storage = mRepository.storageFor(StoredSequence.class);
- StoredSequence seq = storage.prepare();
- seq.setName("overflow");
- seq.setInitialValue(1);
- seq.setNextValue(Long.MAX_VALUE - 50);
- seq.insert();
-
- SequenceValueGenerator generator = new SequenceValueGenerator(mRepository, "overflow");
-
- for (int i=-50; i<=-1; i++) {
- assertEquals(i, generator.nextLongValue());
- }
-
- // Although next value could be zero, overflow logic doesn't work this
- // way. Its not really worth the trouble to allow zero to be returned
- // before overflowing.
-
- try {
- // Overflow.
- generator.nextLongValue();
- fail();
- } catch (PersistException e) {
- }
- }
-
- public void test_largeNumericalValue() throws Exception {
- // Tests string conversion to ensure large unsigned values are properly
- // generated.
-
- SequenceValueGenerator generator =
- new SequenceValueGenerator(mRepository, "goo", Long.MAX_VALUE, 1);
-
- assertEquals("9223372036854775807", generator.nextDecimalValue());
- // Next values are too large to fit in an unsigned long
- assertEquals("9223372036854775808", generator.nextDecimalValue());
- assertEquals("9223372036854775809", generator.nextDecimalValue());
- }
-
- public void test_radix() throws Exception {
- SequenceValueGenerator generator = new SequenceValueGenerator(mRepository, "goo");
-
- for (int i=1; i<=1000; i++) {
- assertEquals(Integer.toString(i, 36), generator.nextNumericalValue(36, 1));
- }
- }
-
- public void test_pad() throws Exception {
- SequenceValueGenerator generator = new SequenceValueGenerator(mRepository, "goo");
-
- for (int i=1; i<=2000; i++) {
- String next = generator.nextNumericalValue(10, 3);
- assertTrue(next.length() >= 3);
- int value = Integer.parseInt(next);
- assertEquals(i, value);
- }
- }
-
- public void test_concurrentAccess() throws Exception {
- // Simple test ensuring that values are reserved properly even when
- // multiple processes may be sharing the sequence.
-
- SequenceValueGenerator g1 = new SequenceValueGenerator(mRepository, "goo", 1, 1, 100);
- SequenceValueGenerator g2 = new SequenceValueGenerator(mRepository, "goo", 1, 1, 100);
-
- for (int i=1; i<=100; i++) {
- assertEquals(i, g1.nextLongValue());
- assertEquals(i + 100, g2.nextLongValue());
- }
-
- for (int i=201; i<=300; i++) {
- assertEquals(i, g2.nextLongValue());
- assertEquals(i + 100, g1.nextLongValue());
- }
-
- assertTrue(g1.returnReservedValues());
- assertFalse(g2.returnReservedValues());
- }
-
- // FIXME: move this test somewhere else
- /* Takes too long
- public void test_heavyConcurrentAccess() throws Exception {
- // Heavy test with multiple processes sharing the sequence.
-
- final Storage<StorableTestBasic> storage =
- mRepository.storageFor(StorableTestBasic.class);
- final Random rnd = new Random(376296292);
- final int loopCount = 10000;
-
- Thread[] threads = new Thread[10];
- for (int i=0; i<threads.length; i++) {
- threads[i] = new Thread() {
- public void run() {
- try {
- SequenceValueGenerator generator =
- new SequenceValueGenerator(mRepository, "seq");
- for (int i=0; i<loopCount; i++) {
- StorableTestBasic stb = storage.prepare();
- stb.setId(generator.nextIntValue());
- stb.initBasicProperties();
- stb.insert();
- if (rnd.nextInt(500) == 0) {
- generator.returnReservedValues();
- }
- }
- } catch (Exception e) {
- e.printStackTrace(System.out);
- fail(e.toString());
- }
- }
- };
-
- threads[i].start();
- }
-
- for (Thread t : threads) {
- t.join();
- }
- }
- */
-}
diff --git a/src/test/java/com/amazon/carbonado/spi/TestStorableSerializer.java b/src/test/java/com/amazon/carbonado/spi/TestStorableSerializer.java deleted file mode 100644 index 664bf12..0000000 --- a/src/test/java/com/amazon/carbonado/spi/TestStorableSerializer.java +++ /dev/null @@ -1,115 +0,0 @@ -/*
- * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
- * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
- * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.amazon.carbonado.spi;
-
-import java.io.*;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import com.amazon.carbonado.*;
-import com.amazon.carbonado.lob.*;
-
-import com.amazon.carbonado.repo.toy.ToyRepository;
-import com.amazon.carbonado.stored.*;
-
-/**
- * Test case for {@link StorableSerializer}.
- *
- * @author Brian S O'Neill
- */
-public class TestStorableSerializer extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static TestSuite suite() {
- return new TestSuite(TestStorableSerializer.class);
- }
-
- private Repository mRepository;
-
- public TestStorableSerializer(String name) {
- super(name);
- }
-
- protected void setUp() {
- mRepository = new ToyRepository();
- }
-
- protected void tearDown() {
- mRepository.close();
- mRepository = null;
- }
-
- public void testReadAndWrite() throws Exception {
- Storage<StorableTestBasic> storage = mRepository.storageFor(StorableTestBasic.class);
- StorableTestBasic stb = storage.prepare();
- stb.setId(50);
- stb.setStringProp("hello");
- stb.setIntProp(100);
- stb.setLongProp(999);
- stb.setDoubleProp(2.718281828d);
-
- StorableSerializer<StorableTestBasic> serializer =
- StorableSerializer.forType(StorableTestBasic.class);
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream(bout);
-
- serializer.write(stb, (DataOutput) dout);
- dout.flush();
-
- byte[] bytes = bout.toByteArray();
-
- ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
- DataInputStream din = new DataInputStream(bin);
-
- StorableTestBasic stb2 = serializer.read(storage, (DataInput) din);
-
- assertEquals(stb, stb2);
- }
-
- /*
- public void testReadAndWriteLobs() throws Exception {
- Storage<StorableWithLobs> storage = mRepository.storageFor(StorableWithLobs.class);
- StorableWithLobs s = storage.prepare();
- s.setBlobValue(new ByteArrayBlob("Hello Blob".getBytes()));
- s.setClobValue(new StringClob("Hello Clob"));
-
- StorableSerializer<StorableWithLobs> serializer =
- StorableSerializer.forType(StorableWithLobs.class);
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream(bout);
-
- serializer.write(s, (DataOutput) dout);
- dout.flush();
-
- byte[] bytes = bout.toByteArray();
-
- ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
- DataInputStream din = new DataInputStream(bin);
-
- StorableWithLobs s2 = serializer.read(storage, (DataInput) din);
-
- assertEquals(s, s2);
- }
- */
-}
diff --git a/src/test/java/com/amazon/carbonado/spi/TestTriggerManager.java b/src/test/java/com/amazon/carbonado/spi/TestTriggerManager.java deleted file mode 100644 index cad4f0f..0000000 --- a/src/test/java/com/amazon/carbonado/spi/TestTriggerManager.java +++ /dev/null @@ -1,334 +0,0 @@ -/*
- * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
- * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
- * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.amazon.carbonado.spi;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import com.amazon.carbonado.Storable;
-import com.amazon.carbonado.Trigger;
-
-import com.amazon.carbonado.stored.Dummy;
-
-/**
- * Tests for TriggerManager.
- *
- * @author Brian S O'Neill
- */
-public class TestTriggerManager extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static TestSuite suite() {
- return new TestSuite(TestTriggerManager.class);
- }
-
- public TestTriggerManager(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() {
- beforeTriggers = new ArrayList<TestTrigger>();
- afterTriggers = new ArrayList<TestTrigger>();
- failedTriggers = new ArrayList<TestTrigger>();
- }
-
- @Override
- protected void tearDown() {
- }
-
- List<TestTrigger> beforeTriggers;
- List<TestTrigger> afterTriggers;
- List<TestTrigger> failedTriggers;
-
- public void testAddAndRemove() {
- TriggerManager<Dummy> set = new TriggerManager<Dummy>(null, null);
- Trigger<Dummy> trigger = new TestTrigger<Dummy>();
-
- assertNull(set.getInsertTrigger());
- assertNull(set.getUpdateTrigger());
- assertNull(set.getDeleteTrigger());
-
- assertTrue(set.addTrigger(trigger));
- assertNotNull(set.getInsertTrigger());
- assertNotNull(set.getUpdateTrigger());
- assertNotNull(set.getDeleteTrigger());
-
- assertFalse(set.addTrigger(trigger));
- assertNotNull(set.getInsertTrigger());
- assertNotNull(set.getUpdateTrigger());
- assertNotNull(set.getDeleteTrigger());
-
- assertTrue(set.removeTrigger(trigger));
- assertNull(set.getInsertTrigger());
- assertNull(set.getUpdateTrigger());
- assertNull(set.getDeleteTrigger());
-
- assertFalse(set.removeTrigger(trigger));
- assertNull(set.getInsertTrigger());
- assertNull(set.getUpdateTrigger());
- assertNull(set.getDeleteTrigger());
-
- Trigger<Dummy> trigger2 = new TestTrigger<Dummy>();
- assertTrue(set.addTrigger(trigger));
- assertTrue(set.addTrigger(trigger2));
- assertNotNull(set.getInsertTrigger());
- assertNotNull(set.getUpdateTrigger());
- assertNotNull(set.getDeleteTrigger());
-
- assertTrue(set.removeTrigger(trigger));
- assertNotNull(set.getInsertTrigger());
- assertNotNull(set.getUpdateTrigger());
- assertNotNull(set.getDeleteTrigger());
- assertTrue(set.removeTrigger(trigger2));
- assertNull(set.getInsertTrigger());
- assertNull(set.getUpdateTrigger());
- assertNull(set.getDeleteTrigger());
- }
-
- public void testBeforeAndAfterOps() throws Exception {
- TriggerManager<Dummy> set = new TriggerManager<Dummy>(null, null);
- TestTrigger<Dummy> trigger = new TestTrigger<Dummy>();
- set.addTrigger(trigger);
- Dummy d = new Dummy();
-
- Object state = set.getInsertTrigger().beforeInsert(d);
- assertEquals(1, trigger.beforeInsertCount);
- assertEquals(0, trigger.beforeUpdateCount);
- assertEquals(0, trigger.beforeDeleteCount);
-
- set.getInsertTrigger().afterInsert(d, state);
- assertEquals(1, trigger.afterInsertCount);
- assertEquals(0, trigger.afterUpdateCount);
- assertEquals(0, trigger.afterDeleteCount);
-
- state = set.getUpdateTrigger().beforeUpdate(d);
- assertEquals(1, trigger.beforeUpdateCount);
- assertEquals(0, trigger.beforeDeleteCount);
-
- set.getUpdateTrigger().afterUpdate(d, state);
- assertEquals(1, trigger.afterUpdateCount);
- assertEquals(0, trigger.afterDeleteCount);
-
- state = set.getDeleteTrigger().beforeDelete(d);
- assertEquals(1, trigger.beforeDeleteCount);
-
- set.getDeleteTrigger().afterDelete(d, state);
- assertEquals(1, trigger.afterDeleteCount);
- }
-
- public void testBeforeAndFailedOps() throws Exception {
- TriggerManager<Dummy> set = new TriggerManager<Dummy>(null, null);
- TestTrigger<Dummy> trigger = new TestTrigger<Dummy>();
- set.addTrigger(trigger);
- Dummy d = new Dummy();
-
- Object state = set.getInsertTrigger().beforeInsert(d);
- assertEquals(1, trigger.beforeInsertCount);
- assertEquals(0, trigger.beforeUpdateCount);
- assertEquals(0, trigger.beforeDeleteCount);
-
- set.getInsertTrigger().failedInsert(d, state);
- assertEquals(1, trigger.failedInsertCount);
- assertEquals(0, trigger.failedUpdateCount);
- assertEquals(0, trigger.failedDeleteCount);
-
- state = set.getUpdateTrigger().beforeUpdate(d);
- assertEquals(1, trigger.beforeUpdateCount);
- assertEquals(0, trigger.beforeDeleteCount);
-
- set.getUpdateTrigger().failedUpdate(d, state);
- assertEquals(1, trigger.failedUpdateCount);
- assertEquals(0, trigger.failedDeleteCount);
-
- state = set.getDeleteTrigger().beforeDelete(d);
- assertEquals(1, trigger.beforeDeleteCount);
-
- set.getDeleteTrigger().failedDelete(d, state);
- assertEquals(1, trigger.failedDeleteCount);
- }
-
- public void testExecutionOrder() throws Exception {
- TriggerManager<Dummy> set = new TriggerManager<Dummy>(null, null);
- TestTrigger<Dummy> trigger = new TestTrigger<Dummy>(null);
- TestTrigger<Dummy> trigger2 = new TestTrigger<Dummy>();
- set.addTrigger(trigger);
- set.addTrigger(trigger2);
- Dummy d = new Dummy();
-
- // Insert
- {
- Object state = set.getInsertTrigger().beforeInsert(d);
- assertEquals(2, beforeTriggers.size());
- assertEquals(trigger2, beforeTriggers.get(0));
- assertEquals(trigger, beforeTriggers.get(1));
-
- set.getInsertTrigger().afterInsert(d, state);
- assertEquals(2, afterTriggers.size());
- assertEquals(trigger, afterTriggers.get(0));
- assertEquals(trigger2, afterTriggers.get(1));
-
- state = set.getInsertTrigger().beforeInsert(d);
- set.getInsertTrigger().failedInsert(d, state);
- assertEquals(2, failedTriggers.size());
- assertEquals(trigger, failedTriggers.get(0));
- assertEquals(trigger2, failedTriggers.get(1));
- }
-
- beforeTriggers.clear();
- afterTriggers.clear();
- failedTriggers.clear();
-
- // Update
- {
- Object state = set.getUpdateTrigger().beforeUpdate(d);
- assertEquals(2, beforeTriggers.size());
- assertEquals(trigger2, beforeTriggers.get(0));
- assertEquals(trigger, beforeTriggers.get(1));
-
- set.getUpdateTrigger().afterUpdate(d, state);
- assertEquals(2, afterTriggers.size());
- assertEquals(trigger, afterTriggers.get(0));
- assertEquals(trigger2, afterTriggers.get(1));
-
- state = set.getUpdateTrigger().beforeUpdate(d);
- set.getUpdateTrigger().failedUpdate(d, state);
- assertEquals(2, failedTriggers.size());
- assertEquals(trigger, failedTriggers.get(0));
- assertEquals(trigger2, failedTriggers.get(1));
- }
-
- beforeTriggers.clear();
- afterTriggers.clear();
- failedTriggers.clear();
-
- // Delete
- {
- Object state = set.getDeleteTrigger().beforeDelete(d);
- assertEquals(2, beforeTriggers.size());
- assertEquals(trigger2, beforeTriggers.get(0));
- assertEquals(trigger, beforeTriggers.get(1));
-
- set.getDeleteTrigger().afterDelete(d, state);
- assertEquals(2, afterTriggers.size());
- assertEquals(trigger, afterTriggers.get(0));
- assertEquals(trigger2, afterTriggers.get(1));
-
- state = set.getDeleteTrigger().beforeDelete(d);
- set.getDeleteTrigger().failedDelete(d, state);
- assertEquals(2, failedTriggers.size());
- assertEquals(trigger, failedTriggers.get(0));
- assertEquals(trigger2, failedTriggers.get(1));
- }
- }
-
- class TestTrigger<S extends Storable> extends Trigger<S> {
- final Object stateObj;
-
- int beforeInsertCount;
- int afterInsertCount;
- int failedInsertCount;
-
- int beforeUpdateCount;
- int afterUpdateCount;
- int failedUpdateCount;
-
- int beforeDeleteCount;
- int afterDeleteCount;
- int failedDeleteCount;
-
- TestTrigger() {
- this.stateObj = new Object();
- }
-
- TestTrigger(Object stateObj) {
- this.stateObj = stateObj;
- }
-
- @Override
- public Object beforeInsert(S storable) {
- beforeInsertCount++;
- beforeTriggers.add(this);
- return stateObj;
- }
-
- @Override
- public void afterInsert(S storable, Object state) {
- Assert.assertEquals(stateObj, state);
- afterTriggers.add(this);
- afterInsertCount++;
- }
-
- @Override
- public void failedInsert(S storable, Object state) {
- Assert.assertEquals(stateObj, state);
- failedTriggers.add(this);
- failedInsertCount++;
- }
-
- @Override
- public Object beforeUpdate(S storable) {
- beforeUpdateCount++;
- beforeTriggers.add(this);
- return stateObj;
- }
-
- @Override
- public void afterUpdate(S storable, Object state) {
- Assert.assertEquals(stateObj, state);
- afterTriggers.add(this);
- afterUpdateCount++;
- }
-
- @Override
- public void failedUpdate(S storable, Object state) {
- Assert.assertEquals(stateObj, state);
- failedTriggers.add(this);
- failedUpdateCount++;
- }
-
- @Override
- public Object beforeDelete(S storable) {
- beforeDeleteCount++;
- beforeTriggers.add(this);
- return stateObj;
- }
-
- @Override
- public void afterDelete(S storable, Object state) {
- Assert.assertEquals(stateObj, state);
- afterTriggers.add(this);
- afterDeleteCount++;
- }
-
- @Override
- public void failedDelete(S storable, Object state) {
- Assert.assertEquals(stateObj, state);
- failedTriggers.add(this);
- failedDeleteCount++;
- }
-
- }
-}
|