Skip to content

Commit

Permalink
Fix WireTypeConverterWithUnknownClassesLookupTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
yevgenp committed Jan 30, 2024
1 parent 4a04f97 commit 05fa50e
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public Class<?> forName(CharSequence name) throws ClassNotFoundRuntimeException
try {
return delegate.forName(name);
} catch (Exception e) {
String className = name.toString();
String[] parts = name.toString().split("\\.");
String className = parts[parts.length - 1];
Class<?> unknownClass;
try {
unknownClass = CACHED_COMPILER.loadFromJava(className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,126 @@
import net.openhft.chronicle.wire.internal.UnknownClassLookup;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class WireTypeConverterWithUnknownClassesLookupTest { //extends WireTestCommon {
@Test
public void fromYamlToJsonAndBackToYaml() {
//WireTypeConverter wireTypeConverter = new WireTypeConverter(new UnknownClassLookup(ClassAliasPool.CLASS_ALIASES));
WireTypeConverter wireTypeConverter = new WireTypeConverter();
WireTypeConverter wireTypeConverter = new WireTypeConverter(new UnknownClassLookup(ClassAliasPool.CLASS_ALIASES));
Wires.GENERATE_TUPLES = true;
Wires.THROW_CNFRE = false;
String yaml = "!ChronicleServicesCfg {\n" +
" queues: {\n" +
" in: { path: tmp/benchmark/in },\n" +
" sender-one-out: { path: tmp/benchmark/sender-one-out, builder: !SingleChronicleQueueBuilder { useSparseFiles: true, rollCycle: HUGE_DAILY } },\n" +
" sender-two-out: { path: tmp/benchmark/sender-two-out, builder: !SingleChronicleQueueBuilder { useSparseFiles: true, rollCycle: HUGE_DAILY } },\n" +
" sender-three-out: { path: tmp/benchmark/sender-three-out, builder: !SingleChronicleQueueBuilder { useSparseFiles: true, rollCycle: HUGE_DAILY } },\n" +
" receiver-out: { path: tmp/benchmark/receiver-out },\n" +
" },\n" +
" services: {\n" +
" sender-one: {\n" +
" inputs: [ in ],\n" +
" output: sender-one-out,\n" +
" startFromStrategy: ${property.name},\n" +
" affinityCpu: any,\n" +
" pretouchMS: 100,\n" +
" serviceConfig: {\n" +
" param: !CustomClass1 {\n" +
" param2: value\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
" queues: {\n" +
" in: {\n" +
" path: tmp/benchmark/in\n" +
" },\n" +
" sender-one-out: {\n" +
" path: tmp/benchmark/sender-one-out,\n" +
" builder: !SingleChronicleQueueBuilder {\n" +
" useSparseFiles: true,\n" +
" rollCycle: HUGE_DAILY\n" +
" }\n" +
" },\n" +
" sender-two-out: {\n" +
" path: tmp/benchmark/sender-two-out,\n" +
" builder: !SingleChronicleQueueBuilder {\n" +
" useSparseFiles: true,\n" +
" rollCycle: HUGE_DAILY\n" +
" }\n" +
" },\n" +
" sender-three-out: {\n" +
" path: tmp/benchmark/sender-three-out,\n" +
" builder: !SingleChronicleQueueBuilder {\n" +
" useSparseFiles: true,\n" +
" rollCycle: HUGE_DAILY\n" +
" }\n" +
" },\n" +
" receiver-out: {\n" +
" path: tmp/benchmark/receiver-out\n" +
" }\n" +
" },\n" +
" services: {\n" +
" sender-one: {\n" +
" inputs: [\n" +
" in\n" +
" ],\n" +
" output: sender-one-out,\n" +
" startFromStrategy: $property.name,\n" +
" affinityCpu: any,\n" +
" pretouchMS: 100,\n" +
" serviceConfig: {\n" +
" param: !CustomClass1 {\n" +
" param2: value\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n";

CharSequence json = wireTypeConverter.yamlToJson(yaml);
System.out.println(json);

CharSequence backToYaml = wireTypeConverter.jsonToYaml(json);
System.out.println(backToYaml);
CharSequence backToYaml = wireTypeConverter.jsonToYaml(json.toString());

assertEquals(yaml, backToYaml.toString());
}

@Test
public void typeReference() {
//WireTypeConverter wireTypeConverter = new WireTypeConverter(new UnknownClassLookup(ClassAliasPool.CLASS_ALIASES));
WireTypeConverter wireTypeConverter = new WireTypeConverter();
WireTypeConverter wireTypeConverter = new WireTypeConverter(new UnknownClassLookup(ClassAliasPool.CLASS_ALIASES));
Wires.GENERATE_TUPLES = true;
Wires.THROW_CNFRE = false;
String yaml = "!ChronicleServicesCfg {\n" +
" queues: {\n" +
" in: { path: tmp/benchmark/in },\n" +
" sender-one-out: { path: tmp/benchmark/sender-one-out, builder: !SingleChronicleQueueBuilder { useSparseFiles: true, rollCycle: HUGE_DAILY } },\n" +
" sender-two-out: { path: tmp/benchmark/sender-two-out, builder: !SingleChronicleQueueBuilder { useSparseFiles: true, rollCycle: HUGE_DAILY } },\n" +
" sender-three-out: { path: tmp/benchmark/sender-three-out, builder: !SingleChronicleQueueBuilder { useSparseFiles: true, rollCycle: HUGE_DAILY } },\n" +
" receiver-out: { path: tmp/benchmark/receiver-out },\n" +
" },\n" +
" services: {\n" +
" sender-one: {\n" +
" inputs: [ in ],\n" +
" output: sender-one-out,\n" +
" startFromStrategy: START,\n" +
" affinityCpu: any,\n" +
" pretouchMS: 100,\n" +
" implClass: !type non.existing.package.SenderOneService,\n" +
" serviceConfig: {\n" +
" param: !CustomClass1 {\n" +
" param2: value\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
" queues: {\n" +
" in: {\n" +
" path: tmp/benchmark/in\n" +
" },\n" +
" sender-one-out: {\n" +
" path: tmp/benchmark/sender-one-out,\n" +
" builder: !SingleChronicleQueueBuilder {\n" +
" useSparseFiles: true,\n" +
" rollCycle: HUGE_DAILY\n" +
" }\n" +
" },\n" +
" sender-two-out: {\n" +
" path: tmp/benchmark/sender-two-out,\n" +
" builder: !SingleChronicleQueueBuilder {\n" +
" useSparseFiles: true,\n" +
" rollCycle: HUGE_DAILY\n" +
" }\n" +
" },\n" +
" sender-three-out: {\n" +
" path: tmp/benchmark/sender-three-out,\n" +
" builder: !SingleChronicleQueueBuilder {\n" +
" useSparseFiles: true,\n" +
" rollCycle: HUGE_DAILY\n" +
" }\n" +
" },\n" +
" receiver-out: {\n" +
" path: tmp/benchmark/receiver-out\n" +
" }\n" +
" },\n" +
" services: {\n" +
" sender-one: {\n" +
" inputs: [\n" +
" in\n" +
" ],\n" +
" output: sender-one-out,\n" +
" startFromStrategy: START,\n" +
" affinityCpu: any,\n" +
" pretouchMS: 100,\n" +
" serviceConfig: {\n" +
" param: !CustomClass1 {\n" +
" param2: value\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n";

CharSequence json = wireTypeConverter.yamlToJson(yaml);
System.out.println(json);

CharSequence backToYaml = wireTypeConverter.jsonToYaml(json);
System.out.println(backToYaml);
CharSequence backToYaml = wireTypeConverter.jsonToYaml(json.toString());

assertEquals(yaml, backToYaml.toString());
}
}

0 comments on commit 05fa50e

Please sign in to comment.