usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [4/8] git commit: more tests
Date Thu, 02 Oct 2014 21:12:53 GMT
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/two-dot-o
Commit: a784ebe9c32d3d80fc5e6b610a48c136f7cf4520
Parents: 25e8504
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Thu Oct 2 14:41:13 2014 -0600
Committer: Shawn Feldman <sfeldman@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 );
 


Mime
View raw message