This is an automated email from the ASF dual-hosted git repository. smiklosovic pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push: new 31ee3a795b Make more unit tests generate test-related files in the temporary directory 31ee3a795b is described below commit 31ee3a795b023c3a6611621105040ab3c89c16d2 Author: maoling <maol...@apache.org> AuthorDate: Fri May 31 23:00:00 2024 +0800 Make more unit tests generate test-related files in the temporary directory patch by Ling Mao; reviewed by Isaac Reath, Paulo Motta, Stefan Miklosovic for CASSANDRA-19672 --- .../service/StorageServiceServerTest.java | 23 +++++++++ .../cassandra/tools/CompactionStressTest.java | 59 +++++++++++++--------- .../apache/cassandra/tools/cqlsh/CqlshTest.java | 7 ++- .../cassandra/tools/nodetool/GetAuditLogTest.java | 22 ++++++++ 4 files changed, 85 insertions(+), 26 deletions(-) diff --git a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java index 83e060fe32..7814b82ba0 100644 --- a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java +++ b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java @@ -21,6 +21,8 @@ package org.apache.cassandra.service; import java.io.IOException; import java.net.UnknownHostException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -36,6 +38,7 @@ import org.junit.Test; import org.apache.cassandra.ServerTestUtils; import org.apache.cassandra.audit.AuditLogManager; +import org.apache.cassandra.audit.AuditLogOptions; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.dht.Murmur3Partitioner; import org.apache.cassandra.dht.Murmur3Partitioner.LongToken; @@ -562,6 +565,9 @@ public class StorageServiceServerTest @Test public void testAuditLogEnableLoggerNotFound() throws Exception { + AuditLogOptions options = getBaseAuditLogOptions(); + DatabaseDescriptor.setAuditLoggingOptions(options); + StorageService.instance.enableAuditLog(null, null, null, null, null, null, null, null); assertTrue(AuditLogManager.instance.isEnabled()); try @@ -578,6 +584,9 @@ public class StorageServiceServerTest @Test public void testAuditLogEnableLoggerTransitions() throws Exception { + AuditLogOptions options = getBaseAuditLogOptions(); + DatabaseDescriptor.setAuditLoggingOptions(options); + StorageService.instance.enableAuditLog(null, null, null, null, null, null, null, null); assertTrue(AuditLogManager.instance.isEnabled()); @@ -594,4 +603,18 @@ public class StorageServiceServerTest assertTrue(AuditLogManager.instance.isEnabled()); StorageService.instance.disableAuditLog(); } + + /** + 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("StorageServiceServerTestForAuditLog"); + options.audit_logs_dir = tmpDir.toString(); + + return options; + } } diff --git a/test/unit/org/apache/cassandra/tools/CompactionStressTest.java b/test/unit/org/apache/cassandra/tools/CompactionStressTest.java index 148856ed90..07afeb4243 100644 --- a/test/unit/org/apache/cassandra/tools/CompactionStressTest.java +++ b/test/unit/org/apache/cassandra/tools/CompactionStressTest.java @@ -18,12 +18,15 @@ package org.apache.cassandra.tools; - -import org.apache.cassandra.io.util.File; import org.junit.Test; +import org.apache.cassandra.distributed.shared.WithProperties; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.tools.ToolRunner.ToolResult; +import static org.apache.cassandra.config.CassandraRelevantProperties.LOG_DIR; + public class CompactionStressTest extends OfflineToolUtils { @Test @@ -36,30 +39,36 @@ public class CompactionStressTest extends OfflineToolUtils @Test public void testWriteAndCompact() { - ClassLoader classLoader = getClass().getClassLoader(); - File file = new File(classLoader.getResource("blogpost.yaml").getFile()); - String profileFile = file.absolutePath(); + File tmpDir = FileUtils.getTempDir(); + tmpDir.deleteRecursiveOnExit(); - ToolResult tool = ToolRunner.invokeClass("org.apache.cassandra.stress.CompactionStress", - "write", - "-d", - "build/test/cassandra", - "-g", - "0", - "-p", - profileFile, - "-t", - "8"); - tool.assertOnCleanExit(); + // For the implementation of CompactionLogger, set the LOG_DIR to a tmp + // directory, the generated compaction.log file will be thrown in. + try (WithProperties ignore = new WithProperties().set(LOG_DIR, tmpDir.toString())) + { + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("blogpost.yaml").getFile()); + String profileFile = file.absolutePath(); + + ToolRunner.invokeClass("org.apache.cassandra.stress.CompactionStress", + "write", + "-d", + "build/test/cassandra", + "-g", + "0", + "-p", + profileFile, + "-t", + "8").assertOnCleanExit(); - tool = ToolRunner.invokeClass("org.apache.cassandra.stress.CompactionStress", - "compact", - "-d", - "build/test/cassandra", - "-p", - profileFile, - "-t", - "8"); - tool.assertOnCleanExit(); + ToolRunner.invokeClass("org.apache.cassandra.stress.CompactionStress", + "compact", + "-d", + "build/test/cassandra", + "-p", + profileFile, + "-t", + "8").assertOnCleanExit(); + } } } diff --git a/test/unit/org/apache/cassandra/tools/cqlsh/CqlshTest.java b/test/unit/org/apache/cassandra/tools/cqlsh/CqlshTest.java index 356769b840..9b7868c118 100644 --- a/test/unit/org/apache/cassandra/tools/cqlsh/CqlshTest.java +++ b/test/unit/org/apache/cassandra/tools/cqlsh/CqlshTest.java @@ -29,6 +29,8 @@ import org.junit.Test; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.cql3.UntypedResultSet; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.tools.ToolRunner; import org.apache.cassandra.tools.ToolRunner.ToolResult; @@ -133,7 +135,10 @@ public class CqlshTest extends CQLTester Path csv = prepareCSVFile(rows); // when running COPY via cqlsh - ToolRunner.ToolResult result = ToolRunner.invokeCqlsh(format("COPY %s.%s FROM '%s'", KEYSPACE, currentTable(), csv.toAbsolutePath())); + Path tmpDir = Files.createTempDirectory("CqlshTest"); + File tempFile = FileUtils.createTempFile("testCopyOnlyThoseRowsThatMatchVectorTypeSize", "", new File(tmpDir)); + // Since this test has failure, with ERRFILE option of COPY command, we can put the err file to tmp directory + ToolRunner.ToolResult result = ToolRunner.invokeCqlsh(format("COPY %s.%s FROM '%s' WITH ERRFILE = '%s'", KEYSPACE, currentTable(), csv.toAbsolutePath(), tempFile)); // then only rows that match type size should be imported result.asserts().failure(); diff --git a/test/unit/org/apache/cassandra/tools/nodetool/GetAuditLogTest.java b/test/unit/org/apache/cassandra/tools/nodetool/GetAuditLogTest.java index b96187fb0c..e23c7f8c3d 100644 --- a/test/unit/org/apache/cassandra/tools/nodetool/GetAuditLogTest.java +++ b/test/unit/org/apache/cassandra/tools/nodetool/GetAuditLogTest.java @@ -18,10 +18,16 @@ package org.apache.cassandra.tools.nodetool; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; +import org.apache.cassandra.audit.AuditLogOptions; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.tools.ToolRunner; @@ -32,6 +38,8 @@ public class GetAuditLogTest extends CQLTester @BeforeClass public static void setup() throws Exception { + AuditLogOptions options = getBaseAuditLogOptions(); + DatabaseDescriptor.setAuditLoggingOptions(options); requireNetwork(); startJMXServer(); } @@ -150,4 +158,18 @@ public class GetAuditLogTest extends CQLTester assertThat(output).contains("included_users \n"); assertThat(output).endsWith("excluded_users"); } + + /** + 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("GetAuditLogTest"); + options.audit_logs_dir = tmpDir.toString(); + + return options; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org