gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [06/37] gora git commit: Add Simple Test for Native Cassandra Serialization
Date Wed, 23 Aug 2017 20:55:04 GMT
http://git-wip-us.apache.org/repos/asf/gora/blob/2695794a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithNativeSerialization.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithNativeSerialization.java
b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithNativeSerialization.java
index f302cd5..217dea3 100644
--- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithNativeSerialization.java
+++ b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithNativeSerialization.java
@@ -5,6 +5,7 @@ import org.apache.gora.cassandra.test.nativeSerialization.User;
 import org.apache.gora.store.DataStore;
 import org.junit.After;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -14,7 +15,7 @@ import java.util.Properties;
 import java.util.UUID;
 
 /**
- * This class tests Cassandra Store functionality with Cassandra Native Serialization
+ * This class tests Cassandra Store functionality with Cassandra Native Serialization.
  */
 public class TestCassandraStoreWithNativeSerialization {
   private static GoraCassandraTestDriver testDriver = new GoraCassandraTestDriver();
@@ -25,19 +26,20 @@ public class TestCassandraStoreWithNativeSerialization {
   public static void setUpClass() throws Exception {
     setProperties();
     testDriver.setParameters(parameter);
-    testDriver.setUpClass();
+//    testDriver.setUpClass();
     userDataStore = testDriver.createDataStore(UUID.class, User.class);
-
   }
 
   private static void setProperties() {
     parameter = new Properties();
-    parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERVERS,"localhost");
-    parameter.setProperty(CassandraStoreParameters.PORT,"9160");
+    parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERVERS, "localhost");
+    parameter.setProperty(CassandraStoreParameters.PORT, "9042");
     parameter.setProperty(CassandraStoreParameters.USE_CASSANDRA_NATIVE_SERIALIZATION, "true");
+    parameter.setProperty(CassandraStoreParameters.PROTOCOL_VERSION, "3");
+    parameter.setProperty(CassandraStoreParameters.CLUSTER_NAME,"Test Cluster");
+    parameter.setProperty("gora.cassandrastore.mapping.file", "nativeSerialization/gora-cassandra-mapping.xml");
   }
 
-
   @After
   public void tearDown() throws Exception {
     testDriver.tearDown();
@@ -45,13 +47,41 @@ public class TestCassandraStoreWithNativeSerialization {
 
   @AfterClass
   public static void tearDownClass() throws Exception {
-    testDriver.tearDownClass();
+//    testDriver.tearDownClass();
   }
 
+  /**
+   * In this test case, put and get behavior of the data store are testing.
+   */
   @Test
-  public void testCreate() {
+  public void testSimplePutandGet() {
     UUID id = UUID.randomUUID();
     User user1 = new User(id, "madhawa", Date.from(Instant.now()));
+    // storing data;
+    userDataStore.put(id, user1);
+    // get data;
+    User olduser = userDataStore.get(id);
+    Assert.assertEquals(olduser.getName(), user1.getName());
+    Assert.assertEquals(olduser.getDateOfBirth(), user1.getDateOfBirth());
+  }
+
+  /**
+   * In this test case, put and delete behavior of the data store are testing.
+   */
+  @Test
+  public void testSimplePutDeleteandGet() {
+    UUID id = UUID.randomUUID();
+    User user1 = new User(id, "kasun", Date.from(Instant.now()));
+    // storing data;
     userDataStore.put(id, user1);
+    // get data;
+    User olduser =  userDataStore.get(id);
+    Assert.assertEquals(olduser.getName(), user1.getName());
+    Assert.assertEquals(olduser.getDateOfBirth(), user1.getDateOfBirth());
+    // delete data;
+    userDataStore.delete(id);
+    // get data
+    User deletedUser = userDataStore.get(id);
+    Assert.assertNull(deletedUser);
   }
 }

http://git-wip-us.apache.org/repos/asf/gora/blob/2695794a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/DateAsStringCodec.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/DateAsStringCodec.java
b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/DateAsStringCodec.java
new file mode 100644
index 0000000..f6061cf
--- /dev/null
+++ b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/DateAsStringCodec.java
@@ -0,0 +1,33 @@
+package org.apache.gora.cassandra.test.nativeSerialization;
+
+import com.datastax.driver.core.TypeCodec;
+import com.datastax.driver.extras.codecs.MappingCodec;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Sample Class for Custom Codec
+ * {@link com.datastax.driver.extras.codecs.MappingCodec}
+ */
+public class DateAsStringCodec extends MappingCodec<String, Date> {
+  public DateAsStringCodec() {
+    super(TypeCodec.timestamp(), String.class);
+  }
+
+  @Override
+  protected Date serialize(String value) {
+    try {
+      return new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(value);
+    } catch (ParseException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Override
+  protected String deserialize(Date value) {
+    return String.valueOf(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/2695794a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/User.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/User.java
b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/User.java
index 760fa30..0f4c7ee 100644
--- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/User.java
+++ b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/User.java
@@ -3,25 +3,22 @@ package org.apache.gora.cassandra.test.nativeSerialization;
 import com.datastax.driver.mapping.annotations.Column;
 import com.datastax.driver.mapping.annotations.PartitionKey;
 import com.datastax.driver.mapping.annotations.Table;
-import org.apache.avro.Schema;
-import org.apache.gora.persistency.Persistent;
-import org.apache.gora.persistency.Tombstone;
-import org.apache.gora.persistency.impl.PersistentBase;
+import com.datastax.driver.mapping.annotations.Transient;
+import org.apache.gora.cassandra.serializers.CassandraNativePersistent;
 
 import java.util.Date;
-import java.util.List;
 import java.util.UUID;
 
 /**
  * Created by madhawa on 6/23/17.
  */
 
-@Table(keyspace = "ks", name = "users",
+@Table(keyspace = "nativeTestKeySpace", name = "users",
         readConsistency = "QUORUM",
         writeConsistency = "QUORUM",
         caseSensitiveKeyspace = false,
         caseSensitiveTable = false)
-public class User implements Persistent {
+public class User extends CassandraNativePersistent {
   @PartitionKey
   @Column(name = "user_id")
   private UUID userId;
@@ -30,16 +27,19 @@ public class User implements Persistent {
   @Column(name = "dob")
   private Date dateOfBirth;
 
-  public User () {
+  @Transient
+  private boolean dirty;
+
+  public User() {
 
   }
+
   public User(UUID userId, String name, Date dateOfBirth) {
     this.userId = userId;
     this.name = name;
     this.dateOfBirth = dateOfBirth;
   }
 
-
   public void setUserId(UUID userId) {
     this.userId = userId;
   }
@@ -52,71 +52,15 @@ public class User implements Persistent {
     this.dateOfBirth = dateOfBirth;
   }
 
-  @Override
-  public void clear() {
-  }
-
-  @Override
-  public boolean isDirty(int fieldIndex) {
-    return false;
+  public UUID getUserId() {
+    return userId;
   }
 
-  @Override
-  public boolean isDirty(String field) {
-    return false;
-  }
-
-  @Override
-  public void setDirty() {
-
-  }
-
-  @Override
-  public void setDirty(int fieldIndex) {
-
-  }
-
-  @Override
-  public void setDirty(String field) {
-
-  }
-
-  @Override
-  public void clearDirty(int fieldIndex) {
-
+  public String getName() {
+    return name;
   }
 
-  @Override
-  public void clearDirty(String field) {
-
-  }
-
-
-
-
-
-  @Override
-  public Tombstone getTombstone() {
-    return null;
-  }
-
-  @Override
-  public List<Schema.Field> getUnmanagedFields() {
-    return null;
-  }
-
-  @Override
-  public Persistent newInstance() {
-    return new User();
-  }
-
-  @Override
-  public boolean isDirty() {
-    return false;
-  }
-
-  @Override
-  public void clearDirty() {
-
+  public Date getDateOfBirth() {
+    return dateOfBirth;
   }
 }

http://git-wip-us.apache.org/repos/asf/gora/blob/2695794a/gora-tutorial/pom.xml
----------------------------------------------------------------------
diff --git a/gora-tutorial/pom.xml b/gora-tutorial/pom.xml
index 26011a9..aa3a707 100644
--- a/gora-tutorial/pom.xml
+++ b/gora-tutorial/pom.xml
@@ -115,7 +115,7 @@
 
     <dependency>
       <groupId>org.apache.gora</groupId>
-      <artifactId>gora-cassandra</artifactId>
+      <artifactId>gora-cassandra-cql</artifactId>
     </dependency>
 
     <dependency>

http://git-wip-us.apache.org/repos/asf/gora/blob/2695794a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7c66dcf..35f3192 100644
--- a/pom.xml
+++ b/pom.xml
@@ -718,7 +718,7 @@
     <module>gora-compiler-cli</module>
     <module>gora-core</module>
     <module>gora-accumulo</module>
-    <module>gora-cassandra</module>
+    <module>gora-cassandra-cql</module>
     <module>gora-goraci</module>
     <module>gora-hbase</module>
     <module>gora-infinispan</module>
@@ -787,7 +787,7 @@
     <maven-jar-plugin.version>2.3.2</maven-jar-plugin.version>
     <maven-dependency-plugin.version>2.9</maven-dependency-plugin.version>
     <build-helper-maven-plugin.version>1.7</build-helper-maven-plugin.version>
-    <maven-surfire-plugin.version>2.12</maven-surfire-plugin.version>
+    <maven-surfire-plugin.version>2.20</maven-surfire-plugin.version>
     <maven-release-plugin.version>2.5</maven-release-plugin.version>
     <maven-bundle-plugin.version>2.5.3</maven-bundle-plugin.version>
     <maven-source-plugin.version>2.1.2</maven-source-plugin.version>
@@ -852,12 +852,12 @@
 
       <dependency>
         <groupId>org.apache.gora</groupId>
-        <artifactId>gora-cassandra</artifactId>
+        <artifactId>gora-cassandra-cql</artifactId>
         <version>${project.version}</version>
       </dependency>
       <dependency>
         <groupId>org.apache.gora</groupId>
-        <artifactId>gora-cassandra</artifactId>
+        <artifactId>gora-cassandra-cql</artifactId>
         <version>${project.version}</version>
         <type>test-jar</type>
       </dependency>


Mime
View raw message