Skip to content

Commit

Permalink
Issue/471 (#480)
Browse files Browse the repository at this point in the history
* Remove addPadding(true) for useTextDocuments() #471

* Remove addPadding(true) for useTextDocuments() #471

* Improve handling of null in a sequence #471

* rename broken test - check behaviour of MethodIds in generated MethodReader

* sonar code smells

* deprecate VanillaMethodReaderBuilder.ignoreDefaults

* deprecate VanillaMethodWriterBuilder.methodWriterInterceptorReturns

* Updating to bom version 2.23ea44

* [maven-release-plugin] prepare release chronicle-wire-2.23ea9

* [maven-release-plugin] prepare for next development iteration

* Reverting back to bom version 2.23ea-SNAPSHOT

* Infinite message loop is possible with dontWriteHistoryForEventsWithNoOutput=false, closes ChronicleEnterprise/Chronicle-Services-Enterprise#330

* For functions with with primitive return values, make generated method writers behave the same as Proxy method writers

* Enhance ChainedMethodsTest for old-style proxies and also generated code

* un-Ignore tests

* Updating to bom version 2.23ea45

* [maven-release-plugin] prepare release chronicle-wire-2.23ea10

* [maven-release-plugin] prepare for next development iteration

* Reverting back to bom version 2.23ea-SNAPSHOT

* fix generated code method writer for generic return types

* Add methods (#474)

* update.

* update.

* Add replay method and tests.

* Added a test for the microservice

* Add Javadoc.

Co-authored-by: Peter Lawrey <peter.lawrey@chronicle.software>
Co-authored-by: Peter K Lawrey <peter.lawrey@higherfrequencytrading.com>

* Added a YamlTester interface to simplify running YAML based tests #475

* Added a YamlTester interface to simplify running YAML based tests #475

* Added a YamlTester interface to simplify running YAML based tests #475

* Added a YamlTester interface to simplify running YAML based tests #475

* Updating to bom version 2.23ea49

* [maven-release-plugin] prepare release chronicle-wire-2.23ea12

* [maven-release-plugin] prepare for next development iteration

* Reverting back to bom version 2.23ea-SNAPSHOT

* Updating parent POM (automated)

* Ignore some packages in SOT (#479)

* Ignore flappy test #482

* Ignore flappy test #482

* Remove delegate from generated MethodReader to proxied MethodReader. Support defaultParselet. Warnings for users of deprecated methods. Better reporting of method writer compilation failure. Warning that proxies will be dropped in x.25

* Updating parent POM (automated)

* Un-pin the binary-compatibility-enforcer version

* Flaky test fix

closes #486

* Remove addPadding(true) for useTextDocuments() #471

* Remove addPadding(true) for useTextDocuments() #471

Co-authored-by: Peter Lawrey <peter.lawrey@chronicle.software>
Co-authored-by: Jerry Shea <jerry.shea@chronicle.software>
Co-authored-by: hft-team-city <teamcity@chronicle.software>
Co-authored-by: Ivan Rakov <ivan.glukos@gmail.com>
Co-authored-by: Forough Goudarzi <forough.goudarzi@chronicle.software>
Co-authored-by: Per-Åke Minborg <minborg@speedment.com>
Co-authored-by: Nick Tindall <nick@tindall.id.au>
Co-authored-by: Ilya Kaznacheev <ilya.kaznacheev@chronicle.software>
  • Loading branch information
9 people committed Jun 6, 2022
1 parent 0487c48 commit 8cf056b
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 54 deletions.
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 @@ -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 @@ -50,7 +50,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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MethodWriter2Test extends WireTestCommon {

@Test
public void allowThrough() {
ignoreException("Generated code to call updateInterceptor for public abstract void net.openhft.chronicle.wire.method.FundingListener.fundingPrimitive(int) will box and generate garbage");
check(true, ARGUMENT.DTO);
}

Expand Down
Loading

0 comments on commit 8cf056b

Please sign in to comment.