You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/08/28 05:45:28 UTC

git commit: Fixes bug with multirow iterator and empty pages

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-188 e040fdf4c -> bc70fe7e1


Fixes bug with multirow iterator and empty pages


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bc70fe7e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bc70fe7e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bc70fe7e

Branch: refs/heads/USERGRID-188
Commit: bc70fe7e1c6c493b6b1abca8b2e9c1db2c468f50
Parents: e040fdf
Author: Todd Nine <to...@apache.org>
Authored: Wed Aug 27 21:45:20 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Aug 27 21:45:20 2014 -0600

----------------------------------------------------------------------
 .../core/astyanax/MultiRowColumnIterator.java   |   4 +-
 .../astyanax/MultiRowColumnIteratorTest.java    | 133 +++++++++++++++++--
 .../graph/GraphManagerShardConsistencyIT.java   |   2 +-
 .../src/test/resources/usergrid-UNIT.properties |   2 +-
 4 files changed, 129 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bc70fe7e/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIterator.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIterator.java
index 155ce84..0a7cca5 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIterator.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIterator.java
@@ -238,7 +238,9 @@ public class MultiRowColumnIterator<R, C, T> implements Iterator<T> {
         //we've parsed everything truncate to the first pageSize, it's all we can ensure is correct without another
         //trip back to cassandra
 
-        startColumn = mergedResults.last();
+        if(!mergedResults.isEmpty()) {
+            startColumn = mergedResults.last();
+        }
 
         moreToFollow = mergedResults.size() == pageSize;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bc70fe7e/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
index 8a8d0b0..c9eeb07 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
@@ -48,11 +48,11 @@ import com.netflix.astyanax.util.RangeBuilder;
 
 import rx.Observable;
 import rx.Observer;
-import rx.Subscription;
 import rx.functions.Action1;
 import rx.functions.Func1;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 
 public class MultiRowColumnIteratorTest {
@@ -207,6 +207,121 @@ public class MultiRowColumnIteratorTest {
 
 
     @Test
+    public void multiIteratorPageBoundary() throws InterruptedException {
+
+        final String rowKey1 = UUIDGenerator.newTimeUUID().toString();
+
+        final String rowKey2 = UUIDGenerator.newTimeUUID().toString();
+
+        final String rowKey3 = UUIDGenerator.newTimeUUID().toString();
+
+
+        final long maxValue = 200;
+
+        final CountDownLatch latch = new CountDownLatch( 3 );
+
+
+        //only write with 1 row key to simulate ending on a page break the last iteration
+        writeData( latch, rowKey1, maxValue, 1 );
+        writeData( latch, rowKey2, maxValue, 2 );
+        writeData( latch, rowKey3, maxValue, 10 );
+
+
+        latch.await();
+
+
+        //create 3 iterators
+
+
+        final ColumnParser<Long, Long> longParser = new ColumnParser<Long, Long>() {
+            @Override
+            public Long parseColumn( final Column<Long> column ) {
+                return column.getName();
+            }
+        };
+
+
+        final ColumnSearch<Long> ascendingSearch = new ColumnSearch<Long>() {
+            @Override
+            public void buildRange( final RangeBuilder rangeBuilder, final Long value ) {
+                rangeBuilder.setStart( value );
+            }
+
+
+            @Override
+            public void buildRange( final RangeBuilder rangeBuilder ) {
+
+            }
+        };
+
+
+        final Comparator<Long> ascendingComparator = new Comparator<Long>() {
+
+            @Override
+            public int compare( final Long o1, final Long o2 ) {
+                return Long.compare( o1, o2 );
+            }
+        };
+
+
+        final Collection<String> rowKeys = Arrays.asList( rowKey1, rowKey2, rowKey3 );
+
+        MultiRowColumnIterator<String, Long, Long> ascendingItr =
+                new MultiRowColumnIterator<>( keyspace, COLUMN_FAMILY, ConsistencyLevel.CL_QUORUM, longParser,
+                        ascendingSearch, ascendingComparator, rowKeys, ( int ) maxValue / 2 );
+
+
+        //ensure we have to make several trips, purposefully set to a nonsensical value to ensure we make all the
+        // trips required
+
+
+        for ( long i = 0; i < maxValue; i++ ) {
+            assertEquals( i, ascendingItr.next().longValue() );
+        }
+
+        //now advance one more time. There should be no values
+
+        assertFalse( "Should not throw exception", ascendingItr.hasNext() );
+
+
+        final ColumnSearch<Long> descendingSearch = new ColumnSearch<Long>() {
+            @Override
+            public void buildRange( final RangeBuilder rangeBuilder, final Long value ) {
+                rangeBuilder.setStart( value );
+                buildRange( rangeBuilder );
+            }
+
+
+            @Override
+            public void buildRange( final RangeBuilder rangeBuilder ) {
+                rangeBuilder.setReversed( true );
+            }
+        };
+
+
+        final Comparator<Long> descendingComparator = new Comparator<Long>() {
+
+            @Override
+            public int compare( final Long o1, final Long o2 ) {
+                return ascendingComparator.compare( o1, o2 ) * -1;
+            }
+        };
+
+
+        MultiRowColumnIterator<String, Long, Long> descendingItr =
+                new MultiRowColumnIterator<>( keyspace, COLUMN_FAMILY, ConsistencyLevel.CL_QUORUM, longParser,
+                        descendingSearch, descendingComparator, rowKeys, 712 );
+
+        for ( long i = maxValue - 1; i > -1; i-- ) {
+            assertEquals( i, descendingItr.next().longValue() );
+        }
+        //now advance one more time. There should be no values
+
+        assertFalse( "Should not throw exception", ascendingItr.hasNext() );
+    }
+
+
+    @Test
     public void singleIterator() {
 
         final String rowKey1 = UUIDGenerator.newTimeUUID().toString();
@@ -334,7 +449,7 @@ public class MultiRowColumnIteratorTest {
     }
 
 
-    private void writeData(final CountDownLatch latch, final String rowKey, final long maxValue, final long mod){
+    private void writeData( final CountDownLatch latch, final String rowKey, final long maxValue, final long mod ) {
 
         Observable.just( rowKey ).doOnNext( new Action1<String>() {
             @Override
@@ -349,13 +464,13 @@ public class MultiRowColumnIteratorTest {
                     }
 
                     if ( i % 1000 == 0 ) {
-                                               try {
-                                                   batch.execute();
-                                               }
-                                               catch ( ConnectionException e ) {
-                                                   throw new RuntimeException( e );
-                                               }
-                                           }
+                        try {
+                            batch.execute();
+                        }
+                        catch ( ConnectionException e ) {
+                            throw new RuntimeException( e );
+                        }
+                    }
                 }
 
                 try {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bc70fe7e/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
index c01d157..279e4e1 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
@@ -122,7 +122,7 @@ public class GraphManagerShardConsistencyIT {
         ConfigurationManager.getConfigInstance().setProperty( GraphFig.SHARD_SIZE, 1000 );
 
 
-        final long cacheTimeout = 5000;
+        final long cacheTimeout = 2000;
         //set our cache timeout to the above value
         ConfigurationManager.getConfigInstance().setProperty( GraphFig.SHARD_CACHE_TIMEOUT, cacheTimeout );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bc70fe7e/stack/corepersistence/graph/src/test/resources/usergrid-UNIT.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/resources/usergrid-UNIT.properties b/stack/corepersistence/graph/src/test/resources/usergrid-UNIT.properties
index 1cb970f..b4761fd 100644
--- a/stack/corepersistence/graph/src/test/resources/usergrid-UNIT.properties
+++ b/stack/corepersistence/graph/src/test/resources/usergrid-UNIT.properties
@@ -6,7 +6,7 @@ cassandra.hosts=localhost
 cassandra.cluster_name=Usergrid
 collections.keyspace=Usergrid_Collections
 cassandra.timeout=5000
-#cassandra.embedded=true
+cassandra.embedded=true
 
 
 collections.keyspace.strategy.options=replication_factor:1