gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmarroq...@apache.org
Subject svn commit: r1576727 - in /gora/branches/GORA_94: gora-cassandra/src/main/java/org/apache/gora/cassandra/store/ gora-cassandra/src/test/conf/ gora-core/src/test/java/org/apache/gora/store/
Date Wed, 12 Mar 2014 13:13:47 GMT
Author: rmarroquin
Date: Wed Mar 12 13:13:46 2014
New Revision: 1576727

URL: http://svn.apache.org/r1576727
Log:
GORA-245. Fixing failing test and adding GORA-154 to branch GORA_94.

Modified:
    gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
    gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
    gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
    gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/HectorUtils.java
    gora/branches/GORA_94/gora-cassandra/src/test/conf/gora-cassandra-mapping.xml
    gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java

Modified: gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java?rev=1576727&r1=1576726&r2=1576727&view=diff
==============================================================================
--- gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
(original)
+++ gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
Wed Mar 12 13:13:46 2014
@@ -106,7 +106,7 @@ public class CassandraClient<K, T extend
     // "describe keyspace <keyspaceName>;" query
     KeyspaceDefinition keyspaceDefinition = this.cluster.describeKeyspace(this.cassandraMapping.getKeyspaceName());
     if (keyspaceDefinition == null) {
-      List<ColumnFamilyDefinition> columnFamilyDefinitions = this.cassandraMapping.getColumnFamilyDefinitions();
     
+      List<ColumnFamilyDefinition> columnFamilyDefinitions = this.cassandraMapping.getColumnFamilyDefinitions();
 
       // GORA-197
       for (ColumnFamilyDefinition cfDef : columnFamilyDefinitions) {
@@ -155,12 +155,11 @@ public class CassandraClient<K, T extend
       }
     }
   }
-  
+
   /**
    * Drop keyspace.
    */
   public void dropKeyspace() {
-    // "drop keyspace <keyspaceName>;" query
     this.cluster.dropKeyspace(this.cassandraMapping.getKeyspaceName());
   }
 
@@ -178,18 +177,41 @@ public class CassandraClient<K, T extend
     ByteBuffer byteBuffer = toByteBuffer(value);
     String columnFamily = this.cassandraMapping.getFamily(fieldName);
     String columnName = this.cassandraMapping.getColumn(fieldName);
+    String ttlAttr = this.cassandraMapping.getColumnsAttribs().get(fieldName);
+    if (ttlAttr == null)
+      ttlAttr = CassandraMapping.DEFAULT_COLUMNS_TTL;
 
     if (columnName == null) {
       LOG.warn("Column name is null for field=" + fieldName + " with value=" + value.toString());
       return;
     }
-    
     synchronized(mutator) {
-      HectorUtils.insertColumn(mutator, key, columnFamily, columnName, byteBuffer);
+      HectorUtils.insertColumn(mutator, key, columnFamily, columnName, byteBuffer, ttlAttr);
+    }
+  }
+
+  /**
+   * Delete a row within the keyspace.
+   * @param key
+   * @param fieldName
+   * @param columnName
+   */
+  public void deleteColumn(K key, String familyName, ByteBuffer columnName) {
+    synchronized(mutator) {
+      HectorUtils.deleteColumn(mutator, key, familyName, columnName);
     }
   }
 
   /**
+   * Deletes an entry based on its key.
+   * @param key
+   */
+  public void deleteByKey(K key) {
+    Map<String, String> familyMap = this.cassandraMapping.getFamilyMap();
+    deleteColumn(key, familyMap.values().iterator().next().toString(), null);
+  }
+
+  /**
    * Insert a member in a super column. This is used for map and record Avro types.
    * @param key the row key
    * @param fieldName the field name
@@ -205,9 +227,11 @@ public class CassandraClient<K, T extend
     
     String columnFamily = this.cassandraMapping.getFamily(fieldName);
     String superColumnName = this.cassandraMapping.getColumn(fieldName);
-    
+    String ttlAttr = this.cassandraMapping.getColumnsAttribs().get(fieldName);
+    if (ttlAttr == null)
+      ttlAttr = CassandraMapping.DEFAULT_COLUMNS_TTL;
     synchronized(mutator) {
-      HectorUtils.insertSubColumn(mutator, key, columnFamily, superColumnName, columnName,
byteBuffer);
+      HectorUtils.insertSubColumn(mutator, key, columnFamily, superColumnName, columnName,
byteBuffer, ttlAttr);
     }
   }
 
@@ -250,10 +274,28 @@ public class CassandraClient<K, T extend
     }
   }
 
+  /**
+   * Deletes a subColumn 
+   * @param key
+   * @param fieldName
+   * @param columnName
+   */
   public void deleteSubColumn(K key, String fieldName, String columnName) {
     deleteSubColumn(key, fieldName, StringSerializer.get().toByteBuffer(columnName));
   }
 
+  /**
+   * Deletes all subcolumns from a super column.
+   * @param key the row key.
+   * @param fieldName the field name.
+   */
+  public void deleteSubColumn(K key, String fieldName) {
+    String columnFamily = this.cassandraMapping.getFamily(fieldName);
+    String superColumnName = this.cassandraMapping.getColumn(fieldName);
+    synchronized(mutator) {
+      HectorUtils.deleteSubColumn(mutator, key, columnFamily, superColumnName, null);
+    }
+  }
 
   public void addGenericArray(K key, String fieldName, GenericArray<?> array) {
     if (isSuper( cassandraMapping.getFamily(fieldName) )) {
@@ -281,21 +323,25 @@ public class CassandraClient<K, T extend
 
   public void addStatefulHashMap(K key, String fieldName, Map<CharSequence,Object>
map) {
     if (isSuper( cassandraMapping.getFamily(fieldName) )) {
-      for (CharSequence mapKey: map.keySet()) {
-
-        // TODO: hack, do not store empty arrays
-        Object mapValue = map.get(mapKey);
-        if (mapValue instanceof GenericArray<?>) {
-          if (((List<?>)mapValue).size() == 0) {
-            continue;
-          }
-        } else if (mapValue instanceof Map<?,?>) {
-          if (((Map<?, ?>)mapValue).size() == 0) {
-            continue;
+      // as we don't know what has changed inside the map or If it's an empty map, then delete
its content.
+      deleteSubColumn(key, fieldName);
+      // update if there is anything to update.
+      if (!map.isEmpty()) {
+        // If it's not empty, then update its content.
+        for (CharSequence mapKey: map.keySet()) {
+          // TODO: hack, do not store empty arrays
+          Object mapValue = map.get(mapKey);
+          if (mapValue instanceof GenericArray<?>) {
+            if (((List<?>)mapValue).size() == 0) {
+              continue;
+            }
+          } else if (mapValue instanceof Map<?,?>) {
+            if (((Map<?, ?>)mapValue).size() == 0) {
+              continue;
+            }
           }
+          addSubColumn(key, fieldName, mapKey.toString(), mapValue);
         }
-
-        addSubColumn(key, fieldName, mapKey.toString(), mapValue);
       }
     }
     else {
@@ -356,7 +402,6 @@ public class CassandraClient<K, T extend
     QueryResult<OrderedRows<K, ByteBuffer, ByteBuffer>> queryResult = rangeSlicesQuery.execute();
     OrderedRows<K, ByteBuffer, ByteBuffer> orderedRows = queryResult.get();
     
-    
     return orderedRows.getList();
   }
   
@@ -397,11 +442,9 @@ public class CassandraClient<K, T extend
         list = new ArrayList<String>();
         map.put(family, list);
       }
-      
       if (column != null) {
         list.add(column);
       }
-      
     }
     
     return map;
@@ -434,7 +477,12 @@ public class CassandraClient<K, T extend
     
     return map;
   }
-  
+
+  /**
+   * Determines if a column is a superColumn or not.
+   * @param family
+   * @return boolean
+   */
   public boolean isSuper(String family) {
     return this.cassandraMapping.isSuper(family);
   }

Modified: gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java?rev=1576727&r1=1576726&r2=1576727&view=diff
==============================================================================
--- gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
(original)
+++ gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
Wed Mar 12 13:13:46 2014
@@ -44,6 +44,10 @@ public class CassandraMapping {
   private static final String CLUSTER_ATTRIBUTE = "cluster";
   private static final String HOST_ATTRIBUTE = "host";
 
+  private static final String GCGRACE_SECONDS_ATTRIBUTE = "gc_grace_seconds";
+  private static final String COLUMNS_TTL_ATTRIBUTE = "ttl";
+  public static final String DEFAULT_COLUMNS_TTL = "60";
+  public static final int DEFAULT_GCGRACE_SECONDS = 30;
 
   private String hostName;
   private String clusterName;
@@ -66,6 +70,11 @@ public class CassandraMapping {
   private Map<String, String> columnMap = new HashMap<String, String>();
 
   /**
+   * Helps storing attributes defined for each field.
+   */
+  private Map<String, String> columnAttrMap = new HashMap<String, String>();
+  
+  /**
    * Look up the column family from its name.
    */
   private Map<String, BasicColumnFamilyDefinition> columnFamilyDefinitions = 
@@ -117,7 +126,7 @@ public class CassandraMapping {
     }
     this.keyspaceName = keyspace.getAttributeValue(NAME_ATTRIBUTE);
     if (this.keyspaceName == null) {
-    	LOG.error("Error locating Cassandra Keyspace name attribute!");
+      LOG.error("Error locating Cassandra Keyspace name attribute!");
     } else {
       if (LOG.isDebugEnabled()) {
         LOG.debug("Located Cassandra Keyspace name: '" + keyspaceName + "'");
@@ -154,6 +163,16 @@ public class CassandraMapping {
           LOG.debug("Located column family: '" + familyName + "'" );
         }
       }
+      String gcgrace_scs = element.getAttributeValue(GCGRACE_SECONDS_ATTRIBUTE);
+      if (gcgrace_scs == null) {
+        LOG.warn("Error locating gc_grace_seconds attribute for '" + familyName + "' column
family");
+        LOG.warn("Using default set to: " + DEFAULT_GCGRACE_SECONDS);
+      } else {
+        if (LOG.isDebugEnabled()) {
+        LOG.debug("Located gc_grace_seconds: '" + gcgrace_scs + "'" );
+        }
+      }
+
       String superAttribute = element.getAttributeValue(SUPER_ATTRIBUTE);
       if (superAttribute != null) {
         if (LOG.isDebugEnabled()) {
@@ -166,12 +185,13 @@ public class CassandraMapping {
         cfDef.setColumnType(ColumnType.SUPER);
         cfDef.setSubComparatorType(ComparatorType.BYTESTYPE);
       }
-      
+
       cfDef.setKeyspaceName(this.keyspaceName);
       cfDef.setName(familyName);
       cfDef.setComparatorType(ComparatorType.BYTESTYPE);
       cfDef.setDefaultValidationClass(ComparatorType.BYTESTYPE.getClassName());
-      
+
+      cfDef.setGcGraceSeconds(gcgrace_scs!=null?Integer.parseInt(gcgrace_scs):DEFAULT_GCGRACE_SECONDS);
       this.columnFamilyDefinitions.put(familyName, cfDef);
 
     }
@@ -182,6 +202,7 @@ public class CassandraMapping {
       String fieldName = element.getAttributeValue(NAME_ATTRIBUTE);
       String familyName = element.getAttributeValue(FAMILY_ATTRIBUTE);
       String columnName = element.getAttributeValue(COLUMN_ATTRIBUTE);
+      String ttlValue = element.getAttributeValue(COLUMNS_TTL_ATTRIBUTE);
       if (fieldName == null) {
        LOG.error("Field name is not declared.");
         continue;
@@ -194,16 +215,20 @@ public class CassandraMapping {
         LOG.warn("Column name (qualifier) is not declared for \"" + fieldName + "\" field.");
         columnName = fieldName;
       }
+      if (ttlValue == null) {
+        LOG.warn("TTL value is not defined for \"" + fieldName + "\" field. \n Using default
value: " + DEFAULT_COLUMNS_TTL);
+      }
 
       BasicColumnFamilyDefinition columnFamilyDefinition = this.columnFamilyDefinitions.get(familyName);
       if (columnFamilyDefinition == null) {
         LOG.warn("Family " + familyName + " was not declared in the keyspace.");
       }
-      
+
       this.familyMap.put(fieldName, familyName);
       this.columnMap.put(fieldName, columnName);
-      
-    }    
+      // TODO we should find a way of storing more values into this map
+      this.columnAttrMap.put(columnName, ttlValue!=null?ttlValue:DEFAULT_COLUMNS_TTL);
+    }
   }
 
   /**
@@ -225,6 +250,14 @@ public class CassandraMapping {
     return this.columnMap.get(name);
   }
 
+  public Map<String,String> getFamilyMap(){
+    return this.familyMap;
+  }
+
+  public Map<String, String> getColumnsAttribs(){
+    return this.columnAttrMap;
+  }
+
   /**
    * Read family super attribute.
    * @param family the family name

Modified: gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java?rev=1576727&r1=1576726&r2=1576727&view=diff
==============================================================================
--- gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
(original)
+++ gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
Wed Mar 12 13:13:46 2014
@@ -148,8 +148,8 @@ public class CassandraStore<K, T extends
 
   @Override
   public boolean delete(K key) {
-    LOG.debug("delete " + key);
-    return false;
+    this.cassandraClient.deleteByKey(key);
+    return true;
   }
 
   @Override
@@ -580,7 +580,8 @@ public class CassandraStore<K, T extends
           addOrUpdateField(key, field, unionSchema, value);
           //this.cassandraClient.addColumn(key, field.name(), value);
         } else {
-          LOG.warn("Union with 'null' value not supported for field: " + field.name());
+          LOG.warn("Setting content of: " + field.name() + " to null.");
+          delete(key);
         }
         break;
       default:

Modified: gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/HectorUtils.java
URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/HectorUtils.java?rev=1576727&r1=1576726&r2=1576727&view=diff
==============================================================================
--- gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/HectorUtils.java
(original)
+++ gora/branches/GORA_94/gora-cassandra/src/main/java/org/apache/gora/cassandra/store/HectorUtils.java
Wed Mar 12 13:13:46 2014
@@ -38,38 +38,38 @@ import org.apache.gora.persistency.Persi
  */
 public class HectorUtils<K,T extends Persistent> {
 
-  public static<K> void insertColumn(Mutator<K> mutator, K key, String columnFamily,
ByteBuffer columnName, ByteBuffer columnValue) {
-    mutator.insert(key, columnFamily, createColumn(columnName, columnValue));
+  public static<K> void insertColumn(Mutator<K> mutator, K key, String columnFamily,
ByteBuffer columnName, ByteBuffer columnValue, String ttlAttr) {
+    mutator.insert(key, columnFamily, createColumn(columnName, columnValue, ttlAttr));
   }
 
-  public static<K> void insertColumn(Mutator<K> mutator, K key, String columnFamily,
String columnName, ByteBuffer columnValue) {
-    mutator.insert(key, columnFamily, createColumn(columnName, columnValue));
+  public static<K> void insertColumn(Mutator<K> mutator, K key, String columnFamily,
String columnName, ByteBuffer columnValue, String ttlAttr) {
+    mutator.insert(key, columnFamily, createColumn(columnName, columnValue, ttlAttr));
   }
 
 
-  public static<K> HColumn<ByteBuffer,ByteBuffer> createColumn(ByteBuffer name,
ByteBuffer value) {
-    return HFactory.createColumn(name, value, ByteBufferSerializer.get(), ByteBufferSerializer.get());
+  public static<K> HColumn<ByteBuffer,ByteBuffer> createColumn(ByteBuffer name,
ByteBuffer value, String ttlAttr) {
+    return HFactory.createColumn(name, value, ByteBufferSerializer.get(), ByteBufferSerializer.get()).setTtl(Integer.parseInt(ttlAttr));
   }
 
-  public static<K> HColumn<String,ByteBuffer> createColumn(String name, ByteBuffer
value) {
-    return HFactory.createColumn(name, value, StringSerializer.get(), ByteBufferSerializer.get());
+  public static<K> HColumn<String,ByteBuffer> createColumn(String name, ByteBuffer
value, String ttlAttr) {
+    return HFactory.createColumn(name, value, StringSerializer.get(), ByteBufferSerializer.get()).setTtl(Integer.parseInt(ttlAttr));
   }
 
-  public static<K> HColumn<Integer,ByteBuffer> createColumn(Integer name, ByteBuffer
value) {
-    return HFactory.createColumn(name, value, IntegerSerializer.get(), ByteBufferSerializer.get());
+  public static<K> HColumn<Integer,ByteBuffer> createColumn(Integer name, ByteBuffer
value, String ttlAttr) {
+    return HFactory.createColumn(name, value, IntegerSerializer.get(), ByteBufferSerializer.get()).setTtl(Integer.parseInt(ttlAttr));
   }
 
 
-  public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily,
String superColumnName, ByteBuffer columnName, ByteBuffer columnValue) {
-    mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue));
+  public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily,
String superColumnName, ByteBuffer columnName, ByteBuffer columnValue, String ttlAttr) {
+    mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue,
ttlAttr));
   }
 
-  public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily,
String superColumnName, String columnName, ByteBuffer columnValue) {
-    mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue));
+  public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily,
String superColumnName, String columnName, ByteBuffer columnValue, String ttlAttr) {
+    mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue,
ttlAttr));
   }
 
-  public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily,
String superColumnName, Integer columnName, ByteBuffer columnValue) {
-    mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue));
+  public static<K> void insertSubColumn(Mutator<K> mutator, K key, String columnFamily,
String superColumnName, Integer columnName, ByteBuffer columnValue, String ttlAttr) {
+    mutator.insert(key, columnFamily, createSuperColumn(superColumnName, columnName, columnValue,
ttlAttr));
   }
 
 
@@ -77,20 +77,20 @@ public class HectorUtils<K,T extends Per
     mutator.subDelete(key, columnFamily, superColumnName, columnName, StringSerializer.get(),
ByteBufferSerializer.get());
   }
 
+  public static<K> void deleteColumn(Mutator<K> mutator, K key, String columnFamily,
ByteBuffer columnName){
+    mutator.delete(key, columnFamily, columnName, ByteBufferSerializer.get());
+  }
 
-  @SuppressWarnings("unchecked")
-  public static<K> HSuperColumn<String,ByteBuffer,ByteBuffer> createSuperColumn(String
superColumnName, ByteBuffer columnName, ByteBuffer columnValue) {
-    return HFactory.createSuperColumn(superColumnName, Arrays.asList(createColumn(columnName,
columnValue)), StringSerializer.get(), ByteBufferSerializer.get(), ByteBufferSerializer.get());
+  public static<K> HSuperColumn<String,ByteBuffer,ByteBuffer> createSuperColumn(String
superColumnName, ByteBuffer columnName, ByteBuffer columnValue, String ttlAttr) {
+    return HFactory.createSuperColumn(superColumnName, Arrays.asList(createColumn(columnName,
columnValue, ttlAttr)), StringSerializer.get(), ByteBufferSerializer.get(), ByteBufferSerializer.get());
   }
 
-  @SuppressWarnings("unchecked")
-  public static<K> HSuperColumn<String,String,ByteBuffer> createSuperColumn(String
superColumnName, String columnName, ByteBuffer columnValue) {
-    return HFactory.createSuperColumn(superColumnName, Arrays.asList(createColumn(columnName,
columnValue)), StringSerializer.get(), StringSerializer.get(), ByteBufferSerializer.get());
+  public static<K> HSuperColumn<String,String,ByteBuffer> createSuperColumn(String
superColumnName, String columnName, ByteBuffer columnValue, String ttlAttr) {
+    return HFactory.createSuperColumn(superColumnName, Arrays.asList(createColumn(columnName,
columnValue, ttlAttr)), StringSerializer.get(), StringSerializer.get(), ByteBufferSerializer.get());
   }
 
-  @SuppressWarnings("unchecked")
-  public static<K> HSuperColumn<String,Integer,ByteBuffer> createSuperColumn(String
superColumnName, Integer columnName, ByteBuffer columnValue) {
-    return HFactory.createSuperColumn(superColumnName, Arrays.asList(createColumn(columnName,
columnValue)), StringSerializer.get(), IntegerSerializer.get(), ByteBufferSerializer.get());
+  public static<K> HSuperColumn<String,Integer,ByteBuffer> createSuperColumn(String
superColumnName, Integer columnName, ByteBuffer columnValue, String ttlAttr) {
+    return HFactory.createSuperColumn(superColumnName, Arrays.asList(createColumn(columnName,
columnValue, ttlAttr)), StringSerializer.get(), IntegerSerializer.get(), ByteBufferSerializer.get());
   }
 
 }

Modified: gora/branches/GORA_94/gora-cassandra/src/test/conf/gora-cassandra-mapping.xml
URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-cassandra/src/test/conf/gora-cassandra-mapping.xml?rev=1576727&r1=1576726&r2=1576727&view=diff
==============================================================================
--- gora/branches/GORA_94/gora-cassandra/src/test/conf/gora-cassandra-mapping.xml (original)
+++ gora/branches/GORA_94/gora-cassandra/src/test/conf/gora-cassandra-mapping.xml Wed Mar
12 13:13:46 2014
@@ -19,40 +19,40 @@
 
 <gora-orm>
   <keyspace name="Employee" host="localhost" cluster="Gora Cassandra Test Cluster">
-    <family name="p"/>
+    <family name="p" gc_grace_seconds="5"/>
      <family name="sc" type="super" />
   </keyspace>
 
   <keyspace name="WebPage" host="localhost" cluster="Gora Cassandra Test Cluster">
-    <family name="p"/>
+    <family name="p" gc_grace_seconds="5"/>
     <family name="sc" type="super"/>
   </keyspace>
 
   <keyspace name="TokenDatum" host="localhost" cluster="Gora Cassandra Test Cluster">
-    <family name="p"/>
+    <family name="p" gc_grace_seconds="5"/>
     <family name="sc" type="super"/>
   </keyspace>
 
   <class name="org.apache.gora.examples.generated.Employee" keyClass="java.lang.String"
keyspace="Employee">
-    <field name="name"  family="p" qualifier="info:nm"/>
-    <field name="dateOfBirth"  family="p" qualifier="info:db"/>
-    <field name="ssn"  family="p" qualifier="info:sn"/>
-    <field name="salary"  family="p" qualifier="info:sl"/>
-    <field name="boss" family="p" qualifier="info:bs"/>
-    <field name="webpage" family="p" qualifier="info:wp"/>
+    <field name="name"  family="p" qualifier="info:nm" ttl="10"/>
+    <field name="dateOfBirth"  family="p" qualifier="info:db" ttl="10"/>
+    <field name="ssn"  family="p" qualifier="info:sn" ttl="10"/>
+    <field name="salary"  family="p" qualifier="info:sl" ttl="10"/>
+    <field name="boss" family="p" qualifier="info:bs" ttl="10"/>
+    <field name="webpage" family="p" qualifier="info:wp" ttl="10"/>
   </class>
 
   <class name="org.apache.gora.examples.generated.WebPage" keyClass="java.lang.String"
keyspace="WebPage">
-    <field name="url" family="p" qualifier="c:u"/>
-    <field name="content" family="p" qualifier="p:cnt:c"/>
-    <field name="parsedContent" family="sc" qualifier="p:parsedContent"/>
-    <field name="outlinks" family="sc" qualifier="p:outlinks"/>
-    <field name="headers" family="sc" qualifier="p:headers"/>
-    <field name="metadata" family="p" qualifier="c:mt"/>
+    <field name="url" family="p" qualifier="c:u" ttl="10"/>
+    <field name="content" family="p" qualifier="p:cnt:c" ttl="10"/>
+    <field name="parsedContent" family="sc" qualifier="p:parsedContent" ttl="10"/>
+    <field name="outlinks" family="sc" qualifier="p:outlinks" ttl="10"/>
+    <field name="headers" family="sc" qualifier="p:headers" ttl="10"/>
+    <field name="metadata" family="p" qualifier="c:mt" ttl="10"/>
   </class>
 
   <class name="org.apache.gora.examples.generated.TokenDatum" keyClass="java.lang.String"
keyspace="TokenDatum">
-    <field name="count"  family="p" qualifier="common:count"/>
+    <field name="count"  family="p" qualifier="common:count" ttl="10"/>
   </class>
 
 </gora-orm>

Modified: gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java
URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java?rev=1576727&r1=1576726&r2=1576727&view=diff
==============================================================================
--- gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java
(original)
+++ gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java
Wed Mar 12 13:13:46 2014
@@ -57,6 +57,8 @@ import org.apache.gora.util.AvroUtils;
 import org.apache.gora.util.ByteUtils;
 import org.apache.gora.util.StringUtils;
 
+import com.sun.istack.logging.Logger;
+
 /**
  * Test utilities for DataStores. This utility class provides everything
  * necessary for convenience tests in {@link DataStoreTestBase} to execute cleanly.
@@ -542,7 +544,6 @@ public class DataStoreTestUtil {
       }
       dataStore.put(webPage.getUrl().toString(), webPage);
     }
-
     dataStore.flush();
 
     for (int i = 0; i < urls.length; i++) {
@@ -557,14 +558,12 @@ public class DataStoreTestUtil {
       }
       dataStore.put(webPage.getUrl().toString(), webPage);
     }
-
     dataStore.flush();
 
     for (int i = 0; i < urls.length; i++) {
       WebPage webPage = dataStore.get(urls[i]);
-      int j = 0;
       int count = 0;
-      for (j = 0; j < urls.length; j++) {  //TODO j++ or j+=2 ?
+      for (int j = 1; j < urls.length; j += 2) {
         CharSequence link = webPage.getOutlinks().get(new Utf8(anchor + j));
         assertNotNull(link);
         assertEquals(urls[j], link.toString());
@@ -613,7 +612,7 @@ public class DataStoreTestUtil {
       WebPage webPage = dataStore.get(urls[i]);
       int j = 0;
       int count = 0;
-      for (j = 0; j < headers.length; j++) {  //TODO j++ or j+=2 ?
+      for (j = 0; j < headers.length; j+=2) {  //TODO j++ or j+=2 ?
         CharSequence headerSample = webPage.getHeaders().get(new Utf8(header + j));
         assertNotNull(headerSample);
         assertEquals(headers[j], headerSample.toString());
@@ -645,8 +644,10 @@ public class DataStoreTestUtil {
     // map entry removal test
     for (int i = 0; i < urls.length; i++) {
       WebPage webPage = dataStore.get(urls[i]);
+      webPage.getOutlinks().clear();
+      //webPage.setOutlinks(new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)new
HashMap<CharSequence, CharSequence>()));
       for (int j = 1; j < urls.length; j += 2) {
-        webPage.getOutlinks().put(new Utf8(anchor + j), null);
+        webPage.getOutlinks().put(new Utf8(anchor + j), new Utf8(urls[j]));
       }
       dataStore.put(webPage.getUrl().toString(), webPage);
     }
@@ -658,10 +659,11 @@ public class DataStoreTestUtil {
       WebPage webPage = dataStore.get(urls[i]);
       for (int j = 1; j < urls.length; j += 2) {
         CharSequence link = webPage.getOutlinks().get(new Utf8(anchor + j));
-        assertNull(link);
+        assertNotNull(link);
+        assertEquals(urls[j], link.toString());
         count++;
       }
-      assertEquals(urls.length - count, webPage.getOutlinks().size());
+      assertEquals(count, webPage.getOutlinks().size());
     }
   }
 



Mime
View raw message