Skip to content

Commit

Permalink
Added two tests: one to ensure that a specified string is written to
Browse files Browse the repository at this point in the history
the writeLock file, and another to ensure that nothing is written to
the readLock file.
  • Loading branch information
jeffrey-a-meunier committed Sep 18, 2019
1 parent 82c541b commit 75877e8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/test/java/com/upserve/uppend/FileStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.nio.ByteBuffer;
import java.nio.file.*;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -197,6 +199,28 @@ public void testCreateDirectoriesWithParentSymlink() throws Exception {
SafeDeleting.removeDirectory(base);
}

@Test
public void testLockFileAndContent_readWrite() throws IOException {
String expectedWriteLockContent = "write lock message";
MyFileStore v = new MyFileStore(path, 1, expectedWriteLockContent);
Path writeLockFilePath = Paths.get(path.toString(), "writeLock");
try (FileReader fr = new FileReader(writeLockFilePath.toString());
BufferedReader br = new BufferedReader(fr)) {
String writeLockContent = br.readLine();
assertTrue(Pattern.matches(expectedWriteLockContent, writeLockContent));
}
SafeDeleting.removeDirectory(path);
}

@Test
public void testLockFileAndContent_readOnly() throws IOException {
MyFileStore v = new MyFileStore(path, 1, true);
Path readLockFilePath = Paths.get(path.toString(), "readLock");
File file = readLockFilePath.toFile();
assertEquals(0, file.length());
SafeDeleting.removeDirectory(path);
}

@Test
public void testReaderWriter() throws InterruptedException {

Expand Down Expand Up @@ -253,5 +277,14 @@ private class MyFileStore extends FileAppendOnlyStore {
.withMetadataTTL(30)
);
}

MyFileStore(Path dir, int numPartitions, String writeLockContentString) {
super(false, new AppendOnlyStoreBuilder()
.withDir(dir)
.withPartitionCount(numPartitions)
.withMetadataTTL(30)
.withWriteLockContentString(writeLockContentString)
);
}
}
}

0 comments on commit 75877e8

Please sign in to comment.