Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 96B9B200CFC for ; Thu, 24 Aug 2017 00:16:38 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9539C169D76; Wed, 23 Aug 2017 22:16:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F125D169D70 for ; Thu, 24 Aug 2017 00:16:35 +0200 (CEST) Received: (qmail 74489 invoked by uid 500); 23 Aug 2017 22:16:35 -0000 Mailing-List: contact commits-help@gora.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@gora.apache.org Delivered-To: mailing list commits@gora.apache.org Received: (qmail 74289 invoked by uid 99); 23 Aug 2017 22:16:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Aug 2017 22:16:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3A9EEF5F05; Wed, 23 Aug 2017 22:16:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lewismc@apache.org To: commits@gora.apache.org Date: Wed, 23 Aug 2017 22:16:38 -0000 Message-Id: In-Reply-To: <86b5a12473e346e8806952898733a3d7@git.apache.org> References: <86b5a12473e346e8806952898733a3d7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/13] gora git commit: Rename gora-cassandra-cql module into gora-cassandra module archived-at: Wed, 23 Aug 2017 22:16:38 -0000 http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java ---------------------------------------------------------------------- diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java deleted file mode 100644 index ce9e2df..0000000 --- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * 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.gora.cassandra.store; - -import org.apache.gora.cassandra.GoraCassandraTestDriver; -import org.apache.gora.examples.WebPageDataCreator; -import org.apache.gora.examples.generated.WebPage; -import org.apache.gora.query.Query; -import org.apache.gora.store.DataStore; -import org.apache.gora.store.DataStoreTestBase; -import org.apache.gora.store.DataStoreTestUtil; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Properties; - -import static org.apache.gora.examples.WebPageDataCreator.SORTED_URLS; -import static org.apache.gora.examples.WebPageDataCreator.URLS; -import static org.apache.gora.store.DataStoreTestUtil.assertEmptyResults; -import static org.apache.gora.store.DataStoreTestUtil.assertNumResults; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -/** - * - * Testing class for all standard gora-cassandra functionality. - * We extend DataStoreTestBase enabling us to run the entire base test - * suite for Gora. - * - * Test Avro Serialization for CassandraStore. - */ -public class TestCassandraStore extends DataStoreTestBase { - private static final Logger LOG = LoggerFactory.getLogger(TestCassandraStore.class); - private static Properties properties; - - static { - GoraCassandraTestDriver testDriver = new GoraCassandraTestDriver(); - setProperties(); - testDriver.setParameters(properties); - setTestDriver(testDriver); - } - - private static void setProperties() { - properties = new Properties(); - properties.setProperty(CassandraStoreParameters.CASSANDRA_SERVERS, "localhost"); - properties.setProperty(CassandraStoreParameters.PORT, "9042"); - properties.setProperty(CassandraStoreParameters.CASSANDRA_SERIALIZATION_TYPE, "avro"); - properties.setProperty(CassandraStoreParameters.PROTOCOL_VERSION, "3"); - properties.setProperty(CassandraStoreParameters.CLUSTER_NAME, "Test Cluster"); - properties.setProperty(CassandraStoreParameters.READ_CONSISTENCY_LEVEL,"ONE"); - properties.setProperty(CassandraStoreParameters.WRITE_CONSISTENCY_LEVEL,"ONE"); - properties.setProperty("gora.cassandrastore.mapping.file", "avro/gora-cassandra-mapping.xml"); - } - - @Before - public void setUp() throws Exception { - super.setUp(); - } - - @Ignore() - @Override - public void testGetPartitions() throws IOException { - } - - private void preConfiguration() { - if (webPageStore.schemaExists()) { - webPageStore.truncateSchema(); - } else { - webPageStore.createSchema(); - } - } - - @Test - public void testQuery() throws Exception { - preConfiguration(); - log.info("test method: testQuery"); - DataStoreTestUtil.testQueryWebPages(webPageStore); - } - - @Test - public void testQueryStartKey() throws Exception { - preConfiguration(); - log.info("test method: testQueryStartKey"); - DataStoreTestUtil.testQueryWebPageStartKey(webPageStore); - } - - @Test - public void testQueryEndKey() throws Exception { - preConfiguration(); - log.info("test method: testQueryEndKey"); - DataStoreTestUtil.testQueryWebPageEndKey(webPageStore); - } - - @Test - public void testQueryKeyRange() throws Exception { - preConfiguration(); - log.info("test method: testQueryKetRange"); - DataStoreTestUtil.testQueryWebPageKeyRange(webPageStore); - } - - @Test - public void testDelete() throws Exception { - preConfiguration(); - log.info("test method: testDelete"); - DataStoreTestUtil.testDelete(webPageStore); - } - - @Test - public void testDeleteByQuery() throws Exception { - preConfiguration(); - log.info("test method: testDeleteByQuery"); - DataStore store = webPageStore; - Query query; - //test 1 - delete all - WebPageDataCreator.createWebPageData(store); - - query = store.newQuery(); - - assertNumResults(store.newQuery(), URLS.length); - store.deleteByQuery(query); - store.flush(); - assertEmptyResults(store.newQuery()); - store.truncateSchema(); - } - - @Test - public void testDeleteByQueryFields() throws Exception { - preConfiguration(); - log.info("test method: testQueryByQueryFields"); - //test 5 - delete all with some fields - WebPageDataCreator.createWebPageData(webPageStore); - Query query = webPageStore.newQuery(); - query.setFields("outlinks", "parsedContent", "content"); - - for (String SORTED_URL : SORTED_URLS) { - query.setKey(SORTED_URL); - webPageStore.deleteByQuery(query); - WebPage page = webPageStore.get(SORTED_URL); - assertNotNull(page); - assertNotNull(page.getUrl()); - assertEquals(page.getUrl().toString(), SORTED_URL); - assertEquals("Map of Outlinks should have a size of '0' as the deleteByQuery " - + "not only removes the data but also the data structure.", 0, page.getOutlinks().size()); - assertEquals(0, page.getParsedContent().size()); - if (page.getContent() != null) { - LOG.info("url:" + page.getUrl().toString()); - LOG.info("limit:" + page.getContent().limit()); - } else { - assertNull(page.getContent()); - } - } - } - - @Ignore("Type 3 Union is not supported for Cassandra") - public void testGet3UnionField() { - } -} http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithCassandraKey.java ---------------------------------------------------------------------- diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithCassandraKey.java b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithCassandraKey.java deleted file mode 100644 index 3ae3152..0000000 --- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithCassandraKey.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * 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.gora.cassandra.store; - -import org.apache.avro.util.Utf8; -import org.apache.gora.cassandra.GoraCassandraTestDriver; -import org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey; -import org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraRecord; -import org.apache.gora.cassandra.query.CassandraQuery; -import org.apache.gora.query.Query; -import org.apache.gora.query.Result; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * This class tests Cassandra Store functionality with CassandraKey. - */ -public class TestCassandraStoreWithCassandraKey { - private static GoraCassandraTestDriver testDriver = new GoraCassandraTestDriver(); - private static CassandraStore cassandraRecordDataStore; - private static Properties parameter; - - @BeforeClass - public static void setUpClass() throws Exception { - setProperties(); - testDriver.setParameters(parameter); - testDriver.setUpClass(); - cassandraRecordDataStore = (CassandraStore) testDriver.createDataStore(CassandraKey.class, CassandraRecord.class); - } - - private static void setProperties() { - parameter = new Properties(); - parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERVERS, "localhost"); - parameter.setProperty(CassandraStoreParameters.PORT, "9042"); - parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERIALIZATION_TYPE, "avro"); - parameter.setProperty(CassandraStoreParameters.PROTOCOL_VERSION, "3"); - parameter.setProperty(CassandraStoreParameters.CLUSTER_NAME, "Test Cluster"); - parameter.setProperty("gora.cassandrastore.mapping.file", "compositeKey/gora-cassandra-mapping.xml"); - } - - @AfterClass - public static void tearDownClass() throws Exception { - testDriver.tearDownClass(); - } - - @After - public void tearDown() throws Exception { - testDriver.tearDown(); - } - - /** - * In this test case, schema exists method behavior of the data store is testing. - */ - @Test - public void testSchemaRelatedBehaviour() { - cassandraRecordDataStore.createSchema(); - Assert.assertTrue(cassandraRecordDataStore.schemaExists()); - cassandraRecordDataStore.deleteSchema(); - Assert.assertFalse(cassandraRecordDataStore.schemaExists()); - cassandraRecordDataStore.createSchema(); - Assert.assertTrue(cassandraRecordDataStore.schemaExists()); - } - - /** - * In this test case, get, put and delete methods behaviour of the data store is testing. - */ - @Test - public void testSimplePutGet() { - cassandraRecordDataStore.createSchema(); - CassandraRecord record = new CassandraRecord(); - record.setDataLong(719411002L); - record.setDataString(new Utf8("M.K.H. Gunasekara")); - record.setDataInt(144); - record.setDataBytes(ByteBuffer.wrap("No 144, Gunasekara Mawatha, Mattumgala, Ragama".getBytes(Charset.defaultCharset()))); - record.setDataDouble(3.14159d); - CassandraKey key = new CassandraKey(); - key.setTimestamp(2027L); - key.setUrl("www.apache.org"); - cassandraRecordDataStore.put(key, record); - CassandraRecord retrievedRecord = cassandraRecordDataStore.get(key); - Assert.assertEquals(record.getDataInt(), retrievedRecord.getDataInt()); - Assert.assertEquals(record.getDataString(), retrievedRecord.getDataString()); - Assert.assertEquals(record.getDataLong(), retrievedRecord.getDataLong()); - Assert.assertEquals(record.getDataBytes(), retrievedRecord.getDataBytes()); - Assert.assertEquals(record.getDataDouble(), retrievedRecord.getDataDouble()); - cassandraRecordDataStore.delete(key); - Assert.assertNull(cassandraRecordDataStore.get(key)); - } - - /** - * In this test case, execute and deleteByQuery methods behaviour of the data store is testing. - * - * @throws Exception - */ - @Test - public void testExecuteQuery() throws Exception { - Query query = cassandraRecordDataStore.newQuery(); - cassandraRecordDataStore.truncateSchema(); - CassandraKey key = new CassandraKey(); - key.setTimestamp(2027L); - key.setUrl("www.apache.org"); - query.setKey(key); - Result result = query.execute(); - Assert.assertFalse(result.next()); - CassandraRecord record = new CassandraRecord(); - record.setDataLong(719411002L); - record.setDataString(new Utf8("M.K.H. Gunasekara")); - record.setDataInt(144); - record.setDataBytes(ByteBuffer.wrap("No 144, Gunasekara Mawatha, Mattumgala, Ragama".getBytes(Charset.defaultCharset()))); - record.setDataDouble(3.14159d); - // test simple put and query with setKey - cassandraRecordDataStore.put(key, record); - CassandraRecord retrievedRecord = cassandraRecordDataStore.get(key); - Assert.assertEquals(record.getDataInt(), retrievedRecord.getDataInt()); - Assert.assertEquals(record.getDataString(), retrievedRecord.getDataString()); - Assert.assertEquals(record.getDataLong(), retrievedRecord.getDataLong()); - Assert.assertEquals(record.getDataBytes(), retrievedRecord.getDataBytes()); - Assert.assertEquals(record.getDataDouble(), retrievedRecord.getDataDouble()); - result = query.execute(); - Assert.assertTrue(result.next()); - // verify data - retrievedRecord = result.get(); - Assert.assertEquals(record.getDataInt(), retrievedRecord.getDataInt()); - Assert.assertEquals(record.getDataString(), retrievedRecord.getDataString()); - Assert.assertEquals(record.getDataLong(), retrievedRecord.getDataLong()); - Assert.assertEquals(record.getDataBytes(), retrievedRecord.getDataBytes()); - Assert.assertEquals(record.getDataDouble(), retrievedRecord.getDataDouble()); - // test delete by query - cassandraRecordDataStore.deleteByQuery(query); - result = query.execute(); - Assert.assertFalse(result.next()); - // test empty query - Query emptyQuery = cassandraRecordDataStore.newQuery(); - result = emptyQuery.execute(); - Assert.assertFalse(result.next()); - cassandraRecordDataStore.put(key, record); - result = query.execute(); - Assert.assertTrue(result.next()); - } - - @Test - public void testExecuteQueryWithRange() throws Exception { - // test Range with Query - cassandraRecordDataStore.truncateSchema(); - //insert data - CassandraRecord record1 = new CassandraRecord(); - CassandraRecord record2 = new CassandraRecord(); - CassandraRecord record3 = new CassandraRecord(); - CassandraRecord record4 = new CassandraRecord(); - record1.setDataLong(719411002L); - record1.setDataString(new Utf8("Madawa")); - record1.setDataInt(100); - record2.setDataLong(712778588L); - record2.setDataString(new Utf8("Kasun")); - record2.setDataInt(101); - record3.setDataLong(716069539L); - record3.setDataString(new Utf8("Charith")); - record3.setDataInt(102); - record4.setDataLong(112956051L); - record4.setDataString(new Utf8("Bhanuka")); - record4.setDataInt(103); - CassandraKey key1 = new CassandraKey(); - key1.setTimestamp(200L); - key1.setUrl("www.apache.org"); - CassandraKey key2 = new CassandraKey(); - key2.setTimestamp(205L); - key2.setUrl("www.apache.org"); - CassandraKey key3 = new CassandraKey(); - key3.setTimestamp(210L); - key3.setUrl("www.apache.org"); - CassandraKey key4 = new CassandraKey(); - key4.setTimestamp(215L); - key4.setUrl("www.apache.org"); - cassandraRecordDataStore.put(key1, record1); - cassandraRecordDataStore.put(key2, record2); - cassandraRecordDataStore.put(key3, record3); - cassandraRecordDataStore.put(key4, record4); - Query rangeQuery = cassandraRecordDataStore.newQuery(); - rangeQuery.setStartKey(key2); - rangeQuery.setEndKey(key2); - Result result = rangeQuery.execute(); - int i = 0; - while (result.next()) { - i++; - } - Assert.assertEquals(1, i); - - rangeQuery.setStartKey(key2); - rangeQuery.setEndKey(key3); - result = rangeQuery.execute(); - i = 0; - while (result.next()) { - i++; - } - Assert.assertEquals(2, i); - } - - @Test - public void testUpdateByQuery() { - cassandraRecordDataStore.truncateSchema(); - //insert data - CassandraRecord record1 = new CassandraRecord(); - CassandraRecord record2 = new CassandraRecord(); - CassandraRecord record3 = new CassandraRecord(); - CassandraRecord record4 = new CassandraRecord(); - record1.setDataLong(719411002L); - record1.setDataString(new Utf8("Madawa")); - record1.setDataInt(100); - record2.setDataLong(712778588L); - record2.setDataString(new Utf8("Kasun")); - record2.setDataInt(101); - record3.setDataLong(716069539L); - record3.setDataString(new Utf8("Charith")); - record3.setDataInt(102); - record4.setDataLong(112956051L); - record4.setDataString(new Utf8("Bhanuka")); - record4.setDataInt(103); - CassandraKey key1 = new CassandraKey(); - key1.setTimestamp(200L); - key1.setUrl("www.apache.org"); - CassandraKey key2 = new CassandraKey(); - key2.setTimestamp(205L); - key2.setUrl("www.apache.org"); - CassandraKey key3 = new CassandraKey(); - key3.setTimestamp(210L); - key3.setUrl("www.apache.org"); - CassandraKey key4 = new CassandraKey(); - key4.setTimestamp(215L); - key4.setUrl("www.apache.org"); - cassandraRecordDataStore.put(key1, record1); - cassandraRecordDataStore.put(key2, record2); - cassandraRecordDataStore.put(key3, record3); - cassandraRecordDataStore.put(key4, record4); - CassandraQuery query = new CassandraQuery<>(cassandraRecordDataStore); - query.setKey(key1); - query.addUpdateField("dataString", new Utf8("test123")); - cassandraRecordDataStore.updateByQuery(query); - CassandraRecord result = cassandraRecordDataStore.get(key1); - Assert.assertEquals(new Utf8("test123"), result.getDataString()); - } - - - @Test - public void testDataTypes() { - cassandraRecordDataStore.truncateSchema(); - CassandraRecord record = new CassandraRecord(); - record.setDataLong(719411002L); - record.setDataString(new Utf8("M.K.H. Gunasekara")); - record.setDataInt(144); - record.setDataBytes(ByteBuffer.wrap("No 144, Gunasekara Mawatha, Mattumgala, Ragama".getBytes(Charset.defaultCharset()))); - record.setDataDouble(3.14159d); - ArrayList doubles = new ArrayList<>(); - doubles.add(2.1D); - doubles.add(3.14D); - record.setArrayDouble(doubles); - ArrayList integers = new ArrayList<>(); - integers.add(2); - integers.add(3); - record.setArrayInt(integers); - ArrayList longs = new ArrayList<>(); - longs.add(2L); - longs.add(3L); - record.setArrayLong(longs); - ArrayList strings = new ArrayList<>(); - strings.add(new Utf8("Hello World")); - strings.add(new Utf8("Srilanka")); - record.setArrayString(strings); - HashMap map = new HashMap<>(); - map.put(new Utf8("Life"), 7.3D); - record.setMapDouble(map); - CassandraKey key = new CassandraKey(); - key.setTimestamp(2027L); - key.setUrl("www.apache.org"); - cassandraRecordDataStore.put(key, record); - CassandraRecord retrievedRecord = cassandraRecordDataStore.get(key); - Assert.assertEquals(record.getDataInt(), retrievedRecord.getDataInt()); - Assert.assertEquals(record.getDataString(), retrievedRecord.getDataString()); - Assert.assertEquals(record.getDataLong(), retrievedRecord.getDataLong()); - Assert.assertEquals(record.getDataBytes(), retrievedRecord.getDataBytes()); - Assert.assertEquals(record.getDataDouble(), retrievedRecord.getDataDouble()); - int i = 0; - for (Double obj : retrievedRecord.getArrayDouble()) { - Assert.assertEquals(doubles.get(i), obj); - i++; - } - i = 0; - for (Integer obj : retrievedRecord.getArrayInt()) { - Assert.assertEquals(integers.get(i), obj); - i++; - } - i = 0; - for (Long obj : retrievedRecord.getArrayLong()) { - Assert.assertEquals(longs.get(i), obj); - i++; - } - i = 0; - for (CharSequence obj : retrievedRecord.getArrayString()) { - Assert.assertEquals(strings.get(i), obj); - i++; - } - - for (Map.Entry entry : map.entrySet()) { - Assert.assertEquals(entry.getValue(), retrievedRecord.getMapDouble().get(entry.getKey())); - } - } -} http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/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 deleted file mode 100644 index 489732c..0000000 --- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStoreWithNativeSerialization.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * 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.gora.cassandra.store; - -import org.apache.gora.cassandra.GoraCassandraTestDriver; -import org.apache.gora.cassandra.example.generated.nativeSerialization.ComplexTypes; -import org.apache.gora.cassandra.example.generated.nativeSerialization.User; -import org.apache.gora.cassandra.query.CassandraQuery; -import org.apache.gora.query.Query; -import org.apache.gora.query.Result; -import org.apache.gora.store.DataStore; -import org.apache.gora.util.GoraException; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; - -/** - * This class tests Cassandra Store functionality with Cassandra Native Serialization. - */ -public class TestCassandraStoreWithNativeSerialization { - private static GoraCassandraTestDriver testDriver = new GoraCassandraTestDriver(); - private static CassandraStore userDataStore; - private static Properties parameter; - - @BeforeClass - public static void setUpClass() throws Exception { - setProperties(); - testDriver.setParameters(parameter); - testDriver.setUpClass(); - userDataStore = (CassandraStore) testDriver.createDataStore(UUID.class, User.class); - } - - private static void setProperties() { - parameter = new Properties(); - parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERVERS, "localhost"); - parameter.setProperty(CassandraStoreParameters.PORT, "9042"); - parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERIALIZATION_TYPE, "native"); - parameter.setProperty(CassandraStoreParameters.PROTOCOL_VERSION, "3"); - parameter.setProperty(CassandraStoreParameters.CLUSTER_NAME, "Test Cluster"); - parameter.setProperty("gora.cassandrastore.mapping.file", "nativeSerialization/gora-cassandra-mapping.xml"); - } - - @AfterClass - public static void tearDownClass() throws Exception { - testDriver.tearDownClass(); - } - - @After - public void tearDown() throws Exception { - testDriver.tearDown(); - } - - /** - * In this test case, put and get behavior of the data store are testing. - */ - @Test - 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(user1.getUserId()); - Assert.assertEquals(olduser.getName(), user1.getName()); - Assert.assertEquals(olduser.getDateOfBirth(), user1.getDateOfBirth()); - // delete data; - userDataStore.delete(user1.getUserId()); - // get data - User deletedUser = userDataStore.get(id); - Assert.assertNull(deletedUser); - } - - /** - * In this test case, schema exists method behavior of the data store is testing. - */ - @Test() - public void testSchemaExists() { - userDataStore.deleteSchema(); - Assert.assertFalse(userDataStore.schemaExists()); - userDataStore.createSchema(); - Assert.assertTrue(userDataStore.schemaExists()); - } - - /** - * In this test case, schema exists method behavior of the data store is testing. - */ - @Test - public void testTruncateSchema() { - if (!userDataStore.schemaExists()) { - userDataStore.createSchema(); - } - UUID id = UUID.randomUUID(); - User user1 = new User(id, "Madhawa Kasun", Date.from(Instant.now())); - userDataStore.put(id, user1); - User olduser = userDataStore.get(id); - Assert.assertEquals(olduser.getName(), user1.getName()); - Assert.assertEquals(olduser.getDateOfBirth(), user1.getDateOfBirth()); - userDataStore.truncateSchema(); - olduser = userDataStore.get(id); - Assert.assertNull(olduser); - } - - /** - * In this test case, get with fields method behavior of the data store is testing. - */ - @Test - public void testGetWithFields() { - UUID id = UUID.randomUUID(); - User user1 = new User(id, "Madhawa Kasun Gunasekara", Date.from(Instant.now())); - userDataStore.put(id, user1); - // get data; - User olduser = userDataStore.get(user1.getUserId()); - Assert.assertEquals(olduser.getName(), user1.getName()); - Assert.assertEquals(olduser.getDateOfBirth(), user1.getDateOfBirth()); - User olduserWithFields = userDataStore.get(id, new String[]{"name"}); - Assert.assertNull(olduserWithFields.getDateOfBirth()); - } - - /** - * In this test case, get with fields method behavior of the data store is testing. - */ - @Test - public void testExecute() throws Exception { - userDataStore.truncateSchema(); - Map users = new HashMap<>(); - UUID id1 = UUID.randomUUID(); - User user1 = new User(id1, "user1", Date.from(Instant.now())); - users.put(id1, user1); - userDataStore.put(id1, user1); - UUID id2 = UUID.randomUUID(); - User user2 = new User(id2, "user2", Date.from(Instant.now())); - users.put(id2, user2); - userDataStore.put(id2, user2); - UUID id3 = UUID.randomUUID(); - User user3 = new User(id3, "user3", Date.from(Instant.now())); - users.put(id3, user3); - userDataStore.put(id3, user3); - Query query1 = userDataStore.newQuery(); - Result result1 = userDataStore.execute(query1); - int i = 0; - Assert.assertEquals(result1.getProgress(), 0.0, 0.0); - while (result1.next()) { - // check objects values - Assert.assertEquals(result1.get().getName(), users.get(result1.getKey()).getName()); - Assert.assertEquals(result1.get().getDateOfBirth(), users.get(result1.getKey()).getDateOfBirth()); - Assert.assertEquals(result1.get().getUserId(), users.get(result1.getKey()).getUserId()); - i++; - } - Assert.assertEquals(result1.getProgress(), 1.0, 0.0); - Assert.assertEquals(3, i); - - // Check limit query - Query query2 = userDataStore.newQuery(); - query2.setLimit(2); - Result result2 = userDataStore.execute(query2); - i = 0; - while (result2.next()) { - Assert.assertEquals(result2.get().getName(), users.get(result2.getKey()).getName()); - Assert.assertEquals(result2.get().getDateOfBirth(), users.get(result2.getKey()).getDateOfBirth()); - Assert.assertEquals(result2.get().getUserId(), users.get(result2.getKey()).getUserId()); - i++; - } - Assert.assertEquals(2, i); - - // check key element - Query query3 = userDataStore.newQuery(); - query3.setKey(id1); - - Result result3 = userDataStore.execute(query3); - i = 0; - while (result3.next()) { - Assert.assertEquals(result3.get().getName(), users.get(result3.getKey()).getName()); - Assert.assertEquals(result3.get().getDateOfBirth(), users.get(result3.getKey()).getDateOfBirth()); - Assert.assertEquals(result3.get().getUserId(), users.get(result3.getKey()).getUserId()); - i++; - } - Assert.assertEquals(1, i); - } - - /** - * In this test case, delete by query method behavior of the data store is testing. - */ - @Test - public void testDeleteByQuery() throws Exception { - userDataStore.truncateSchema(); - UUID id1 = UUID.randomUUID(); - User user1 = new User(id1, "user1", Date.from(Instant.now())); - userDataStore.put(id1, user1); - UUID id2 = UUID.randomUUID(); - User user2 = new User(id2, "user2", Date.from(Instant.now())); - userDataStore.put(id2, user2); - Query query1 = userDataStore.newQuery(); - query1.setKey(id1); - userDataStore.deleteByQuery(query1); - User user = userDataStore.get(id1); - Assert.assertNull(user); - - //test deleteByFields - Query query2 = userDataStore.newQuery(); - query2.setKey(id2); - query2.setFields("name"); - userDataStore.deleteByQuery(query2); - User partialDeletedUser = userDataStore.get(id2); - Assert.assertNull(partialDeletedUser.getName()); - Assert.assertEquals(partialDeletedUser.getDateOfBirth(), user2.getDateOfBirth()); - } - - /** - * In this test case, update by quert method behavior of the data store is testing. - */ - @Test - public void testUpdateByQuery() { - userDataStore.truncateSchema(); - UUID id1 = UUID.randomUUID(); - User user1 = new User(id1, "user1", Date.from(Instant.now())); - userDataStore.put(id1, user1); - UUID id2 = UUID.randomUUID(); - User user2 = new User(id2, "user2", Date.from(Instant.now())); - userDataStore.put(id2, user2); - Query query1 = userDataStore.newQuery(); - if (query1 instanceof CassandraQuery) { - ((CassandraQuery) query1).addUpdateField("name", "madhawa"); - } - query1.setKey(id1); - if (userDataStore instanceof CassandraStore) { - userDataStore.updateByQuery(query1); - } - User user = userDataStore.get(id1); - Assert.assertEquals(user.getName(), "madhawa"); - } - - @Test - public void testComplexTypes() throws GoraException { - DataStore documentDataStore = testDriver.createDataStore(String.class, ComplexTypes.class); - ComplexTypes document = new ComplexTypes("document1"); - document.setIntArrayDataType(new int[]{1, 2, 3}); - document.setStringArrayDataType(new String[]{"madhawa", "kasun", "gunasekara", "pannipitiya", "srilanka"}); - document.setListDataType(new ArrayList<>(Arrays.asList("gora", "nutch", "tika", "opennlp", "olingo"))); - document.setSetDataType(new HashSet<>(Arrays.asList("important", "keeper"))); - HashMap map = new HashMap<>(); - map.put("LK", "Colombo"); - document.setMapDataType(map); - documentDataStore.put("document1", document); - ComplexTypes retrievedDocuemnt = documentDataStore.get("document1"); - // verify list data - for (int i = 0; i < document.getListDataType().size(); i++) { - Assert.assertEquals(document.getListDataType().get(i), retrievedDocuemnt.getListDataType().get(i)); - } - // verify set data - for (int i = 0; i < document.getSetDataType().size(); i++) { - Assert.assertTrue(Arrays.equals(document.getSetDataType().toArray(), retrievedDocuemnt.getSetDataType().toArray())); - } - // verify array data - for (int i = 0; i < document.getIntArrayDataType().length; i++) { - Assert.assertTrue(Arrays.equals(document.getIntArrayDataType(), retrievedDocuemnt.getIntArrayDataType())); - } - for (int i = 0; i < document.getStringArrayDataType().length; i++) { - Assert.assertTrue(Arrays.equals(document.getStringArrayDataType(), retrievedDocuemnt.getStringArrayDataType())); - } - // verify map data - Assert.assertEquals(map.get("LK"), retrievedDocuemnt.getMapDataType().get("LK")); - } -} http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestNativeSerializationWithUDT.java ---------------------------------------------------------------------- diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestNativeSerializationWithUDT.java b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestNativeSerializationWithUDT.java deleted file mode 100644 index f9b5df4..0000000 --- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestNativeSerializationWithUDT.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * 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.gora.cassandra.store; - -import org.apache.gora.cassandra.GoraCassandraTestDriver; -import org.apache.gora.cassandra.example.generated.nativeSerialization.Customer; -import org.apache.gora.cassandra.example.generated.nativeSerialization.Document; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.Properties; - -/** - * This class contains the tests cases to test the behaviour of Native Serialization with UDT dataType. - */ -public class TestNativeSerializationWithUDT { - - private static GoraCassandraTestDriver testDriver = new GoraCassandraTestDriver(); - private static CassandraStore documentCassandraStore; - private static Properties parameter; - - @BeforeClass - public static void setUpClass() throws Exception { - setProperties(); - testDriver.setParameters(parameter); - testDriver.setUpClass(); - documentCassandraStore = (CassandraStore) testDriver.createDataStore(String.class, Document.class); - } - - private static void setProperties() { - parameter = new Properties(); - parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERVERS, "localhost"); - parameter.setProperty(CassandraStoreParameters.PORT, "9042"); - parameter.setProperty(CassandraStoreParameters.CASSANDRA_SERIALIZATION_TYPE, "native"); - parameter.setProperty(CassandraStoreParameters.PROTOCOL_VERSION, "3"); - parameter.setProperty(CassandraStoreParameters.CLUSTER_NAME, "Test Cluster"); - parameter.setProperty("gora.cassandrastore.mapping.file", "nativeUDT/gora-cassandra-mapping.xml"); - } - - @AfterClass - public static void tearDownClass() throws Exception { - testDriver.tearDownClass(); - } - - @After - public void tearDown() throws Exception { - testDriver.tearDown(); - } - - /** - * This is for testGetNested() with UDT dataType with native serialization. - */ - @Test - public void testSimplePutAndGEt() { - documentCassandraStore.createSchema(); - Document document = new Document(); - document.setDefaultId("yawamu.com"); - Customer customer = new Customer(); - customer.setId("144"); - customer.setName("Madhawa"); - document.setCustomer(customer); - documentCassandraStore.put("yawamu.com", document); - Document retrievedDocument = documentCassandraStore.get("yawamu.com"); - Assert.assertEquals(customer.getId(), retrievedDocument.getCustomer().getId()); - Assert.assertEquals(customer.getName(), retrievedDocument.getCustomer().getName()); - } - -} http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/package-info.java ---------------------------------------------------------------------- diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/package-info.java b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/package-info.java deleted file mode 100644 index 6e1c6b8..0000000 --- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ -/** - * This package contains all the unit tests for basic CRUD operations - * functionality of the Cassandra dataStore. - */ -package org.apache.gora.cassandra.store; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/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 deleted file mode 100644 index b5ffedb..0000000 --- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/test/nativeSerialization/DateAsStringCodec.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.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 { - 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/89683c74/gora-cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/gora-cassandra/pom.xml b/gora-cassandra/pom.xml new file mode 100644 index 0000000..99ede48 --- /dev/null +++ b/gora-cassandra/pom.xml @@ -0,0 +1,219 @@ + + + + + 4.0.0 + + + org.apache.gora + gora + 0.8-SNAPSHOT + ../ + + gora-cassandra + bundle + + Apache Gora :: Cassandra - CQL + http://gora.apache.org + The Apache Gora open source framework provides an in-memory data model and + persistence for big data. Gora supports persisting to column stores, key value stores, + document stores and RDBMSs, and analyzing the data with extensive Apache Hadoop MapReduce + support. + + 2010 + + The Apache Software Foundation + http://www.apache.org/ + + + JIRA + https://issues.apache.org/jira/browse/GORA + + + Jenkins + https://builds.apache.org/job/Gora-trunk/ + + + + 18.0 + * + org.apache.gora.cassandra*;version="${project.version}";-noimport:=true + + + + target + target/classes + ${project.artifactId}-${project.version} + target/test-classes + src/test/java + src/main/java + + + ${project.basedir}/src/test/conf + + **/* + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + generate-sources + + add-source + + + + src/examples/java + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.maven.surefire + surefire-junit47 + 2.20 + + + + always + -Xmx1024m -XX:MaxPermSize=512m + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.gora.cassandra.compiler.GoraCassandraNativeCompiler + org.apache.gora.cassandra.compiler + + + + + + + + + + + org.apache.gora + gora-core + + + org.apache.gora + gora-core + test-jar + test + + + + com.datastax.cassandra + cassandra-driver-core + ${cassandra-driver.version} + + + com.datastax.cassandra + cassandra-driver-mapping + ${cassandra-driver.version} + + + com.datastax.cassandra + cassandra-driver-extras + ${cassandra-driver.version} + + + + org.apache.cassandra + cassandra-all + test + + + org.apache.cassandra.deps + avro + + + org.slf4j + slf4j-log4j12 + + + io.netty + netty-handler + + + org.slf4j + log4j-over-slf4j + + + + + org.apache.gora + gora-hbase + + + + com.google.guava + guava + ${guava.version} + + + org.jdom + jdom + + + org.apache.avro + avro + + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + javax.jms + jms + + + + + + junit + junit + + + org.apache.hadoop + hadoop-minicluster + + + http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra/src/examples/avro/cassandraKey.json ---------------------------------------------------------------------- diff --git a/gora-cassandra/src/examples/avro/cassandraKey.json b/gora-cassandra/src/examples/avro/cassandraKey.json new file mode 100644 index 0000000..141282e --- /dev/null +++ b/gora-cassandra/src/examples/avro/cassandraKey.json @@ -0,0 +1,22 @@ +{ + "type": "record", + "name": "CassandraKey", + "default": null, + "namespace": "org.apache.gora.cassandra.example.generated.AvroSerialization", + "doc": "This Object is created to used as Cassandra Key to test cassandra data store, Cassandra Key can be used to define partition keys, clustering keys.", + "fields": [ + { + "name": "url", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "timestamp", + "type": "long", + "default": 0 + } + ] +} http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra/src/examples/avro/cassandraRecord.json ---------------------------------------------------------------------- diff --git a/gora-cassandra/src/examples/avro/cassandraRecord.json b/gora-cassandra/src/examples/avro/cassandraRecord.json new file mode 100644 index 0000000..9bd8d21 --- /dev/null +++ b/gora-cassandra/src/examples/avro/cassandraRecord.json @@ -0,0 +1,107 @@ +{ + "type": "record", + "name": "CassandraRecord", + "default": null, + "namespace": "org.apache.gora.cassandra.example.generated.AvroSerialization", + "doc": "This object created to used as Persistent Object to test cassandra data store", + "fields": [ + { + "name": "dataString", + "type": "string", + "default": "" + }, + { + "name": "dataInt", + "type": "int", + "default": 0 + }, + { + "name": "dataLong", + "type": [ + "null", + "long" + ], + "default": null + }, + { + "name": "dataDouble", + "type": [ + "null", + "double" + ], + "default": null + }, + { + "name": "dataBytes", + "type": [ + "null", + "bytes" + ], + "default": null + }, + { + "name": "arrayInt", + "type": { + "type": "array", + "items": "int" + }, + "default": null + }, + { + "name": "arrayString", + "type": { + "type": "array", + "items": "string" + }, + "default": null + }, + { + "name": "arrayLong", + "type": { + "type": "array", + "items": "long" + }, + "default": null + }, + { + "name": "arrayDouble", + "type": { + "type": "array", + "items": "double" + }, + "default": null + }, + { + "name": "mapInt", + "type": { + "type": "map", + "values": "int" + }, + "default": {} + }, + { + "name": "mapString", + "type": { + "type": "map", + "values": "string" + }, + "default": {} + }, + { + "name": "mapLong", + "type": { + "type": "map", + "values": "long" + }, + "default": {} + }, + { + "name": "mapDouble", + "type": { + "type": "map", + "values": "double" + }, + "default": {} + } + ] +} http://git-wip-us.apache.org/repos/asf/gora/blob/89683c74/gora-cassandra/src/examples/java/org/apache/gora/cassandra/example/generated/AvroSerialization/CassandraKey.java ---------------------------------------------------------------------- diff --git a/gora-cassandra/src/examples/java/org/apache/gora/cassandra/example/generated/AvroSerialization/CassandraKey.java b/gora-cassandra/src/examples/java/org/apache/gora/cassandra/example/generated/AvroSerialization/CassandraKey.java new file mode 100644 index 0000000..6b89c33 --- /dev/null +++ b/gora-cassandra/src/examples/java/org/apache/gora/cassandra/example/generated/AvroSerialization/CassandraKey.java @@ -0,0 +1,446 @@ +/** + * 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.gora.cassandra.example.generated.AvroSerialization; + +/** + * This Object is created to used as Cassandra Key to test cassandra data store, Cassandra Key can be used to define partition keys, clustering keys. + */ +public class CassandraKey extends org.apache.gora.persistency.impl.PersistentBase implements org.apache.avro.specific.SpecificRecord, org.apache.gora.persistency.Persistent { + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"CassandraKey\",\"namespace\":\"org.apache.gora.cassandra.example.generated.AvroSerialization\",\"doc\":\"This Object is created to used as Cassandra Key to test cassandra data store, Cassandra Key can be used to define partition keys, clustering keys. \",\"fields\":[{\"name\":\"url\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"timestamp\",\"type\":\"long\",\"default\":0}],\"default\":null}"); + public static final String[] _ALL_FIELDS = { + "url", + "timestamp", + }; + private static final long serialVersionUID = -4231222814786458061L; + + ; + private static final Tombstone TOMBSTONE = new Tombstone(); + private static final org.apache.avro.io.DatumWriter + DATUM_WRITER$ = new org.apache.avro.specific.SpecificDatumWriter(SCHEMA$); + private static final org.apache.avro.io.DatumReader + DATUM_READER$ = new org.apache.avro.specific.SpecificDatumReader(SCHEMA$); + private java.lang.CharSequence url; + private long timestamp; + + /** + * Creates a new CassandraKey RecordBuilder + */ + public static org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder newBuilder() { + return new org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder(); + } + + /** + * Creates a new CassandraKey RecordBuilder by copying an existing Builder + */ + public static org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder newBuilder(org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder other) { + return new org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder(other); + } + + /** + * Creates a new CassandraKey RecordBuilder by copying an existing CassandraKey instance + */ + public static org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder newBuilder(org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey other) { + return new org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder(other); + } + + private static java.nio.ByteBuffer deepCopyToReadOnlyBuffer( + java.nio.ByteBuffer input) { + java.nio.ByteBuffer copy = java.nio.ByteBuffer.allocate(input.capacity()); + int position = input.position(); + input.reset(); + int mark = input.position(); + int limit = input.limit(); + input.rewind(); + input.limit(input.capacity()); + copy.put(input); + input.rewind(); + copy.rewind(); + input.position(mark); + input.mark(); + copy.position(mark); + copy.mark(); + input.position(position); + copy.position(position); + input.limit(limit); + copy.limit(limit); + return copy.asReadOnlyBuffer(); + } + + /** + * Gets the total field count. + * + * @return int field count + */ + public int getFieldsCount() { + return CassandraKey._ALL_FIELDS.length; + } + + public org.apache.avro.Schema getSchema() { + return SCHEMA$; + } + + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: + return url; + case 1: + return timestamp; + default: + throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value = "unchecked") + public void put(int field$, java.lang.Object value) { + switch (field$) { + case 0: + url = (java.lang.CharSequence) (value); + break; + case 1: + timestamp = (java.lang.Long) (value); + break; + default: + throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'url' field. + */ + public java.lang.CharSequence getUrl() { + return url; + } + + /** + * Sets the value of the 'url' field. + * + * @param value the value to set. + */ + public void setUrl(java.lang.CharSequence value) { + this.url = value; + setDirty(0); + } + + /** + * Checks the dirty status of the 'url' field. A field is dirty if it represents a change that has not yet been written to the database. + * + * @param value the value to set. + */ + public boolean isUrlDirty() { + return isDirty(0); + } + + /** + * Gets the value of the 'timestamp' field. + */ + public java.lang.Long getTimestamp() { + return timestamp; + } + + /** + * Sets the value of the 'timestamp' field. + * + * @param value the value to set. + */ + public void setTimestamp(java.lang.Long value) { + this.timestamp = value; + setDirty(1); + } + + /** + * Checks the dirty status of the 'timestamp' field. A field is dirty if it represents a change that has not yet been written to the database. + * + * @param value the value to set. + */ + public boolean isTimestampDirty() { + return isDirty(1); + } + + public CassandraKey.Tombstone getTombstone() { + return TOMBSTONE; + } + + public CassandraKey newInstance() { + return newBuilder().build(); + } + + /** + * Writes AVRO data bean to output stream in the form of AVRO Binary encoding format. This will transform + * AVRO data bean from its Java object form to it s serializable form. + * + * @param out java.io.ObjectOutput output stream to write data bean in serializable form + */ + @Override + public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + out.write(super.getDirtyBytes().array()); + DATUM_WRITER$.write(this, org.apache.avro.io.EncoderFactory.get() + .directBinaryEncoder((java.io.OutputStream) out, + null)); + } + + /** + * Reads AVRO data bean from input stream in it s AVRO Binary encoding format to Java object format. + * This will transform AVRO data bean from it s serializable form to deserialized Java object form. + * + * @param in java.io.ObjectOutput input stream to read data bean in serializable form + */ + @Override + public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + byte[] __g__dirty = new byte[getFieldsCount()]; + in.read(__g__dirty); + super.setDirtyBytes(java.nio.ByteBuffer.wrap(__g__dirty)); + DATUM_READER$.read(this, org.apache.avro.io.DecoderFactory.get() + .directBinaryDecoder((java.io.InputStream) in, + null)); + } + + /** + * Enum containing all data bean's fields. + */ + public static enum Field { + URL(0, "url"), + TIMESTAMP(1, "timestamp"),; + /** + * Field's index. + */ + private int index; + + /** + * Field's name. + */ + private String name; + + /** + * Field's constructor + * + * @param index field's index. + * @param name field's name. + */ + Field(int index, String name) { + this.index = index; + this.name = name; + } + + /** + * Gets field's index. + * + * @return int field's index. + */ + public int getIndex() { + return index; + } + + /** + * Gets field's name. + * + * @return String field's name. + */ + public String getName() { + return name; + } + + /** + * Gets field's attributes to string. + * + * @return String field's attributes to string. + */ + public String toString() { + return name; + } + } + + /** + * RecordBuilder for CassandraKey instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.CharSequence url; + private long timestamp; + + /** + * Creates a new Builder + */ + private Builder() { + super(org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder + */ + private Builder(org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder other) { + super(other); + } + + /** + * Creates a Builder by copying an existing CassandraKey instance + */ + private Builder(org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey other) { + super(org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.SCHEMA$); + if (isValidValue(fields()[0], other.url)) { + this.url = (java.lang.CharSequence) data().deepCopy(fields()[0].schema(), other.url); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.timestamp)) { + this.timestamp = (java.lang.Long) data().deepCopy(fields()[1].schema(), other.timestamp); + fieldSetFlags()[1] = true; + } + } + + /** + * Gets the value of the 'url' field + */ + public java.lang.CharSequence getUrl() { + return url; + } + + /** + * Sets the value of the 'url' field + */ + public org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder setUrl(java.lang.CharSequence value) { + validate(fields()[0], value); + this.url = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'url' field has been set + */ + public boolean hasUrl() { + return fieldSetFlags()[0]; + } + + /** + * Clears the value of the 'url' field + */ + public org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder clearUrl() { + url = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'timestamp' field + */ + public java.lang.Long getTimestamp() { + return timestamp; + } + + /** + * Sets the value of the 'timestamp' field + */ + public org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder setTimestamp(long value) { + validate(fields()[1], value); + this.timestamp = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'timestamp' field has been set + */ + public boolean hasTimestamp() { + return fieldSetFlags()[1]; + } + + /** + * Clears the value of the 'timestamp' field + */ + public org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey.Builder clearTimestamp() { + fieldSetFlags()[1] = false; + return this; + } + + @Override + public CassandraKey build() { + try { + CassandraKey record = new CassandraKey(); + record.url = fieldSetFlags()[0] ? this.url : (java.lang.CharSequence) defaultValue(fields()[0]); + record.timestamp = fieldSetFlags()[1] ? this.timestamp : (java.lang.Long) defaultValue(fields()[1]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + public static final class Tombstone extends CassandraKey implements org.apache.gora.persistency.Tombstone { + + private Tombstone() { + } + + /** + * Gets the value of the 'url' field. + */ + public java.lang.CharSequence getUrl() { + throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones"); + } + + /** + * Sets the value of the 'url' field. + * + * @param value the value to set. + */ + public void setUrl(java.lang.CharSequence value) { + throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones"); + } + + /** + * Checks the dirty status of the 'url' field. A field is dirty if it represents a change that has not yet been written to the database. + * + * @param value the value to set. + */ + public boolean isUrlDirty() { + throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones"); + } + + /** + * Gets the value of the 'timestamp' field. + */ + public java.lang.Long getTimestamp() { + throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones"); + } + + /** + * Sets the value of the 'timestamp' field. + * + * @param value the value to set. + */ + public void setTimestamp(java.lang.Long value) { + throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones"); + } + + /** + * Checks the dirty status of the 'timestamp' field. A field is dirty if it represents a change that has not yet been written to the database. + * + * @param value the value to set. + */ + public boolean isTimestampDirty() { + throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones"); + } + + + } + +} +