You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/02 22:43:17 UTC

[1/2] git commit: more tests

Repository: incubator-usergrid
Updated Branches:
  refs/heads/map 25e850471 -> 0152dcbd6


more tests


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

Branch: refs/heads/map
Commit: a784ebe9c32d3d80fc5e6b610a48c136f7cf4520
Parents: 25e8504
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 2 14:41:13 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 2 14:41:13 2014 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/map/MapManager.java    |  4 +-
 .../persistence/map/impl/MapManagerImpl.java    | 11 +--
 .../persistence/map/impl/MapSerialization.java  |  4 +-
 .../map/impl/MapSerializationImpl.java          | 95 +++++++++++++++-----
 .../persistence/map/MapManagerTest.java         | 81 ++++++++++++++++-
 5 files changed, 160 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a784ebe9/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
index d1d5f1b..58b0153 100644
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
@@ -48,7 +48,7 @@ public interface MapManager {
     /**
      * Return the uuid, null if not found
      */
-    public UUID putUuid( final String key, final UUID putUuid );
+    public void putUuid( final String key, final UUID putUuid );
 
     /**
      * Return the long, null if not found
@@ -58,7 +58,7 @@ public interface MapManager {
     /**
      * Return the long, null if not found
      */
-    public Long putLong( final String key, final Long value );
+    public void putLong( final String key, final Long value );
 
     /**
      * Delete the key

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a784ebe9/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
index 7b5062b..e58d8aa 100644
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
@@ -57,9 +57,6 @@ import com.netflix.astyanax.serializers.StringSerializer;
  */
 public class MapManagerImpl implements MapManager {
 
-
-
-
     private final MapScope scope;
     private final MapSerialization mapSerialization;
 
@@ -90,8 +87,8 @@ public class MapManagerImpl implements MapManager {
 
 
     @Override
-    public UUID putUuid( final String key, final UUID putUuid ) {
-        return mapSerialization.putUuid(scope,key,putUuid);
+    public void putUuid( final String key, final UUID putUuid ) {
+         mapSerialization.putUuid(scope,key,putUuid);
     }
 
 
@@ -102,8 +99,8 @@ public class MapManagerImpl implements MapManager {
 
 
     @Override
-    public Long putLong( final String key, final Long value ) {
-        return mapSerialization.putLong(scope,key,value);
+    public void putLong( final String key, final Long value ) {
+         mapSerialization.putLong(scope,key,value);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a784ebe9/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
index 5b1abaa..f0428cb 100644
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
@@ -44,7 +44,7 @@ public interface MapSerialization extends Migration {
     /**
      * Return the uuid, null if not found
      */
-    public UUID putUuid(final MapScope scope,  final String key, final UUID putUuid );
+    public void putUuid(final MapScope scope,  final String key, final UUID putUuid );
 
     /**
      * Return the long, null if not found
@@ -54,7 +54,7 @@ public interface MapSerialization extends Migration {
     /**
      * Return the long, null if not found
      */
-    public Long putLong(final MapScope scope,  final String key, final Long value );
+    public void putLong(final MapScope scope,  final String key, final Long value );
 
     /**
      * Delete the key

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a784ebe9/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
index 54bb77b..4e585fa 100644
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.UUID;
 
+import com.google.common.base.Preconditions;
 import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.marshal.UTF8Type;
 
@@ -88,28 +89,16 @@ public class MapSerializationImpl implements MapSerialization {
 
     @Override
     public String getString( final MapScope scope, final String key ) {
-         //add it to the entry
-        final ScopedRowKey<ApplicationScope, MapEntryKey> entryRowKey = MapEntryKey.fromKey( scope, key );
-
-
-        try {
-            final Column<Boolean> result =
-                    keyspace.prepareQuery( MAP_ENTRIES ).getKey( entryRowKey ).getColumn( true ).execute().getResult();
-
-            return result.getStringValue();
-        }
-        catch ( NotFoundException nfe ) {
-            //nothing to return
-            return null;
-        }
-        catch ( ConnectionException e ) {
-            throw new RuntimeException( "Unable to connect to cassandra", e );
-        }
+        Column<Boolean> col = getValue(scope, key);
+        return (col !=null) ?  col.getStringValue(): null;
     }
 
 
     @Override
     public void putString( final MapScope scope, final String key, final String value ) {
+        Preconditions.checkNotNull(scope, "mapscope is required");
+        Preconditions.checkNotNull( key, "key is required" );
+        Preconditions.checkNotNull( value, "value is required" );
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
         //add it to the entry
@@ -134,25 +123,65 @@ public class MapSerializationImpl implements MapSerialization {
 
     @Override
     public UUID getUuid( final MapScope scope, final String key ) {
-        return null;
+
+        Column<Boolean> col = getValue(scope, key);
+        return (col !=null) ?  col.getUUIDValue(): null;
     }
 
 
     @Override
-    public UUID putUuid( final MapScope scope, final String key, final UUID putUuid ) {
-        return null;
+    public void putUuid( final MapScope scope, final String key, final UUID putUuid ) {
+
+        final MutationBatch batch = keyspace.prepareMutationBatch();
+
+        //add it to the entry
+        final ScopedRowKey<ApplicationScope, MapEntryKey> entryRowKey = MapEntryKey.fromKey(scope, key);
+
+        //serialize to the entry
+        batch.withRow(MAP_ENTRIES, entryRowKey).putColumn(true, putUuid);
+
+        //add it to the keys
+
+        final ScopedRowKey<ApplicationScope, String> keyRowKey =
+                ScopedRowKey.fromKey((ApplicationScope) scope, key);
+
+        //serialize to the entry
+        batch.withRow(MAP_KEYS, keyRowKey).putColumn(key, true);
+
+        executeBatch(batch);
+
     }
 
 
     @Override
     public Long getLong( final MapScope scope, final String key ) {
-        return null;
+        Column<Boolean> col = getValue(scope, key);
+        return (col !=null) ?  col.getLongValue(): null;
     }
 
 
+
+
     @Override
-    public Long putLong( final MapScope scope, final String key, final Long value ) {
-        return null;
+    public void putLong( final MapScope scope, final String key, final Long value ) {
+
+        final MutationBatch batch = keyspace.prepareMutationBatch();
+
+        //add it to the entry
+        final ScopedRowKey<ApplicationScope, MapEntryKey> entryRowKey = MapEntryKey.fromKey(scope, key);
+
+        //serialize to the entry
+        batch.withRow(MAP_ENTRIES, entryRowKey).putColumn(true, value);
+
+        //add it to the keys
+
+        final ScopedRowKey<ApplicationScope, String> keyRowKey =
+                ScopedRowKey.fromKey((ApplicationScope) scope, key);
+
+        //serialize to the entry
+        batch.withRow(MAP_KEYS, keyRowKey).putColumn(key, true);
+
+        executeBatch(batch);
     }
 
 
@@ -187,6 +216,26 @@ public class MapSerializationImpl implements MapSerialization {
         return Arrays.asList( mapEntries, mapKeys );
     }
 
+    private  Column<Boolean> getValue(MapScope scope, String key) {
+        //add it to the entry
+        final ScopedRowKey<ApplicationScope, MapEntryKey> entryRowKey = MapEntryKey.fromKey(scope, key);
+
+
+        try {
+            final Column<Boolean> result =
+                    keyspace.prepareQuery( MAP_ENTRIES ).getKey( entryRowKey ).getColumn( true ).execute().getResult();
+
+            return result;
+        }
+        catch ( NotFoundException nfe ) {
+            //nothing to return
+            return null;
+        }
+        catch ( ConnectionException e ) {
+            throw new RuntimeException( "Unable to connect to cassandra", e );
+        }
+    }
+
     private void executeBatch(MutationBatch batch) {
         try {
             batch.execute();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a784ebe9/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
index 19db661..9702532 100644
--- a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
+++ b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
@@ -1,6 +1,7 @@
 package org.apache.usergrid.persistence.map;
 
 
+import org.apache.usergrid.persistence.collection.UUIDComparatorTest;
 import org.jukito.UseModules;
 import org.junit.Before;
 import org.junit.Rule;
@@ -15,6 +16,8 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
 
 import com.google.inject.Inject;
 
+import java.util.UUID;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
@@ -55,6 +58,34 @@ public class MapManagerTest {
         assertEquals( value, returned );
     }
 
+    @Test
+    public void writeReadUUID() {
+        MapManager mm = mmf.getMapManager( this.scope );
+
+        final String key = "key";
+        final UUID value = UUID.randomUUID();
+
+        mm.putUuid( key, value );
+
+        final UUID returned = mm.getUuid( key );
+
+        assertEquals( value, returned );
+    }
+
+    @Test
+    public void writeReadLong() {
+        MapManager mm = mmf.getMapManager( this.scope );
+
+        final String key = "key";
+        final Long value = 1234L;
+
+        mm.putLong( key, value );
+
+        final Long returned = mm.getLong( key );
+
+        assertEquals( value, returned );
+    }
+
 
     @Test
     public void readMissingEntry() {
@@ -63,6 +94,14 @@ public class MapManagerTest {
         final String returned = mm.getString( "key" );
 
         assertNull( returned );
+
+        final Long returnedL = mm.getLong( "key" );
+
+        assertNull( returnedL );
+
+        final UUID returnedUUID = mm.getUuid( "key" );
+
+        assertNull( returnedUUID );
     }
 
 
@@ -86,8 +125,48 @@ public class MapManagerTest {
         assertNull( postDelete );
     }
 
+    @Test
+    public void deleteUUID() {
+        MapManager mm = mmf.getMapManager( this.scope );
+
+        final String key = "key";
+        final UUID value = UUID.randomUUID();
+
+        mm.putUuid( key, value );
+
+        final UUID returned = mm.getUuid( key );
+
+        assertEquals( value, returned );
+
+        mm.delete( key );
+
+        final UUID postDelete = mm.getUuid( key );
+
+        assertNull( postDelete );
+    }
+
+    @Test
+    public void deleteLong() {
+        MapManager mm = mmf.getMapManager( this.scope );
+
+        final String key = "key";
+        final Long value = 1L;
+
+        mm.putLong( key, value );
+
+        final Long returned = mm.getLong( key );
+
+        assertEquals( value, returned );
+
+        mm.delete( key );
+
+        final Long postDelete = mm.getLong( key );
+
+        assertNull( postDelete );
+    }
+
 
-    @Test( expected = IllegalArgumentException.class )
+    @Test( expected = NullPointerException.class )
     public void nullInput() {
         MapManager mm = mmf.getMapManager( this.scope );
 


[2/2] git commit: more tests

Posted by sf...@apache.org.
more tests


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

Branch: refs/heads/map
Commit: 0152dcbd6bd6a64ca2e6566fc4e2440dedc6fd11
Parents: a784ebe
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 2 14:43:03 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 2 14:43:03 2014 -0600

----------------------------------------------------------------------
 .../persistence/map/impl/MapSerializationImpl.java   |  9 +++++++++
 .../usergrid/persistence/map/MapManagerTest.java     | 15 ++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0152dcbd/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
index 4e585fa..c6004f7 100644
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
@@ -99,6 +99,7 @@ public class MapSerializationImpl implements MapSerialization {
         Preconditions.checkNotNull(scope, "mapscope is required");
         Preconditions.checkNotNull( key, "key is required" );
         Preconditions.checkNotNull( value, "value is required" );
+
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
         //add it to the entry
@@ -132,6 +133,10 @@ public class MapSerializationImpl implements MapSerialization {
     @Override
     public void putUuid( final MapScope scope, final String key, final UUID putUuid ) {
 
+        Preconditions.checkNotNull(scope, "mapscope is required");
+        Preconditions.checkNotNull( key, "key is required" );
+        Preconditions.checkNotNull( putUuid, "value is required" );
+
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
         //add it to the entry
@@ -165,6 +170,10 @@ public class MapSerializationImpl implements MapSerialization {
     @Override
     public void putLong( final MapScope scope, final String key, final Long value ) {
 
+        Preconditions.checkNotNull(scope, "mapscope is required");
+        Preconditions.checkNotNull( key, "key is required" );
+        Preconditions.checkNotNull( value, "value is required" );
+
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
         //add it to the entry

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0152dcbd/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
index 9702532..6977f35 100644
--- a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
+++ b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
@@ -167,9 +167,22 @@ public class MapManagerTest {
 
 
     @Test( expected = NullPointerException.class )
-    public void nullInput() {
+    public void nullInputString() {
         MapManager mm = mmf.getMapManager( this.scope );
 
         mm.putString( null, null );
     }
+
+    @Test( expected = NullPointerException.class )
+    public void nullInputLong() {
+        MapManager mm = mmf.getMapManager( this.scope );
+
+        mm.putLong( null, null );
+    }
+    @Test( expected = NullPointerException.class )
+     public void nullInputUUID() {
+        MapManager mm = mmf.getMapManager( this.scope );
+
+        mm.putUuid( null, null );
+    }
 }