-
Notifications
You must be signed in to change notification settings - Fork 565
Expand file tree
/
Copy pathFileShrinkageTest.java
More file actions
54 lines (41 loc) · 1.91 KB
/
FileShrinkageTest.java
File metadata and controls
54 lines (41 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package net.openhft.chronicle.queue.impl.single;
import net.openhft.chronicle.core.time.SetTimeProvider;
import net.openhft.chronicle.queue.ChronicleQueueTestBase;
import net.openhft.chronicle.queue.ExcerptAppender;
import net.openhft.chronicle.queue.RollCycles;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
public class FileShrinkageTest extends ChronicleQueueTestBase {
@Test
public void testShrinkSynchronously() throws IOException, InterruptedException {
final File dataDir = getTmpDir();
final SetTimeProvider timeProvider = new SetTimeProvider();
File file;
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir)
.rollCycle(RollCycles.TEST_SECONDLY)
.fileShrinkage(FileShrinkage.SHRINK_SYNCHRONOUSLY)
.timeProvider(timeProvider).build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
excerptAppender.writeText("hello");
file = excerptAppender.currentFile();
}
timeProvider.advanceMillis(2_000);
Thread.sleep(2_000);
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir)
.rollCycle(RollCycles.TEST_SECONDLY)
.timeProvider(timeProvider)
.fileShrinkage(FileShrinkage.SHRINK_SYNCHRONOUSLY)
.build()) {
// we should not have to do this, but even if we do it still does not work.
// queue.acquireAppender();
try (final RandomAccessFile raf = new RandomAccessFile(file, "r")) {
final long len = raf.length();
System.out.println("len=" + len + ", file=" + file.getAbsolutePath());
Assert.assertTrue("len=" + len, len > 520000 && len < 530000);
}
}
}
}