You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2014/02/03 21:32:36 UTC

[2/4] Merge branch 'cassandra-2.0' into trunk

http://git-wip-us.apache.org/repos/asf/cassandra/blob/63f110b5/test/unit/org/apache/cassandra/db/ScrubTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/db/ScrubTest.java
index 38c8b62,08dd435..d8ab9ff
--- a/test/unit/org/apache/cassandra/db/ScrubTest.java
+++ b/test/unit/org/apache/cassandra/db/ScrubTest.java
@@@ -39,9 -41,9 +41,11 @@@ import org.apache.cassandra.db.compacti
  import org.apache.cassandra.exceptions.ConfigurationException;
  import org.apache.cassandra.db.columniterator.IdentityQueryFilter;
  import org.apache.cassandra.db.compaction.CompactionManager;
++import org.apache.cassandra.exceptions.WriteTimeoutException;
  import org.apache.cassandra.io.sstable.*;
  import org.apache.cassandra.utils.ByteBufferUtil;
  
++import static org.apache.cassandra.Util.cellname;
  import static org.apache.cassandra.Util.column;
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.fail;
@@@ -76,6 -79,53 +81,53 @@@ public class ScrubTest extends SchemaLo
      }
  
      @Test
 -    public void testScrubCorruptedCounterRow() throws IOException, InterruptedException, ExecutionException
++    public void testScrubCorruptedCounterRow() throws IOException, InterruptedException, ExecutionException, WriteTimeoutException
+     {
+         CompactionManager.instance.disableAutoCompaction();
+         Keyspace keyspace = Keyspace.open(KEYSPACE);
+         ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(COUNTER_CF);
+         cfs.clearUnsafe();
+ 
+         fillCounterCF(cfs, 2);
+ 
+         List<Row> rows = cfs.getRangeSlice(Util.range("", ""), null, new IdentityQueryFilter(), 1000);
+         assertEquals(2, rows.size());
+ 
+         SSTableReader sstable = cfs.getSSTables().iterator().next();
+ 
+         // overwrite one row with garbage
+         long row0Start = sstable.getPosition(RowPosition.forKey(ByteBufferUtil.bytes("0"), sstable.partitioner), SSTableReader.Operator.EQ).position;
+         long row1Start = sstable.getPosition(RowPosition.forKey(ByteBufferUtil.bytes("1"), sstable.partitioner), SSTableReader.Operator.EQ).position;
+         long startPosition = row0Start < row1Start ? row0Start : row1Start;
+         long endPosition = row0Start < row1Start ? row1Start : row0Start;
+ 
+         RandomAccessFile file = new RandomAccessFile(sstable.getFilename(), "rw");
+         file.seek(startPosition);
+         file.writeBytes(StringUtils.repeat('z', (int) (endPosition - startPosition)));
+         file.close();
+ 
+         // with skipCorrupted == false, the scrub is expected to fail
+         Scrubber scrubber = new Scrubber(cfs, sstable, false);
+         try
+         {
+             scrubber.scrub();
+             fail("Expected a CorruptSSTableException to be thrown");
+         }
+         catch (IOError err) {}
+ 
+         // with skipCorrupted == true, the corrupt row will be skipped
+         scrubber = new Scrubber(cfs, sstable, true);
+         scrubber.scrub();
+         scrubber.close();
+         cfs.replaceCompactedSSTables(Collections.singletonList(sstable), Collections.singletonList(scrubber.getNewSSTable()), OperationType.SCRUB);
+         assertEquals(1, cfs.getSSTables().size());
+ 
+         // verify that we can read all of the rows, and there is now one less row
+         rows = cfs.getRangeSlice(Util.range("", ""), null, new IdentityQueryFilter(), 1000);
+         assertEquals(1, rows.size());
+     }
+ 
+     @Test
      public void testScrubDeletedRow() throws IOException, ExecutionException, InterruptedException, ConfigurationException
      {
          CompactionManager.instance.disableAutoCompaction();
@@@ -207,4 -256,20 +258,20 @@@
  
          cfs.forceBlockingFlush();
      }
+ 
 -    protected void fillCounterCF(ColumnFamilyStore cfs, int rowsPerSSTable) throws ExecutionException, InterruptedException, IOException
++    protected void fillCounterCF(ColumnFamilyStore cfs, int rowsPerSSTable) throws ExecutionException, InterruptedException, IOException, WriteTimeoutException
+     {
+         for (int i = 0; i < rowsPerSSTable; i++)
+         {
+             String key = String.valueOf(i);
+             ColumnFamily cf = TreeMapBackedSortedColumns.factory.create(KEYSPACE, COUNTER_CF);
 -            RowMutation rm = new RowMutation(KEYSPACE, ByteBufferUtil.bytes(key), cf);
 -            rm.addCounter(COUNTER_CF, ByteBufferUtil.bytes("Column1"), 100);
++            Mutation rm = new Mutation(KEYSPACE, ByteBufferUtil.bytes(key), cf);
++            rm.addCounter(COUNTER_CF, cellname("Column1"), 100);
+             CounterMutation cm = new CounterMutation(rm, ConsistencyLevel.ONE);
+             cm.apply();
+         }
+ 
+         cfs.forceBlockingFlush();
+     }
+ 
 -}
 +}