From 5e2985f10e261eb9d48b49d57c9d4bfce249f6fe Mon Sep 17 00:00:00 2001 From: Derek Chen-Becker Date: Mon, 14 Aug 2023 22:32:29 -0600 Subject: [PATCH] Ensure unit tests honor tmp.dir Modify unit tests so that any files created are rooted in the directory specified by the "tmp.dir" Ant property. Ant already passes the value of tmp.dir to the JVM's java.io.tmpdir parameter, so the primary changes are to make use of Files.createTempDirectory to generate per-test work directories. Also update the test checkstyle rules to catch any future usage of hardcoded "/tmp". Patch by Derek Chen-Becker; reviewed by bereng and brandonwilliams for CASSANDRA-18750 --- .build/checkstyle_test.xml | 7 +++ build.xml | 7 ++- .../cassandra/audit/AuditLoggerTest.java | 59 +++++++++++-------- .../apache/cassandra/db/DirectoriesTest.java | 20 ++++--- .../cassandra/db/DiskBoundaryManagerTest.java | 21 ++++--- .../org/apache/cassandra/db/ImportTest.java | 8 ++- .../writers/CompactionAwareWriterTest.java | 25 +++++--- .../cassandra/fql/FullQueryLoggerTest.java | 7 ++- .../cassandra/io/sstable/DescriptorTest.java | 52 ++++++++-------- .../io/sstable/SSTableReaderTest.java | 4 +- .../cassandra/io/util/FileUtilsTest.java | 10 ++-- .../cassandra/service/StartupChecksTest.java | 2 +- 12 files changed, 137 insertions(+), 85 deletions(-) diff --git a/.build/checkstyle_test.xml b/.build/checkstyle_test.xml index 96de3d548d..5b6e16e8b2 100644 --- a/.build/checkstyle_test.xml +++ b/.build/checkstyle_test.xml @@ -59,6 +59,13 @@ + + + + + + + diff --git a/build.xml b/build.xml index 8d9b8f5516..c639748150 100644 --- a/build.xml +++ b/build.xml @@ -81,7 +81,10 @@ - + + + @@ -402,6 +405,7 @@ + @@ -1532,6 +1536,7 @@ + diff --git a/test/unit/org/apache/cassandra/audit/AuditLoggerTest.java b/test/unit/org/apache/cassandra/audit/AuditLoggerTest.java index 1ee66f7340..6801cfa6da 100644 --- a/test/unit/org/apache/cassandra/audit/AuditLoggerTest.java +++ b/test/unit/org/apache/cassandra/audit/AuditLoggerTest.java @@ -59,9 +59,9 @@ import static org.junit.Assert.fail; public class AuditLoggerTest extends CQLTester { @BeforeClass - public static void setUp() + public static void setUp() throws IOException { - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.enabled = true; options.logger = new ParameterizedClass("InMemoryAuditLogger", null); DatabaseDescriptor.setAuditLoggingOptions(options); @@ -69,7 +69,7 @@ public class AuditLoggerTest extends CQLTester } @Before - public void beforeTestMethod() + public void beforeTestMethod() throws IOException { AuditLogOptions options = new AuditLogOptions(); enableAuditLogOptions(options); @@ -81,7 +81,20 @@ public class AuditLoggerTest extends CQLTester disableAuditLogOptions(); } - private void enableAuditLogOptions(AuditLogOptions options) + /** + Create a new AuditLogOptions instance with the log dir set appropriately to a temp dir for unit testing. + */ + private static AuditLogOptions getBaseAuditLogOptions() throws IOException { + AuditLogOptions options = new AuditLogOptions(); + + // Ensure that we create a new audit log directory to separate outputs + Path tmpDir = Files.createTempDirectory("AuditLoggerTest"); + options.audit_logs_dir = tmpDir.toString(); + + return options; + } + + private void enableAuditLogOptions(AuditLogOptions options) throws IOException { String loggerName = "InMemoryAuditLogger"; String includedKeyspaces = options.included_keyspaces; @@ -106,7 +119,7 @@ public class AuditLoggerTest extends CQLTester execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra"); execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test"); - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.excluded_keyspaces += ',' + KEYSPACE; enableAuditLogOptions(options); @@ -114,7 +127,7 @@ public class AuditLoggerTest extends CQLTester ResultSet rs = executeAndAssertNoAuditLog(cql, 1); assertEquals(1, rs.all().size()); - options = new AuditLogOptions(); + options = getBaseAuditLogOptions(); options.included_keyspaces = KEYSPACE; enableAuditLogOptions(options); @@ -122,7 +135,7 @@ public class AuditLoggerTest extends CQLTester rs = executeAndAssertWithPrepare(cql, AuditLogEntryType.SELECT, 1); assertEquals(1, rs.all().size()); - options = new AuditLogOptions(); + options = getBaseAuditLogOptions(); options.included_keyspaces = KEYSPACE; options.excluded_keyspaces += ',' + KEYSPACE; enableAuditLogOptions(options); @@ -131,7 +144,7 @@ public class AuditLoggerTest extends CQLTester rs = executeAndAssertNoAuditLog(cql, 1); assertEquals(1, rs.all().size()); - options = new AuditLogOptions(); + options = getBaseAuditLogOptions(); enableAuditLogOptions(options); cql = "SELECT id, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE id = ?"; @@ -146,7 +159,7 @@ public class AuditLoggerTest extends CQLTester execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra"); execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test"); - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.excluded_keyspaces += ',' + KEYSPACE; enableAuditLogOptions(options); @@ -163,7 +176,7 @@ public class AuditLoggerTest extends CQLTester rs = executeAndAssertDisableAuditLog(cql, 1); assertEquals(1, rs.all().size()); - options = new AuditLogOptions(); + options = getBaseAuditLogOptions(); options.included_keyspaces = KEYSPACE; options.excluded_keyspaces += ',' + KEYSPACE; enableAuditLogOptions(options); @@ -180,9 +193,9 @@ public class AuditLoggerTest extends CQLTester } @Test - public void testAuditLogExceptions() + public void testAuditLogExceptions() throws IOException { - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.excluded_keyspaces += ',' + KEYSPACE; enableAuditLogOptions(options); Assert.assertTrue(AuditLogManager.instance.isEnabled()); @@ -196,7 +209,7 @@ public class AuditLoggerTest extends CQLTester execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra"); execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test"); - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.excluded_categories = "QUERY"; options.included_categories = "QUERY,DML,PREPARE"; enableAuditLogOptions(options); @@ -619,7 +632,7 @@ public class AuditLoggerTest extends CQLTester @Test public void testIncludeSystemKeyspaces() throws Throwable { - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.included_categories = "QUERY,DML,PREPARE"; options.excluded_keyspaces = "system_schema,system_virtual_schema"; enableAuditLogOptions(options); @@ -637,7 +650,7 @@ public class AuditLoggerTest extends CQLTester @Test public void testExcludeSystemKeyspaces() throws Throwable { - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); options.included_categories = "QUERY,DML,PREPARE"; options.excluded_keyspaces = "system,system_schema,system_virtual_schema"; enableAuditLogOptions(options); @@ -655,7 +668,7 @@ public class AuditLoggerTest extends CQLTester disableAuditLogOptions(); assertEquals(0, QueryEvents.instance.listenerCount()); assertEquals(0, AuthEvents.instance.listenerCount()); - enableAuditLogOptions(new AuditLogOptions()); + enableAuditLogOptions(getBaseAuditLogOptions()); assertEquals(1, QueryEvents.instance.listenerCount()); assertEquals(1, AuthEvents.instance.listenerCount()); @@ -673,10 +686,10 @@ public class AuditLoggerTest extends CQLTester } @Test - public void testConflictingPaths() + public void testConflictingPaths() throws IOException { disableAuditLogOptions(); - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); DatabaseDescriptor.setAuditLoggingOptions(options); StorageService.instance.enableAuditLog(null, null, options.included_keyspaces, options.excluded_keyspaces, options.included_categories, options.excluded_categories, options.included_users, options.excluded_users); try @@ -696,10 +709,10 @@ public class AuditLoggerTest extends CQLTester @Test - public void testConflictingPathsFQLFirst() + public void testConflictingPathsFQLFirst() throws IOException { disableAuditLogOptions(); - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); DatabaseDescriptor.setAuditLoggingOptions(options); StorageService.instance.enableFullQueryLogger(options.audit_logs_dir, RollCycles.HOURLY.toString(), false, 1000, 1000, null, 0); try @@ -718,10 +731,10 @@ public class AuditLoggerTest extends CQLTester } @Test - public void testJMXArchiveCommand() + public void testJMXArchiveCommand() throws IOException { disableAuditLogOptions(); - AuditLogOptions options = new AuditLogOptions(); + AuditLogOptions options = getBaseAuditLogOptions(); try { @@ -736,7 +749,7 @@ public class AuditLoggerTest extends CQLTester } options.archive_command = "/xyz/not/null"; - options.audit_logs_dir = "/tmp/abc"; + DatabaseDescriptor.setAuditLoggingOptions(options); StorageService.instance.enableAuditLog("BinAuditLogger", Collections.emptyMap(), "", "", "", "", "", "", 10, true, options.roll_cycle, diff --git a/test/unit/org/apache/cassandra/db/DirectoriesTest.java b/test/unit/org/apache/cassandra/db/DirectoriesTest.java index c701516d1e..09dea6e65c 100644 --- a/test/unit/org/apache/cassandra/db/DirectoriesTest.java +++ b/test/unit/org/apache/cassandra/db/DirectoriesTest.java @@ -705,12 +705,14 @@ public class DirectoriesTest } @Test - public void testGetLocationForDisk() + public void testGetLocationForDisk() throws IOException { Collection paths = new ArrayList<>(); - paths.add(new DataDirectory(new File("/tmp/aaa"))); - paths.add(new DataDirectory(new File("/tmp/aa"))); - paths.add(new DataDirectory(new File("/tmp/a"))); + + Path tmpDir = Files.createTempDirectory("testGetLocationForDisk"); + paths.add(new DataDirectory(tmpDir.resolve("aaa"))); + paths.add(new DataDirectory(tmpDir.resolve("aa"))); + paths.add(new DataDirectory(tmpDir.resolve("a"))); for (TableMetadata cfm : CFM) { @@ -745,12 +747,14 @@ public class DirectoriesTest } @Test - public void getDataDirectoryForFile() + public void getDataDirectoryForFile() throws IOException { Collection paths = new ArrayList<>(); - paths.add(new DataDirectory("/tmp/a")); - paths.add(new DataDirectory("/tmp/aa")); - paths.add(new DataDirectory("/tmp/aaa")); + + Path tmpDir = Files.createTempDirectory("getDataDirectoryForFile"); + paths.add(new DataDirectory(tmpDir.resolve("a"))); + paths.add(new DataDirectory(tmpDir.resolve("aa"))); + paths.add(new DataDirectory(tmpDir.resolve("aaa"))); for (TableMetadata cfm : CFM) { diff --git a/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java b/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java index cdf9a9ad97..518f8c5c44 100644 --- a/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java +++ b/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java @@ -18,7 +18,10 @@ package org.apache.cassandra.db; +import java.io.IOException; import java.net.UnknownHostException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import com.google.common.collect.Lists; @@ -45,17 +48,21 @@ public class DiskBoundaryManagerTest extends CQLTester private DiskBoundaryManager dbm; private MockCFS mock; private Directories dirs; + private List datadirs; + private Path tmpDir; @Before - public void setup() + public void setup() throws IOException { DisallowedDirectories.clearUnwritableUnsafe(); TokenMetadata metadata = StorageService.instance.getTokenMetadata(); metadata.updateNormalTokens(BootStrapper.getRandomTokens(metadata, 10), FBUtilities.getBroadcastAddressAndPort()); createTable("create table %s (id int primary key, x text)"); - dirs = new Directories(getCurrentColumnFamilyStore().metadata(), Lists.newArrayList(new Directories.DataDirectory(new File("/tmp/1")), - new Directories.DataDirectory(new File("/tmp/2")), - new Directories.DataDirectory(new File("/tmp/3")))); + tmpDir = Files.createTempDirectory("DiskBoundaryManagerTest"); + datadirs = Lists.newArrayList(new Directories.DataDirectory(new File(tmpDir, "1")), + new Directories.DataDirectory(new File(tmpDir, "2")), + new Directories.DataDirectory(new File(tmpDir, "3"))); + dirs = new Directories(getCurrentColumnFamilyStore().metadata(), datadirs); mock = new MockCFS(getCurrentColumnFamilyStore(), dirs); dbm = mock.diskBoundaryManager; } @@ -74,11 +81,11 @@ public class DiskBoundaryManagerTest extends CQLTester DiskBoundaries dbv = dbm.getDiskBoundaries(mock); Assert.assertEquals(3, dbv.positions.size()); assertEquals(dbv.directories, dirs.getWriteableLocations()); - DisallowedDirectories.maybeMarkUnwritable(new File("/tmp/3")); + DisallowedDirectories.maybeMarkUnwritable(new File(tmpDir, "3")); dbv = dbm.getDiskBoundaries(mock); Assert.assertEquals(2, dbv.positions.size()); - Assert.assertEquals(Lists.newArrayList(new Directories.DataDirectory(new File("/tmp/1")), - new Directories.DataDirectory(new File("/tmp/2"))), + Assert.assertEquals(Lists.newArrayList(new Directories.DataDirectory(new File(tmpDir, "1")), + new Directories.DataDirectory(new File(tmpDir, "2"))), dbv.directories); } diff --git a/test/unit/org/apache/cassandra/db/ImportTest.java b/test/unit/org/apache/cassandra/db/ImportTest.java index ff843fac41..8244ff67e7 100644 --- a/test/unit/org/apache/cassandra/db/ImportTest.java +++ b/test/unit/org/apache/cassandra/db/ImportTest.java @@ -283,9 +283,11 @@ public class ImportTest extends CQLTester getCurrentColumnFamilyStore().clearUnsafe(); File dir = moveToBackupDir(toMove); - Directories dirs = new Directories(getCurrentColumnFamilyStore().metadata(), Lists.newArrayList(new Directories.DataDirectory(new File("/tmp/1")), - new Directories.DataDirectory(new File("/tmp/2")), - new Directories.DataDirectory(new File("/tmp/3")))); + Path tmpDir = Files.createTempDirectory("ImportTest"); + + Directories dirs = new Directories(getCurrentColumnFamilyStore().metadata(), Lists.newArrayList(new Directories.DataDirectory(new File(tmpDir, "1")), + new Directories.DataDirectory(new File(tmpDir, "2")), + new Directories.DataDirectory(new File(tmpDir, "3")))); MockCFS mock = new MockCFS(getCurrentColumnFamilyStore(), dirs); SSTableImporter importer = new SSTableImporter(mock); diff --git a/test/unit/org/apache/cassandra/db/compaction/writers/CompactionAwareWriterTest.java b/test/unit/org/apache/cassandra/db/compaction/writers/CompactionAwareWriterTest.java index a641be1b53..0540ac7fcc 100644 --- a/test/unit/org/apache/cassandra/db/compaction/writers/CompactionAwareWriterTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/writers/CompactionAwareWriterTest.java @@ -17,8 +17,17 @@ */ package org.apache.cassandra.db.compaction.writers; +import java.io.IOException; import java.nio.ByteBuffer; -import java.util.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; import com.google.common.primitives.Longs; import org.junit.*; @@ -169,15 +178,17 @@ public class CompactionAwareWriterTest extends CQLTester } @Test - public void testMultiDatadirCheck() + public void testMultiDatadirCheck() throws IOException { createTable("create table %s (id int primary key)"); + Path tmpDir = Files.createTempDirectory("testMultiDatadirCheck"); + Directories.DataDirectory [] dataDirs = new Directories.DataDirectory[] { - new MockDataDirectory(new File("/tmp/1")), - new MockDataDirectory(new File("/tmp/2")), - new MockDataDirectory(new File("/tmp/3")), - new MockDataDirectory(new File("/tmp/4")), - new MockDataDirectory(new File("/tmp/5")) + new MockDataDirectory(new File(tmpDir, "1")), + new MockDataDirectory(new File(tmpDir, "2")), + new MockDataDirectory(new File(tmpDir, "3")), + new MockDataDirectory(new File(tmpDir, "4")), + new MockDataDirectory(new File(tmpDir, "5")) }; Set sstables = new HashSet<>(); for (int i = 0; i < 100; i++) diff --git a/test/unit/org/apache/cassandra/fql/FullQueryLoggerTest.java b/test/unit/org/apache/cassandra/fql/FullQueryLoggerTest.java index 799484fc92..51f7fb89dd 100644 --- a/test/unit/org/apache/cassandra/fql/FullQueryLoggerTest.java +++ b/test/unit/org/apache/cassandra/fql/FullQueryLoggerTest.java @@ -17,7 +17,9 @@ */ package org.apache.cassandra.fql; +import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -674,7 +676,7 @@ public class FullQueryLoggerTest extends CQLTester } @Test - public void testJMXArchiveCommand() + public void testJMXArchiveCommand() throws IOException { FullQueryLoggerOptions options = new FullQueryLoggerOptions(); @@ -691,7 +693,8 @@ public class FullQueryLoggerTest extends CQLTester options.allow_nodetool_archive_command = true; options.archive_command = "/xyz/not/null"; - options.log_dir = "/tmp/abc"; + Path tmpDir = Files.createTempDirectory("FullQueryLoggerTest"); + options.log_dir = tmpDir.resolve("abc").toString(); DatabaseDescriptor.setFullQueryLogOptions(options); StorageService.instance.enableFullQueryLogger(options.log_dir, options.roll_cycle, false, 1000, 1000, null, 0); assertTrue(FullQueryLogger.instance.isEnabled()); diff --git a/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java b/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java index 405f3da4f3..e6645d6158 100644 --- a/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java @@ -247,42 +247,42 @@ public class DescriptorTest testKeyspaceTableParsing(filePathsWithBackupsKeyspaceAndTableWithIndices, "backups", "backups.index"); String[] outsideOfCassandra = new String[]{ - "/tmp/some/path/tests/keyspace/table-3424234234234/na-1-big-Index.db", - "/tmp/some/path/tests/keyspace/table-3424234234234/snapshots/snapshots/na-1-big-Index.db", - "/tmp/some/path/tests/keyspace/table-3424234234234/backups/na-1-big-Index.db", - "/tmp/tests/keyspace/table-3424234234234/na-1-big-Index.db", - "/keyspace/table-3424234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/keyspace/table-3424234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/keyspace/table-3424234234234/snapshots/snapshots/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/keyspace/table-3424234234234/backups/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/tests/keyspace/table-3424234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/keyspace/table-3424234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db" + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/na-1-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/snapshots/snapshots/na-1-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/backups/na-1-big-Index.db", + "/testroot/tests/keyspace/table-34234234234234234234234234234234/na-1-big-Index.db", + "/keyspace/table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/snapshots/snapshots/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/backups/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/tests/keyspace/table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/keyspace/table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db" }; testKeyspaceTableParsing(outsideOfCassandra, "keyspace", "table"); String[] outsideOfCassandraUppercaseKeyspaceAndTable = new String[]{ - "/tmp/some/path/tests/Keyspace/Table-23424324234234/na-1-big-Index.db", - "/tmp/some/path/tests/Keyspace/Table-23424324234234/snapshots/snapshots/na-1-big-Index.db", - "/tmp/some/path/tests/Keyspace/Table-23424324234234/backups/na-1-big-Index.db", - "/tmp/tests/Keyspace/Table-23424324234234/na-1-big-Index.db", - "/Keyspace/Table-23424324234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/Keyspace/Table-23424324234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/Keyspace/Table-23424324234234/snapshots/snapshots/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/Keyspace/Table-23424324234234/backups/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/tests/Keyspace/Table-23424324234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/Keyspace/Table-23424324234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db" + "/testroot/some/path/tests/Keyspace/Table-34234234234234234234234234234234/na-1-big-Index.db", + "/testroot/some/path/tests/Keyspace/Table-34234234234234234234234234234234/snapshots/snapshots/na-1-big-Index.db", + "/testroot/some/path/tests/Keyspace/Table-34234234234234234234234234234234/backups/na-1-big-Index.db", + "/testroot/tests/Keyspace/Table-34234234234234234234234234234234/na-1-big-Index.db", + "/Keyspace/Table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/Keyspace/Table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/Keyspace/Table-34234234234234234234234234234234/snapshots/snapshots/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/Keyspace/Table-34234234234234234234234234234234/backups/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/tests/Keyspace/Table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/Keyspace/Table-34234234234234234234234234234234/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db" }; testKeyspaceTableParsing(outsideOfCassandraUppercaseKeyspaceAndTable, "Keyspace", "Table"); String[] outsideOfCassandraIndexes = new String[]{ - "/tmp/some/path/tests/keyspace/table-32423423423423/.index/na-1-big-Index.db", - "/tmp/some/path/tests/keyspace/table-32423423423423/snapshots/snapshots/.index/na-1-big-Index.db", - "/tmp/some/path/tests/keyspace/table-32423423423423/backups/.index/na-1-big-Index.db", - "/tmp/some/path/tests/keyspace/table-32423423423423/.index/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/keyspace/table-32423423423423/snapshots/snapshots/.index/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", - "/tmp/some/path/tests/keyspace/table-32423423423423/backups/.index/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db" + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/.index/na-1-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/snapshots/snapshots/.index/na-1-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/backups/.index/na-1-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/.index/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/snapshots/snapshots/.index/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db", + "/testroot/some/path/tests/keyspace/table-34234234234234234234234234234234/backups/.index/nb-3g1m_0nuf_3vj5m2k1125165rxa7-big-Index.db" }; testKeyspaceTableParsing(outsideOfCassandraIndexes, "keyspace", "table.index"); diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java index f064f19fd9..eaae045dea 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java @@ -752,7 +752,7 @@ public class SSTableReaderTest Keyspace keyspace = Keyspace.open(KEYSPACE1); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD); SSTableReader sstable = getNewSSTable(cfs); - Descriptor notLiveDesc = new Descriptor(new File("/tmp"), "", "", SSTableIdFactory.instance.defaultBuilder().generator(Stream.empty()).get()); + Descriptor notLiveDesc = new Descriptor(new File("/testdir"), "", "", SSTableIdFactory.instance.defaultBuilder().generator(Stream.empty()).get()); SSTableReader.moveAndOpenSSTable(cfs, sstable.descriptor, notLiveDesc, sstable.components, false); } @@ -762,7 +762,7 @@ public class SSTableReaderTest Keyspace keyspace = Keyspace.open(KEYSPACE1); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD); SSTableReader sstable = getNewSSTable(cfs); - Descriptor notLiveDesc = new Descriptor(new File("/tmp"), "", "", SSTableIdFactory.instance.defaultBuilder().generator(Stream.empty()).get()); + Descriptor notLiveDesc = new Descriptor(new File("/testdir"), "", "", SSTableIdFactory.instance.defaultBuilder().generator(Stream.empty()).get()); SSTableReader.moveAndOpenSSTable(cfs, notLiveDesc, sstable.descriptor, sstable.components, false); } diff --git a/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java b/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java index 6f25b2e2ee..c8359e07a3 100644 --- a/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java +++ b/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java @@ -122,11 +122,11 @@ public class FileUtilsTest @Test public void testIsContained() { - assertTrue(FileUtils.isContained(new File("/tmp/abc"), new File("/tmp/abc"))); - assertFalse(FileUtils.isContained(new File("/tmp/abc"), new File("/tmp/abcd"))); - assertTrue(FileUtils.isContained(new File("/tmp/abc"), new File("/tmp/abc/d"))); - assertTrue(FileUtils.isContained(new File("/tmp/abc/../abc"), new File("/tmp/abc/d"))); - assertFalse(FileUtils.isContained(new File("/tmp/abc/../abc"), new File("/tmp/abcc"))); + assertTrue(FileUtils.isContained(new File("/testroot/abc"), new File("/testroot/abc"))); + assertFalse(FileUtils.isContained(new File("/testroot/abc"), new File("/testroot/abcd"))); + assertTrue(FileUtils.isContained(new File("/testroot/abc"), new File("/testroot/abc/d"))); + assertTrue(FileUtils.isContained(new File("/testroot/abc/../abc"), new File("/testroot/abc/d"))); + assertFalse(FileUtils.isContained(new File("/testroot/abc/../abc"), new File("/testroot/abcc"))); } @Test diff --git a/test/unit/org/apache/cassandra/service/StartupChecksTest.java b/test/unit/org/apache/cassandra/service/StartupChecksTest.java index 72f8804ffe..3c43e1d5db 100644 --- a/test/unit/org/apache/cassandra/service/StartupChecksTest.java +++ b/test/unit/org/apache/cassandra/service/StartupChecksTest.java @@ -146,7 +146,7 @@ public class StartupChecksTest Path dirWithoutNumbers = StartupChecks.getReadAheadKBPath("/dev/sca"); Assert.assertEquals(Paths.get("/sys/block/sca/queue/read_ahead_kb"), dirWithoutNumbers); - Path invalidDir = StartupChecks.getReadAheadKBPath("/tmp/xpto"); + Path invalidDir = StartupChecks.getReadAheadKBPath("/invaliddir/xpto"); Assert.assertNull(invalidDir); }