forked from OpenHFT/Chronicle-Wire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GPT-4 generated example * Fix for windows, and add coverage for DTOs * Fix for windows, and add coverage for DTOs --------- Co-authored-by: Peter Lawrey <[email protected]>
- Loading branch information
1 parent
8f8dee4
commit d83fc08
Showing
18 changed files
with
377 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/net/openhft/chronicle/wire/generated/ChronicleWireMethodExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package net.openhft.chronicle.wire.generated; | ||
|
||
import net.openhft.chronicle.bytes.Bytes; | ||
import net.openhft.chronicle.bytes.MethodReader; | ||
import net.openhft.chronicle.wire.Wire; | ||
import net.openhft.chronicle.wire.WireType; | ||
|
||
interface MyService { | ||
void foo(int arg1, String arg2); | ||
|
||
int bar(String arg1, long arg2); | ||
} | ||
|
||
class MyServiceImpl implements MyService { | ||
@Override | ||
public void foo(int arg1, String arg2) { | ||
System.out.printf("MyServiceImpl.foo(%d, %s)\n", arg1, arg2); | ||
} | ||
|
||
@Override | ||
public int bar(String arg1, long arg2) { | ||
System.out.printf("MyServiceImpl.bar(%s, %d)\n", arg1, arg2); | ||
return arg1.length() + (int) arg2; | ||
} | ||
} | ||
|
||
public class ChronicleWireMethodExample { | ||
|
||
// GPT-4 Generated example | ||
public static void main(String[] args) { | ||
|
||
MyService service = new MyServiceImpl(); | ||
|
||
// Create a MethodWriter | ||
Bytes<?> bytes = Bytes.elasticByteBuffer(); | ||
Wire wire = WireType.BINARY.apply(bytes); | ||
MyService writer = wire.methodWriter(MyService.class); | ||
|
||
// Call methods on the MethodWriter | ||
writer.foo(123, "hello world"); | ||
int result = writer.bar("hello", 12345L); | ||
|
||
// Create a MethodReader | ||
Wire wire2 = WireType.BINARY.apply(bytes); | ||
int counter = 0; | ||
MethodReader reader = wire2.methodReader(service, new MyServiceImpl()); | ||
|
||
// Read and process the method calls from the BytesStore | ||
while (reader.readOne()) { | ||
counter++; | ||
} | ||
|
||
// Check that the correct number of method calls were read | ||
assert (counter == 2); | ||
|
||
// Print the return value of the second method call | ||
System.out.println("Result: " + result); | ||
|
||
// Clean up | ||
bytes.releaseLast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/run/chronicle/account/dto/AccountStatusFailedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package run.chronicle.account.dto; | ||
|
||
import net.openhft.chronicle.wire.Marshallable; | ||
import net.openhft.chronicle.wire.converter.Base85; | ||
import org.junit.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static run.chronicle.account.dto.AccountStatusTest.getAccountStatus; | ||
|
||
public class AccountStatusFailedTest { | ||
@Test | ||
public void testFromString() { | ||
AccountStatusFailed asf = Marshallable.fromString(""+ | ||
"!run.chronicle.account.dto.AccountStatusFailed {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001/02/03T04:05:06.007008009,\n" + | ||
" accountStatus: {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.007008009,\n" + | ||
" name: name,\n" + | ||
" account: 2,\n" + | ||
" currency: CURR,\n" + | ||
" amount: 1.0" + | ||
" },\n" + | ||
" reason: reasons\n" + | ||
"}"); | ||
assertEquals("sender", Base85.INSTANCE.asString(asf.sender())); | ||
assertEquals("target", Base85.INSTANCE.asString(asf.target())); | ||
assertEquals("reasons", asf.reason()); | ||
assertEquals(getAccountStatus(), asf.accountStatus()); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/run/chronicle/account/dto/AccountStatusOKTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package run.chronicle.account.dto; | ||
|
||
import net.openhft.chronicle.wire.Marshallable; | ||
import net.openhft.chronicle.wire.converter.Base85; | ||
import org.junit.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static run.chronicle.account.dto.AccountStatusTest.getAccountStatus; | ||
|
||
public class AccountStatusOKTest { | ||
@Test | ||
public void testFromString() { | ||
AccountStatusOK asf = Marshallable.fromString(""+ | ||
"!run.chronicle.account.dto.AccountStatusOK {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001/02/03T04:05:06.007008009,\n" + | ||
" accountStatus: {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.007008009,\n" + | ||
" name: name,\n" + | ||
" account: 2,\n" + | ||
" currency: CURR,\n" + | ||
" amount: 1.0" + | ||
" }\n" + | ||
"}"); | ||
assertEquals("sender", Base85.INSTANCE.asString(asf.sender())); | ||
assertEquals("target", Base85.INSTANCE.asString(asf.target())); | ||
assertEquals(getAccountStatus(), asf.accountStatus()); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/run/chronicle/account/dto/AccountStatusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package run.chronicle.account.dto; | ||
|
||
import net.openhft.chronicle.wire.converter.Base85; | ||
import net.openhft.chronicle.wire.converter.NanoTime; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class AccountStatusTest { | ||
@Test | ||
public void testToString() { | ||
assertEquals("" + | ||
"!run.chronicle.account.dto.AccountStatus {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.007008009,\n" + | ||
" name: name,\n" + | ||
" account: 2,\n" + | ||
" currency: CURR,\n" + | ||
" amount: 1.0\n" + | ||
"}\n", | ||
getAccountStatus().toString()); | ||
} | ||
|
||
static AccountStatus getAccountStatus() { | ||
return new AccountStatus() | ||
.sender(Base85.INSTANCE.parse("sender")) | ||
.target(Base85.INSTANCE.parse("target")) | ||
.sendingTime(NanoTime.INSTANCE.parse("2001/02/03T04:05:06.007008009")) | ||
.amount(1) | ||
.account(2) | ||
.currency((int) Base85.INSTANCE.parse("CURR")) | ||
.name("name"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/run/chronicle/account/dto/TransferFailedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package run.chronicle.account.dto; | ||
|
||
import net.openhft.chronicle.wire.Marshallable; | ||
import net.openhft.chronicle.wire.converter.Base85; | ||
import net.openhft.chronicle.wire.converter.NanoTime; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TransferFailedTest { | ||
|
||
public static final String EXPECTED = "" + | ||
"!run.chronicle.account.dto.TransferFailed {\n" + | ||
" sender: target,\n" + | ||
" target: sender,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.777888999,\n" + | ||
" transfer: {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.007008009,\n" + | ||
" from: 12345,\n" + | ||
" to: 67890,\n" + | ||
" currency: CURR,\n" + | ||
" amount: 1.0,\n" + | ||
" reference: reference\n" + | ||
" },\n" + | ||
" reason: reasons\n" + | ||
"}\n"; | ||
|
||
@Test | ||
public void testToString() { | ||
assertEquals(EXPECTED, | ||
new TransferFailed() | ||
.target(Base85.INSTANCE.parse("sender")) | ||
.sender(Base85.INSTANCE.parse("target")) | ||
.sendingTime(NanoTime.INSTANCE.parse("2001/02/03T04:05:06.777888999")) | ||
.reason("reasons") | ||
.transfer(TransferTest.getTransfer()) | ||
.toString()); | ||
} | ||
|
||
@Test | ||
public void testFromString() { | ||
TransferFailed tf = Marshallable.fromString(EXPECTED); | ||
assertEquals(TransferTest.getTransfer(), tf.transfer()); | ||
assertEquals("reasons", tf.reason()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/run/chronicle/account/dto/TransferOKTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package run.chronicle.account.dto; | ||
|
||
import net.openhft.chronicle.bytes.Bytes; | ||
import net.openhft.chronicle.wire.Marshallable; | ||
import net.openhft.chronicle.wire.converter.Base85; | ||
import net.openhft.chronicle.wire.converter.NanoTime; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static run.chronicle.account.dto.TransferTest.getTransfer; | ||
|
||
public class TransferOKTest { | ||
|
||
public static final String EXPECTED = "" + | ||
"!run.chronicle.account.dto.TransferOK {\n" + | ||
" sender: target,\n" + | ||
" target: sender,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.777888999,\n" + | ||
" transfer: {\n" + | ||
" sender: sender,\n" + | ||
" target: target,\n" + | ||
" sendingTime: 2001-02-03T04:05:06.007008009,\n" + | ||
" from: 12345,\n" + | ||
" to: 67890,\n" + | ||
" currency: CURR,\n" + | ||
" amount: 1.0,\n" + | ||
" reference: reference\n" + | ||
" }\n" + | ||
"}\n"; | ||
|
||
@Test | ||
public void testToString() { | ||
assertEquals(EXPECTED, | ||
new TransferOK() | ||
.target(Base85.INSTANCE.parse("sender")) | ||
.sender(Base85.INSTANCE.parse("target")) | ||
.sendingTime(NanoTime.INSTANCE.parse("2001/02/03T04:05:06.777888999")) | ||
.transfer(getTransfer()) | ||
.toString()); | ||
} | ||
|
||
@Test | ||
public void testFromString() { | ||
TransferOK tok = Marshallable.fromString(EXPECTED); | ||
assertEquals(TransferTest.getTransfer(), tok.transfer()); | ||
} | ||
} |
Oops, something went wrong.