From 3e06414b61dbfdfd8a05a80d4c591dff18ff5d5f Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 19 Jan 2010 21:23:08 +0000 Subject: [PATCH] expose failing test by moving it where other tests are not covering it up somehow. patch by jbellis git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@900964 13f79535-47bb-0310-9956-ffa450edef68 --- .../cassandra/db/CompactionsPurgeTest.java | 134 ++++++++++++++++++ .../apache/cassandra/db/CompactionsTest.java | 91 ------------ 2 files changed, 134 insertions(+), 91 deletions(-) create mode 100644 test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java diff --git a/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java b/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java new file mode 100644 index 0000000000..cef7444677 --- /dev/null +++ b/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java @@ -0,0 +1,134 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.cassandra.db; + +import java.io.IOException; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import org.junit.Test; + +import org.apache.cassandra.CleanupHelper; +import org.apache.cassandra.db.filter.IdentityQueryFilter; +import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.io.SSTableReader; +import org.apache.cassandra.utils.FBUtilities; + +import static junit.framework.Assert.assertEquals; + +public class CompactionsPurgeTest extends CleanupHelper +{ + public static final String TABLE1 = "Keyspace1"; + + @Test + public void testCompactionPurge() throws IOException, ExecutionException, InterruptedException + { + CompactionManager.instance.disableAutoCompaction(); + + Table table = Table.open(TABLE1); + String cfName = "Standard1"; + ColumnFamilyStore store = table.getColumnFamilyStore(cfName); + + String key = "key1"; + RowMutation rm; + + // inserts + rm = new RowMutation(TABLE1, key); + for (int i = 0; i < 10; i++) + { + rm.add(new QueryPath(cfName, null, String.valueOf(i).getBytes()), new byte[0], 0); + } + rm.apply(); + store.forceBlockingFlush(); + + // deletes + for (int i = 0; i < 10; i++) + { + rm = new RowMutation(TABLE1, key); + rm.delete(new QueryPath(cfName, null, String.valueOf(i).getBytes()), 1); + rm.apply(); + } + store.forceBlockingFlush(); + + // resurrect one column + rm = new RowMutation(TABLE1, key); + rm.add(new QueryPath(cfName, null, String.valueOf(5).getBytes()), new byte[0], 2); + rm.apply(); + store.forceBlockingFlush(); + + // verify that non-major compaction does no GC to ensure correctness (see CASSANDRA-604) + Collection sstablesIncomplete = store.getSSTables(); + rm = new RowMutation(TABLE1, key + "x"); + rm.add(new QueryPath(cfName, null, "0".getBytes()), new byte[0], 0); + rm.apply(); + store.forceBlockingFlush(); + CompactionManager.instance.doCompaction(store, sstablesIncomplete, CompactionManager.getDefaultGCBefore()); + ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); + assert cf.getColumnCount() == 10; + + // major compact and test that all columns but the resurrected one is completely gone + CompactionManager.instance.submitMajor(store, 0, Integer.MAX_VALUE).get(); + cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); + assert cf.getColumnCount() == 1; + assert cf.getColumn(String.valueOf(5).getBytes()) != null; + } + + @Test + public void testCompactionPurgeOneFile() throws IOException, ExecutionException, InterruptedException + { + CompactionManager.instance.disableAutoCompaction(); + + Table table = Table.open(TABLE1); + String cfName = "Standard2"; + ColumnFamilyStore store = table.getColumnFamilyStore(cfName); + + String key = "key1"; + RowMutation rm; + + // inserts + rm = new RowMutation(TABLE1, key); + for (int i = 0; i < 5; i++) + { + rm.add(new QueryPath(cfName, null, String.valueOf(i).getBytes()), new byte[0], 0); + } + rm.apply(); + + // deletes + for (int i = 0; i < 5; i++) + { + rm = new RowMutation(TABLE1, key); + rm.delete(new QueryPath(cfName, null, String.valueOf(i).getBytes()), 1); + rm.apply(); + } + store.forceBlockingFlush(); + + assert store.getSSTables().size() == 1 : store.getSSTables(); // inserts & deletes were in the same memtable -> only deletes in sstable + + // compact and test that the row is completely gone + CompactionManager.instance.submitMajor(store, 0, Integer.MAX_VALUE).get(); + assert store.getSSTables().isEmpty(); + ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); + assert cf == null : cf; + } +} \ No newline at end of file diff --git a/test/unit/org/apache/cassandra/db/CompactionsTest.java b/test/unit/org/apache/cassandra/db/CompactionsTest.java index 52aa04be05..7bc58f9555 100644 --- a/test/unit/org/apache/cassandra/db/CompactionsTest.java +++ b/test/unit/org/apache/cassandra/db/CompactionsTest.java @@ -77,97 +77,6 @@ public class CompactionsTest extends CleanupHelper assertEquals(inserted.size(), table.getColumnFamilyStore("Standard1").getKeyRange("", "", 10000).keys.size()); } - @Test - public void testCompactionPurge() throws IOException, ExecutionException, InterruptedException - { - CompactionManager.instance.disableAutoCompaction(); - - Table table = Table.open(TABLE1); - String cfName = "Standard1"; - ColumnFamilyStore store = table.getColumnFamilyStore(cfName); - - String key = "key1"; - RowMutation rm; - - // inserts - rm = new RowMutation(TABLE1, key); - for (int i = 0; i < 10; i++) - { - rm.add(new QueryPath(cfName, null, String.valueOf(i).getBytes()), new byte[0], 0); - } - rm.apply(); - store.forceBlockingFlush(); - - // deletes - for (int i = 0; i < 10; i++) - { - rm = new RowMutation(TABLE1, key); - rm.delete(new QueryPath(cfName, null, String.valueOf(i).getBytes()), 1); - rm.apply(); - } - store.forceBlockingFlush(); - - // resurrect one column - rm = new RowMutation(TABLE1, key); - rm.add(new QueryPath(cfName, null, String.valueOf(5).getBytes()), new byte[0], 2); - rm.apply(); - store.forceBlockingFlush(); - - // verify that non-major compaction does no GC to ensure correctness (see CASSANDRA-604) - Collection sstablesIncomplete = store.getSSTables(); - rm = new RowMutation(TABLE1, key + "x"); - rm.add(new QueryPath(cfName, null, "0".getBytes()), new byte[0], 0); - rm.apply(); - store.forceBlockingFlush(); - CompactionManager.instance.doCompaction(store, sstablesIncomplete, CompactionManager.getDefaultGCBefore()); - ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); - assert cf.getColumnCount() == 10; - - // major compact and test that all columns but the resurrected one is completely gone - CompactionManager.instance.submitMajor(store, 0, Integer.MAX_VALUE).get(); - cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); - assert cf.getColumnCount() == 1; - assert cf.getColumn(String.valueOf(5).getBytes()) != null; - } - - @Test - public void testCompactionPurgeOneFile() throws IOException, ExecutionException, InterruptedException - { - CompactionManager.instance.disableAutoCompaction(); - - Table table = Table.open(TABLE1); - String cfName = "Standard2"; - ColumnFamilyStore store = table.getColumnFamilyStore(cfName); - - String key = "key1"; - RowMutation rm; - - // inserts - rm = new RowMutation(TABLE1, key); - for (int i = 0; i < 5; i++) - { - rm.add(new QueryPath(cfName, null, String.valueOf(i).getBytes()), new byte[0], 0); - } - rm.apply(); - - // deletes - for (int i = 0; i < 5; i++) - { - rm = new RowMutation(TABLE1, key); - rm.delete(new QueryPath(cfName, null, String.valueOf(i).getBytes()), 1); - rm.apply(); - } - store.forceBlockingFlush(); - - assert store.getSSTables().size() == 1 : store.getSSTables(); // inserts & deletes were in the same memtable -> only deletes in sstable - - // compact and test that the row is completely gone - CompactionManager.instance.submitMajor(store, 0, Integer.MAX_VALUE).get(); - assert store.getSSTables().isEmpty(); - ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); - assert cf == null : cf; - } - @Test public void testCompactionReadonly() throws IOException, ExecutionException, InterruptedException {