Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/471 #480

Merged
merged 40 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9f28ee2
Remove addPadding(true) for useTextDocuments() #471
peter-lawrey May 11, 2022
5e7a910
Remove addPadding(true) for useTextDocuments() #471
peter-lawrey May 11, 2022
b3064d5
Improve handling of null in a sequence #471
peter-lawrey May 27, 2022
5ad0e73
rename broken test - check behaviour of MethodIds in generated Method…
JerryShea May 7, 2022
5cbcde5
sonar code smells
JerryShea May 7, 2022
dee3bb6
deprecate VanillaMethodReaderBuilder.ignoreDefaults
JerryShea May 7, 2022
4a827be
deprecate VanillaMethodWriterBuilder.methodWriterInterceptorReturns
JerryShea May 8, 2022
795616b
Updating to bom version 2.23ea44
May 12, 2022
377eeed
[maven-release-plugin] prepare release chronicle-wire-2.23ea9
May 12, 2022
6f59e86
[maven-release-plugin] prepare for next development iteration
May 12, 2022
5e8c440
Reverting back to bom version 2.23ea-SNAPSHOT
May 12, 2022
1c2ed1b
Infinite message loop is possible with dontWriteHistoryForEventsWithN…
glukos May 12, 2022
75d6c3a
For functions with with primitive return values, make generated metho…
JerryShea May 8, 2022
ed00653
Enhance ChainedMethodsTest for old-style proxies and also generated code
JerryShea May 8, 2022
7d75596
un-Ignore tests
JerryShea May 8, 2022
fd8a149
Updating to bom version 2.23ea45
May 12, 2022
110e0c0
[maven-release-plugin] prepare release chronicle-wire-2.23ea10
May 12, 2022
51eea52
[maven-release-plugin] prepare for next development iteration
May 12, 2022
041b789
Reverting back to bom version 2.23ea-SNAPSHOT
May 12, 2022
4ac7d03
fix generated code method writer for generic return types
JerryShea May 13, 2022
18b0118
Add methods (#474)
May 17, 2022
54dfb15
Added a YamlTester interface to simplify running YAML based tests #475
peter-lawrey May 18, 2022
8844934
Added a YamlTester interface to simplify running YAML based tests #475
peter-lawrey May 18, 2022
a918d5a
Added a YamlTester interface to simplify running YAML based tests #475
peter-lawrey May 18, 2022
d5226e0
Added a YamlTester interface to simplify running YAML based tests #475
peter-lawrey May 18, 2022
1169828
Updating to bom version 2.23ea49
May 19, 2022
718b9e0
[maven-release-plugin] prepare release chronicle-wire-2.23ea12
May 19, 2022
8bb034a
[maven-release-plugin] prepare for next development iteration
May 19, 2022
8dc2b41
Reverting back to bom version 2.23ea-SNAPSHOT
May 19, 2022
c1efded
Updating parent POM (automated)
May 27, 2022
facde44
Ignore some packages in SOT (#479)
minborg May 27, 2022
89476b1
Ignore flappy test #482
nicktindall May 31, 2022
68d3a8c
Ignore flappy test #482
nicktindall May 31, 2022
5535549
Remove delegate from generated MethodReader to proxied MethodReader. …
JerryShea May 7, 2022
d44630a
Updating parent POM (automated)
Jun 6, 2022
b77bb90
Un-pin the binary-compatibility-enforcer version
Jun 6, 2022
cea753a
Flaky test fix
Jun 3, 2022
4a815df
Remove addPadding(true) for useTextDocuments() #471
peter-lawrey May 11, 2022
6bb8252
Remove addPadding(true) for useTextDocuments() #471
peter-lawrey Jun 6, 2022
05adc77
Merge branch 'develop' into issue/471
peter-lawrey Jun 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/net/openhft/chronicle/wire/WireDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ else if (Wires.isNotComplete(header))
len = (int) textBytes.readRemaining();
}
try {
// trim spaces
for (; len > 0; len--)
if (textBytes.readUnsignedByte(textBytes.readPosition() + len - 1) != ' ')
break;
for (int i = 0; i < len; i++) {
int ch = textBytes.readUnsignedByte();
sb.append((char) ch);
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/net/openhft/chronicle/wire/WireType.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ public enum WireType implements Function<Bytes<?>, Wire>, LicenceCheck {

TEXT {
private final boolean TEXT_AS_YAML = Jvm.getBoolean("wire.testAsYaml");

@NotNull
@Override
public Wire apply(@NotNull Bytes<?> bytes) {
if (TEXT_AS_YAML)
return YAML.apply(bytes);
return new TextWire(bytes).useBinaryDocuments();
final TextWire wire = new TextWire(bytes).useBinaryDocuments();
wire.usePadding(true);
return wire;
}

@Override
Expand All @@ -77,9 +80,10 @@ public <T> T fromString(Class<T> tClass, @NotNull CharSequence cs) {
Bytes<?> bytes = Bytes.allocateElasticDirect(cs.length());
try {
bytes.appendUtf8(cs);
@NotNull TextWire wire = (TextWire) apply(bytes);
@NotNull Wire wire = apply(bytes);
wire.consumePadding();
wire.consumeDocumentStart();
if (!TEXT_AS_YAML)
((TextWire) wire).consumeDocumentStart();
return wire.getValueIn().object(tClass);
} finally {
bytes.releaseLast();
Expand Down Expand Up @@ -277,7 +281,9 @@ public <T> T fromString(@NotNull CharSequence cs) {
@NotNull
@Override
public Wire apply(@NotNull Bytes<?> bytes) {
return new JSONWire(bytes).useBinaryDocuments();
final TextWire wire = new JSONWire(bytes).useBinaryDocuments();
wire.usePadding(true);
return wire;
}

@Override
Expand All @@ -301,7 +307,9 @@ public boolean isText() {
@NotNull
@Override
public Wire apply(@NotNull Bytes<?> bytes) {
return new YamlWire(bytes).useBinaryDocuments();
final YamlWire wire = new YamlWire(bytes).useBinaryDocuments();
wire.usePadding(true);
return wire;
}

@Override
Expand Down Expand Up @@ -463,7 +471,7 @@ public String asString(Object marshallable) {
private Bytes<?> asBytes(Object marshallable) {
Bytes<?> bytes = getBytesForToString();
Wire wire = apply(bytes);
wire.usePadding(AbstractWire.DEFAULT_USE_PADDING);
wire.usePadding(wire.isBinary() && AbstractWire.DEFAULT_USE_PADDING);
@NotNull final ValueOut valueOut = wire.getValueOut();

if (marshallable instanceof WriteMarshallable)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/openhft/chronicle/wire/YamlWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,9 @@ public <T> WireIn int32(@Nullable IntValue value, T t, @NotNull BiConsumer<T, In
@Override
public <T> boolean sequence(@NotNull T t, @NotNull BiConsumer<T, ValueIn> tReader) {
consumePadding();
if (isNull()) {
return false;
}
if (yt.current() == YamlToken.SEQUENCE_START) {
int minIndent = yt.secondTopContext().indent;
yt.next(Integer.MAX_VALUE);
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/net/openhft/chronicle/wire/BinaryWire2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,9 @@ public void testSequence() {
@NotNull Wire wire = createWire();
writeMessage(wire);

// System.out.println(wire.bytes().toHexString());

@NotNull Wire twire = WireType.TEXT.apply(Bytes.elasticByteBuffer());
twire.usePadding(true);
writeMessage(twire);

// System.out.println(Wires.fromSizePrefixedBlobs(twire.bytes()));

wire.bytes().releaseLast();
twire.bytes().releaseLast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class DocumentContextTest extends WireTestCommon {
@Test
public void multiMessageText() {
Wire wire = WireType.TEXT.apply(Bytes.allocateElasticOnHeap());
wire.usePadding(true);
Bytes<?> bytes = doTest(wire);
bytes.readSkip(4);
assertEquals("one: 1\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static Collection<Object[]> data() {
@Test
public void marshableStringBuilderTest() throws Exception {
final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());
CLASS_ALIASES.addAlias(MDTO2.class, "MDTO");

wire.writeDocument(false, w -> new MDTO2(1, 2, "3").writeMarshallable(w));
Expand All @@ -79,7 +79,7 @@ public void backwardsCompatibility() {
expectException("Replaced class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityMarshallableTest$MDTO1 with class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityMarshallableTest$MDTO2");

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());
CLASS_ALIASES.addAlias(MDTO1.class, "MDTO");

wire.writeDocument(false, w -> w.getValueOut().typedMarshallable(new MDTO1(1)));
Expand All @@ -106,7 +106,7 @@ public void forwardCompatibility() {
expectException("Replaced class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityMarshallableTest$MDTO2 with class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityMarshallableTest$MDTO1");

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());
CLASS_ALIASES.addAlias(MDTO2.class, "MDTO");

wire.writeDocument(false, w -> w.getValueOut().typedMarshallable(new MDTO2(1, 2, "3")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void backwardsCompatibility() {
expectException("Replaced class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityTest$DTO1 with class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityTest$DTO2");

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());
CLASS_ALIASES.addAlias(DTO1.class, "DTO");

wire.writeDocument(false, w -> w.getValueOut().typedMarshallable(new DTO1(1)));
Expand All @@ -80,7 +80,7 @@ public void forwardCompatibility() {
expectException("Replaced class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityTest$DTO2 with class net.openhft.chronicle.wire.ForwardAndBackwardCompatibilityTest$DTO1");

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());
CLASS_ALIASES.addAlias(DTO2.class, "DTO");

wire.writeDocument(false, w -> w.getValueOut().typedMarshallable(new DTO2(1, 2, 3)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public void testUnsuccessfulCallIsDelegatedYamlWire() {
}

private void doTestUnsuccessfullCallIsDelegated(Wire wire) {
wire.usePadding(true);

final MyInterface writer = wire.methodWriter(MyInterface.class);
writer.myCall();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void testMappedTopLevel() {
public void testMapReadAndWrite() {
Bytes<?> bytes = Bytes.elasticByteBuffer();
Wire wire = wireType.apply(bytes);
wire.usePadding(true);
wire.usePadding(wire.isBinary());

@NotNull final Map<Integer, Integer> expected = new HashMap<>();
expected.put(1, 2);
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/net/openhft/chronicle/wire/RFCExamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void testPuts() {
writeMessageOne(text);

// System.out.println(Wires.fromSizePrefixedBlobs(bytes));
assertEquals("--- !!meta-data\n" +
assertEquals("" +
"--- !!meta-data\n" +
"csp: ///service-lookup\n" +
"tid: 149873598325\n" +
" \n" +
"# position: 48, header: 0\n" +
"--- !!data\n" +
"lookup: {\n" +
Expand All @@ -64,8 +64,7 @@ public void testPuts() {
" keyType: !type Integer,\n" +
" valueType: !type String\n" +
" }\n" +
"}\n" +
" \n",
"}\n",
Wires.fromSizePrefixedBlobs(bytes));

@NotNull Wire wire = new BinaryWire(bytes);
Expand Down Expand Up @@ -105,21 +104,18 @@ public void testPuts() {
"--- !!meta-data\n" +
"csp: //server1/test\n" +
"cid: 1\n" +
" \n" +
"# position: 32, header: 0\n" +
"--- !!data\n" +
"put: {\n" +
" key: 1,\n" +
" value: hello\n" +
"}\n" +
" \n" +
"# position: 72, header: 1\n" +
"--- !!data\n" +
"put: {\n" +
" key: 2,\n" +
" value: world\n" +
"}\n" +
" \n" +
"# position: 112, header: 2\n" +
"--- !!data\n" +
"put: {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void testWritingNotCompleteDocumentShared() throws IOException {
@NotNull MappedBytes b = MappedBytes.mappedBytes(File.createTempFile("delete", "me"), 64 << 10);
assertTrue(b.sharedMemory());
@NotNull Wire wire = WireType.TEXT.apply(b);
wire.usePadding(true);
assertTrue(wire.notCompleteIsNotPresent());

try (DocumentContext dc = wire.readingDocument()) {
Expand Down Expand Up @@ -116,7 +115,6 @@ public void testEmptyMessage() {
Bytes<?> b = Bytes.elasticByteBuffer();

Wire textWire = WireType.TEXT.apply(b);
textWire.usePadding(true);

textWire.writeDocument(true, w -> {
});
Expand Down Expand Up @@ -145,7 +143,6 @@ public void testReadingADocumentThatHasNotBeenFullyReadFromTheTcpSocketAt2Bytes(
Bytes<?> b = Bytes.elasticByteBuffer();

Wire textWire = WireType.TEXT.apply(b);
textWire.usePadding(true);

textWire.writeDocument(true, w -> w.write("key").text("someText"));
textWire.writeDocument(true, w -> w.write("key").text("someText"));
Expand Down Expand Up @@ -191,7 +188,6 @@ public void testReadingADocumentThatHasNotBeenFullyReadFromTheTcpSocketAt5Bytes(
Bytes<?> b = Bytes.elasticByteBuffer();

Wire wire = WireType.TEXT.apply(b);
wire.usePadding(true);

wire.writeDocument(true, w -> w.write("key").text("someText"));
wire.writeDocument(true, w -> w.write("key").text("someText"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ public void example5() {
Bytes<ByteBuffer> bytes = Bytes.elasticByteBuffer();

@NotNull Wire wire = WireType.TEXT.apply(bytes);
wire.usePadding(true);

ClassAliasPool.CLASS_ALIASES.addAlias(Data.class);

Expand Down Expand Up @@ -386,7 +385,6 @@ public void example6() {
Bytes<ByteBuffer> bytes = Bytes.elasticByteBuffer();

@NotNull Wire wire = WireType.TEXT.apply(bytes);
wire.usePadding(true);

ClassAliasPool.CLASS_ALIASES.addAlias(Data.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testValueOf() {

public Wire createWire() {
final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());
return wire;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class TextDocumentTest extends WireTestCommon {
public void testDocument() {
@NotNull Bytes<?> bytes1 = Bytes.allocateElasticOnHeap();
@NotNull final Wire wire = WireType.TEXT.apply(bytes1);
wire.usePadding(true);
@NotNull final Header wheader = new Header();
@NotNull final Header rheader = new Header();

Expand Down
6 changes: 2 additions & 4 deletions src/test/java/net/openhft/chronicle/wire/TextWireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ public void testWrite() {
private Wire createWire() {
bytes = allocateElasticOnHeap();
final Wire wire = WireType.TEXT.apply(bytes);
wire.usePadding(true);
return wire;
}

Expand Down Expand Up @@ -1496,13 +1495,12 @@ public void testByteArray() {
@NotNull byte[] four = {1, 2, 3, 4};
wire.writeDocument(false, w -> w.write("four").object(four));

assertEquals("--- !!data\n" +
assertEquals("" +
"--- !!data\n" +
"nothing: !byte[] !!binary \n" +
" \n" +
"# position: 32, header: 1\n" +
"--- !!data\n" +
"one: !byte[] !!binary AQ==\n" +
" \n" +
"# position: 64, header: 2\n" +
"--- !!data\n" +
"four: !byte[] !!binary AQIDBA==\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ private static BinaryWire createWire() {
final boolean fieldLess = false;
final int compressedSize = 128;
@NotNull BinaryWire wire = new BinaryWire(bytes, fixed, numericField, fieldLess, compressedSize, "lzw", false);
wire.usePadding(true);
assert wire.startUse();
return wire;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void testUpdateInterceptorNoReturnType() {

static Wire createWire() {
final Wire wire = BINARY.apply(Bytes.allocateElasticOnHeap());
wire.usePadding(true);
return wire;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void testConverMarshallableToTextName() {
Bytes<ByteBuffer> byteBufferBytes = Bytes.elasticByteBuffer();

@NotNull Wire wire = WireType.TEXT.apply(byteBufferBytes);
wire.usePadding(true);
wire.bytes().readPosition();

wire.writeDocument(false, d -> d.write(() -> "any-key").marshallable(testMarshallable));
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/net/openhft/chronicle/wire/ValueOutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static Collection<Object[]> data() {
public void test() {

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());

assert wire.startUse();
@NotNull final byte[] expected = "this is my byte array".getBytes(ISO_8859_1);
Expand All @@ -76,7 +76,7 @@ public void test() {
public void testRequestedType() {

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());

assert wire.startUse();
@NotNull final byte[] expected = "this is my byte array".getBytes(ISO_8859_1);
Expand All @@ -96,7 +96,7 @@ public void testRequestedType() {
public void testAllBytes() {

final Wire wire = wireType.apply(Bytes.elasticByteBuffer());
wire.usePadding(true);
wire.usePadding(wire.isBinary());

assert wire.startUse();
for (int i = -128; i < 127; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public WireDumperTest(final String name, final WireType wireType) {
bytes = Bytes.allocateElasticOnHeap();
wire = wireType.apply(bytes);
wire.usePadding(true);

this.wireType = wireType;
initTestData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void testMappedBytesWireRelease2() throws Exception {
assertEquals(1, t.refCount());
assertEquals(1, t.mappedFile().refCount());
Wire wire = WireType.TEXT.apply(t);
wire.usePadding(true);

assertEquals(1, t.refCount()); // not really using it yet
assertEquals(1, t.mappedFile().refCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void chainedPlainText() {
@Test
public void nestedText() {
Wire wire = WireType.TEXT.apply(Bytes.allocateElasticOnHeap());
wire.usePadding(true);

writeThreeKeys(wire);
assertEquals(21, wire.bytes().readInt());
Expand All @@ -68,7 +67,6 @@ public void nestedText() {
@Test
public void chainedText() {
Wire wire = WireType.TEXT.apply(Bytes.allocateElasticOnHeap());
wire.usePadding(true);

writeThreeChainedKeys(wire);
assertEquals(21, wire.bytes().readInt());
Expand Down
1 change: 0 additions & 1 deletion src/test/java/net/openhft/chronicle/wire/YamlWireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,6 @@ public void testConsumeAny() {
public void testMapReadAndWriteStrings() {
@NotNull final Bytes<?> bytes = allocateElasticOnHeap();
@NotNull final Wire wire = new YamlWire(bytes);
wire.usePadding(true);

@NotNull final Map<String, String> expected = new LinkedHashMap<>();

Expand Down
Loading