cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [7/9] cassandra git commit: Do not reuse cfs in MockSchema
Date Wed, 03 Jun 2015 12:10:22 GMT
Do not reuse cfs in MockSchema

patch by stefania; reviewed by benedict for CASSANDRA-9537


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

Branch: refs/heads/cassandra-2.2
Commit: 99da210229b9ddab8ce46d0664c46fe92282c6e3
Parents: c1c7855
Author: stefania <stefania.alborghetti@datastax.com>
Authored: Wed Jun 3 13:07:21 2015 +0100
Committer: Benedict Elliott Smith <benedict@apache.org>
Committed: Wed Jun 3 13:07:21 2015 +0100

----------------------------------------------------------------------
 test/unit/org/apache/cassandra/MockSchema.java  | 21 +++-----
 .../cassandra/db/lifecycle/HelpersTest.java     |  7 ++-
 .../db/lifecycle/LifecycleTransactionTest.java  | 52 ++++++++++++--------
 .../cassandra/db/lifecycle/TrackerTest.java     | 24 ++++++---
 .../apache/cassandra/db/lifecycle/ViewTest.java | 24 +++++----
 5 files changed, 74 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/99da2102/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 86593c2..94313cd 100644
--- a/test/unit/org/apache/cassandra/MockSchema.java
+++ b/test/unit/org/apache/cassandra/MockSchema.java
@@ -62,38 +62,33 @@ public class MockSchema
     }
     private static final AtomicInteger id = new AtomicInteger();
     public static final Keyspace ks = Keyspace.mockKS(new KSMetaData("mockks", SimpleStrategy.class,
ImmutableMap.of("replication_factor", "1"), false));
-    public static final ColumnFamilyStore cfs = newCFS();
 
     private static final IndexSummary indexSummary;
     private static final SegmentedFile segmentedFile = new BufferedSegmentedFile(new ChannelProxy(temp("mocksegmentedfile")),
0);
 
-    public static Memtable memtable()
+    public static Memtable memtable(ColumnFamilyStore cfs)
     {
         return new Memtable(cfs.metadata);
     }
 
-    public static SSTableReader sstable(int generation)
+    public static SSTableReader sstable(int generation, ColumnFamilyStore cfs)
     {
-        return sstable(generation, false);
+        return sstable(generation, false, cfs);
     }
 
-    public static SSTableReader sstable(int generation, boolean keepRef)
+    public static SSTableReader sstable(int generation, boolean keepRef, ColumnFamilyStore
cfs)
     {
-        return sstable(generation, 0, keepRef);
+        return sstable(generation, 0, keepRef, cfs);
     }
 
-    public static SSTableReader sstable(int generation, int size)
+    public static SSTableReader sstable(int generation, int size, ColumnFamilyStore cfs)
     {
-        return sstable(generation, size, false);
+        return sstable(generation, size, false, cfs);
     }
 
-    public static SSTableReader sstable(int generation, int size, boolean keepRef)
-    {
-        return sstable(generation, size, keepRef, cfs);
-    }
     public static SSTableReader sstable(int generation, int size, boolean keepRef, ColumnFamilyStore
cfs)
     {
-        Descriptor descriptor = new Descriptor(temp("mockcfdir").getParentFile(), "mockks",
"mockcf", generation, Descriptor.Type.FINAL);
+        Descriptor descriptor = new Descriptor(temp("mockcfdir").getParentFile(), ks.getName(),
cfs.getColumnFamilyName(), generation, Descriptor.Type.FINAL);
         Set<Component> components = ImmutableSet.of(Component.DATA, Component.PRIMARY_INDEX,
Component.FILTER, Component.TOC);
         for (Component component : components)
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/99da2102/test/unit/org/apache/cassandra/db/lifecycle/HelpersTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/lifecycle/HelpersTest.java b/test/unit/org/apache/cassandra/db/lifecycle/HelpersTest.java
index d53a830..24d2bda 100644
--- a/test/unit/org/apache/cassandra/db/lifecycle/HelpersTest.java
+++ b/test/unit/org/apache/cassandra/db/lifecycle/HelpersTest.java
@@ -30,6 +30,7 @@ import org.junit.Test;
 import junit.framework.Assert;
 import org.apache.cassandra.MockSchema;
 import org.apache.cassandra.Util;
+import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.io.sstable.Descriptor;
 import org.apache.cassandra.io.sstable.format.SSTableReader;
 import org.apache.cassandra.io.sstable.format.big.BigTableReader;
@@ -135,7 +136,8 @@ public class HelpersTest
     @Test
     public void testSetupDeletionNotification()
     {
-        Iterable<SSTableReader> readers = Lists.newArrayList(MockSchema.sstable(1),
MockSchema.sstable(2));
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        Iterable<SSTableReader> readers = Lists.newArrayList(MockSchema.sstable(1,
cfs), MockSchema.sstable(2, cfs));
         Throwable accumulate = Helpers.setReplaced(readers, null);
         Assert.assertNull(accumulate);
         for (SSTableReader reader : readers)
@@ -147,7 +149,8 @@ public class HelpersTest
     @Test
     public void testMarkObsolete()
     {
-        Iterable<SSTableReader> readers = Lists.newArrayList(MockSchema.sstable(1),
MockSchema.sstable(2));
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        Iterable<SSTableReader> readers = Lists.newArrayList(MockSchema.sstable(1,
cfs), MockSchema.sstable(2, cfs));
         Throwable accumulate = Helpers.markObsolete(readers, null);
         Assert.assertNull(accumulate);
         for (SSTableReader reader : readers)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/99da2102/test/unit/org/apache/cassandra/db/lifecycle/LifecycleTransactionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/lifecycle/LifecycleTransactionTest.java b/test/unit/org/apache/cassandra/db/lifecycle/LifecycleTransactionTest.java
index 3153ef1..2c6c830 100644
--- a/test/unit/org/apache/cassandra/db/lifecycle/LifecycleTransactionTest.java
+++ b/test/unit/org/apache/cassandra/db/lifecycle/LifecycleTransactionTest.java
@@ -28,11 +28,13 @@ import org.junit.Test;
 import junit.framework.Assert;
 import org.apache.cassandra.MockSchema;
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.compaction.OperationType;
 import org.apache.cassandra.db.lifecycle.LifecycleTransaction.ReaderState;
 import org.apache.cassandra.db.lifecycle.LifecycleTransaction.ReaderState.Action;
 import org.apache.cassandra.io.sstable.SSTableDeletingTask;
 import org.apache.cassandra.io.sstable.format.SSTableReader;
+import org.apache.cassandra.metrics.ColumnFamilyMetrics;
 import org.apache.cassandra.utils.Pair;
 import org.apache.cassandra.utils.concurrent.AbstractTransactionalTest;
 import org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional.State;
@@ -66,10 +68,11 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
     @Test
     public void testUpdates() // (including obsoletion)
     {
+        ColumnFamilyStore cfs = MockSchema.newCFS();
         Tracker tracker = new Tracker(null, false);
-        SSTableReader[] readers = readersArray(0, 3);
-        SSTableReader[] readers2 = readersArray(0, 4);
-        SSTableReader[] readers3 = readersArray(0, 4);
+        SSTableReader[] readers = readersArray(0, 3, cfs);
+        SSTableReader[] readers2 = readersArray(0, 4, cfs);
+        SSTableReader[] readers3 = readersArray(0, 4, cfs);
         tracker.addInitialSSTables(copyOf(readers));
         LifecycleTransaction txn = tracker.tryModify(copyOf(readers), OperationType.UNKNOWN);
 
@@ -129,15 +132,16 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
     @Test
     public void testCancellation()
     {
+        ColumnFamilyStore cfs = MockSchema.newCFS();
         Tracker tracker = new Tracker(null, false);
-        List<SSTableReader> readers = readers(0, 3);
+        List<SSTableReader> readers = readers(0, 3, cfs);
         tracker.addInitialSSTables(readers);
         LifecycleTransaction txn = tracker.tryModify(readers, OperationType.UNKNOWN);
 
         SSTableReader cancel = readers.get(0);
-        SSTableReader update = readers(1, 2).get(0);
-        SSTableReader fresh = readers(3, 4).get(0);
-        SSTableReader notPresent = readers(4, 5).get(0);
+        SSTableReader update = readers(1, 2, cfs).get(0);
+        SSTableReader fresh = readers(3, 4,cfs).get(0);
+        SSTableReader notPresent = readers(4, 5, cfs).get(0);
 
         txn.cancel(cancel);
         txn.update(update, true);
@@ -172,8 +176,9 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
     @Test
     public void testSplit()
     {
+        ColumnFamilyStore cfs = MockSchema.newCFS();
         Tracker tracker = new Tracker(null, false);
-        List<SSTableReader> readers = readers(0, 3);
+        List<SSTableReader> readers = readers(0, 3, cfs);
         tracker.addInitialSSTables(readers);
         LifecycleTransaction txn = tracker.tryModify(readers, OperationType.UNKNOWN);
         LifecycleTransaction txn2 = txn.split(readers.subList(0, 1));
@@ -181,7 +186,7 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
         Assert.assertTrue(all(readers.subList(1, 3), in(txn.originals())));
         Assert.assertEquals(1, txn2.originals().size());
         Assert.assertTrue(all(readers.subList(0, 1), in(txn2.originals())));
-        txn.update(readers(1, 2).get(0), true);
+        txn.update(readers(1, 2, cfs).get(0), true);
         boolean failed = false;
         try
         {
@@ -255,21 +260,26 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
         final Tracker tracker;
         final LifecycleTransaction txn;
 
-        private static Tracker tracker(List<SSTableReader> readers)
+        private static Tracker tracker(ColumnFamilyStore cfs, List<SSTableReader> readers)
         {
-            Tracker tracker = new Tracker(MockSchema.cfs, false);
+            Tracker tracker = new Tracker(cfs, false);
             tracker.addInitialSSTables(readers);
             return tracker;
         }
 
         private TxnTest()
         {
-            this(readers(0, 8));
+            this(MockSchema.newCFS());
         }
 
-        private TxnTest(List<SSTableReader> readers)
+        private TxnTest(ColumnFamilyStore cfs)
         {
-            this(tracker(readers), readers);
+            this(cfs, readers(0, 8, cfs));
+        }
+
+        private TxnTest(ColumnFamilyStore cfs, List<SSTableReader> readers)
+        {
+            this(tracker(cfs, readers), readers);
         }
 
         private TxnTest(Tracker tracker, List<SSTableReader> readers)
@@ -283,11 +293,11 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
             this.tracker = tracker;
             this.originals = readers;
             this.txn = txn;
-            update(txn, loggedUpdate = readers(0, 2), true);
+            update(txn, loggedUpdate = readers(0, 2, tracker.cfstore), true);
             obsolete(txn, loggedObsolete = readers.subList(2, 4));
-            update(txn, loggedNew = readers(8, 10), false);
+            update(txn, loggedNew = readers(8, 10, tracker.cfstore), false);
             txn.checkpoint();
-            update(txn, stagedNew = readers(10, 12), false);
+            update(txn, stagedNew = readers(10, 12, tracker.cfstore), false);
             obsolete(txn, stagedObsolete = copyOf(concat(loggedUpdate, originals.subList(4,
6))));
             untouchedOriginals = originals.subList(6, 8);
         }
@@ -385,16 +395,16 @@ public class LifecycleTransactionTest extends AbstractTransactionalTest
         }
     }
 
-    private static SSTableReader[] readersArray(int lb, int ub)
+    private static SSTableReader[] readersArray(int lb, int ub, ColumnFamilyStore cfs)
     {
-        return readers(lb, ub).toArray(new SSTableReader[0]);
+        return readers(lb, ub, cfs).toArray(new SSTableReader[0]);
     }
 
-    private static List<SSTableReader> readers(int lb, int ub)
+    private static List<SSTableReader> readers(int lb, int ub, ColumnFamilyStore cfs)
     {
         List<SSTableReader> readers = new ArrayList<>();
         for (int i = lb ; i < ub ; i++)
-            readers.add(MockSchema.sstable(i, i, true));
+            readers.add(MockSchema.sstable(i, i, true, cfs));
         return copyOf(readers);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/99da2102/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 1859e70..0d46153 100644
--- a/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java
+++ b/test/unit/org/apache/cassandra/db/lifecycle/TrackerTest.java
@@ -82,7 +82,7 @@ public class TrackerTest
     {
         ColumnFamilyStore cfs = MockSchema.newCFS();
         Tracker tracker = new Tracker(cfs, false);
-        List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0), MockSchema.sstable(1),
MockSchema.sstable(2));
+        List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0, cfs),
MockSchema.sstable(1, cfs), MockSchema.sstable(2, cfs));
         tracker.addInitialSSTables(copyOf(readers));
         try (LifecycleTransaction txn = tracker.tryModify(readers.get(0), OperationType.COMPACTION);)
         {
@@ -101,8 +101,9 @@ public class TrackerTest
     @Test
     public void testApply()
     {
+        final ColumnFamilyStore cfs = MockSchema.newCFS();
         final Tracker tracker = new Tracker(null, false);
-        final View resultView = ViewTest.fakeView(0, 0);
+        final View resultView = ViewTest.fakeView(0, 0, cfs);
         final AtomicInteger count = new AtomicInteger();
         tracker.apply(new Predicate<View>()
         {
@@ -110,7 +111,7 @@ public class TrackerTest
             {
                 // confound the CAS by swapping the view, and check we retry
                 if (count.incrementAndGet() < 3)
-                    tracker.view.set(ViewTest.fakeView(0, 0));
+                    tracker.view.set(ViewTest.fakeView(0, 0, cfs));
                 return true;
             }
         }, new Function<View, View>()
@@ -143,7 +144,9 @@ public class TrackerTest
     {
         ColumnFamilyStore cfs = MockSchema.newCFS();
         Tracker tracker = new Tracker(cfs, false);
-        List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0, 17), MockSchema.sstable(1,
121), MockSchema.sstable(2, 9));
+        List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0, 17, cfs),
+                                                       MockSchema.sstable(1, 121, cfs),
+                                                       MockSchema.sstable(2, 9, cfs));
         tracker.addInitialSSTables(copyOf(readers));
 
         Assert.assertEquals(3, tracker.view.get().sstables.size());
@@ -163,7 +166,9 @@ public class TrackerTest
         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));
+        List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0, 17, cfs),
+                                                       MockSchema.sstable(1, 121, cfs),
+                                                       MockSchema.sstable(2, 9, cfs));
         tracker.addSSTables(copyOf(readers));
 
         Assert.assertEquals(3, tracker.view.get().sstables.size());
@@ -193,7 +198,9 @@ public class TrackerTest
         Tracker tracker = cfs.getTracker();
         MockListener listener = new MockListener(false);
         tracker.subscribe(listener);
-        final List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0,
9, true), MockSchema.sstable(1, 15, true), MockSchema.sstable(2, 71, true));
+        final List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0,
9, true, cfs),
+                                                             MockSchema.sstable(1, 15, true,
cfs),
+                                                             MockSchema.sstable(2, 71, true,
cfs));
         tracker.addInitialSSTables(copyOf(readers));
 
         try
@@ -321,7 +328,8 @@ public class TrackerTest
     @Test
     public void testNotifications()
     {
-        SSTableReader r1 = MockSchema.sstable(0), r2 = MockSchema.sstable(1);
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        SSTableReader r1 = MockSchema.sstable(0, cfs), r2 = MockSchema.sstable(1, cfs);
         Tracker tracker = new Tracker(null, false);
         MockListener listener = new MockListener(false);
         tracker.subscribe(listener);
@@ -338,7 +346,7 @@ public class TrackerTest
         tracker.notifySSTableRepairedStatusChanged(singleton(r1));
         Assert.assertEquals(singleton(r1), ((SSTableRepairStatusChanged) listener.received.get(0)).sstable);
         listener.received.clear();
-        Memtable memtable = MockSchema.memtable();
+        Memtable memtable = MockSchema.memtable(cfs);
         tracker.notifyRenewed(memtable);
         Assert.assertEquals(memtable, ((MemtableRenewedNotification) listener.received.get(0)).renewed);
         listener.received.clear();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/99da2102/test/unit/org/apache/cassandra/db/lifecycle/ViewTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/lifecycle/ViewTest.java b/test/unit/org/apache/cassandra/db/lifecycle/ViewTest.java
index 811e025..aa99fbd 100644
--- a/test/unit/org/apache/cassandra/db/lifecycle/ViewTest.java
+++ b/test/unit/org/apache/cassandra/db/lifecycle/ViewTest.java
@@ -30,6 +30,7 @@ import org.junit.Test;
 
 import junit.framework.Assert;
 import org.apache.cassandra.MockSchema;
+import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.Memtable;
 import org.apache.cassandra.db.RowPosition;
 import org.apache.cassandra.dht.AbstractBounds;
@@ -46,7 +47,8 @@ public class ViewTest
     @Test
     public void testSSTablesInBounds()
     {
-        View initialView = fakeView(0, 5);
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        View initialView = fakeView(0, 5, cfs);
         for (int i = 0 ; i < 5 ; i++)
         {
             for (int j = i ; j < 5 ; j++)
@@ -70,7 +72,8 @@ public class ViewTest
     @Test
     public void testCompaction()
     {
-        View initialView = fakeView(0, 5);
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        View initialView = fakeView(0, 5, cfs);
         View cur = initialView;
         List<SSTableReader> readers = ImmutableList.copyOf(initialView.sstables);
         Assert.assertTrue(View.permitCompacting(readers).apply(cur));
@@ -96,7 +99,7 @@ public class ViewTest
         testFailure(View.updateCompacting(copyOf(readers.subList(0, 1)), readers.subList(1,
2)), cur);
 
         // make equivalents of readers.subList(0, 3) that are different instances
-        SSTableReader r0 = MockSchema.sstable(0), r1 = MockSchema.sstable(1), r2 = MockSchema.sstable(2);
+        SSTableReader r0 = MockSchema.sstable(0, cfs), r1 = MockSchema.sstable(1, cfs), r2
= MockSchema.sstable(2, cfs);
         // attempt to mark compacting a version not in the live set
         testFailure(View.updateCompacting(emptySet(), of(r2)), cur);
         // update one compacting, one non-compacting, of the liveset to another instance
of the same readers;
@@ -138,17 +141,18 @@ public class ViewTest
     @Test
     public void testFlushing()
     {
-        View initialView = fakeView(1, 0);
+        ColumnFamilyStore cfs = MockSchema.newCFS();
+        View initialView = fakeView(1, 0, cfs);
         View cur = initialView;
         Memtable memtable1 = initialView.getCurrentMemtable();
-        Memtable memtable2 = MockSchema.memtable();
+        Memtable memtable2 = MockSchema.memtable(cfs);
 
         cur = View.switchMemtable(memtable2).apply(cur);
         Assert.assertEquals(2, cur.liveMemtables.size());
         Assert.assertEquals(memtable1, cur.liveMemtables.get(0));
         Assert.assertEquals(memtable2, cur.getCurrentMemtable());
 
-        Memtable memtable3 = MockSchema.memtable();
+        Memtable memtable3 = MockSchema.memtable(cfs);
         cur = View.switchMemtable(memtable3).apply(cur);
         Assert.assertEquals(3, cur.liveMemtables.size());
         Assert.assertEquals(0, cur.flushingMemtables.size());
@@ -179,7 +183,7 @@ public class ViewTest
         Assert.assertEquals(memtable1, cur.flushingMemtables.get(0));
         Assert.assertEquals(memtable3, cur.getCurrentMemtable());
 
-        SSTableReader sstable = MockSchema.sstable(1);
+        SSTableReader sstable = MockSchema.sstable(1, cfs);
         cur = View.replaceFlushed(memtable1, sstable).apply(cur);
         Assert.assertEquals(0, cur.flushingMemtables.size());
         Assert.assertEquals(1, cur.liveMemtables.size());
@@ -188,14 +192,14 @@ public class ViewTest
         Assert.assertEquals(sstable, cur.sstablesMap.get(sstable));
     }
 
-    static View fakeView(int memtableCount, int sstableCount)
+    static View fakeView(int memtableCount, int sstableCount, ColumnFamilyStore cfs)
     {
         List<Memtable> memtables = new ArrayList<>();
         List<SSTableReader> sstables = new ArrayList<>();
         for (int i = 0 ; i < memtableCount ; i++)
-            memtables.add(MockSchema.memtable());
+            memtables.add(MockSchema.memtable(cfs));
         for (int i = 0 ; i < sstableCount ; i++)
-            sstables.add(MockSchema.sstable(i));
+            sstables.add(MockSchema.sstable(i, cfs));
         return new View(ImmutableList.copyOf(memtables), Collections.<Memtable>emptyList(),
Helpers.identityMap(sstables),
                         Collections.<SSTableReader>emptySet(), SSTableIntervalTree.build(sstables));
     }


Mime
View raw message