diff options
| author | Brian S. O'Neill <bronee@gmail.com> | 2008-07-25 06:13:20 +0000 |
|---|---|---|
| committer | Brian S. O'Neill <bronee@gmail.com> | 2008-07-25 06:13:20 +0000 |
| commit | 799ead1e727d9abe87d55d890644c409b337f524 (patch) | |
| tree | a8936526fb896c147a3922c370549093ff882e28 /src/test/java | |
| parent | c991e3fc885200737682f088969845f43c0c4f4c (diff) | |
Complete BigDecimal support -- ensure that failed update rolls back normalization.
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/com/amazon/carbonado/TestStorables.java | 40 | ||||
| -rw-r--r-- | src/test/java/com/amazon/carbonado/stored/WithBigDecimalVersioned.java | 43 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/test/java/com/amazon/carbonado/TestStorables.java b/src/test/java/com/amazon/carbonado/TestStorables.java index c54099e..bfedd12 100644 --- a/src/test/java/com/amazon/carbonado/TestStorables.java +++ b/src/test/java/com/amazon/carbonado/TestStorables.java @@ -3156,6 +3156,46 @@ public class TestStorables extends TestCase { return bd.stripTrailingZeros(); } + public void test_BigDecimalVersioned() throws Exception { + BigDecimal bd = new BigDecimal("123.000"); + BigDecimal expected = expected(bd); + + Storage<WithBigDecimalVersioned> storage = + getRepository().storageFor(WithBigDecimalVersioned.class); + + WithBigDecimalVersioned s = storage.prepare(); + s.setId(1); + s.setNumber(bd); + s.insert(); + + // Ensure insert behaves as if Storable was reloaded. + assertEquals(expected, s.getNumber()); + + int version = s.getVersion(); + + bd = new BigDecimal("200.000"); + expected = expected(bd); + + s = storage.prepare(); + s.setId(1); + s.setNumber(bd); + s.setVersion(version - 1); + try { + s.update(); + fail(); + } catch (OptimisticLockException e) { + } + + // Since no update actually happened, scale should stay the same. + assertEquals(bd, s.getNumber()); + + s.setVersion(version); + s.update(); + + // Now side-effect should be visble. + assertEquals(expected, s.getNumber()); + } + public void test_BigDecimalCompare() throws Exception { BigDecimal bd1 = new BigDecimal("123.0"); BigDecimal bd2 = new BigDecimal("123"); diff --git a/src/test/java/com/amazon/carbonado/stored/WithBigDecimalVersioned.java b/src/test/java/com/amazon/carbonado/stored/WithBigDecimalVersioned.java new file mode 100644 index 0000000..01ccfc7 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/WithBigDecimalVersioned.java @@ -0,0 +1,43 @@ +/*
+ * Copyright 2008 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.stored;
+
+import java.math.BigDecimal;
+
+import com.amazon.carbonado.*;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+@PrimaryKey("id")
+@Indexes(@Index("number"))
+public interface WithBigDecimalVersioned extends Storable {
+ int getId();
+ void setId(int id);
+
+ @Nullable
+ BigDecimal getNumber();
+ void setNumber(BigDecimal number);
+
+ @Version
+ int getVersion();
+ void setVersion(int version);
+}
|
