Initial commit for FilePerMap implementation.

This commit is contained in:
danielshaya
2015-04-23 18:37:53 +01:00
parent 05368a987b
commit e9f995379d
5 changed files with 440 additions and 258 deletions
@@ -13,22 +13,13 @@ import static org.junit.Assert.*;
* JUnit test class to support {@link FilePerKeyMapTest}
*/
public class FilePerKeyMapTest {
/**
* FilePerMapKey only works with Strings
*/
@Test(expected = AssertionError.class)
public void testWrongType(){
FilePerKeyMap<Integer, String> map = new FilePerKeyMap<>("/tmp/filepermaptests");
map.put(1, "test");
}
/**
* Testing all the methods of the map with simple tests.
*/
@Test
public void testMapMethods() {
//There are no entries in the map so null should be returned
FilePerKeyMap<String, String> map = new FilePerKeyMap<>("/tmp/filepermaptests");
FilePerKeyMap map = new FilePerKeyMap("/tmp/filepermaptests");
//just in case it hasn't been cleared up last time
map.clear();
@@ -122,7 +113,7 @@ public class FilePerKeyMapTest {
@Test
public void perfTest(){
//There are no entries in the map so null should be returned
FilePerKeyMap<String, String> map = new FilePerKeyMap<>("/tmp/filepermaptests");
FilePerKeyMap map = new FilePerKeyMap("/tmp/filepermaptests");
//just in case it hasn't been cleared up last time
map.clear();
@@ -133,8 +124,8 @@ public class FilePerKeyMapTest {
}
String value = sb.toString();
//warmup
for (int i = 0; i < 1000; i++) {
//small warm-up
for (int i = 0; i < 10; i++) {
map.put("big file", value);
}
@@ -147,4 +138,30 @@ public class FilePerKeyMapTest {
System.out.println("Time to update "+ iterations + " iterations " + (System.currentTimeMillis()-time));
}
@Test
public void eventTest(){
//There are no entries in the map so null should be returned
FilePerKeyMap map = new FilePerKeyMap("/tmp/filepermaptests");
//just in case it hasn't been cleared up last time
map.clear();
map.registerForEvents(new FPMListener() {
@Override
public void onEvent(FPMEvent e) {
System.out.println(e);
}
});
map.put("one", "one");
map.put("one", "one");
try {
Thread.sleep(300000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}