mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Respect BytesMarshallable#usesSelfDescribingMessage #318
This commit is contained in:
@@ -3,13 +3,15 @@ package net.openhft.chronicle.map;
|
||||
import net.openhft.chronicle.wire.BytesInBinaryMarshallable;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import net.openhft.chronicle.wire.SelfDescribingMarshallable;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
// From https://github.com/OpenHFT/Chronicle-Map/issues/183
|
||||
public class SerializableTest {
|
||||
@@ -23,17 +25,10 @@ public class SerializableTest {
|
||||
.entries(10)
|
||||
.create()) {
|
||||
|
||||
System.out.println("put 1");
|
||||
map.put(1, new Foo(i));
|
||||
System.out.println("get 1");
|
||||
map.get(1);
|
||||
System.out.println("works");
|
||||
System.out.println("put 2");
|
||||
map.put(2, new Foo(i + 1));
|
||||
System.out.println("get 2");
|
||||
assertEquals(i + 2,
|
||||
map.get(2).x.length());
|
||||
System.out.println("doesn't work");
|
||||
assertEquals(i + 2, map.get(2).x.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +66,8 @@ public class SerializableTest {
|
||||
|
||||
Bar value = new Bar(expected);
|
||||
map.put(1, value);
|
||||
assertFalse(value.usesSelfDescribingMessage());
|
||||
assertFalse(value.writeMarshallableWireOutCalled);
|
||||
String actual = map.get(1).x;
|
||||
|
||||
assertEquals(expected, actual);
|
||||
@@ -90,6 +87,9 @@ public class SerializableTest {
|
||||
|
||||
Bar2 value = new Bar2(expected);
|
||||
map.put(1, value);
|
||||
assertTrue(value.usesSelfDescribingMessage());
|
||||
// TODO: should be assertTrue - https://github.com/OpenHFT/Chronicle-Map/issues/318 ?
|
||||
assertFalse("we call bytes marshallable in this case", value.writeMarshallableWireOutCalled);
|
||||
String actual = map.get(1).x;
|
||||
|
||||
assertEquals(expected, actual);
|
||||
@@ -109,6 +109,8 @@ public class SerializableTest {
|
||||
|
||||
Bar2 value = new Bar2(expected);
|
||||
map.put(1, value);
|
||||
assertTrue(value.usesSelfDescribingMessage());
|
||||
assertTrue(value.writeMarshallableWireOutCalled);
|
||||
Bar2 bar2 = (Bar2) map.get(1);
|
||||
String actual = bar2.x;
|
||||
|
||||
@@ -132,18 +134,48 @@ public class SerializableTest {
|
||||
static class Bar extends BytesInBinaryMarshallable {
|
||||
|
||||
final String x;
|
||||
transient boolean writeMarshallableWireOutCalled;
|
||||
|
||||
public Bar(String expected) {
|
||||
this.x = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wire) {
|
||||
this.writeMarshallableWireOutCalled = true;
|
||||
super.writeMarshallable(wire);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Bar{" +
|
||||
"x='" + x + '\'' +
|
||||
", writeMarshallableWireOutCalled=" + writeMarshallableWireOutCalled +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
static class Bar2 extends SelfDescribingMarshallable {
|
||||
|
||||
final String x;
|
||||
transient boolean writeMarshallableWireOutCalled;
|
||||
|
||||
public Bar2(String expected) {
|
||||
this.x = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wire) {
|
||||
this.writeMarshallableWireOutCalled = true;
|
||||
super.writeMarshallable(wire);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Bar2{" +
|
||||
"x='" + x + '\'' +
|
||||
", writeMarshallableWireOutCalled=" + writeMarshallableWireOutCalled +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user