From c8def03073e7098faa9a4a5de4efa8958af4416e Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 29 Dec 2009 23:40:44 +0000 Subject: [PATCH] extend cleanuphelper in more places, and make cleanuphelper stricter about cleaning out old data. fixes test heisenbugs. patch by jbellis git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@894517 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/cassandra/CleanupHelper.java | 42 +++++++------------ .../cassandra/db/OneCompactionTest.java | 3 +- .../cassandra/db/RemoveColumnFamilyTest.java | 3 +- .../db/RemoveColumnFamilyWithFlush1Test.java | 3 +- .../db/RemoveColumnFamilyWithFlush2Test.java | 3 +- .../apache/cassandra/db/RemoveColumnTest.java | 3 +- .../cassandra/db/RemoveSubColumnTest.java | 3 +- .../cassandra/db/RemoveSuperColumnTest.java | 3 +- .../service/AntiEntropyServiceTest.java | 22 ++++------ 9 files changed, 37 insertions(+), 48 deletions(-) diff --git a/test/unit/org/apache/cassandra/CleanupHelper.java b/test/unit/org/apache/cassandra/CleanupHelper.java index e3cde8d8e7..df835de223 100644 --- a/test/unit/org/apache/cassandra/CleanupHelper.java +++ b/test/unit/org/apache/cassandra/CleanupHelper.java @@ -24,6 +24,8 @@ import java.io.IOException; import org.junit.BeforeClass; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.io.util.FileUtils; + import org.apache.log4j.Logger; public class CleanupHelper @@ -31,25 +33,19 @@ public class CleanupHelper private static Logger logger = Logger.getLogger(CleanupHelper.class); @BeforeClass - public static void cleanupAndLeaveDirs() + public static void cleanupAndLeaveDirs() throws IOException { mkdirs(); cleanup(); mkdirs(); } - public static void cleanup() + public static void cleanup() throws IOException { - // we clean the fs twice, once to start with (so old data files don't get stored by anything static if this is the first run) - // and once after flushing stuff (to try to clean things out if it is not.) part #2 seems to be less than perfect. + // clean up commitlog String[] directoryNames = { DatabaseDescriptor.getLogFileLocation(), }; - - // try to delete the directories themselves too. don't panic if this fails. it probably means that the process - // doesn't have permissions to do so, or it contains non-cassandra generated files that were intentionally - // put there. - for (String dirName : directoryNames) { File dir = new File(dirName); @@ -59,17 +55,12 @@ public class CleanupHelper } for (File f : dir.listFiles()) { - if (!f.delete()) - { - logger.error("could not delete " + f); - } + FileUtils.deleteWithConfirm(f); } - - if (!dir.delete()) - logger.warn("could not delete " + dir.getPath()); + FileUtils.deleteWithConfirm(dir); } - // cleanup data directory which are stored as data directory/table/data files + // clean up data directory which are stored as data directory/table/data files for (String dirName : DatabaseDescriptor.getAllDataFileLocations()) { File dir = new File(dirName); @@ -80,19 +71,16 @@ public class CleanupHelper for (File tableFile : dir.listFiles()) { // table directory - if (tableFile.isDirectory()) { - for (File dataFile : tableFile.listFiles()) { - if (!dataFile.delete()) { - logger.error("could not delete " + dataFile); - } + if (tableFile.isDirectory()) + { + for (File dataFile : tableFile.listFiles()) + { + FileUtils.deleteWithConfirm(dataFile); } } - if (!tableFile.delete()) - logger.warn("could not delete " + dir.getPath()); + FileUtils.deleteWithConfirm(tableFile); } - - if (!dir.delete()) - logger.warn("could not delete " + dir.getPath()); + FileUtils.deleteWithConfirm(dir); } } diff --git a/test/unit/org/apache/cassandra/db/OneCompactionTest.java b/test/unit/org/apache/cassandra/db/OneCompactionTest.java index b53e0fbe5d..1b310442ad 100644 --- a/test/unit/org/apache/cassandra/db/OneCompactionTest.java +++ b/test/unit/org/apache/cassandra/db/OneCompactionTest.java @@ -28,8 +28,9 @@ import org.junit.Test; import static junit.framework.Assert.assertEquals; import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.CleanupHelper; -public class OneCompactionTest +public class OneCompactionTest extends CleanupHelper { private void testCompaction(String columnFamilyName, int insertsPerTable) throws IOException, ExecutionException, InterruptedException { diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java index 35efad195e..7cc940d8c7 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java @@ -26,8 +26,9 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.IdentityQueryFilter; import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.CleanupHelper; -public class RemoveColumnFamilyTest +public class RemoveColumnFamilyTest extends CleanupHelper { @Test public void testRemoveColumnFamily() throws IOException, ExecutionException, InterruptedException diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java index 423ad5ad20..512d2d3793 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java @@ -26,8 +26,9 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.IdentityQueryFilter; import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.CleanupHelper; -public class RemoveColumnFamilyWithFlush1Test +public class RemoveColumnFamilyWithFlush1Test extends CleanupHelper { @Test public void testRemoveColumnFamilyWithFlush1() throws IOException, ExecutionException, InterruptedException diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java index 74220bdabd..f1a08d9ec3 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java @@ -26,8 +26,9 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.IdentityQueryFilter; import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.CleanupHelper; -public class RemoveColumnFamilyWithFlush2Test +public class RemoveColumnFamilyWithFlush2Test extends CleanupHelper { @Test public void testRemoveColumnFamilyWithFlush2() throws IOException, ExecutionException, InterruptedException diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveColumnTest.java index dcc9093169..31ae44f9e1 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnTest.java @@ -27,8 +27,9 @@ import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.IdentityQueryFilter; import org.apache.cassandra.db.filter.NamesQueryFilter; import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.CleanupHelper; -public class RemoveColumnTest +public class RemoveColumnTest extends CleanupHelper { @Test public void testRemoveColumn() throws IOException, ExecutionException, InterruptedException diff --git a/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java index a2e3e61b9c..2f7175754f 100644 --- a/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java @@ -28,8 +28,9 @@ import org.apache.cassandra.db.filter.IdentityQueryFilter; import org.apache.cassandra.db.filter.QueryPath; import static org.apache.cassandra.Util.addMutation; import static org.apache.cassandra.Util.getBytes; +import org.apache.cassandra.CleanupHelper; -public class RemoveSubColumnTest +public class RemoveSubColumnTest extends CleanupHelper { @Test public void testRemoveSubColumn() throws IOException, ExecutionException, InterruptedException diff --git a/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java index e51167d834..18b0942e2d 100644 --- a/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java @@ -33,9 +33,10 @@ import org.apache.cassandra.db.filter.QueryPath; import static org.apache.cassandra.Util.addMutation; import static org.apache.cassandra.Util.getBytes; import org.apache.cassandra.Util; +import org.apache.cassandra.CleanupHelper; import static junit.framework.Assert.assertNotNull; -public class RemoveSuperColumnTest +public class RemoveSuperColumnTest extends CleanupHelper { @Test public void testRemoveSuperColumn() throws IOException, ExecutionException, InterruptedException diff --git a/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java b/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java index dd067670ea..e48968a6a5 100644 --- a/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java +++ b/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java @@ -45,19 +45,21 @@ import static org.junit.Assert.*; public class AntiEntropyServiceTest extends CleanupHelper { - public static InetAddress LOCAL = FBUtilities.getLocalAddress(); - // table and column family to test against public AntiEntropyService aes; public static String tablename; public static String cfname; - public static InetAddress REMOTE; + public static InetAddress LOCAL, REMOTE; - static + private static boolean initialized; + + @Before + public void prepare() throws Exception { - try + if (!initialized) { + LOCAL = FBUtilities.getLocalAddress(); // bump the replication factor so that local overlaps with REMOTE below DatabaseDescriptorTest.setReplicationFactor(2); @@ -71,16 +73,8 @@ public class AntiEntropyServiceTest extends CleanupHelper tablename = DatabaseDescriptor.getTables().get(0); cfname = Table.open(tablename).getColumnFamilies().iterator().next(); + initialized = true; } - catch(Exception e) - { - throw new RuntimeException(e); - } - } - - @Before - public void prepare() throws Exception - { aes = AntiEntropyService.instance(); }