Author: [email protected]
Date: Wed Sep 14 10:50:36 2011
New Revision: 1360
Log:
[AMDATUCASSANDRA-83] Fixed by adding method <T> Iterator<SuperRow<String,
String, String, T>> getSuperRows(String columnFamily, String superColumn,
Class<T> clazz);
Modified:
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/CassandraPersistenceManager.java
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/HectorCassandraPersistenceManagerImpl.java
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/CassandraPersistenceManagerTest.java
trunk/amdatu-cassandra/test-unit/src/main/java/org/amdatu/cassandra/test/unit/framework/mock/CassandraPersistenceManagerMock.java
Modified:
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/CassandraPersistenceManager.java
==============================================================================
---
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/CassandraPersistenceManager.java
(original)
+++
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/CassandraPersistenceManager.java
Wed Sep 14 10:50:36 2011
@@ -206,6 +206,8 @@
* which contains all Super Columns and Columns. This method assumes that
the values stored in all Columns are of
* type T. If the specified ColumnFamily does not exist, an unchecked
exception will be thrown.
*
+ * @param <T>
+ * The expected return type of the value contained by the specified
column
* @param columnFamily
* The name of the ColumnFamily to retrieve all super rows for.
* @param clazz
@@ -216,6 +218,27 @@
<T> Iterator<SuperRow<String, String, String, T>> getSuperRows(String
columnFamily, Class<T> clazz);
/**
+ * Returns an iterator over all super rows in the specified Column Family
(which must be of type "Super")
+ * which contains only the Super Columns matching the specified name. This
method assumes that the values
+ * stored in all Columns are of type T. If the specified ColumnFamily does
not exist, an unchecked exception
+ * will be thrown.
+ *
+ * @param <T>
+ * The expected return type of the value contained by the specified
column
+ * @param columnFamily
+ * The name of the ColumnFamily to retrieve all super rows for.
+ * @param superColumn
+ * The name of the superColumns to retrieve
+ * @param clazz
+ * The generic type T of all values being retrieved (i.e.
String.class).
+ * @return Iterator over all super rows in the specified ColumnFamily but
containing only the SuperColumns
+ * matching the specified superColumn name and assuming all values
are of type T.
+ * Returns null if there is no row with the specified row key.
+ */
+ <T> Iterator<SuperRow<String, String, String, T>> getSuperRows(String
columnFamily, String superColumn,
+ Class<T> clazz);
+
+ /**
* Returns an iterator over all rows in the specified Column Family (which
must be of type "Standard")
* which contains all Columns. This method assumes that the values stored
in all Columns are of type T.
* If the specified ColumnFamily does not exist, an unchecked exception
will be thrown.
@@ -283,7 +306,7 @@
* @param columnFamily
* The name of the ColumnFamily to remove the super column from
* @param rowKey
- * The key of the row to remove the super column from. If there is
no row that matches this row key, this
+ * The key of the row to remove the super column from. If there is
no row that matches this row key, this
* method does nothing.
* @param superColumn
* The name of the super column to remove. If the row does not
contain this super column, this method
@@ -301,10 +324,10 @@
* The key of the row to remove the column from. If there is no row
that matches this row key,
* this method does nothing.
* @param superColumn
- * The name of the super column to remove the column from. If the
row does not contain this super column,
+ * The name of the super column to remove the column from. If the
row does not contain this super column,
* this method does nothing.
* @param column
- * The name of the column in the super column to remove. If the row
does not contain this column,
+ * The name of the column in the super column to remove. If the row
does not contain this column,
* this method does nothing.
*/
void deleteColumn(String columnFamily, String rowKey, String superColumn,
String column);
Modified:
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/HectorCassandraPersistenceManagerImpl.java
==============================================================================
---
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/HectorCassandraPersistenceManagerImpl.java
(original)
+++
trunk/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/HectorCassandraPersistenceManagerImpl.java
Wed Sep 14 10:50:36 2011
@@ -308,6 +308,11 @@
final Class<T> clazz) {
return getSuperRows(columnFamilyName, clazz, COLUMN_LIMIT, null, null);
}
+
+ public <T> Iterator<SuperRow<String, String, String, T>>
getSuperRows(String columnFamilyName, String superColumn,
+ Class<T> clazz) {
+ return getSuperRows(columnFamilyName, clazz, COLUMN_LIMIT, null,
superColumn);
+ }
public <T> Iterator<Row<String, String, T>> getRows(final String
columnFamilyName, final Class<T> clazz) {
return getRows(columnFamilyName, clazz, COLUMN_LIMIT, null);
Modified:
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/CassandraPersistenceManagerTest.java
==============================================================================
---
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/CassandraPersistenceManagerTest.java
(original)
+++
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/CassandraPersistenceManagerTest.java
Wed Sep 14 10:50:36 2011
@@ -17,8 +17,12 @@
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import junit.framework.Assert;
+import me.prettyprint.hector.api.beans.HSuperColumn;
+import me.prettyprint.hector.api.beans.SuperRow;
import org.amdatu.cassandra.application.ThriftException;
import org.amdatu.cassandra.listener.ColumnFamilyDefinition.ColumnType;
@@ -54,26 +58,71 @@
public void execute() throws Exception {
setUp();
-
- // Perform intensive getValue/setValue test (see AMDATU-137)
- String rowKey = "test";
- String superColumn = "TestSuperColumn";
- String column = "TestColumn";
- int failures = 0;
- for (int i = 0; i < 10000; i++) {
- int randomNumber = new Double(Math.floor(10000 *
Math.random())).intValue();
- String value = "amdatutest-" + randomNumber;
- byte[] byteValue = value.getBytes(DEFAULT_CHARSET);
- String failure = verifySetValue(KEYSPACE, COLUMNFAMILY, rowKey,
superColumn, column, byteValue);
- if (failure != null) {
- failures++;
- }
- }
- if (failures > 0) {
- Assert.fail("Cassandra setValue/getValue test failed. " + failures
+ " failures detected.");
- }
+
+ // Test the getSuperRows methods
+ testGetSuperRows();
+
+ // Verifies that a value that was set is also returned by the get
(previously failed, see AMDATU-137)
+ testSetGetValue();
tearDown();
+ }
+
+ private void testSetGetValue() throws UnsupportedEncodingException {
+ // Perform intensive getValue/setValue test (see AMDATU-137)
+ String rowKey = "test";
+ String superColumn = "TestSuperColumn";
+ String column = "TestColumn";
+ int failures = 0;
+ for (int i = 0; i < 10000; i++) {
+ int randomNumber = new Double(Math.floor(10000 *
Math.random())).intValue();
+ String value = "amdatutest-" + randomNumber;
+ byte[] byteValue = value.getBytes(DEFAULT_CHARSET);
+ String failure = verifySetValue(KEYSPACE, COLUMNFAMILY, rowKey,
superColumn, column, byteValue);
+ if (failure != null) {
+ failures++;
+ }
+ }
+ if (failures > 0) {
+ Assert.fail("Cassandra setValue/getValue test failed. " + failures
+ " failures detected.");
+ }
+ }
+
+ private void testGetSuperRows() {
+ // Append 5 super column values to the test Column Family
+ String rowKey = "test";
+ String column = "TestColumn";
+ int colSize = 5;
+ for (int i=1;i<=colSize;i++) {
+ String superColumnName = "SuperColumn_" + i;
+ m_pm.setValue(COLUMNFAMILY, rowKey, superColumnName, column,
"value_" + i);
+ }
+
+ // Verify getSuperRows. Only 1 superRow should be returned with rowkey
"test", and it should return
+ // all superColumns "SuperColumn_1",...,"Super[Column_colSize]"
+ Iterator<SuperRow<String, String, String, String>> superRows =
m_pm.getSuperRows(COLUMNFAMILY, String.class);
+ int count = 1;
+ while (superRows.hasNext()) {
+ SuperRow<String, String, String, String> superRow =
superRows.next();
+ Assert.assertTrue(superRow.getKey().equals(rowKey));
+ List<HSuperColumn<String, String, String>> superColumns =
superRow.getSuperSlice().getSuperColumns();
+ Assert.assertTrue(superColumns.size() == colSize);
+ Assert.assertTrue(count == 1);
+ count++;
+ }
+
+ // Verify getSuperRows with specific superColumn. Only 1 superRow
should be returned with rowkey "test",
+ // and it should return only the superColumns "SuperColumn_[colSize-1]"
+ superRows = m_pm.getSuperRows(COLUMNFAMILY, "SuperColumn_" +
(colSize-1), String.class);
+ count = 1;
+ while (superRows.hasNext()) {
+ SuperRow<String, String, String, String> superRow =
superRows.next();
+ Assert.assertTrue(superRow.getKey().equals(rowKey));
+ List<HSuperColumn<String, String, String>> superColumns =
superRow.getSuperSlice().getSuperColumns();
+ Assert.assertTrue(superColumns.size() == 1);
+ Assert.assertTrue(count == 1);
+ count++;
+ }
}
/**
Modified:
trunk/amdatu-cassandra/test-unit/src/main/java/org/amdatu/cassandra/test/unit/framework/mock/CassandraPersistenceManagerMock.java
==============================================================================
---
trunk/amdatu-cassandra/test-unit/src/main/java/org/amdatu/cassandra/test/unit/framework/mock/CassandraPersistenceManagerMock.java
(original)
+++
trunk/amdatu-cassandra/test-unit/src/main/java/org/amdatu/cassandra/test/unit/framework/mock/CassandraPersistenceManagerMock.java
Wed Sep 14 10:50:36 2011
@@ -182,6 +182,12 @@
public <T> Iterator<SuperRow<String, String, String, T>>
getSuperRows(String columnFamily, Class<T> clazz) {
throw new IllegalArgumentException("This method is not (yet)
implemented by this mock object");
}
+
+ @Override
+ public <T> Iterator<SuperRow<String, String, String, T>>
getSuperRows(String columnFamily, String superColumn,
+ Class<T> clazz) {
+ throw new IllegalArgumentException("This method is not (yet)
implemented by this mock object");
+ }
@Override
public <T> Iterator<me.prettyprint.hector.api.beans.Row<String, String,
T>> getRows(String columnFamily,
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits