mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Changes to FilePerKeyMap made after testing on Linux.
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -13,17 +12,18 @@ import static org.junit.Assert.*;
|
||||
* JUnit test class to support {@link FilePerKeyMapTest}
|
||||
*/
|
||||
public class FilePerKeyMapTest {
|
||||
private static FilePerKeyMap map;
|
||||
@BeforeClass
|
||||
public static void createMap(){
|
||||
map = new FilePerKeyMap("/tmp/filepermaptests");
|
||||
//just in case it hasn't been cleared up last time
|
||||
map.clear();
|
||||
}
|
||||
/**
|
||||
* 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 map = new FilePerKeyMap("/tmp/filepermaptests");
|
||||
|
||||
//just in case it hasn't been cleared up last time
|
||||
map.clear();
|
||||
|
||||
String val = map.put("one", "test1");
|
||||
assertEquals(val, null);
|
||||
|
||||
@@ -103,25 +103,11 @@ public class FilePerKeyMapTest {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
map.clear();
|
||||
map.close();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void perfTest(){
|
||||
//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();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 2_000_000; i++) {
|
||||
sb.append('x');
|
||||
@@ -139,32 +125,46 @@ public class FilePerKeyMapTest {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
map.put("big file", value);
|
||||
}
|
||||
System.out.println("Time to update "+ iterations + " iterations " + (System.currentTimeMillis()-time));
|
||||
System.out.println("Time to update " + iterations + " iterations " + (System.currentTimeMillis() - time));
|
||||
|
||||
map.clear();
|
||||
map.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventTest() {
|
||||
//There are no entries in the map so null should be returned
|
||||
FilePerKeyMap map = new FilePerKeyMap("/tmp/filepermaptests");
|
||||
final List<FPMEvent> events = new ArrayList<>();
|
||||
|
||||
//just in case it hasn't been cleared up last time
|
||||
map.clear();
|
||||
|
||||
map.registerForEvents(e -> System.out.println(e));
|
||||
Consumer<FPMEvent> fpmEventConsumer = (FPMEvent e) -> {
|
||||
System.out.println(e);
|
||||
events.add(e);
|
||||
};
|
||||
map.registerForEvents(fpmEventConsumer);
|
||||
|
||||
map.put("one", "one");
|
||||
map.put("one", "two");
|
||||
map.remove("one");
|
||||
map.put("one", "one");
|
||||
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
//Allow all events to be played through
|
||||
Thread.sleep(1000);
|
||||
//Check the events
|
||||
assertEquals(4, events.size());
|
||||
|
||||
assertEquals(FPMEvent.EventType.NEW,events.get(0).getEventType());
|
||||
assertEquals(FPMEvent.EventType.UPDATE, events.get(1).getEventType());
|
||||
assertEquals(FPMEvent.EventType.DELETE, events.get(2).getEventType());
|
||||
assertEquals(FPMEvent.EventType.NEW, events.get(3).getEventType());
|
||||
|
||||
assertEquals(true, events.get(0).isProgrammatic());
|
||||
assertEquals(true, events.get(1).isProgrammatic());
|
||||
assertEquals(true, events.get(2).isProgrammatic());
|
||||
assertEquals(true, events.get(3).isProgrammatic());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
map.unregisterForEvents(fpmEventConsumer);
|
||||
map.clear();
|
||||
map.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user