1.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/MultivaluedBtree.java Wed Nov 13 16:25:48 2002 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/MultivaluedBtree.java Thu Nov 14 10:35:11 2002 +0000
1.3 @@ -162,7 +162,9 @@
1.4
1.5 List result = new LinkedList ();
1.6 byte [] prefixBytes = keyInfo.toBuffer (prefix);
1.7 - SearchResult location = getLocation (prefixBytes);
1.8 + SearchResult location = getLocation (prefixBytes);
1.9 + if (location.entryNum == location.page.numEntries())
1.10 + BtreePage.getNext (null, location);
1.11
1.12 while ((location.entryNum < location.page.numEntries()) &&
1.13 SinglevaluedBtree.isPrefix (prefixBytes, location.page.getKey (location.entryNum))) {
2.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/SinglevaluedBtree.java Wed Nov 13 16:25:48 2002 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreeindex/SinglevaluedBtree.java Thu Nov 14 10:35:11 2002 +0000
2.3 @@ -234,6 +234,8 @@
2.4 List result = new LinkedList ();
2.5 byte [] prefixBytes = keyInfo.toBuffer (prefix);
2.6 SearchResult location = getLocation (prefixBytes);
2.7 + if (location.entryNum == location.page.numEntries())
2.8 + BtreePage.getNext (null, location);
2.9
2.10 while ((location.entryNum < location.page.numEntries()) &&
2.11 isPrefix (prefixBytes, location.page.getKey (location.entryNum))) {
2.12 @@ -245,7 +247,7 @@
2.13 );
2.14 result.add (entry);
2.15 BtreePage.getNext (null, location);
2.16 - } // while
2.17 + } // while
2.18 return result;
2.19 }
2.20
3.1 --- a/mdr/test/cfg-unit.xml Wed Nov 13 16:25:48 2002 +0000
3.2 +++ b/mdr/test/cfg-unit.xml Thu Nov 14 10:35:11 2002 +0000
3.3 @@ -38,6 +38,7 @@
3.4 <include name="org/netbeans/mdr/test/AdditionalIndexTest.class"/>
3.5 <include name="org/netbeans/mdr/test/StaticFeaturesTest.class"/>
3.6 <include name="org/netbeans/mdr/test/DTDProducerTest.class"/>
3.7 + <include name="org/netbeans/mdr/test/QueryByPrefixTest.class"/>
3.8 <!-- <include name="org/netbeans/mdr/test/RecoveryTest.class"/> -->
3.9 <exclude name="org/netbeans/mdr/test/MDRExportImportTest.class/testUML"/>
3.10 </patternset>
4.1 --- a/mdr/test/unit/src/org/netbeans/mdr/test/QueryByPrefixTest.java Wed Nov 13 16:25:48 2002 +0000
4.2 +++ b/mdr/test/unit/src/org/netbeans/mdr/test/QueryByPrefixTest.java Thu Nov 14 10:35:11 2002 +0000
4.3 @@ -77,8 +77,7 @@
4.4 doSingleTest (storage);
4.5 doMultiTest (storage);
4.6
4.7 - storage.close ();
4.8 - System.out.println("BtreeStorage test finished.");
4.9 + storage.close ();
4.10 } catch (Exception e) {
4.11 e.printStackTrace ();
4.12 fail (e.getMessage ());
4.13 @@ -94,8 +93,7 @@
4.14 doSingleTest (storage);
4.15 doMultiTest (storage);
4.16
4.17 - storage.close ();
4.18 - System.out.println("MemoryStorage test finished.");
4.19 + storage.close ();
4.20 } catch (Exception e) {
4.21 e.printStackTrace ();
4.22 fail (e.getMessage ());
4.23 @@ -104,8 +102,6 @@
4.24
4.25 public void doSingleTest (Storage storage) {
4.26 try {
4.27 - System.out.println("single index");
4.28 -
4.29 SinglevaluedIndex primaryIndex = storage.getPrimaryIndex ();
4.30
4.31 Storage.EntryType entryType = Storage.EntryType.STRING;
4.32 @@ -124,7 +120,6 @@
4.33 for (int x = 0; x < PREFIXES_NUM; x++) {
4.34 counts [x] = 0;
4.35 prefixes [x] = randomString ("" + (char)('a' + x), 5, 8);
4.36 - //System.out.println(prefixes [x]);
4.37 }
4.38 for (int x = 0; x < MAX; x++) {
4.39 String s = randomString ("");
4.40 @@ -156,21 +151,27 @@
4.41 // query keys starting with the specified prefix ...
4.42 Collection list = index.queryByKeyPrefix (prefixes [x], primaryIndex);
4.43 if (counts [x] != list.size ()) {
4.44 - System.out.println("FAILED: " + x + ", " + prefixes [x] + ": found "
4.45 + fail("#" + x + ", " + prefixes [x] + ": found "
4.46 + list.size () + ", expected " + counts [x]);
4.47 }
4.48 + for (Iterator iter = list.iterator (); iter.hasNext ();) {
4.49 + Map.Entry entry = (Map.Entry) iter.next ();
4.50 + if (!entry.getValue ().equals (entry.getKey ())) {
4.51 + fail ();
4.52 + }
4.53 + } // for
4.54 }
4.55
4.56 // should return an empty collection
4.57 Collection list = index.queryByKeyPrefix ("000", primaryIndex);
4.58 if (list.size () != 0) {
4.59 - System.out.println("FAILED (2): " + list.size ());
4.60 + fail(list.size () + " != 0");
4.61 }
4.62
4.63 index.add (LAST_ELEMENT, LAST_ELEMENT);
4.64 list = index.queryByKeyPrefix (LAST_ELEMENT, primaryIndex);
4.65 if (list.size () != 1) {
4.66 - System.out.println("FAILED (3): " + list.size ());
4.67 + fail(list.size () + " != 1");
4.68 }
4.69
4.70 storage.commitChanges ();
4.71 @@ -182,8 +183,6 @@
4.72
4.73 public void doMultiTest (Storage storage) {
4.74 try {
4.75 - System.out.println("multi index");
4.76 -
4.77 SinglevaluedIndex primaryIndex = storage.getPrimaryIndex ();
4.78
4.79 Storage.EntryType entryType = Storage.EntryType.STRING;
4.80 @@ -202,7 +201,6 @@
4.81 for (int x = 0; x < PREFIXES_NUM; x++) {
4.82 counts [x] = 0;
4.83 prefixes [x] = randomString ("" + (char)('a' + x), 5, 8);
4.84 - //System.out.println(prefixes [x]);
4.85 }
4.86 for (int x = 0; x < MAX; x++) {
4.87 String s = randomString ("");
4.88 @@ -235,21 +233,32 @@
4.89 // query keys starting with the specified prefix ...
4.90 Collection list = index.queryByKeyPrefix (prefixes [x], primaryIndex);
4.91 if (counts [x] != list.size ()) {
4.92 - System.out.println("FAILED: " + x + ", " + prefixes [x] + ": found "
4.93 + fail("#" + x + ", " + prefixes [x] + ": found "
4.94 + list.size () + ", expected " + counts [x]);
4.95 }
4.96 - }
4.97 + for (Iterator iter = list.iterator (); iter.hasNext ();) {
4.98 + Map.Entry entry = (Map.Entry) iter.next ();
4.99 + Collection values = (Collection) entry.getValue ();
4.100 + if (values.size () != 1) {
4.101 + fail (values.size () + " != 1");
4.102 + }
4.103 + Object val = values.iterator ().next ();
4.104 + if (!val.equals (entry.getKey ())) {
4.105 + fail ();
4.106 + }
4.107 + } // for
4.108 + } // for
4.109
4.110 // should return an empty collection
4.111 Collection list = index.queryByKeyPrefix ("000", primaryIndex);
4.112 if (list.size () != 0) {
4.113 - System.out.println("FAILED (2): " + list.size ());
4.114 + fail(list.size () + " != 0");
4.115 }
4.116
4.117 index.add (LAST_ELEMENT, LAST_ELEMENT);
4.118 list = index.queryByKeyPrefix (LAST_ELEMENT, primaryIndex);
4.119 if (list.size () != 1) {
4.120 - System.out.println("FAILED (3): " + list.size ());
4.121 + fail(list.size () + " != 1");
4.122 }
4.123
4.124 storage.commitChanges ();