usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [03/24] usergrid git commit: Cache now working with ExpandingShardLocator and BucketScopedRowKey fun.
Date Wed, 21 Oct 2015 20:36:20 GMT
Cache now working with ExpandingShardLocator and BucketScopedRowKey fun.


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

Branch: refs/heads/master
Commit: 6f5db8082618ed0e1d5256fab779273640b0dc68
Parents: af5d260
Author: Dave Johnson <snoopdave@apache.org>
Authored: Mon Sep 21 10:57:58 2015 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Mon Sep 21 10:57:58 2015 -0400

----------------------------------------------------------------------
 stack/corepersistence/cache/pom.xml             |  15 +-
 .../persistence/cache/guice/CacheModule.java    |  11 +-
 .../cache/impl/CacheFactoryImpl.java            |  34 ++-
 .../persistence/cache/impl/ScopedCacheImpl.java |  12 +-
 .../cache/impl/ScopedCacheSerialization.java    |   5 +-
 .../impl/ScopedCacheSerializationImpl.java      | 260 ++++++++++++++++++-
 .../persistence/cache/CacheTestModule.java      |  34 +++
 .../persistence/cache/ScopedCacheTest.java      |  27 +-
 .../persistence/map/guice/TestMapModule.java    |  18 ++
 stack/corepersistence/pom.xml                   |  12 -
 10 files changed, 391 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/pom.xml b/stack/corepersistence/cache/pom.xml
index dc71284..f6aec2d 100644
--- a/stack/corepersistence/cache/pom.xml
+++ b/stack/corepersistence/cache/pom.xml
@@ -34,25 +34,27 @@ limitations under the License.
     <dependencies>
 
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>${commons.lang.version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.usergrid</groupId>
             <artifactId>common</artifactId>
             <version>${project.version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-lang3</artifactId>
-            <version>${commons.lang.version}</version>
-        </dependency>
+        <!-- test deps -->
 
         <dependency>
             <groupId>org.apache.usergrid</groupId>
             <artifactId>common</artifactId>
             <version>${project.version}</version>
             <classifier>tests</classifier>
-            <scope>test</scope>
         </dependency>
 
+        <!--
         <dependency>
             <groupId>org.apache.usergrid</groupId>
             <artifactId>collection</artifactId>
@@ -60,6 +62,7 @@ limitations under the License.
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        -->
 
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
index 7646ad0..d744fcf 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
@@ -18,11 +18,14 @@
 package org.apache.usergrid.persistence.cache.guice;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Key;
 import com.google.inject.TypeLiteral;
+import com.google.inject.multibindings.Multibinder;
 import org.apache.usergrid.persistence.cache.CacheFactory;
 import org.apache.usergrid.persistence.cache.impl.CacheFactoryImpl;
 import org.apache.usergrid.persistence.cache.impl.ScopedCacheSerialization;
 import org.apache.usergrid.persistence.cache.impl.ScopedCacheSerializationImpl;
+import org.apache.usergrid.persistence.core.migration.schema.Migration;
 
 import java.util.Map;
 
@@ -39,7 +42,13 @@ public class CacheModule extends AbstractModule {
         bind( ScopedCacheSerialization.class ).to( ScopedCacheSerializationImpl.class );
 
         bind( new TypeLiteral<CacheFactory<String, Map<String, Object>>>()
{} )
-            .to( new TypeLiteral<CacheFactoryImpl<String, Map<String, Object>>>()
{} );
+            .to(new TypeLiteral<CacheFactoryImpl<String, Map<String, Object>>>()
{});
+
+        bind( new TypeLiteral<ScopedCacheSerialization<String, Map<String, Object>>>()
{} )
+            .to(new TypeLiteral<ScopedCacheSerializationImpl<String, Map<String,
Object>>>() {});
+
+        Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(),
Migration.class );
+        migrationBinding.addBinding().to(Key.get(ScopedCacheSerialization.class));
 
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
index 8d35321..11a1a4b 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
@@ -17,17 +17,45 @@
 
 package org.apache.usergrid.persistence.cache.impl;
 
+import com.google.common.base.Preconditions;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
 import org.apache.usergrid.persistence.cache.CacheFactory;
 import org.apache.usergrid.persistence.cache.CacheScope;
 import org.apache.usergrid.persistence.cache.ScopedCache;
 
+import java.util.concurrent.ExecutionException;
+
 /**
  * Access to caches.
  */
-public class CacheFactoryImpl<K,V> implements CacheFactory<K,V> {
+@Singleton
+public class CacheFactoryImpl<K, V> implements CacheFactory<K, V> {
+
+    private LoadingCache<CacheScope, ScopedCache> cacheCache;
+
+    @Inject
+    public CacheFactoryImpl( final ScopedCacheSerialization serializer ) {
+
+        cacheCache = CacheBuilder.newBuilder().maximumSize(1000).build(
+            new CacheLoader<CacheScope, ScopedCache>() {
+                public ScopedCache load(CacheScope scope) {
+                    return new ScopedCacheImpl(scope, serializer);
+                }
+            });
+    }
+
 
     @Override
-    public ScopedCache<K,V> getScopedCache( CacheScope scope ) {
-        return new ScopedCacheImpl<K,V>(scope);
+    public ScopedCache<K, V> getScopedCache(CacheScope scope) {
+        Preconditions.checkNotNull(scope);
+        try{
+            return cacheCache.get(scope);
+        } catch (ExecutionException ee) {
+            throw new RuntimeException(ee);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
index ad5b7b4..4ed6150 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.persistence.cache.impl;
 
+import com.google.inject.Inject;
 import org.apache.usergrid.persistence.cache.CacheScope;
 import org.apache.usergrid.persistence.cache.ScopedCache;
 
@@ -27,22 +28,25 @@ public class ScopedCacheImpl<K,V> implements ScopedCache<K,V>
{
 
     CacheScope scope;
 
-    public ScopedCacheImpl( CacheScope scope ) {
+    ScopedCacheSerialization<K,V> serializer;
+
+    public ScopedCacheImpl( CacheScope scope, ScopedCacheSerialization<K,V> serializer
) {
         this.scope = scope;
+        this.serializer = serializer;
     }
 
     @Override
     public void put(K key, V value, long ttl) {
-
+        serializer.writeValue( scope, key, value, ttl );
     }
 
     @Override
     public V get(K key) {
-        return null;
+        return serializer.readValue( scope, key );
     }
 
     @Override
     public void invalidate() {
-
+        throw new UnsupportedOperationException( "TODO" ); // TODO
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
index 02813aa..7829222 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
@@ -18,16 +18,17 @@ package org.apache.usergrid.persistence.cache.impl;
 
 
 import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.core.migration.schema.Migration;
 
 
 /**
  * Serialize cache to/from Cassandra.
  */
-public interface ScopedCacheSerialization<K,V> {
+public interface ScopedCacheSerialization<K,V> extends Migration {
 
     V readValue( CacheScope scope, K key );
 
-    void writeValue( CacheScope scope, K key, V value );
+    void writeValue( CacheScope scope, K key, V value, long ttl );
 
     void invalidate( CacheScope scope );
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
index 385c088..2f116d1 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
@@ -16,7 +16,36 @@
  */
 package org.apache.usergrid.persistence.cache.impl;
 
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Preconditions;
+import com.google.common.hash.Funnel;
+import com.google.common.hash.PrimitiveSink;
+import com.google.inject.Inject;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.Serializer;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
+import com.netflix.astyanax.model.Column;
+import com.netflix.astyanax.model.ColumnList;
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.CompositeParser;
+import com.netflix.astyanax.serializers.ObjectSerializer;
+import com.netflix.astyanax.serializers.StringSerializer;
+import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.core.astyanax.*;
+import org.apache.usergrid.persistence.core.shard.ExpandingShardLocator;
+import org.apache.usergrid.persistence.core.shard.StringHashUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
 
 
 /**
@@ -24,19 +53,248 @@ import org.apache.usergrid.persistence.cache.CacheScope;
  */
 public class ScopedCacheSerializationImpl<K,V> implements ScopedCacheSerialization<K,V>
{
 
+    // row-keys are application ID + consistent hash key
+    // column names are K key toString()
+    // column values are serialization of V value
+
+    public static final Logger logger = LoggerFactory.getLogger(ScopedCacheSerializationImpl.class);
+
+
+    private static final CacheRowKeySerializer ROWKEY_SERIALIZER = new CacheRowKeySerializer();
+
+    private static final BucketScopedRowKeySerializer<String> BUCKET_ROWKEY_SERIALIZER
=
+        new BucketScopedRowKeySerializer<>( ROWKEY_SERIALIZER );
+
+    private static final Serializer<String> COLUMN_NAME_SERIALIZER = StringSerializer.get();
+
+    private static final ObjectSerializer COLUMN_VALUE_SERIALIZER = ObjectSerializer.get();
+
+    public static final MultiTennantColumnFamily<BucketScopedRowKey<String>, String>
SCOPED_CACHE
+        = new MultiTennantColumnFamily<>( "SCOPED_CACHE",
+            BUCKET_ROWKEY_SERIALIZER, COLUMN_NAME_SERIALIZER, COLUMN_VALUE_SERIALIZER );
+
+    /** Number of buckets to hash across */
+    private static final int[] NUM_BUCKETS = {20};
+
+    /** How to funnel keys for buckets */
+    private static final Funnel<String> MAP_KEY_FUNNEL = new Funnel<String>()
{
+
+        @Override
+        public void funnel( final String key, final PrimitiveSink into ) {
+            into.putString(key, StringHashUtils.UTF8);
+        }
+    };
+
+    /**
+     * Locator to get us all buckets
+     */
+    private static final ExpandingShardLocator<String>
+        BUCKET_LOCATOR = new ExpandingShardLocator<>(MAP_KEY_FUNNEL, NUM_BUCKETS);
+
+    private final Keyspace keyspace;
+
+    private final JsonFactory JSON_FACTORY = new JsonFactory();
+
+    private final ObjectMapper MAPPER = new ObjectMapper( JSON_FACTORY );
+
+
+    //------------------------------------------------------------------------------------------
+
+    @Inject
+    public ScopedCacheSerializationImpl( final Keyspace keyspace ) {
+        this.keyspace = keyspace;
+    }
+
 
     @Override
     public V readValue(CacheScope scope, K key) {
+
+        Preconditions.checkNotNull(scope, "scope is required");
+        Preconditions.checkNotNull(key, "key is required");
+
+        // determine bucketed row-key based application UUID
+
+        String rowKeyString = scope.getApplication().getUuid().toString();
+        final int bucket = BUCKET_LOCATOR.getCurrentBucket(rowKeyString);
+
+        final BucketScopedRowKey<String> keyRowKey =
+            BucketScopedRowKey.fromKey(scope.getApplication(), rowKeyString, bucket);
+
+        // determine column name based on K key to string
+        String columnName = key.toString();
+
+        try {
+            try {
+                Column<String> result = keyspace.prepareQuery(SCOPED_CACHE)
+                    .getKey(keyRowKey).getColumn( columnName ).execute().getResult();
+
+                result.getByteBufferValue();
+                V value = MAPPER.readValue(result.getByteArrayValue(), new TypeReference<V>()
{});
+                return value;
+
+            } catch (NotFoundException nfe) {
+                logger.info("Value not found");
+            } catch (IOException ioe) {
+                logger.error("Error reading column value", ioe);
+            }
+
+        } catch (ConnectionException e) {
+            throw new RuntimeException("Unable to connect to cassandra", e);
+        }
         return null;
     }
 
+
     @Override
-    public void writeValue(CacheScope scope, K key, V value) {
+    public void writeValue(CacheScope scope, K key, V value, long ttl) {
+
+        Preconditions.checkNotNull( scope, "scope is required");
+        Preconditions.checkNotNull( key, "key is required" );
+        Preconditions.checkNotNull( value, "value is required");
+
+        // determine bucketed row-key based application UUID
+
+        String rowKeyString = scope.getApplication().getUuid().toString();
+        final int bucket = BUCKET_LOCATOR.getCurrentBucket(rowKeyString);
+
+        final BucketScopedRowKey<String> keyRowKey =
+            BucketScopedRowKey.fromKey( scope.getApplication(), rowKeyString, bucket);
+
+        // determine column name based on K key to string
+        String columnName = key.toString();
+
+        // serialize cache item
+        byte[] cacheBytes;
+        try {
+            cacheBytes = MAPPER.writeValueAsBytes(value);
+        } catch (JsonProcessingException jpe) {
+            throw new RuntimeException("Unable to serialize cache value", jpe);
+        }
+
+        // serialize to the entry
+        final MutationBatch batch = keyspace.prepareMutationBatch();
+        batch.withRow(SCOPED_CACHE, keyRowKey).putColumn(columnName, cacheBytes);
 
+        executeBatch(batch);
     }
 
+
     @Override
     public void invalidate(CacheScope scope) {
 
     }
+
+
+    private void executeBatch(MutationBatch batch) {
+        try {
+            batch.execute();
+        } catch (ConnectionException e) {
+            throw new RuntimeException("Unable to connect to cassandra", e);
+        }
+    }
+
+
+    //------------------------------------------------------------------------------------------
+
+    @Override
+    public Collection<MultiTennantColumnFamilyDefinition> getColumnFamilies() {
+        final MultiTennantColumnFamilyDefinition scopedCache =
+            new MultiTennantColumnFamilyDefinition( SCOPED_CACHE,
+                BytesType.class.getSimpleName(),
+                BytesType.class.getSimpleName(),
+                BytesType.class.getSimpleName(),
+                MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
+
+        return Arrays.asList(scopedCache);
+    }
+
+
+    //------------------------------------------------------------------------------------------
+
+//    /**
+//     * Entries for serializing cache entries keys to a row
+//     */
+//    private static class CacheKey {
+//        public final String key;
+//
+//        private CacheKey( final String key ) {
+//            this.key = key;
+//        }
+//
+//        /**
+//         * Create a scoped row key from the key
+//         */
+//        public static ScopedRowKey<CacheKey> fromKey(
+//            final CacheScope cacheScope, final String key ) {
+//            return ScopedRowKey.fromKey( cacheScope.getApplication(), new CacheKey( key
) );
+//        }
+//    }
+
+    /**
+     * Inner class to serialize cache key
+     */
+    private static class CacheRowKeySerializer implements CompositeFieldSerializer<String>
{
+
+        @Override
+        public void toComposite( final CompositeBuilder builder, final String key ) {
+            builder.addString(key);
+        }
+
+        @Override
+        public String fromComposite( final CompositeParser composite ) {
+            final String key = composite.readString();
+            return key;
+        }
+    }
+
+
+//    /**
+//     * Inner class to serialize cache value
+//     */
+//    private static class CacheEntitySerializer implements CompositeFieldSerializer {
+//
+//        @Override
+//        public void toComposite(CompositeBuilder builder, Object value) {
+//
+//        }
+//
+//        @Override
+//        public Object fromComposite( final CompositeParser composite ) {
+//            return null;
+//        }
+//    }
+
+
+//    /**
+//     * Build the results from the row keys
+//     */
+//    private static interface ResultsBuilder<T> {
+//
+//        public T buildResults(final  Rows<ScopedRowKey<CacheKey>, Boolean>
rows);
+//    }
+//
+//    public static class StringResultsBuilder implements ResultsBuilder<Map<String,
String>>{
+//
+//        @Override
+//        public Map<String, String> buildResults( final Rows<ScopedRowKey<CacheKey>,
Boolean> rows ) {
+//            final int size = rows.size();
+//
+//            final Map<String, String> results = new HashMap<>(size);
+//
+//            for(int i = 0; i < size; i ++){
+//
+//                final Row<ScopedRowKey<CacheKey>, Boolean> row = rows.getRowByIndex(
i );
+//
+//                final String value = row.getColumns().getStringValue( true, null );
+//
+//                if(value == null){
+//                    continue;
+//                }
+//
+//                results.put( row.getKey().getKey().key,  value );
+//            }
+//
+//            return results;
+//        }
+//    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/CacheTestModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/CacheTestModule.java
b/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/CacheTestModule.java
new file mode 100644
index 0000000..47f6ccf
--- /dev/null
+++ b/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/CacheTestModule.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.cache;
+
+
+import org.apache.usergrid.persistence.cache.guice.CacheModule;
+import org.apache.usergrid.persistence.core.guice.CommonModule;
+
+
+public class CacheTestModule extends org.apache.usergrid.persistence.core.guice.TestModule
{
+
+    @Override
+    protected void configure() {
+        install( new CommonModule());
+        install( new CacheModule() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
b/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
index 60f34c3..683e2e9 100644
--- a/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
+++ b/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
@@ -21,28 +21,32 @@ package org.apache.usergrid.persistence.cache;
 
 
 import com.google.inject.Inject;
-import org.apache.usergrid.persistence.cache.guice.CacheModule;
+import org.apache.usergrid.persistence.core.guice.MigrationManagerRule;
 import org.apache.usergrid.persistence.core.test.ITRunner;
 import org.apache.usergrid.persistence.core.test.UseModules;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
 
 
 @RunWith( ITRunner.class )
-@UseModules( { CacheModule.class } )
+@UseModules( { CacheTestModule.class } )
 public class ScopedCacheTest {
 
-    @Inject
-    protected CacheFactory<String, Map<String, Object>> cf;
+    // this ensures that SCOPED_CACHE column family is created
+    @Inject @Rule public MigrationManagerRule migrationManagerRule;
 
-    protected CacheScope scope;
+    @Inject protected CacheFactory<String, Map<String, Object>> cf;
 
+    protected CacheScope scope;
 
     @Before
     public void mockApp(){
@@ -53,8 +57,15 @@ public class ScopedCacheTest {
     @Test
     public void testBasicOperation() {
 
-        ScopedCache cache = cf.getScopedCache(scope);
-        assertNotNull( cache );
-    }
+        ScopedCache<String, Map<String, Object>> cache = cf.getScopedCache(scope);
+        assertNotNull("should get a cache", cache);
 
+        Map<String, Object> item = new HashMap<String, Object>() {{
+            put("field1", "value1");
+        }};
+        cache.put("item", item, 0);
+        Map<String, Object> retrievedItem = cache.get("item");
+        assertNotNull( "should get back item", retrievedItem );
+        assertEquals("value1", retrievedItem.get("field1"));
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
index 19700c6..ff622de 100644
--- a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
+++ b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.usergrid.persistence.map.guice;
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f5db808/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 5af8dfd..e0e4024 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -21,18 +21,6 @@ limitations under the License.
     <modelVersion>4.0.0</modelVersion>
 
     <description>Prototype for refactoring persistence of usergrid</description>
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.usergrid</groupId>
-            <artifactId>common</artifactId>
-            <version>2.1.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.usergrid</groupId>
-            <artifactId>common</artifactId>
-            <version>2.1.0-SNAPSHOT</version>
-        </dependency>
-    </dependencies>
 
     <groupId>org.apache.usergrid</groupId>
     <artifactId>persistence</artifactId>


Mime
View raw message