usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [12/38] usergrid git commit: Add tests for DataStaxCluster and improve cluster/connection handling to ensure the cluster is always available through the interface.
Date Wed, 17 Aug 2016 21:48:19 GMT
Add tests for DataStaxCluster and improve cluster/connection handling to ensure the cluster
is always available through the interface.


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

Branch: refs/heads/master
Commit: 7ff31ebff0cb431c9655764e922d94d7f215a673
Parents: 29814ef
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Fri Feb 12 21:45:08 2016 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Fri Feb 12 21:45:08 2016 -0800

----------------------------------------------------------------------
 .../persistence/core/datastax/CQLUtils.java     |   4 +-
 .../core/datastax/DataStaxCluster.java          |   2 +
 .../core/datastax/TableDefinition.java          |   7 +-
 .../core/datastax/impl/DatastaxClusterImpl.java | 138 +++++++++++--------
 .../migration/schema/MigrationManagerImpl.java  |  66 +--------
 .../persistence/core/datastax/CQLUtilsTest.java |  30 ++--
 .../core/datastax/DatastaxClusterTest.java      |  63 ++++++++-
 .../map/impl/MapSerializationImpl.java          |  25 ++--
 8 files changed, 186 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/CQLUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/CQLUtils.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/CQLUtils.java
index f2e4f57..38b6b7b 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/CQLUtils.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/CQLUtils.java
@@ -134,10 +134,10 @@ public class CQLUtils {
 
     }
 
-    public static String spaceSeparatedKeyValue(Map<String, String> columns){
+    public static String spaceSeparatedKeyValue(Map<String, ?> columns){
 
         StringJoiner columnsSchema = new StringJoiner(",");
-        columns.forEach( (key, value) -> columnsSchema.add(key+" "+value));
+        columns.forEach( (key, value) -> columnsSchema.add(key+" "+String.valueOf(value)));
 
         return columnsSchema.toString();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/DataStaxCluster.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/DataStaxCluster.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/DataStaxCluster.java
index 7515bf5..206c2a0 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/DataStaxCluster.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/DataStaxCluster.java
@@ -30,4 +30,6 @@ public interface DataStaxCluster {
 
     Session getApplicationSession();
 
+    void waitForSchemaAgreement();
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
index 3dc3145..2f83513 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
@@ -20,6 +20,7 @@
 package org.apache.usergrid.persistence.core.datastax;
 
 
+import com.datastax.driver.core.DataType;
 import com.google.common.base.Preconditions;
 
 import java.util.Collection;
@@ -53,7 +54,7 @@ public class TableDefinition {
     private final String tableName;
     private final Collection<String> partitionKeys;
     private final Collection<String> columnKeys;
-    private final Map<String, String> columns;
+    private final Map<String, DataType.Name> columns;
     private final CacheOption cacheOption;
     private final Map<String, Object> compaction;
     private final String bloomFilterChance;
@@ -63,7 +64,7 @@ public class TableDefinition {
     private final Map<String, String> clusteringOrder;
 
     public TableDefinition( final String tableName, final Collection<String> partitionKeys,
-                            final Collection<String> columnKeys, final Map<String,
String> columns,
+                            final Collection<String> columnKeys, final Map<String,
DataType.Name> columns,
                             final CacheOption cacheOption, final Map<String, String>
clusteringOrder){
 
         Preconditions.checkNotNull(tableName, "Table name cannot be null");
@@ -105,7 +106,7 @@ public class TableDefinition {
         return columnKeys;
     }
 
-    public Map<String, String> getColumns() {
+    public Map<String, DataType.Name> getColumns() {
         return columns;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/impl/DatastaxClusterImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/impl/DatastaxClusterImpl.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/impl/DatastaxClusterImpl.java
index 43e2eb2..1e9061f 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/impl/DatastaxClusterImpl.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/impl/DatastaxClusterImpl.java
@@ -37,63 +37,15 @@ public class DataStaxClusterImpl implements DataStaxCluster {
 
 
     private final CassandraFig cassandraFig;
-    private final Cluster cluster;
+    private Cluster cluster;
     private Session applicationSession;
     private Session clusterSession;
 
     @Inject
     public DataStaxClusterImpl(final CassandraFig cassandraFig ) throws Exception {
         this.cassandraFig = cassandraFig;
+        this.cluster = buildCluster();
 
-        ConsistencyLevel defaultConsistencyLevel;
-        try {
-            defaultConsistencyLevel = ConsistencyLevel.valueOf(cassandraFig.getReadCl());
-        } catch (IllegalArgumentException e){
-
-            logger.error("Unable to parse provided consistency level in property: {}, defaulting
to: {}",
-                CassandraFig.READ_CL,
-                ConsistencyLevel.LOCAL_QUORUM);
-
-            defaultConsistencyLevel = ConsistencyLevel.LOCAL_QUORUM;
-        }
-
-
-        LoadBalancingPolicy loadBalancingPolicy;
-        if( !cassandraFig.getLocalDataCenter().isEmpty() ){
-
-            loadBalancingPolicy = new DCAwareRoundRobinPolicy.Builder()
-                .withLocalDc( cassandraFig.getLocalDataCenter() ).build();
-        }else{
-            loadBalancingPolicy = new DCAwareRoundRobinPolicy.Builder().build();
-        }
-
-        final PoolingOptions poolingOptions = new PoolingOptions()
-            .setCoreConnectionsPerHost(HostDistance.LOCAL, cassandraFig.getConnections()
/ 2)
-            .setMaxConnectionsPerHost(HostDistance.LOCAL, cassandraFig.getConnections())
-            .setIdleTimeoutSeconds(cassandraFig.getTimeout() / 1000)
-            .setPoolTimeoutMillis(cassandraFig.getPoolTimeout());
-
-        final QueryOptions queryOptions = new QueryOptions()
-            .setConsistencyLevel(defaultConsistencyLevel);
-
-        final Cluster.Builder datastaxCluster = Cluster.builder()
-            .withClusterName(cassandraFig.getClusterName())
-            .addContactPoints(cassandraFig.getHosts().split(","))
-            .withCompression(ProtocolOptions.Compression.LZ4)
-            .withLoadBalancingPolicy(loadBalancingPolicy)
-            .withPoolingOptions(poolingOptions)
-            .withQueryOptions(queryOptions)
-            .withProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
-
-        // only add auth credentials if they were provided
-        if ( !cassandraFig.getUsername().isEmpty() && !cassandraFig.getPassword().isEmpty()
){
-            datastaxCluster.withCredentials(
-                cassandraFig.getUsername(),
-                cassandraFig.getPassword()
-            );
-        }
-
-        this.cluster = datastaxCluster.build();
         logger.info("Initialized datastax cluster client. Hosts={}, Idle Timeout={}s,  Pool
Timeout={}s",
             cluster.getMetadata().getAllHosts().toString(),
             cluster.getConfiguration().getPoolingOptions().getIdleTimeoutSeconds(),
@@ -106,14 +58,20 @@ public class DataStaxClusterImpl implements DataStaxCluster {
     @Override
     public Cluster getCluster(){
 
+        // ensure we can build the cluster if it was previously closed
+        if ( cluster.isClosed() ){
+            cluster = buildCluster();
+        }
+
         return cluster;
     }
 
     @Override
     public Session getClusterSession(){
 
+        // always grab cluster from getCluster() in case it was prematurely closed
         if ( clusterSession == null || clusterSession.isClosed() ){
-            clusterSession = cluster.connect();
+            clusterSession = getCluster().connect();
         }
 
         return clusterSession;
@@ -122,34 +80,39 @@ public class DataStaxClusterImpl implements DataStaxCluster {
     @Override
     public Session getApplicationSession(){
 
+        // always grab cluster from getCluster() in case it was prematurely closed
         if ( applicationSession == null || applicationSession.isClosed() ){
-            applicationSession = cluster.connect( CQLUtils.quote(cassandraFig.getApplicationKeyspace()
) );
+            applicationSession = getCluster().connect( CQLUtils.quote(cassandraFig.getApplicationKeyspace()
) );
         }
         return applicationSession;
     }
 
+
+    /**
+     * Execute CQL that will create the keyspace if it doesn't exist and alter it if it does.
+     * @throws Exception
+     */
     private void createOrUpdateKeyspace() throws Exception {
 
         clusterSession = getClusterSession();
 
         final String createApplicationKeyspace = String.format(
-            "CREATE KEYSPACE IF NOT EXISTS \"%s\" WITH replication = %s",
-            cassandraFig.getApplicationKeyspace(),
+            "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = %s",
+            CQLUtils.quote(cassandraFig.getApplicationKeyspace()),
             CQLUtils.getFormattedReplication( cassandraFig.getStrategy(), cassandraFig.getStrategyOptions()
)
 
         );
 
         final String updateApplicationKeyspace = String.format(
-            "ALTER KEYSPACE \"%s\" WITH replication = %s",
-            cassandraFig.getApplicationKeyspace(),
+            "ALTER KEYSPACE %s WITH replication = %s",
+            CQLUtils.quote(cassandraFig.getApplicationKeyspace()),
             CQLUtils.getFormattedReplication( cassandraFig.getStrategy(), cassandraFig.getStrategyOptions()
)
         );
 
-        logger.info("Creating application keyspace with the following CQL: {}", createApplicationKeyspace);
         clusterSession.execute(createApplicationKeyspace);
-        logger.info("Updating application keyspace with the following CQL: {}", updateApplicationKeyspace);
         clusterSession.executeAsync(updateApplicationKeyspace);
 
+        logger.info("Created/Updated keyspace: {}", cassandraFig.getApplicationKeyspace());
 
         waitForSchemaAgreement();
     }
@@ -158,11 +121,11 @@ public class DataStaxClusterImpl implements DataStaxCluster {
      * Wait until all Cassandra nodes agree on the schema.  Sleeps 100ms between checks.
      *
      */
-    private void waitForSchemaAgreement() {
+    public void waitForSchemaAgreement() {
 
         while ( true ) {
 
-            if( cluster.getMetadata().checkSchemaAgreement() ){
+            if( this.cluster.getMetadata().checkSchemaAgreement() ){
                 return;
             }
 
@@ -176,4 +139,59 @@ public class DataStaxClusterImpl implements DataStaxCluster {
         }
     }
 
+    public Cluster buildCluster(){
+
+        ConsistencyLevel defaultConsistencyLevel;
+        try {
+            defaultConsistencyLevel = ConsistencyLevel.valueOf(cassandraFig.getReadCl());
+        } catch (IllegalArgumentException e){
+
+            logger.error("Unable to parse provided consistency level in property: {}, defaulting
to: {}",
+                CassandraFig.READ_CL,
+                ConsistencyLevel.LOCAL_QUORUM);
+
+            defaultConsistencyLevel = ConsistencyLevel.LOCAL_QUORUM;
+        }
+
+
+        LoadBalancingPolicy loadBalancingPolicy;
+        if( !cassandraFig.getLocalDataCenter().isEmpty() ){
+
+            loadBalancingPolicy = new DCAwareRoundRobinPolicy.Builder()
+                .withLocalDc( cassandraFig.getLocalDataCenter() ).build();
+        }else{
+            loadBalancingPolicy = new DCAwareRoundRobinPolicy.Builder().build();
+        }
+
+        final PoolingOptions poolingOptions = new PoolingOptions()
+            .setCoreConnectionsPerHost(HostDistance.LOCAL, cassandraFig.getConnections()
/ 2)
+            .setMaxConnectionsPerHost(HostDistance.LOCAL, cassandraFig.getConnections())
+            .setIdleTimeoutSeconds(cassandraFig.getTimeout() / 1000)
+            .setPoolTimeoutMillis(cassandraFig.getPoolTimeout());
+
+        final QueryOptions queryOptions = new QueryOptions()
+            .setConsistencyLevel(defaultConsistencyLevel);
+
+        Cluster.Builder datastaxCluster = Cluster.builder()
+            .withClusterName(cassandraFig.getClusterName())
+            .addContactPoints(cassandraFig.getHosts().split(","))
+            .withCompression(ProtocolOptions.Compression.LZ4)
+            .withLoadBalancingPolicy(loadBalancingPolicy)
+            .withPoolingOptions(poolingOptions)
+            .withQueryOptions(queryOptions)
+            .withProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
+
+        // only add auth credentials if they were provided
+        if ( !cassandraFig.getUsername().isEmpty() && !cassandraFig.getPassword().isEmpty()
){
+            datastaxCluster.withCredentials(
+                cassandraFig.getUsername(),
+                cassandraFig.getPassword()
+            );
+        }
+
+
+        return datastaxCluster.build();
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java
index d746482..105f93a 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java
@@ -41,7 +41,7 @@ import com.netflix.astyanax.ddl.KeyspaceDefinition;
 
 
 /**
- * Implementation of the migration manager to set up keyspace
+ * Implementation of the migration manager to set up column families / tables
  *
  * @author tnine
  */
@@ -74,8 +74,6 @@ public class MigrationManagerImpl implements MigrationManager {
 
         try {
 
-            createOrUpdateKeyspace();
-
             for ( Migration migration : migrations ) {
 
                 final Collection<MultiTenantColumnFamilyDefinition> columnFamilies
= migration.getColumnFamilies();
@@ -107,8 +105,6 @@ public class MigrationManagerImpl implements MigrationManager {
                 }
 
 
-
-
             }
         }
         catch ( Throwable t ) {
@@ -136,77 +132,23 @@ public class MigrationManagerImpl implements MigrationManager {
 
         logger.info( "Created column family {}", columnFamily.getColumnFamily().getName()
);
 
-        waitForSchemaAgreement();
+        dataStaxCluster.waitForSchemaAgreement();
     }
 
     private void createTable(TableDefinition tableDefinition ) throws Exception {
 
-        logger.info("Creating, if not exists, table: {}", tableDefinition.getTableName());
         String CQL = CQLUtils.getTableCQL( tableDefinition, CQLUtils.ACTION.CREATE );
-        logger.info( CQL );
         if (logger.isDebugEnabled()){
             logger.debug( CQL );
         }
         dataStaxCluster.getApplicationSession()
             .execute( CQL );
 
-        waitForSchemaAgreement();
-    }
-
-
-    /**
-     * Execute CQL to create the keyspace if it does not already exists.  Always update the
keyspace with the
-     * configured strategy options to allow for real time replication updates.
-     *
-     * @throws Exception
-     */
-    private void createOrUpdateKeyspace() throws Exception {
-
-        Session clusterSession = dataStaxCluster.getClusterSession();
-
-        final String createApplicationKeyspace = String.format(
-            "CREATE KEYSPACE IF NOT EXISTS \"%s\" WITH replication = %s",
-            cassandraFig.getApplicationKeyspace(),
-            CQLUtils.getFormattedReplication( cassandraFig.getStrategy(), cassandraFig.getStrategyOptions()
)
-
-        );
-
-        final String updateApplicationKeyspace = String.format(
-            "ALTER KEYSPACE \"%s\" WITH replication = %s",
-            cassandraFig.getApplicationKeyspace(),
-            CQLUtils.getFormattedReplication( cassandraFig.getStrategy(), cassandraFig.getStrategyOptions()
)
-        );
+        logger.info("Created table: {}", tableDefinition.getTableName());
 
-        logger.info("Creating application keyspace with the following CQL: {}", createApplicationKeyspace);
-        clusterSession.execute(createApplicationKeyspace);
-        logger.info("Updating application keyspace with the following CQL: {}", updateApplicationKeyspace);
-        clusterSession.executeAsync(updateApplicationKeyspace);
-
-        waitForSchemaAgreement();
+        dataStaxCluster.waitForSchemaAgreement();
     }
 
 
-    /**
-     * Wait until all Cassandra nodes agree on the schema.  Sleeps 100ms between checks.
-     *
-     */
-    private void waitForSchemaAgreement() {
-
-        while ( true ) {
-
-            if( dataStaxCluster.getCluster().getMetadata().checkSchemaAgreement() ){
-                return;
-            }
-
-            //sleep and try it again
-            try {
-                Thread.sleep( 100 );
-            }
-            catch ( InterruptedException e ) {
-                //swallow
-            }
-        }
-    }
-
 
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/CQLUtilsTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/CQLUtilsTest.java
b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/CQLUtilsTest.java
index 76fcefe..c47312d 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/CQLUtilsTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/CQLUtilsTest.java
@@ -19,6 +19,7 @@
 package org.apache.usergrid.persistence.core.datastax;
 
 
+import com.datastax.driver.core.DataType;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,10 +39,10 @@ public class CQLUtilsTest {
     public void testTableCQL() throws Exception {
 
 
-        Map<String, String> columns = new HashMap<>();
-        columns.put("key", "blob");
-        columns.put("column1", "text");
-        columns.put("value", "blob");
+        Map<String, DataType.Name> columns = new HashMap<>();
+        columns.put("key", DataType.Name.BLOB);
+        columns.put("column1", DataType.Name.TEXT);
+        columns.put("value", DataType.Name.BLOB);
 
         List<String> partitionKeys = new ArrayList<>();
         partitionKeys.add("key");
@@ -55,7 +56,7 @@ public class CQLUtilsTest {
 
 
         TableDefinition table1 = new TableDefinition(
-            "table1",
+            CQLUtils.quote("table1"),
             partitionKeys,
             columnKeys,
             columns,
@@ -66,10 +67,21 @@ public class CQLUtilsTest {
         String createCQL = CQLUtils.getTableCQL(table1, CQLUtils.ACTION.CREATE);
         String updateCQL = CQLUtils.getTableCQL(table1, CQLUtils.ACTION.UPDATE);
 
-        assertTrue( createCQL.contains( CQLUtils.CREATE_TABLE ) && !createCQL.contains(
CQLUtils.ALTER_TABLE ) );
-        assertTrue( updateCQL.contains( CQLUtils.ALTER_TABLE ) && !updateCQL.contains(
CQLUtils.CREATE_TABLE ) );
-        logger.info("CREATE: {}", createCQL);
-        logger.info("UPDATE: {}", updateCQL);
+        assertTrue(
+            createCQL.contains(CQLUtils.CREATE_TABLE ) &&
+                !createCQL.contains( CQLUtils.ALTER_TABLE )  &&
+                createCQL.contains( DataType.Name.BLOB.toString() ) &&
+                createCQL.contains( DataType.Name.TEXT.toString() )
+
+        );
+        assertTrue(
+            updateCQL.contains( CQLUtils.ALTER_TABLE ) &&
+                !updateCQL.contains( CQLUtils.CREATE_TABLE ) &&
+                !updateCQL.contains( DataType.Name.BLOB.toString() ) &&
+                !updateCQL.contains( DataType.Name.TEXT.toString() )
+        );
+        logger.info(createCQL);
+        logger.info(updateCQL);
 
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/DatastaxClusterTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/DatastaxClusterTest.java
b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/DatastaxClusterTest.java
index 5da23ce..81b7d8f 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/DatastaxClusterTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/DatastaxClusterTest.java
@@ -18,7 +18,68 @@
  */
 package org.apache.usergrid.persistence.core.datastax;
 
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import com.google.inject.Inject;
+import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
+import org.apache.usergrid.persistence.core.guice.TestCommonModule;
+import org.apache.usergrid.persistence.core.test.ITRunner;
+import org.apache.usergrid.persistence.core.test.UseModules;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+@RunWith( ITRunner.class )
+@UseModules( TestCommonModule.class )
 public class DatastaxClusterTest {
 
-    //TODO
+
+    @Inject
+    DataStaxCluster dataStaxCluster;
+
+    @Inject
+    CassandraFig cassandraFig;
+
+
+    @Test
+    public void testConnectCloseCluster() {
+
+        Cluster cluster = dataStaxCluster.getCluster();
+
+        assertTrue(!cluster.isClosed());
+
+        cluster.close();
+        assertTrue(cluster.isClosed());
+
+        // validate getCluster will re-init the cluster
+        cluster = dataStaxCluster.getCluster();
+        assertTrue(!cluster.isClosed());
+
+        
+    }
+
+    @Test
+    public void testGetClusterSession() {
+
+        Session session = dataStaxCluster.getClusterSession();
+        String clusterName = session.getCluster().getClusterName();
+        String keyspaceName = session.getLoggedKeyspace();
+
+        // cluster session is not logged to a keyspace
+        assertNull(keyspaceName);
+        assertNotNull(clusterName);
+    }
+
+    @Test
+    public void testGetApplicationSession() {
+
+        Session session = dataStaxCluster.getApplicationSession();
+        String keyspaceName = session.getLoggedKeyspace();
+
+
+        assertEquals(cassandraFig.getApplicationKeyspace(), keyspaceName);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7ff31ebf/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 958b6f2..e2ea681 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
@@ -49,24 +49,25 @@ public class MapSerializationImpl implements MapSerialization {
     private static final String MAP_ENTRIES_TABLE = CQLUtils.quote("Map_Entries");
     private static final Collection<String> MAP_ENTRIES_PARTITION_KEYS = Collections.singletonList("key");
     private static final Collection<String> MAP_ENTRIES_COLUMN_KEYS = Collections.singletonList("column1");
-    private static final Map<String, String> MAP_ENTRIES_COLUMNS =
-        new HashMap<String, String>() {{
-            put( "key", "blob");
-            put( "column1", "blob");
-            put( "value", "blob"); }};
+    private static final Map<String, DataType.Name> MAP_ENTRIES_COLUMNS =
+        new HashMap<String, DataType.Name>() {{
+            put( "key", DataType.Name.BLOB );
+            put( "column1", DataType.Name.BLOB );
+            put( "value", DataType.Name.BLOB ); }};
     private static final Map<String, String> MAP_ENTRIES_CLUSTERING_ORDER =
-        new HashMap<String, String>(){{ put("column1", "ASC"); }};
+        new HashMap<String, String>(){{ put( "column1", "ASC" ); }};
+
 
     private static final String MAP_KEYS_TABLE = CQLUtils.quote("Map_Keys");
     private static final Collection<String> MAP_KEYS_PARTITION_KEYS = Collections.singletonList("key");
     private static final Collection<String> MAP_KEYS_COLUMN_KEYS = Collections.singletonList("column1");
-    private static final Map<String, String> MAP_KEYS_COLUMNS =
-        new HashMap<String, String>() {{
-            put( "key", "blob");
-            put( "column1", "blob");
-            put( "value", "blob"); }};
+    private static final Map<String, DataType.Name> MAP_KEYS_COLUMNS =
+        new HashMap<String, DataType.Name>() {{
+            put( "key", DataType.Name.BLOB );
+            put( "column1", DataType.Name.BLOB );
+            put( "value", DataType.Name.BLOB ); }};
     private static final Map<String, String> MAP_KEYS_CLUSTERING_ORDER =
-        new HashMap<String, String>(){{ put("column1", "ASC"); }};
+        new HashMap<String, String>(){{ put( "column1", "ASC" ); }};
 
 
 


Mime
View raw message