-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add coverage for Uppend and LookupData
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.upserve.uppend; | ||
|
||
import org.junit.*; | ||
|
||
import java.io.*; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class UppendMainTest { | ||
private final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); | ||
private final ByteArrayOutputStream errStream = new ByteArrayOutputStream(); | ||
|
||
@Before | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outStream)); | ||
System.setErr(new PrintStream(errStream)); | ||
} | ||
|
||
@After | ||
public void cleanUpStreams() { | ||
System.setOut(null); | ||
System.setErr(null); | ||
} | ||
|
||
@Test | ||
public void testMain() throws Exception { | ||
Uppend.main("--help"); | ||
String errStr = errStream.toString(); | ||
assertTrue("didn't find expected 'Usage: uppend' in main stderr output: " + errStr, errStr.contains("Usage: uppend")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.upserve.uppend; | ||
|
||
import com.upserve.uppend.util.SafeDeleting; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Test; | ||
|
||
import java.nio.file.*; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
@Slf4j | ||
public class UppendTest { | ||
@Test | ||
public void testVersion() { | ||
// NOTE: source of this value is src/test/resources/com/upserve/uppend/main.properties | ||
assertEquals("test-version", Uppend.VERSION); | ||
} | ||
|
||
@Test | ||
public void testStore() throws Exception { | ||
final String pathStr = "build/tmp/test/uppend-test-store/"; | ||
final Path path = Paths.get(pathStr); | ||
SafeDeleting.removeTempPath(path); | ||
assertFalse(Files.exists(path)); | ||
FileAppendOnlyStore store = Uppend.store(pathStr).build(); | ||
store.append("partition", "foo", "bar".getBytes()); | ||
assertTrue(Files.exists(path)); | ||
store.flush(); | ||
FileAppendOnlyStore store2 = Uppend.store(path).build(); | ||
assertArrayEquals(new String[] { "bar" }, store2.read("partition", "foo").map(String::new).toArray()); | ||
store.close(); | ||
store2.close(); | ||
SafeDeleting.removeTempPath(path); | ||
} | ||
|
||
@Test | ||
public void testCounterStore() throws Exception { | ||
final String pathStr = "build/tmp/test/uppend-test-counter-store/"; | ||
final Path path = Paths.get(pathStr); | ||
SafeDeleting.removeTempPath(path); | ||
assertFalse(Files.exists(path)); | ||
FileCounterStore store = Uppend.counterStore(pathStr).build(); | ||
store.increment("partition", "foo", 5); | ||
assertTrue(Files.exists(path)); | ||
store.flush(); | ||
FileCounterStore store2 = Uppend.counterStore(path).build(); | ||
assertEquals(5, store2.get("partition", "foo")); | ||
store.close(); | ||
store2.close(); | ||
SafeDeleting.removeTempPath(path); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/com/upserve/uppend/lookup/LookupDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.upserve.uppend.lookup; | ||
|
||
import com.upserve.uppend.util.SafeDeleting; | ||
import org.junit.*; | ||
|
||
import java.nio.file.*; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class LookupDataTest { | ||
private Path lookupDir = Paths.get("build/test/tmp/lookup-data"); | ||
|
||
@Before | ||
public void initialize() throws Exception { | ||
SafeDeleting.removeTempPath(lookupDir); | ||
} | ||
|
||
@Test | ||
public void testCtor() throws Exception { | ||
new LookupData(5, lookupDir.resolve("data"), lookupDir.resolve("meta")); | ||
} | ||
|
||
@Test | ||
public void testGetAndPut() throws Exception { | ||
LookupData data = new LookupData(5, lookupDir.resolve("data"), lookupDir.resolve("meta")); | ||
final LookupKey key = new LookupKey("mykey"); // len = 5 | ||
assertEquals(Long.MIN_VALUE, data.get(key)); | ||
data.put(key, 80); | ||
assertEquals(80, data.get(key)); | ||
} | ||
|
||
@Test | ||
public void testPutThrowsWithBadKeySize() throws Exception { | ||
LookupData data = new LookupData(5, lookupDir.resolve("data"), lookupDir.resolve("meta")); | ||
final LookupKey key = new LookupKey("myke"); | ||
Exception expected = null; | ||
try { | ||
data.put(key, 80); | ||
} catch (Exception e) { | ||
expected = e; | ||
} | ||
assertNotNull(expected); | ||
assertTrue(expected.getMessage().contains("unexpected key length")); | ||
} | ||
|
||
@Test | ||
public void testFlushAndClose() throws Exception { | ||
LookupData data = new LookupData(5, lookupDir.resolve("data"), lookupDir.resolve("meta")); | ||
final LookupKey key = new LookupKey("mykey"); // len = 5 | ||
data.put(key, 80); | ||
data.flush(); | ||
data.close(); | ||
data = new LookupData(5, lookupDir.resolve("data"), lookupDir.resolve("meta")); | ||
assertEquals(80, data.get(key)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uppend.version=test-version |