mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-208 Bug with acquireUsing
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user