Issue Details (XML | Word | Printable)

Key: JDO-218
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Michelle Caisse
Reporter: Michelle Caisse
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JDO

checkValues() method of *MapStringValueCollections doesn't work

Created: 18/Nov/05 06:38 AM   Updated: 23/Apr/06 03:17 AM
Return to search
Component/s: tck2
Affects Version/s: None
Fix Version/s: JDO 2 beta

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works JDO-218.patch 2005-11-18 06:49 AM Michelle Caisse 14 kB

Resolution Date: 23/Apr/06 03:17 AM


 Description  « Hide
No map fields with BigDecimal values compare okay. There are several problems.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Michelle Caisse added a comment - 18/Nov/05 06:49 AM
The attached patch fixes the BigDecimal comparison problem. All *MapStringValueCollections tests pass using application identity with this patch applied.
The relevant new code (taking TestMapStringKeyCollections.java as an example) is:

            else if (! expected.equals(actual)) {
                if (TestUtil.getFieldSpecsForMap(
                            MapStringValueCollections.fieldSpecs[i]
                            ).get(0).equals("BigDecimal")) {
                    Set expectedKeySet = expected.keySet();
                    Set actualKeySet = actual.keySet();
                    Iterator expectedIter = expectedKeySet.iterator();
                    while (expectedIter.hasNext()) {
                        BigDecimal expectedKey = (BigDecimal) expectedIter.next();
                        // compare keys
                        if (!TestUtil.containsBigDecimalKey(expectedKey,
                                    actualKeySet)) {
                            sbuf.append("\nFor element " + i +
                                    " expected key = " + expectedKey +
                                    " not found in actual Map. Actual keyset is "
                                    + actualKeySet.toString());
                        // compare values
                        } else {
                            String expectedVal = (String) expected.get(expectedKey);
                            String actualValue = (String)
                               actual.get(TestUtil.getBigDecimalKey(expectedKey,
                                                                    actualKeySet));
                            if (!expectedVal.equals(actualValue)) {
                                sbuf.append("\nFor element " + i +
                                    " expected value = " + expectedVal +
                                    " actual Value = " + actualValue);
                           }
                       }
                    }
            }
Two new static functions were added to TestUtil.java. boolean containsBigDecimalKey(BigDecimal expectedKey, Set actualKeySet) and BigDecimal getBigDecimalKey(BigDecimal expectedKey, Set actualKeySet) use BigDecimal.compareTo to determine equality of two keys.

Michelle Caisse made changes - 18/Nov/05 06:49 AM
Field Original Value New Value
Attachment JDO-218.patch [ 12320765 ]
Michelle Caisse made changes - 18/Nov/05 06:52 AM
Status Open [ 1 ] In Progress [ 3 ]
Repository Revision Date User Message
ASF #345613 Sat Nov 19 00:49:40 UTC 2005 mcaisse JDO-218
Files Changed
MODIFY /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringValueCollections.java
MODIFY /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java
MODIFY /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java
MODIFY /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashMapStringValueCollections.java
MODIFY /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java

Craig Russell added a comment - 19/Nov/05 07:49 AM
It seems like this code has a similar problem in case there is a BigDecimal as a value.

+ String expectedVal = (String) expected.get(expectedKey);
+ String actualValue = (String)
+ actual.get(TestUtil.getBigDecimalKey(expectedKey,
+ actualKeySet));
+ if (!expectedVal.equals(actualValue)) {
+ sbuf.append("\nFor element " + i +
+ " expected value = " + expectedVal +
+ " actual Value = " + actualValue);
+ }

Could it be rewritten to use compareTo instead:

+ String expectedVal = (String) expected.get(expectedKey);
+ String actualValue = (String)
+ actual.get(TestUtil.getBigDecimalKey(expectedKey,
+ actualKeySet));
+ if (expectedVal.equals(actualValue)) {continue;}
if (expectedVal instanceof Comparable && ((Comparable)expectedVal.compareTo(actualValue)) == 0) {continue;}
+ sbuf.append("\nFor element " + i +
+ " expected value = " + expectedVal +
+ " actual Value = " + actualValue);
+ }


Michelle Caisse added a comment - 19/Nov/05 08:57 AM
The code expects only BigDecimal keys. It is for the tests where the values are all String and the keys can be any of a number of types, specifically TestMapStringValueCollections, TestHashMapStringValueCollections, TestHashtableStringValueCollections, and TestTreeMapStringValueCollections. The checkValues() method in the Test*MapStringKeyCollections is different, but in those tests there would be only String keys.

It would be great to be able to generalize this method and pull the code out of the fieldtypes tests, but it is tricky because the data type of the Collection appears in the test. There are also casting and polymorphism issues which vary among the Collection (not Map) tests when iterating through the BigDecimal fields and make this difficult.

Craig Russell added a comment - 19/Nov/05 09:07 AM
I totally missed that the expectedVal and actualVal were cast as Strings! My comments would apply to a more general method but not to this case.

-20-

Michelle Caisse added a comment - 19/Nov/05 09:50 AM
revision 345613

Michelle Caisse made changes - 19/Nov/05 09:50 AM
Status In Progress [ 3 ] Closed [ 6 ]
Resolution Fixed [ 1 ]
Michael Bouschen added a comment - 23/Apr/06 03:14 AM
Reopened to set the Fix Version/s field to JDO 2 beta.

Michael Bouschen made changes - 23/Apr/06 03:14 AM
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Michael Bouschen made changes - 23/Apr/06 03:17 AM
Fix Version/s JDO 2 beta [ 12310683 ]
Status Reopened [ 4 ] Closed [ 6 ]
Resolution Fixed [ 1 ]