updated test cases

This commit is contained in:
Rob Austin
2014-12-22 14:44:54 +00:00
parent 0b765451a8
commit 7ad50e64ea
9 changed files with 518 additions and 242 deletions
@@ -175,9 +175,8 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
*
* <p>If the {@code ChronicleMap} is off-heap updatable, i. e. created via {@link
* ChronicleMapBuilder} builder (values are {@link Byteable}), there is one more option of what
* to do if the key is absent in the map.
* By default, value bytes are just zeroed out, no default value, either provided for key or
* constant, is put for the absent key.
* to do if the key is absent in the map. By default, value bytes are just zeroed out, no
* default value, either provided for key or constant, is put for the absent key.
*
* @param key the key whose associated value is to be returned
* @param usingValue the object to read value data in, if present. Can not be null
@@ -200,10 +199,10 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
<R> R getMapped(K key, @NotNull Function<? super V, R> function);
/**
* Apply a unaryOperator to the value for a key and return a result. A write lock is assumed. <p> If
* there is no entry for this key null will be returned
* Apply a unaryOperator to the value for a key and return a result. A write lock is assumed.
* <p> If there is no entry for this key null will be returned
*
* @param key to apply the mapping to
* @param key to apply the mapping to
* @param unaryOperator to alter the value and calculate a result
* @return the result of the function.
*/
@@ -256,5 +255,15 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
* @return a new empty instance based on the Key type
*/
K newKeyInstance();
/**
* @return the class of <K>
*/
Class<K> keyClass();
/**
* @return the class of <V>
*/
Class<V> valueClass();
}
@@ -195,6 +195,16 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
return VanillaChronicleMap.newInstance(kClass, true);
}
@Override
public Class<K> keyClass() {
return kClass;
}
@Override
public Class<V> valueClass() {
return vClass;
}
private void checkTimeout(long timeoutTime) {
if (timeoutTime < System.currentTimeMillis())
@@ -1703,7 +1713,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
}
}
private void resizeToMessageOutBuffer(long start, @NotNull Exception e) throws Exception{
private void resizeToMessageOutBuffer(long start, @NotNull Exception e) throws Exception {
assert outBytesLock.isHeldByCurrentThread();
assert !inBytesLock.isHeldByCurrentThread();
String message = e.getMessage();
@@ -49,7 +49,6 @@ import org.slf4j.LoggerFactory;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.*;
import java.lang.reflect.Array;
@@ -716,6 +715,16 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
return newInstance(kClass, true);
}
@Override
public Class<K> keyClass() {
return kClass;
}
@Override
public Class<V> valueClass() {
return vClass;
}
static <T> T newInstance(Class<T> aClass, boolean isKey) {
try {
@@ -749,7 +758,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
}
private XStreamConverter xStreamConverter;
private transient XStreamConverter xStreamConverter;
/**
@@ -782,7 +791,8 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
String canonicalName = aClass.getCanonicalName();
return canonicalName.startsWith("net.openhft.lang.values")
|| canonicalName.endsWith("$$Native");
|| canonicalName.endsWith("$$Native") || canonicalName.endsWith
("$$Heap");
}
@@ -815,9 +825,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
}
if (o.getClass().getCanonicalName().startsWith("net.openhft.lang.values")
&& (o.getClass().getCanonicalName().endsWith("$$Native") ||
o.getClass().getCanonicalName().endsWith("$$Heap"))) {
final String canonicalName = o.getClass().getCanonicalName();
if (canonicalName.startsWith("net.openhft.lang.values")
&& (canonicalName.endsWith("$$Native") ||
canonicalName.endsWith("$$Heap"))) {
Method[] methods = o.getClass().getMethods();
@@ -825,19 +837,17 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (method.getName().equals("getValue") &&
method.getParameterTypes().length == 0) {
try {
final Object result = method.invoke(o);
// writer.startNode(o.getClass().getCanonicalName());
marshallingContext.convertAnother(result);
// writer.endNode();
marshallingContext.convertAnother(method.invoke(o));
return;
} catch (Exception e) {
throw new RuntimeException("class=" + o.getClass().getCanonicalName(), e);
throw new RuntimeException("class=" + canonicalName, e);
}
}
}
} else {
if (o.getClass().getCanonicalName().endsWith("$$Native")) {
if (canonicalName.endsWith("$$Native") ||
canonicalName.endsWith("$$Heap")) {
try {
BeanInfo info = getBeanInfo(o.getClass()); // new BeanGenerator
@@ -867,7 +877,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
} catch (IntrospectionException e) {
throw new RuntimeException("class=" + o.getClass().getCanonicalName(), e);
throw new RuntimeException("class=" + canonicalName, e);
}
}
}
@@ -878,10 +888,19 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
UnmarshallingContext unmarshallingContext) {
String canonicalName = unmarshallingContext.getRequiredType().getCanonicalName();
if (canonicalName.endsWith("$$Native")) {
boolean isNative = canonicalName.endsWith("$$Native");
boolean isHeap = canonicalName.endsWith("$$Heap");
if (isNative || isHeap) {
final String nodeName = isNative ?
canonicalName.substring(0, canonicalName.length() -
"$$Native".length()) :
canonicalName.substring(0, canonicalName.length() -
"$$Heap".length());
final String nodeName = canonicalName.substring(0, canonicalName.length() -
"$$Native".length());
Object o;
try {
@@ -959,7 +978,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (kClass.getCanonicalName().startsWith("net.openhft.lang.values")) {
return to$$Native(reader, vClass, true, VanillaChronicleMap.this, unmarshallingContext);
} else if (type.endsWith("$$Native")) {
} else if (type.endsWith("$$Native") || type.endsWith("$$Heap")) {
return XStreamHelper.to$$Native2(reader, vClass, false, VanillaChronicleMap.this, unmarshallingContext, type);
} else {
long keySize = keySizeMarshaller.readSize(buffer);
@@ -971,7 +990,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (vClass.getCanonicalName().startsWith("net.openhft.lang.values")) {
return to$$Native(reader, vClass, false, VanillaChronicleMap.this, unmarshallingContext);
} else if (type.endsWith("$$Native")) {
} else if (type.endsWith("$$Native") || type.endsWith("$$Heap")) {
return XStreamHelper.to$$Native2(reader, vClass, false, VanillaChronicleMap.this, unmarshallingContext, type);
} else {
long valueSize = valueSizeMarshaller.readSize(buffer);
@@ -995,12 +1014,16 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (reader.getAttributeCount() > 0) {
final String type = reader.getAttribute("type");
try {
return (E) unmarshallingContext.convertAnother(null, forName(type));
} catch (ClassNotFoundException e) {
throw new ConversionException(e);
}
} else return (E) unmarshallingContext.convertAnother(null, clazz);
if (type != null)
try {
return (E) unmarshallingContext.convertAnother(null, forName(type));
} catch (ClassNotFoundException e) {
throw new ConversionException(e);
}
}
return (E) unmarshallingContext.convertAnother(null, clazz);
}
@@ -1591,7 +1614,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
return segmentStateProvider.getCopies(copies);
}
static @NotNull SegmentState get(@NotNull ThreadLocalCopies copies) {
static
@NotNull
SegmentState get(@NotNull ThreadLocalCopies copies) {
assertNotNull(copies);
return segmentStateProvider.get(copies, originalSegmentState).get();
}
@@ -34,33 +34,35 @@ class XStreamHelper {
ChronicleMap map, UnmarshallingContext unmarshallingContext, String type) {
if (type.endsWith("$$Native")) {
boolean isNative = type.endsWith("$$Native");
Class<?> aClass = null;
Class<?> aClass;
try {
aClass = Class.forName(type);
} catch (ClassNotFoundException e) {
String clazz = isNative ? type.substring(0, type.length() -
"$$Native".length()) : type.substring(0, type.length() -
"$$Heap".length());
try {
DataValueClasses.newDirectInstance(Class.forName(clazz));
} catch (ClassNotFoundException e1) {
throw new ConversionException(e1);
}
try {
aClass = Class.forName(type);
} catch (ClassNotFoundException e) {
String clazz = type.substring(0, type.length() -
"$$Native".length());
try {
DataValueClasses.newDirectInstance(Class.forName(clazz));
} catch (ClassNotFoundException e1) {
throw new ConversionException(e1);
}
try {
aClass = Class.forName(type);
} catch (ClassNotFoundException e1) {
throw new ConversionException(e1);
}
} catch (ClassNotFoundException e1) {
throw new ConversionException(e1);
}
return unmarshallingContext.convertAnother(null, aClass);
}
throw new ConversionException("setValue(..) method not found in class=" + type);
return unmarshallingContext.convertAnother(null, aClass);
}
static Object to$$Native(HierarchicalStreamReader reader, final Class aClass, final boolean isKey, ChronicleMap map, UnmarshallingContext unmarshallingContext) {