From d421e82ee0ffd66d3f382bfbe0b69b7b275edce3 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 18 Mar 2021 11:23:47 -0500 Subject: [PATCH] Modernize temp dir creation, wrap truncation with flakyTest Patch by brandonwilliams, reviewed by ycai for CASSANDRA-16526 --- .../cassandra/utils/binlog/BinLogTest.java | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java b/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java index 9ca24b02f9..311b924f9e 100644 --- a/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java +++ b/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java @@ -20,7 +20,7 @@ package org.apache.cassandra.utils.binlog; import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -39,7 +39,6 @@ import net.openhft.chronicle.queue.ExcerptTailer; import net.openhft.chronicle.queue.RollCycles; import net.openhft.chronicle.wire.WireOut; import org.apache.cassandra.Util; -import org.apache.cassandra.io.util.FileUtils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -51,10 +50,7 @@ public class BinLogTest { public static Path tempDir() throws Exception { - File f = FileUtils.createTempFile("foo", "bar"); - f.delete(); - f.mkdir(); - return Paths.get(f.getPath()); + return Files.createTempDirectory("binlogtest" + System.nanoTime()); } private static final String testString = "ry@nlikestheyankees"; @@ -417,28 +413,44 @@ public class BinLogTest /** * Test for a bug where files were deleted but the space was not reclaimed when tracking so * all log segemnts were incorrectly deleted when rolled. + * + * Due to some internal state in ChronicleQueue this test is occasionally + * flaky when run in the suite with testPut or testOffer. */ @Test - public void testTrucationReleasesLogSpace() throws Exception + public void testTruncationReleasesLogSpace() throws Exception + { + Util.flakyTest(this::flakyTestTruncationReleasesLogSpace, 2, "Fails occasionally due to Chronicle internal state, see CASSANDRA-16526"); + } + + + private void flakyTestTruncationReleasesLogSpace() { StringBuilder sb = new StringBuilder(); - for (int ii = 0; ii < 1024 * 1024 * 2; ii++) + try { - sb.append('a'); + for (int ii = 0; ii < 1024 * 1024 * 2; ii++) + { + sb.append('a'); + } + + String queryString = sb.toString(); + + //This should fill up the log so when it rolls in the future it will always delete the rolled segment; + for (int ii = 0; ii < 129; ii++) + { + binLog.put(record(queryString)); + } + + for (int ii = 0; ii < 2; ii++) + { + Thread.sleep(2000); + binLog.put(record(queryString)); + } } - - String queryString = sb.toString(); - - //This should fill up the log so when it rolls in the future it will always delete the rolled segment; - for (int ii = 0; ii < 129; ii++) + catch (InterruptedException e) { - binLog.put(record(queryString)); - } - - for (int ii = 0; ii < 2; ii++) - { - Thread.sleep(2000); - binLog.put(record(queryString)); + throw new RuntimeException(e); } Util.spinAssertEquals(2, () -> readBinLogRecords(path).size(), 60);