Skip to content

Commit 98c5f87

Browse files
author
Lee Rhodes
committed
additional unit tests
1 parent f5757f3 commit 98c5f87

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/main/java/com/yahoo/sketches/memory/MemoryMappedFile.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public boolean isLoaded() {
124124
String.format("Encountered %s exception while loading", e.getClass()));
125125
}
126126
}
127-
127+
128128
/**
129129
* Forces any changes made to this content to be written to the storage device
130130
* containing the mapped file.
@@ -201,7 +201,7 @@ private void unmap() throws RuntimeException {
201201
}
202202
}
203203

204-
private static int pageCount(int ps, long length) {
204+
static final int pageCount(int ps, long length) {
205205
long s = 1;
206206
while (s * ps < length) {
207207
s++;
@@ -224,7 +224,8 @@ private void createDummyMbbInstance() throws RuntimeException {
224224
null,
225225
null);
226226
} catch (Exception e) {
227-
throw new RuntimeException(e);
227+
throw new RuntimeException(
228+
"Could not create Dummy MappedByteBuffer instance: " + e.getClass());
228229
}
229230
}
230231

src/test/java/com/yahoo/sketches/memory/MemoryMappedFileTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testIllegalArgumentException() throws Exception {
3434
File file = new File(getClass().getClassLoader().getResource("memory_mapped.txt").getFile());
3535
try {
3636
new MemoryMappedFile(file, -1, Integer.MAX_VALUE);
37-
fail("Failed: testIllegalArgumentException: Pos was negative.");
37+
fail("Failed: testIllegalArgumentException: Position was negative.");
3838
} catch (Exception e) {
3939
// Expected;
4040
}
@@ -47,7 +47,7 @@ public void testIllegalArgumentException() throws Exception {
4747
}
4848

4949
try {
50-
new MemoryMappedFile(file, 1, -2);
50+
new MemoryMappedFile(file, Long.MAX_VALUE, 2);
5151
fail("Failed: testIllegalArgumentException: Sum of position + size is negative.");
5252
} catch (Exception e) {
5353
// Expected;
@@ -64,6 +64,7 @@ public void testMemoryMapAndFree() {
6464
assertEquals(memCapacity, mmf.getCapacity());
6565
mmf.freeMemory();
6666
assertEquals(0L, mmf.getCapacity());
67+
assertEquals(MemoryMappedFile.pageCount(1, 16), 16); //check pageCounter
6768
} catch (Exception e) {
6869
fail("Failed: testMemoryMapAndFree()");
6970
}
@@ -186,6 +187,12 @@ public void testForce() throws Exception {
186187
}
187188
}
188189

190+
@Test
191+
public void checkPassThrough() {
192+
NativeMemory mem = new AllocMemory(1024L);
193+
mem.freeMemory();
194+
}
195+
189196
@SuppressWarnings("resource")
190197
private static File createFile(String fileName, String text) throws FileNotFoundException {
191198
File file = new File(fileName);

0 commit comments

Comments
 (0)