@Test public void dataKeyValueTest() { ChronicleMap<IntValue, LongValue> map = ChronicleMapBuilder.of(IntValue.class, LongValue.class).entries(1000).create(); IntValue heapKey = Values.newHeapInstance(IntValue.class); LongValue heapValue = Values.newHeapInstance(LongValue.class); LongValue directValue = Values.newNativeReference(LongValue.class); heapKey.setValue(1); heapValue.setValue(1); map.put(heapKey, heapValue); assertEquals(1, map.get(heapKey).getValue()); assertEquals(1, map.getUsing(heapKey, heapValue).getValue()); heapKey.setValue(1); map.getUsing(heapKey, directValue).addValue(1); assertEquals(2, map.getUsing(heapKey, heapValue).getValue()); heapKey.setValue(2); heapValue.setValue(3); map.put(heapKey, heapValue); assertEquals(3, map.get(heapKey).getValue()); }
// TODO test passes but is under development. public static void main(String... ignored) throws IOException { AffinityLock lock = AffinityLock.acquireCore(); File file = File.createTempFile("testCHMLatency", "deleteme"); // File file = new File("testCHMLatency.deleteme"); file.delete(); ChronicleMap<LongValue, LongValue> countersMap = ChronicleMapBuilder.of(LongValue.class, LongValue.class) .entries(KEYS) .createPersistedTo(file); // add keys LongValue key = Values.newHeapInstance(LongValue.class); LongValue value = Values.newNativeReference(LongValue.class); for (long i = 0; i < KEYS; i++) { key.setValue(i); countersMap.acquireUsing(key, value); value.setValue(0); } System.out.println("Keys created"); // Monitor monitor = new Monitor(); LongValue value2 = Values.newNativeReference(LongValue.class); for (int t = 0; t < 5; t++) { for (int rate : new int[] { 2 * 1000 * 1000, 1000 * 1000, 500 * 1000 /*, 250 * 1000, 100 * 1000, 50 * 1000*/ }) { Histogram times = new Histogram(); int u = 0; long start = System.nanoTime(); long delay = 1000 * 1000 * 1000L / rate; long next = start + delay; for (long j = 0; j < RUN_TIME * rate; j += KEYS) { int stride = Math.max(1, KEYS / (RUN_TIME * rate)); // the timed part for (int i = 0; i < KEYS && u < RUN_TIME * rate; i += stride) { // busy wait for next time. while (System.nanoTime() < next - 12) ; // monitor.sample = System.nanoTime(); long start0 = next; // start the update. key.setValue(i); LongValue using = countersMap.getUsing(key, value2); if (using == null) assertNotNull(using); value2.addAtomicValue(1); // calculate the time using the time it should have started, not when it was able. long elapse = System.nanoTime() - start0; times.sample(elapse); next += delay; } // monitor.sample = Long.MAX_VALUE; } System.out.printf("run %d %,9d : ", t, rate); times.printPercentiles(" micro-seconds."); } System.out.println(); } // monitor.running = false; countersMap.close(); file.delete(); }