cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/2] cassandra git commit: Add CASSANDRA-9195 unit tests
Date Fri, 01 May 2015 16:49:39 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk c799a98f0 -> 6404e015f


Add CASSANDRA-9195 unit tests

patch by Branimir Lambov


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f43efaa1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f43efaa1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f43efaa1

Branch: refs/heads/trunk
Commit: f43efaa1bdeec1057a8097fdb5ab62b4c9c19e67
Parents: 33c5913
Author: Branimir Lambov <branimir.lambov@datastax.com>
Authored: Fri May 1 19:42:50 2015 +0300
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Fri May 1 19:44:03 2015 +0300

----------------------------------------------------------------------
 .../db/commitlog/CommitLogArchiver.java         |   2 +-
 .../db/RecoveryManagerTruncateTest.java         | 179 +++++++++++++++----
 2 files changed, 142 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f43efaa1/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
index 602cf94..91f3179 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
@@ -56,7 +56,7 @@ public class CommitLogArchiver
     final String archiveCommand;
     final String restoreCommand;
     final String restoreDirectories;
-    public final long restorePointInTime;
+    public long restorePointInTime;
     public final TimeUnit precision;
 
     public CommitLogArchiver()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f43efaa1/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
index 1f7d388..817b8e9 100644
--- a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
+++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
@@ -19,15 +19,14 @@
 package org.apache.cassandra.db;
 
 import static org.apache.cassandra.Util.column;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
 
 import java.io.IOException;
+import org.junit.Test;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.junit.Test;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 /**
@@ -35,46 +34,150 @@ import org.apache.cassandra.utils.ByteBufferUtil;
  */
 public class RecoveryManagerTruncateTest extends SchemaLoader
 {
-	@Test
-	public void testTruncate() throws IOException
-	{
-		Keyspace keyspace = Keyspace.open("Keyspace1");
-		ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
+    @Test
+    public void testTruncate() throws IOException
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
 
-		Mutation rm;
-		ColumnFamily cf;
+        Mutation rm;
+        ColumnFamily cf;
 
-		// add a single cell
+        // add a single cell
         cf = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1");
-		cf.addColumn(column("col1", "val1", 1L));
+        cf.addColumn(column("col1", "val1", 1L));
         rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("keymulti"), cf);
-		rm.apply();
+        rm.apply();
+        long time = System.currentTimeMillis();
 
-		// Make sure data was written
-		assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
+        // Make sure data was written
+        assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
 
-		// and now truncate it
-		cfs.truncateBlocking();
+        // and now truncate it
+        cfs.truncateBlocking();
         CommitLog.instance.resetUnsafe();
-		CommitLog.instance.recover();
-
-		// and validate truncation.
-		assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
-	}
-
-	private Cell getFromTable(Keyspace keyspace, String cfName, String keyName, String columnName)
-	{
-		ColumnFamily cf;
-		ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore(cfName);
-		if (cfStore == null)
-		{
-			return null;
-		}
-		cf = cfStore.getColumnFamily(Util.namesQueryFilter(cfStore, Util.dk(keyName), columnName));
-		if (cf == null)
-		{
-			return null;
-		}
-		return cf.getColumn(Util.cellname(columnName));
-	}
+        CommitLog.instance.recover();
+
+        // and validate truncation.
+        assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
+        assertTrue(SystemKeyspace.getTruncatedAt(cfs.metadata.cfId) > time);
+    }
+
+    @Test
+    public void testTruncatePointInTime() throws IOException
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
+
+        Mutation rm;
+        ColumnFamily cf;
+
+        // add a single cell
+        cf = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col2", "val1", 1L));
+        rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("keymulti"), cf);
+        rm.apply();
+
+        // Make sure data was written
+        long time = System.currentTimeMillis();
+        assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col2"));
+
+        // and now truncate it
+        cfs.truncateBlocking();
+
+        // verify truncation
+        assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col2"));
+
+        try
+        {
+            // Restore to point in time.
+            CommitLog.instance.archiver.restorePointInTime = time;
+            CommitLog.instance.resetUnsafe();
+            CommitLog.instance.recover();
+        }
+        finally
+        {
+            CommitLog.instance.archiver.restorePointInTime = Long.MAX_VALUE;
+        }
+
+        // Validate pre-truncation data was restored.
+        assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col2"));
+        // And that we don't have a truncation record after restore time.
+        assertFalse(SystemKeyspace.getTruncatedAt(cfs.metadata.cfId) > time);
+    }
+
+    @Test
+    public void testTruncatePointInTimeReplayList() throws IOException
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs1 = keyspace.getColumnFamilyStore("Standard1");
+        ColumnFamilyStore cfs2 = keyspace.getColumnFamilyStore("Standard2");
+
+        Mutation rm;
+        ColumnFamily cf;
+
+        // add a single cell
+        cf = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col3", "val1", 1L));
+        rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("keymulti"), cf);
+        rm.apply();
+
+        // add a single cell
+        cf = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard2");
+        cf.addColumn(column("col4", "val1", 1L));
+        rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("keymulti"), cf);
+        rm.apply();
+
+        // Make sure data was written
+        long time = System.currentTimeMillis();
+        assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col3"));
+        assertNotNull(getFromTable(keyspace, "Standard2", "keymulti", "col4"));
+
+        // and now truncate it
+        cfs1.truncateBlocking();
+        cfs2.truncateBlocking();
+
+        // verify truncation
+        assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col3"));
+        assertNull(getFromTable(keyspace, "Standard2", "keymulti", "col4"));
+
+        try
+        {
+            // Restore to point in time.
+            CommitLog.instance.archiver.restorePointInTime = time;
+            System.setProperty("cassandra.replayList", "Keyspace1.Standard1");
+            CommitLog.instance.resetUnsafe();
+            CommitLog.instance.recover();
+        }
+        finally
+        {
+            CommitLog.instance.archiver.restorePointInTime = Long.MAX_VALUE;
+            System.clearProperty("cassandra.replayList");
+        }
+
+        // Validate pre-truncation data was restored.
+        assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col3"));
+        // But only on the replayed table.
+        assertNull(getFromTable(keyspace, "Standard2", "keymulti", "col4"));
+
+        // And that we have the correct truncation records.
+        assertFalse(SystemKeyspace.getTruncatedAt(cfs1.metadata.cfId) > time);
+        assertTrue(SystemKeyspace.getTruncatedAt(cfs2.metadata.cfId) > time);
+    }
+
+    private Cell getFromTable(Keyspace keyspace, String cfName, String keyName, String columnName)
+    {
+        ColumnFamily cf;
+        ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore(cfName);
+        if (cfStore == null)
+        {
+            return null;
+        }
+        cf = cfStore.getColumnFamily(Util.namesQueryFilter(cfStore, Util.dk(keyName), columnName));
+        if (cf == null)
+        {
+            return null;
+        }
+        return cf.getColumn(Util.cellname(columnName));
+    }
 }


Mime
View raw message