cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [1/5] cassandra git commit: Fixed TrackerTest on Linux, CASSANDRA-9514
Date Mon, 01 Jun 2015 15:44:43 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 c11644bbf -> 3b85ea734
  refs/heads/trunk cc6d14298 -> f1d175fba


Fixed TrackerTest on Linux, CASSANDRA-9514


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

Branch: refs/heads/cassandra-2.2
Commit: 8b80b5561112578133a269c37c44ca6c1d1da16b
Parents: c34a329
Author: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Authored: Mon Jun 1 08:49:46 2015 +0200
Committer: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Committed: Mon Jun 1 08:49:46 2015 +0200

----------------------------------------------------------------------
 .../io/sstable/format/SSTableReader.java        |  4 +-
 test/unit/org/apache/cassandra/MockSchema.java  | 16 ++++
 .../cassandra/db/lifecycle/TrackerTest.java     | 94 ++++++++++++--------
 3 files changed, 73 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/8b80b556/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
index 54dff4e..ba634b6 100644
--- a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
@@ -369,7 +369,7 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS
     public static SSTableReader openForBatch(Descriptor descriptor, Set<Component>
components, CFMetaData metadata, IPartitioner partitioner) throws IOException
     {
         // Minimum components without which we can't do anything
-        assert components.contains(Component.DATA) : "Data component is missing for sstable"
+ descriptor;
+        assert components.contains(Component.DATA) : "Data component is missing for sstable
" + descriptor;
         assert components.contains(Component.PRIMARY_INDEX) : "Primary index component is
missing for sstable " + descriptor;
 
         Map<MetadataType, MetadataComponent> sstableMetadata = descriptor.getMetadataSerializer().deserialize(descriptor,
@@ -415,7 +415,7 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS
                                       boolean validate) throws IOException
     {
         // Minimum components without which we can't do anything
-        assert components.contains(Component.DATA) : "Data component is missing for sstable"
+ descriptor;
+        assert components.contains(Component.DATA) : "Data component is missing for sstable
" + descriptor;
         assert components.contains(Component.PRIMARY_INDEX) : "Primary index component is
missing for sstable " + descriptor;
 
         Map<MetadataType, MetadataComponent> sstableMetadata = descriptor.getMetadataSerializer().deserialize(descriptor,

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8b80b556/test/unit/org/apache/cassandra/MockSchema.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/MockSchema.java b/test/unit/org/apache/cassandra/MockSchema.java
index bc236e1..86593c2 100644
--- a/test/unit/org/apache/cassandra/MockSchema.java
+++ b/test/unit/org/apache/cassandra/MockSchema.java
@@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableSet;
 
 import org.apache.cassandra.cache.CachingOptions;
 import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.composites.SimpleSparseCellNameType;
@@ -44,6 +45,7 @@ import org.apache.cassandra.io.sstable.metadata.MetadataType;
 import org.apache.cassandra.io.sstable.metadata.StatsMetadata;
 import org.apache.cassandra.io.util.BufferedSegmentedFile;
 import org.apache.cassandra.io.util.ChannelProxy;
+import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.io.util.Memory;
 import org.apache.cassandra.io.util.SegmentedFile;
 import org.apache.cassandra.locator.SimpleStrategy;
@@ -164,4 +166,18 @@ public class MockSchema
             throw new RuntimeException(e);
         }
     }
+
+    public static void cleanup()
+    {
+        // clean up data directory which are stored as data directory/keyspace/data files
+        for (String dirName : DatabaseDescriptor.getAllDataFileLocations())
+        {
+            File dir = new File(dirName);
+            if (!dir.exists())
+                throw new RuntimeException("No such directory: " + dir.getAbsolutePath());
+            String[] children = dir.list();
+            for (String child : children)
+                FileUtils.deleteRecursive(new File(dir, child));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8b80b556/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java b/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java
index 1eef7b0..1859e70 100644
--- a/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java
+++ b/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java
@@ -30,6 +30,7 @@ import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import junit.framework.Assert;
@@ -70,10 +71,17 @@ public class TrackerTest
         }
     }
 
+    @BeforeClass
+    public static void setUp()
+    {
+        MockSchema.cleanup();
+    }
+
     @Test
     public void testTryModify()
     {
-        Tracker tracker = new Tracker(MockSchema.cfs, false);
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        Tracker tracker = new Tracker(cfs, false);
         List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0), MockSchema.sstable(1),
MockSchema.sstable(2));
         tracker.addInitialSSTables(copyOf(readers));
         try (LifecycleTransaction txn = tracker.tryModify(readers.get(0), OperationType.COMPACTION);)
@@ -151,7 +159,8 @@ public class TrackerTest
     {
         boolean backups = DatabaseDescriptor.isIncrementalBackupsEnabled();
         DatabaseDescriptor.setIncrementalBackupsEnabled(false);
-        Tracker tracker = new Tracker(MockSchema.cfs, false);
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        Tracker tracker = new Tracker(cfs, false);
         MockListener listener = new MockListener(false);
         tracker.subscribe(listener);
         List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0, 17), MockSchema.sstable(1,
121), MockSchema.sstable(2, 9));
@@ -162,7 +171,7 @@ public class TrackerTest
         for (SSTableReader reader : readers)
             Assert.assertTrue(reader.isDeleteNotificationSetup());
 
-        Assert.assertEquals(17 + 121 + 9, MockSchema.cfs.metric.liveDiskSpaceUsed.getCount());
+        Assert.assertEquals(17 + 121 + 9, cfs.metric.liveDiskSpaceUsed.getCount());
         Assert.assertEquals(3, listener.senders.size());
         Assert.assertEquals(tracker, listener.senders.get(0));
         Assert.assertTrue(listener.received.get(0) instanceof SSTableAddedNotification);
@@ -186,51 +195,58 @@ public class TrackerTest
         tracker.subscribe(listener);
         final List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0,
9, true), MockSchema.sstable(1, 15, true), MockSchema.sstable(2, 71, true));
         tracker.addInitialSSTables(copyOf(readers));
-        try (LifecycleTransaction txn = tracker.tryModify(readers.get(0), OperationType.COMPACTION);)
+
+        try
         {
             SSTableDeletingTask.pauseDeletions(true);
-            if (invalidate)
-                cfs.invalidate(false);
-            else
-                tracker.dropSSTables();
-            Assert.assertEquals(95, cfs.metric.totalDiskSpaceUsed.getCount());
-            Assert.assertEquals(9, cfs.metric.liveDiskSpaceUsed.getCount());
-            Assert.assertEquals(1, tracker.getView().sstables.size());
-            SSTableDeletingTask.pauseDeletions(false);
-        }
-        if (!invalidate)
-        {
-            Assert.assertEquals(1, tracker.getView().sstables.size());
-            Assert.assertEquals(readers.get(0), Iterables.getFirst(tracker.getView().sstables,
null));
-            Assert.assertEquals(1, readers.get(0).selfRef().globalCount());
-            Assert.assertFalse(readers.get(0).isMarkedCompacted());
-            for (SSTableReader reader : readers.subList(1, 3))
+            try (LifecycleTransaction txn = tracker.tryModify(readers.get(0), OperationType.COMPACTION))
             {
-                Assert.assertEquals(0, reader.selfRef().globalCount());
-                Assert.assertTrue(reader.isMarkedCompacted());
+                if (invalidate)
+                    cfs.invalidate(false);
+                else
+                    tracker.dropSSTables();
+                Assert.assertEquals(95, cfs.metric.totalDiskSpaceUsed.getCount());
+                Assert.assertEquals(9, cfs.metric.liveDiskSpaceUsed.getCount());
+                Assert.assertEquals(1, tracker.getView().sstables.size());
             }
-            Assert.assertNull(tracker.dropSSTables(new Predicate<SSTableReader>()
+            if (!invalidate)
             {
-                public boolean apply(SSTableReader reader)
+                Assert.assertEquals(1, tracker.getView().sstables.size());
+                Assert.assertEquals(readers.get(0), Iterables.getFirst(tracker.getView().sstables,
null));
+                Assert.assertEquals(1, readers.get(0).selfRef().globalCount());
+                Assert.assertFalse(readers.get(0).isMarkedCompacted());
+                for (SSTableReader reader : readers.subList(1, 3))
                 {
-                    return reader != readers.get(0);
+                    Assert.assertEquals(0, reader.selfRef().globalCount());
+                    Assert.assertTrue(reader.isMarkedCompacted());
                 }
-            }, OperationType.UNKNOWN, null));
-
-            Assert.assertEquals(1, tracker.getView().sstables.size());
-            Assert.assertEquals(1, listener.received.size());
-            Assert.assertEquals(tracker, listener.senders.get(0));
-            Assert.assertEquals(2, ((SSTableListChangedNotification) listener.received.get(0)).removed.size());
-            Assert.assertEquals(0, ((SSTableListChangedNotification) listener.received.get(0)).added.size());
-            Assert.assertEquals(9, cfs.metric.liveDiskSpaceUsed.getCount());
-            readers.get(0).selfRef().release();
+                Assert.assertNull(tracker.dropSSTables(new Predicate<SSTableReader>()
{
+                                                           public boolean apply(SSTableReader
reader)
+                                                           {
+                                                               return reader != readers.get(0);
+                                                           }
+                                                       },
+                                                       OperationType.UNKNOWN,
+                                                       null));
+                Assert.assertEquals(1, tracker.getView().sstables.size());
+                Assert.assertEquals(1, listener.received.size());
+                Assert.assertEquals(tracker, listener.senders.get(0));
+                Assert.assertEquals(2, ((SSTableListChangedNotification) listener.received.get(0)).removed.size());
+                Assert.assertEquals(0, ((SSTableListChangedNotification) listener.received.get(0)).added.size());
+                Assert.assertEquals(9, cfs.metric.liveDiskSpaceUsed.getCount());
+                readers.get(0).selfRef().release();
+            }
+            else
+            {
+                Assert.assertEquals(0, tracker.getView().sstables.size());
+                Assert.assertEquals(0, cfs.metric.liveDiskSpaceUsed.getCount());
+                for (SSTableReader reader : readers)
+                    Assert.assertTrue(reader.isMarkedCompacted());
+            }
         }
-        else
+        finally
         {
-            Assert.assertEquals(0, tracker.getView().sstables.size());
-            Assert.assertEquals(0, cfs.metric.liveDiskSpaceUsed.getCount());
-            for (SSTableReader reader : readers)
-                Assert.assertTrue(reader.isMarkedCompacted());
+            SSTableDeletingTask.pauseDeletions(false);
         }
     }
 


Mime
View raw message