HCOLL-208 Bug with acquireUsing

This commit is contained in:
Peter Lawrey
2014-11-13 00:08:41 +00:00
parent 5b6f3bfdc6
commit 5839bd692a
@@ -9,8 +9,7 @@ import org.junit.Test;
import java.io.File;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
public class DemoChronicleMapTest {
@@ -57,6 +56,52 @@ public class DemoChronicleMapTest {
assertNotNull(v);
}
}
@Test
@Ignore
public void testMapLocked() throws Exception {
File file = File.createTempFile("DummyOrders", ".test");
file.deleteOnExit();
int maxEntries = 1000;
ChronicleMap<IntValue, DemoOrderVOInterface> map = ChronicleMapBuilder
.of(IntValue.class, DemoOrderVOInterface.class)
.putReturnsNull(true)
.removeReturnsNull(true)
.entries(maxEntries)
.createPersistedTo(file);
IntValue key = DataValueClasses.newInstance(IntValue.class);
DemoOrderVOInterface value = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
DemoOrderVOInterface value2 = DataValueClasses.newDirectReference(DemoOrderVOInterface.class);
// Initially populate the map
for (int i = 0; i < maxEntries; i++) {
key.setValue(i);
try (WriteContext wc = map.acquireUsingLocked(key, value)) {
// TODO Shouldn't throw an NPE, because acquire should set the value.
value.setSymbol("IBM-" + i);
value.addAtomicOrderQty(1000);
}
try (ReadContext rc = map.getUsingLocked(key, value2)) {
assertTrue(rc.present());
assertEquals("IBM-" + i, value.getSymbol());
assertEquals(1000, value.getOrderQty(), 0.0);
}
}
for (Map.Entry<IntValue, DemoOrderVOInterface> entry : map.entrySet()) {
IntValue k = entry.getKey();
DemoOrderVOInterface v = entry.getValue();
System.out.println(String.format("Key %d %s", k.getValue(), v == null ? "<null>" : v.getSymbol()));
assertNotNull(v);
}
}
}
interface DemoOrderVOInterface {