Fix up some tests broken from a tidy up of exceptions.

This commit is contained in:
Peter Lawrey
2016-04-15 13:09:59 +01:00
parent ffff33bed1
commit b90ebc3b39
13 changed files with 516 additions and 550 deletions
@@ -19,7 +19,7 @@ package net.openhft.chronicle.map;
import com.google.common.primitives.Chars;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesMarshallable;
import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.util.SerializableFunction;
import net.openhft.chronicle.core.values.*;
import net.openhft.chronicle.hash.serialization.DataAccess;
@@ -54,6 +54,103 @@ import static net.openhft.chronicle.core.Maths.divideRoundUp;
import static net.openhft.chronicle.map.fromdocs.OpenJDKAndHashMapExamplesTest.parseYYYYMMDD;
import static org.junit.Assert.*;
enum ToString implements SerializableFunction<Object, String> {
INSTANCE;
@Override
public String apply(Object o) {
return String.valueOf(o);
}
}
interface IData extends BytesMarshallable {
String getText();
void setText(@MaxUtf8Length(64) String text);
int getNumber();
void setNumber(int number);
class Data implements IData, BytesMarshallable {
static final long MAGIC = 0x8081828384858687L;
static final long MAGIC2 = 0xa0a1a2a3a4a5a6a7L;
String text;
int number;
@Override
public String getText() {
return text;
}
@Override
public void setText(String text) {
this.text = text;
}
@Override
public int getNumber() {
return number;
}
@Override
public void setNumber(int number) {
this.number = number;
}
@Override
public void readMarshallable(@NotNull Bytes in) throws IllegalStateException {
long magic = in.readLong();
if (magic != MAGIC)
throw new AssertionError("Start " + Long.toHexString(magic));
text = in.readUTFΔ();
number = in.readInt();
long magic2 = in.readLong();
if (magic2 != MAGIC2)
throw new AssertionError("End " + Long.toHexString(magic2));
}
@Override
public void writeMarshallable(@NotNull Bytes out) {
out.writeLong(MAGIC);
out.writeUTFΔ(text);
out.writeInt(number);
out.writeLong(MAGIC2);
}
}
}
interface IBean {
long getLong();
void setLong(long num);
double getDouble();
void setDouble(double d);
int getInt();
void setInt(int i);
@Array(length = 7)
void setInnerAt(int index, Inner inner);
Inner getInnerAt(int index);
/* nested interface - empowering an Off-Heap hierarchical “TIER of prices”
as array[ ] value */
interface Inner {
String getMessage();
void setMessage(@MaxUtf8Length(20) String px);
}
}
/**
* This test enumerates common use cases for keys and values.
*/
@@ -61,16 +158,47 @@ import static org.junit.Assert.*;
public class CHMUseCasesTest {
enum TypeOfMap {SIMPLE, SIMPLE_PERSISTED}
static volatile int i = 0;
private final TypeOfMap typeOfMap;
Collection<Closeable> closeables = new ArrayList<Closeable>();
ChronicleMap map1;
ChronicleMap map2;
public CHMUseCasesTest(TypeOfMap typeOfMap) {
this.typeOfMap = typeOfMap;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return asList(new Object[][]{
{
TypeOfMap.SIMPLE
},
{
TypeOfMap.SIMPLE_PERSISTED
}
});
}
private static void appendMode(ByteBuffer valueA) {
valueA.position(valueA.limit());
valueA.limit(valueA.capacity());
}
public static <K, V> Map<K, V> mapOf(K k, V v, Object... keysAndValues) {
Map<K, V> ret = new LinkedHashMap<>();
ret.put(k, v);
for (int i = 0; i < keysAndValues.length - 1; i += 2) {
Object key = keysAndValues[i];
Object value = keysAndValues[i + 1];
ret.put((K) key, (V) value);
}
return ret;
}
@After
public void after() {
for (Closeable c : closeables) {
@@ -86,24 +214,6 @@ public class CHMUseCasesTest {
map1 = null;
}
ChronicleMap map1;
ChronicleMap map2;
@Parameterized.Parameters
public static Collection<Object[]> data() {
return asList(new Object[][]{
{
TypeOfMap.SIMPLE
},
{
TypeOfMap.SIMPLE_PERSISTED
}
});
}
/**
* * waits until map1 and map2 show the same value
*
@@ -114,15 +224,10 @@ public class CHMUseCasesTest {
for (; t < timeOutMs; t++) {
if (map1.equals(map2))
break;
try {
Jvm.pause(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
private void mapChecks() {
if (typeOfMap == TypeOfMap.SIMPLE)
checkJsonSerialization();
@@ -155,7 +260,6 @@ public class CHMUseCasesTest {
}
}
private void checkJsonSerialization() {
File file = null;
try {
@@ -201,8 +305,6 @@ public class CHMUseCasesTest {
}
}
static volatile int i = 0;
private <X, Y> ChronicleMap<X, Y> newInstance(ChronicleMapBuilder<X, Y> builder) throws
IOException {
if (!builder.constantlySizedKeys() && builder.averageKey == null)
@@ -238,38 +340,6 @@ public class CHMUseCasesTest {
}
}
static class PrefixStringFunction implements SerializableFunction<String, String> {
private final String prefix;
public PrefixStringFunction(@NotNull String prefix) {
this.prefix = prefix;
}
@Override
public String apply(String s) {
return prefix + s;
}
@Override
public boolean equals(Object obj) {
return obj instanceof PrefixStringFunction &&
prefix.equals(((PrefixStringFunction) obj).prefix);
}
@Override
public String toString() {
return prefix;
}
}
interface I1 {
@Array(length = 10)
String getStrAt(int i);
void setStrAt(int i, @MaxUtf8Length(10) String str);
}
@Test
public void testArrayOfString() throws ExecutionException, InterruptedException,
IOException {
@@ -313,7 +383,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testCharArrayValue() throws ExecutionException, InterruptedException, IOException {
@@ -401,7 +470,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testEntrySpanningSeveralChunks()
throws ExecutionException, InterruptedException, IOException {
@@ -424,10 +492,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testKeyValueSizeBySample() throws ExecutionException, InterruptedException,
IOException {
@@ -444,7 +508,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testLargeCharSequenceValue()
throws ExecutionException, InterruptedException, IOException {
@@ -483,23 +546,6 @@ public class CHMUseCasesTest {
}
}
private static class StringPrefixUnaryOperator
implements BiFunction<String, String, String>, Serializable {
private String prefix;
StringPrefixUnaryOperator(final String prefix1) {
prefix = prefix1;
}
@Override
public String apply(String k, String v) {
return prefix + v;
}
}
@Test
public void testStringStringMapMutableValue() throws ExecutionException, InterruptedException, IOException {
@@ -548,7 +594,6 @@ public class CHMUseCasesTest {
}
}
/**
* CharSequence is more efficient when object creation is avoided.
* * The key can only be on heap and variable length serialised.
@@ -598,7 +643,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testAcquireUsingWithCharSequence() throws IOException {
@@ -716,12 +760,6 @@ public class CHMUseCasesTest {
}
}
interface StringValue {
CharSequence getValue();
void getUsingValue(StringBuilder using);
void setValue(@net.openhft.chronicle.values.NotNull @MaxUtf8Length(64) CharSequence value);
}
/**
* StringValue represents any bean which contains a String Value
*/
@@ -1050,7 +1088,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testByteBufferByteBufferDefaultKeyValueMarshaller() throws ExecutionException,
InterruptedException, IOException {
@@ -1080,7 +1117,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testByteBufferByteBufferMap()
throws ExecutionException, InterruptedException, IOException {
@@ -1193,11 +1229,6 @@ public class CHMUseCasesTest {
}
}
private static void appendMode(ByteBuffer valueA) {
valueA.position(valueA.limit());
valueA.limit(valueA.capacity());
}
@Test
public void testByteBufferDirectByteBufferMap()
throws ExecutionException, InterruptedException, IOException {
@@ -1353,12 +1384,6 @@ public class CHMUseCasesTest {
}
}
interface UnsignedIntValue {
long getValue();
void setValue(@Range(min = 0, max = (1L << 32) - 1) long value);
long addValue(long addition);
}
/**
* For unsigned int -> unsigned int entries, the key can be on heap or off heap.
*/
@@ -1583,12 +1608,6 @@ public class CHMUseCasesTest {
}
}
interface UnsignedShortValue {
int getValue();
void setValue(@Range(min = 0, max = Character.MAX_VALUE) int value);
int addValue(int addition);
}
/**
* For int -> unsigned short values, the key can be on heap or off heap.
*/
@@ -1794,12 +1813,6 @@ public class CHMUseCasesTest {
}
}
interface UnsignedByteValue {
int getValue();
void setValue(@Range(min = 0, max = 255) int value);
int addValue(int addition);
}
/**
* For int-> byte entries, the key can be on heap or off heap.
*/
@@ -2114,7 +2127,6 @@ public class CHMUseCasesTest {
}
}
/**
* For double values, the key can be on heap or off heap.
*/
@@ -2422,7 +2434,6 @@ public class CHMUseCasesTest {
}
}
@Test
public void testMapStringStringValue() throws IOException {
@@ -2523,17 +2534,6 @@ public class CHMUseCasesTest {
}
}
public static <K, V> Map<K, V> mapOf(K k, V v, Object... keysAndValues) {
Map<K, V> ret = new LinkedHashMap<>();
ret.put(k, v);
for (int i = 0; i < keysAndValues.length - 1; i += 2) {
Object key = keysAndValues[i];
Object value = keysAndValues[i + 1];
ret.put((K) key, (V) value);
}
return ret;
}
@Test
public void testGeneratedDataValue() throws IOException {
@@ -2599,6 +2599,87 @@ public class CHMUseCasesTest {
}
}
enum TypeOfMap {SIMPLE, SIMPLE_PERSISTED}
interface I1 {
@Array(length = 10)
String getStrAt(int i);
void setStrAt(int i, @MaxUtf8Length(10) String str);
}
interface StringValue {
CharSequence getValue();
void setValue(@net.openhft.chronicle.values.NotNull @MaxUtf8Length(64) CharSequence value);
void getUsingValue(StringBuilder using);
}
interface UnsignedIntValue {
long getValue();
void setValue(@Range(min = 0, max = (1L << 32) - 1) long value);
long addValue(long addition);
}
interface UnsignedShortValue {
int getValue();
void setValue(@Range(min = 0, max = Character.MAX_VALUE) int value);
int addValue(int addition);
}
interface UnsignedByteValue {
int getValue();
void setValue(@Range(min = 0, max = 255) int value);
int addValue(int addition);
}
static class PrefixStringFunction implements SerializableFunction<String, String> {
private final String prefix;
public PrefixStringFunction(@NotNull String prefix) {
this.prefix = prefix;
}
@Override
public String apply(String s) {
return prefix + s;
}
@Override
public boolean equals(Object obj) {
return obj instanceof PrefixStringFunction &&
prefix.equals(((PrefixStringFunction) obj).prefix);
}
@Override
public String toString() {
return prefix;
}
}
private static class StringPrefixUnaryOperator
implements BiFunction<String, String, String>, Serializable {
private String prefix;
StringPrefixUnaryOperator(final String prefix1) {
prefix = prefix1;
}
@Override
public String apply(String k, String v) {
return prefix + v;
}
}
private static class DataDataAccess extends BytesMarshallableDataAccess<IData.Data> {
public DataDataAccess() {
super(IData.Data.class);
@@ -2626,100 +2707,3 @@ public class CHMUseCasesTest {
}
}
}
interface IData extends BytesMarshallable {
void setText(@MaxUtf8Length(64) String text);
void setNumber(int number);
String getText();
int getNumber();
class Data implements IData, BytesMarshallable {
static final long MAGIC = 0x8081828384858687L;
static final long MAGIC2 = 0xa0a1a2a3a4a5a6a7L;
String text;
int number;
@Override
public String getText() {
return text;
}
@Override
public void setText(String text) {
this.text = text;
}
@Override
public int getNumber() {
return number;
}
@Override
public void setNumber(int number) {
this.number = number;
}
@Override
public void readMarshallable(@NotNull Bytes in) throws IllegalStateException {
long magic = in.readLong();
if (magic != MAGIC)
throw new AssertionError("Start " + Long.toHexString(magic));
text = in.readUTFΔ();
number = in.readInt();
long magic2 = in.readLong();
if (magic2 != MAGIC2)
throw new AssertionError("End " + Long.toHexString(magic2));
}
@Override
public void writeMarshallable(@NotNull Bytes out) {
out.writeLong(MAGIC);
out.writeUTFΔ(text);
out.writeInt(number);
out.writeLong(MAGIC2);
}
}
}
enum ToString implements SerializableFunction<Object, String> {
INSTANCE;
@Override
public String apply(Object o) {
return String.valueOf(o);
}
}
interface IBean {
long getLong();
void setLong(long num);
double getDouble();
void setDouble(double d);
int getInt();
void setInt(int i);
@Array(length = 7)
void setInnerAt(int index, Inner inner);
Inner getInnerAt(int index);
/* nested interface - empowering an Off-Heap hierarchical “TIER of prices”
as array[ ] value */
interface Inner {
String getMessage();
void setMessage(@MaxUtf8Length(20) String px);
}
}