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
This commit is contained in:
Jonathan Ellis 2009-12-29 23:40:44 +00:00
parent 433a0f9089
commit c8def03073
9 changed files with 37 additions and 48 deletions

View File

@ -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);
}
}

View File

@ -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
{

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();
}