Skip to content
Snippets Groups Projects
Commit b71daace authored by René Schöne's avatar René Schöne
Browse files

Resolve "Refactorings/Clean-Up"

- add cloc and two use cases to pages
- move some aspects into separate template files
- add a method to reset the evaluation counter
- rename forwardingNTA to forwarding
- begin with default mappings using templates 
- also indirectly work on #55 to include marshalling methods only when needed
- move TestUtils to a separate package
parent da232e01
No related branches found
No related tags found
3 merge requests!39Version 1.1.0,!35Version 1.0.0,!33Resolve "Refactorings/Clean-Up"
Showing
with 334 additions and 388 deletions
{{#hasTreeListEndpoints}}
public void {{configJastAddList}}.serialize(com.fasterxml.jackson.core.JsonGenerator g) throws SerializationException {
try {
g.writeStartArray();
for (T child : this) {
child.serialize(g);
}
g.writeEndArray();
} catch (java.io.IOException e) {
throw new SerializationException("unable to serialize {{configJastAddList}}", e);
}
}
protected static <T extends ASTNode> void ASTNode.serializeJavaUtilList(
java.util.List<T> input, com.fasterxml.jackson.core.JsonGenerator g) throws SerializationException {
try {
g.writeStartArray();
for (T child : input) {
child.serialize(g);
}
g.writeEndArray();
} catch (java.io.IOException e) {
throw new SerializationException("unable to serialize list", e);
}
}
{{#typesForReceivingListEndpoints}}
public static {{configJastAddList}}<{{Name}}> {{Name}}.deserializeList(com.fasterxml.jackson.databind.node.ArrayNode node) throws DeserializationException {
{{configJastAddList}}<{{Name}}> result = new {{configJastAddList}}<>();
for (java.util.Iterator<com.fasterxml.jackson.databind.JsonNode> it = node.elements(); it.hasNext();) {
com.fasterxml.jackson.databind.JsonNode element = it.next();
result.add(deserialize(element));
}
return result;
}
{{/typesForReceivingListEndpoints}}
{{/hasTreeListEndpoints}}
{{#configIncrementalOptionActive}}
aspect RagConnectObserver {
class RagConnectObserver implements ASTState.Trace.Receiver {
class RagConnectObserverEntry {
final ASTNode node;
final String attributeString;
final boolean compareParams;
final Object params;
final Runnable attributeCall;
//final RagConnectToken connectToken;
final java.util.List<RagConnectToken> connectList = new java.util.ArrayList<>();
RagConnectObserverEntry(ASTNode node, String attributeString,
boolean compareParams, Object params, Runnable attributeCall) {
this.node = node;
this.attributeString = attributeString;
this.compareParams = compareParams;
this.params = params;
this.attributeCall = attributeCall;
}
boolean baseMembersEqualTo(RagConnectObserverEntry other) {
return baseMembersEqualTo(other.node, other.attributeString, other.compareParams, other.params);
}
boolean baseMembersEqualTo(ASTNode otherNode, String otherAttributeString,
boolean forceCompareParams, Object otherParams) {
return this.node.equals(otherNode) &&
this.attributeString.equals(otherAttributeString) &&
//this.compareParams == otherCompareParams &&
(!(this.compareParams || forceCompareParams) || java.util.Objects.equals(this.params, otherParams));
}
}
{{#configExperimentalJastAdd329}}
class RagConnectObserverStartEntry {
final ASTNode node;
final String attributeString;
final Object flushIncToken;
RagConnectObserverStartEntry(ASTNode node, String attributeString, Object flushIncToken) {
this.node = node;
this.attributeString = attributeString;
this.flushIncToken = flushIncToken;
}
}
{{/configExperimentalJastAdd329}}
ASTState.Trace.Receiver oldReceiver;
java.util.List<RagConnectObserverEntry> observedNodes = new java.util.ArrayList<>();
{{#configExperimentalJastAdd329}}
java.util.Set<RagConnectObserverEntry> entryQueue = new java.util.HashSet<>();
java.util.Deque<RagConnectObserverStartEntry> startEntries = new java.util.LinkedList<>();
{{/configExperimentalJastAdd329}}
RagConnectObserver(ASTNode node) {
// set the receiver. potentially dangerous because overriding existing receiver!
oldReceiver = node.trace().getReceiver();
node.trace().setReceiver(this);
}
void add(RagConnectToken connectToken, ASTNode node, boolean compareParams, Object params,
Runnable attributeCall, String attributeString) {
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer add: {{log_}} on {{log_}}{{log_}}",
node, attributeString, (compareParams ? " (parameterized)" : ""));
{{/configLoggingEnabledForIncremental}}
// either add to an existing entry (with same node, attribute, params) or create new entry
boolean needNewEntry = true;
for (RagConnectObserverEntry entry : observedNodes) {
if (entry.baseMembersEqualTo(node, attributeString, true, params)) {
entry.connectList.add(connectToken);
needNewEntry = false;
break;
}
}
if (needNewEntry) {
RagConnectObserverEntry newEntry = new RagConnectObserverEntry(node, attributeString,
compareParams, params, attributeCall);
newEntry.connectList.add(connectToken);
observedNodes.add(newEntry);
}
}
void remove(RagConnectToken connectToken) {
java.util.List<RagConnectObserverEntry> entriesToDelete = new java.util.ArrayList<>();
for (RagConnectObserverEntry entry : observedNodes) {
entry.connectList.remove(connectToken);
if (entry.connectList.isEmpty()) {
entriesToDelete.add(entry);
}
}
observedNodes.removeAll(entriesToDelete);
}
@Override
public void accept(ASTState.Trace.Event event, ASTNode node, String attribute, Object params, Object value) {
oldReceiver.accept(event, node, attribute, params, value);
{{#configExperimentalJastAdd329}}
// react to INC_FLUSH_START and remember entry
if (event == ASTState.Trace.Event.INC_FLUSH_START) {
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer start: {{log_}} on {{log_}}", node, attribute);
{{/configLoggingEnabledForIncremental}}
startEntries.addFirst(new RagConnectObserverStartEntry(node, attribute, value));
return;
}
// react to INC_FLUSH_END and process queued entries, if it matches start entry
if (event == ASTState.Trace.Event.INC_FLUSH_END) {
if (startEntries.isEmpty()) {
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer end without start! for {{log_}} on {{log_}}", node, attribute);
{{/configLoggingEnabledForIncremental}}
return;
}
RagConnectObserverStartEntry startEntry = startEntries.peekFirst();
if (node == startEntry.node &&
attribute == startEntry.attributeString &&
value == startEntry.flushIncToken) {
// create a copy of the queue to avoid entering this again causing an endless recursion
RagConnectObserverEntry[] entriesToProcess = entryQueue.toArray(new RagConnectObserverEntry[entryQueue.size()]);
entryQueue.clear();
startEntries.removeFirst();
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer process (entries: {{log_}}): {{log_}} on {{log_}}",
entriesToProcess.length, node, attribute);
{{/configLoggingEnabledForIncremental}}
for (RagConnectObserverEntry entry : entriesToProcess) {
entry.attributeCall.run();
}
return;
}
}
{{/configExperimentalJastAdd329}}
// ignore all other events but INC_FLUSH_ATTR
if (event != ASTState.Trace.Event.INC_FLUSH_ATTR) {
return;
}
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer check INC_FLUSH_ATTR event: {{log_}} on {{log_}}", node, attribute);
{{/configLoggingEnabledForIncremental}}
// iterate through list, if matching pair. could maybe be more efficient.
for (RagConnectObserverEntry entry : observedNodes) {
if (entry.baseMembersEqualTo(node, attribute, false, params)) {
// hit. call the attribute/nta-token
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer hit: {{log_}} on {{log_}}", entry.node, entry.attributeString);
{{/configLoggingEnabledForIncremental}}
{{#configExperimentalJastAdd329}}
entryQueue.add(entry);
{{/configExperimentalJastAdd329}}
{{^configExperimentalJastAdd329}}
entry.attributeCall.run();
{{/configExperimentalJastAdd329}}
}
}
}
}
private static RagConnectObserver ASTNode.{{observerInstanceFieldName}};
RagConnectObserver ASTNode.{{observerInstanceSingletonMethodName}}() {
if ({{observerInstanceFieldName}} == null) {
// does not matter, which node is used to create the observer as ASTState/tracing is also static
{{observerInstanceFieldName}} = new RagConnectObserver(this);
}
return {{observerInstanceFieldName}};
}
void ASTNode.{{observerInstanceResetMethodName}}() {
{{observerInstanceFieldName}} = null;
}
}
{{/configIncrementalOptionActive}}
{{#isUsed}}
{{#isTemplateDefaultMappingDefinition}}
{{#isSerializeListMapping}}
public void {{configJastAddList}}.serialize(com.fasterxml.jackson.core.JsonGenerator g) throws SerializationException {
try {
g.writeStartArray();
for (T child : this) {
child.serialize(g);
}
g.writeEndArray();
} catch (java.io.IOException e) {
throw new SerializationException("unable to serialize {{configJastAddList}}", e);
}
}
{{/isSerializeListMapping}}
{{#SerializeJavaUtilListMapping}}
protected static <T extends ASTNode> void ASTNode.serializeJavaUtilList(
java.util.List<T> input, com.fasterxml.jackson.core.JsonGenerator g) throws SerializationException {
try {
g.writeStartArray();
for (T child : input) {
child.serialize(g);
}
g.writeEndArray();
} catch (java.io.IOException e) {
throw new SerializationException("unable to serialize list", e);
}
}
{{/SerializeJavaUtilListMapping}}
{{#DeserializeListMapping}}
public static {{configJastAddList}}<{{Name}}> {{Name}}.deserializeListOf{{Name}}(com.fasterxml.jackson.databind.node.ArrayNode node) throws DeserializationException {
{{configJastAddList}}<{{Name}}> result = new {{configJastAddList}}<>();
for (java.util.Iterator<com.fasterxml.jackson.databind.JsonNode> it = node.elements(); it.hasNext();) {
com.fasterxml.jackson.databind.JsonNode element = it.next();
result.add(deserialize(element));
}
return result;
}
{{/DeserializeListMapping}}
{{/isTemplateDefaultMappingDefinition}}
{{^TemplateDefaultMappingDefinition}}
protected {{{toType}}} ASTNode.{{methodName}}({{{fromType}}} {{FromVariableName}}) throws Exception { protected {{{toType}}} ASTNode.{{methodName}}({{{fromType}}} {{FromVariableName}}) throws Exception {
{{{Content}}} {{{Content}}}
} }
{{/TemplateDefaultMappingDefinition}}
{{/isUsed}}
{{> handler}} {{> handler}}
aspect RagConnect { aspect RagConnect {
{{#allEndpointDefinitionList}} {{#allPortDefinitionList}}
{{#Send}} {{#Send}}
{{> sendDefinition}} {{> sendDefinition}}
{{/Send}} {{/Send}}
{{^Send}} {{^Send}}
{{> receiveDefinition}} {{> receiveDefinition}}
{{/Send}} {{/Send}}
{{/allEndpointDefinitionList}} {{/allPortDefinitionList}}
class RagConnectRejectMappingException extends RuntimeException {} class RagConnectRejectMappingException extends RuntimeException {}
private static void ASTNode.reject() { private static void ASTNode.reject() {
...@@ -15,9 +15,7 @@ aspect RagConnect { ...@@ -15,9 +15,7 @@ aspect RagConnect {
} }
{{#allMappingDefinitions}} {{#allMappingDefinitions}}
{{#isUsed}}
{{> mappingDefinition}} {{> mappingDefinition}}
{{/isUsed}}
{{/allMappingDefinitions}} {{/allMappingDefinitions}}
{{#allDependencyDefinitionList}} {{#allDependencyDefinitionList}}
...@@ -28,9 +26,9 @@ aspect RagConnect { ...@@ -28,9 +26,9 @@ aspect RagConnect {
{{> tokenComponent}} {{> tokenComponent}}
{{/tokenComponentsThatNeedProxy}} {{/tokenComponentsThatNeedProxy}}
{{#typeDeclsOfContextFreeEndpointTargets}} {{#typeDeclsOfContextFreePortTargets}}
{{> typeDecl}} {{> typeDecl}}
{{/typeDeclsOfContextFreeEndpointTargets}} {{/typeDeclsOfContextFreePortTargets}}
{{! --- touchedTerminals ---}} {{! --- touchedTerminals ---}}
{{#allTypeDecls}} {{#allTypeDecls}}
...@@ -65,8 +63,6 @@ aspect RagConnect { ...@@ -65,8 +63,6 @@ aspect RagConnect {
return this; return this;
} }
{{> ListAspect}}
static void ASTNode.{{logConsoleOut}}(String message, Object... args) { static void ASTNode.{{logConsoleOut}}(String message, Object... args) {
System.out.println(String.format(message, args)); System.out.println(String.format(message, args));
} }
...@@ -99,276 +95,6 @@ aspect RagConnect { ...@@ -99,276 +95,6 @@ aspect RagConnect {
} }
} }
{{#configIncrementalOptionActive}} {{> RagConnectObserver}}
aspect RagConnectObserver {
class RagConnectObserver implements ASTState.Trace.Receiver {
class RagConnectObserverEntry {
final ASTNode node;
final String attributeString;
final boolean compareParams;
final Object params;
final Runnable attributeCall;
//final RagConnectToken connectToken;
final java.util.List<RagConnectToken> connectList = new java.util.ArrayList<>();
RagConnectObserverEntry(ASTNode node, String attributeString,
boolean compareParams, Object params, Runnable attributeCall) {
this.node = node;
this.attributeString = attributeString;
this.compareParams = compareParams;
this.params = params;
this.attributeCall = attributeCall;
}
boolean baseMembersEqualTo(RagConnectObserverEntry other) {
return baseMembersEqualTo(other.node, other.attributeString, other.compareParams, other.params);
}
boolean baseMembersEqualTo(ASTNode otherNode, String otherAttributeString,
boolean forceCompareParams, Object otherParams) {
return this.node.equals(otherNode) &&
this.attributeString.equals(otherAttributeString) &&
//this.compareParams == otherCompareParams &&
(!(this.compareParams || forceCompareParams) || java.util.Objects.equals(this.params, otherParams));
}
}
{{#configExperimentalJastAdd329}}
class RagConnectObserverStartEntry {
final ASTNode node;
final String attributeString;
final Object flushIncToken;
RagConnectObserverStartEntry(ASTNode node, String attributeString, Object flushIncToken) {
this.node = node;
this.attributeString = attributeString;
this.flushIncToken = flushIncToken;
}
}
{{/configExperimentalJastAdd329}}
ASTState.Trace.Receiver oldReceiver;
java.util.List<RagConnectObserverEntry> observedNodes = new java.util.ArrayList<>();
{{#configExperimentalJastAdd329}}
java.util.Set<RagConnectObserverEntry> entryQueue = new java.util.HashSet<>();
java.util.Deque<RagConnectObserverStartEntry> startEntries = new java.util.LinkedList<>();
{{/configExperimentalJastAdd329}}
RagConnectObserver(ASTNode node) {
// set the receiver. potentially dangerous because overriding existing receiver!
oldReceiver = node.trace().getReceiver();
node.trace().setReceiver(this);
}
void add(RagConnectToken connectToken, ASTNode node, boolean compareParams, Object params,
Runnable attributeCall, String attributeString) {
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer add: {{log_}} on {{log_}}{{log_}}",
node, attributeString, (compareParams ? " (parameterized)" : ""));
{{/configLoggingEnabledForIncremental}}
// either add to an existing entry (with same node, attribute, params) or create new entry
boolean needNewEntry = true;
for (RagConnectObserverEntry entry : observedNodes) {
if (entry.baseMembersEqualTo(node, attributeString, true, params)) {
entry.connectList.add(connectToken);
needNewEntry = false;
break;
}
}
if (needNewEntry) {
RagConnectObserverEntry newEntry = new RagConnectObserverEntry(node, attributeString,
compareParams, params, attributeCall);
newEntry.connectList.add(connectToken);
observedNodes.add(newEntry);
}
}
void remove(RagConnectToken connectToken) {
java.util.List<RagConnectObserverEntry> entriesToDelete = new java.util.ArrayList<>();
for (RagConnectObserverEntry entry : observedNodes) {
entry.connectList.remove(connectToken);
if (entry.connectList.isEmpty()) {
entriesToDelete.add(entry);
}
}
observedNodes.removeAll(entriesToDelete);
}
@Override
public void accept(ASTState.Trace.Event event, ASTNode node, String attribute, Object params, Object value) {
oldReceiver.accept(event, node, attribute, params, value);
{{#configExperimentalJastAdd329}}
// react to INC_FLUSH_START and remember entry
if (event == ASTState.Trace.Event.INC_FLUSH_START) {
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer start: {{log_}} on {{log_}}", node, attribute);
{{/configLoggingEnabledForIncremental}}
startEntries.addFirst(new RagConnectObserverStartEntry(node, attribute, value));
return;
}
// react to INC_FLUSH_END and process queued entries, if it matches start entry
if (event == ASTState.Trace.Event.INC_FLUSH_END) {
if (startEntries.isEmpty()) {
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer end without start! for {{log_}} on {{log_}}", node, attribute);
{{/configLoggingEnabledForIncremental}}
return;
}
RagConnectObserverStartEntry startEntry = startEntries.peekFirst();
if (node == startEntry.node &&
attribute == startEntry.attributeString &&
value == startEntry.flushIncToken) {
// create a copy of the queue to avoid entering this again causing an endless recursion
RagConnectObserverEntry[] entriesToProcess = entryQueue.toArray(new RagConnectObserverEntry[entryQueue.size()]);
entryQueue.clear();
startEntries.removeFirst();
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer process (entries: {{log_}}): {{log_}} on {{log_}}",
entriesToProcess.length, node, attribute);
{{/configLoggingEnabledForIncremental}}
for (RagConnectObserverEntry entry : entriesToProcess) {
entry.attributeCall.run();
}
return;
}
}
{{/configExperimentalJastAdd329}}
// ignore all other events but INC_FLUSH_ATTR
if (event != ASTState.Trace.Event.INC_FLUSH_ATTR) {
return;
}
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer check INC_FLUSH_ATTR event: {{log_}} on {{log_}}", node, attribute);
{{/configLoggingEnabledForIncremental}}
// iterate through list, if matching pair. could maybe be more efficient.
for (RagConnectObserverEntry entry : observedNodes) {
if (entry.baseMembersEqualTo(node, attribute, false, params)) {
// hit. call the attribute/nta-token
{{#configLoggingEnabledForIncremental}}
{{logDebug}}("** observer hit: {{log_}} on {{log_}}", entry.node, entry.attributeString);
{{/configLoggingEnabledForIncremental}}
{{#configExperimentalJastAdd329}}
entryQueue.add(entry);
{{/configExperimentalJastAdd329}}
{{^configExperimentalJastAdd329}}
entry.attributeCall.run();
{{/configExperimentalJastAdd329}}
}
}
}
}
private static RagConnectObserver ASTNode.{{observerInstanceFieldName}};
RagConnectObserver ASTNode.{{observerInstanceSingletonMethodName}}() {
if ({{observerInstanceFieldName}} == null) {
// does not matter, which node is used to create the observer as ASTState/tracing is also static
{{observerInstanceFieldName}} = new RagConnectObserver(this);
}
return {{observerInstanceFieldName}};
}
void ASTNode.{{observerInstanceResetMethodName}}() {
{{observerInstanceFieldName}} = null;
}
}
{{/configIncrementalOptionActive}}
aspect EvaluationCounter {
public String ASTNode.{{evaluationCounterSummaryMethodName}}() {
{{#configEvaluationCounter}}
return {{evaluationCounterVariable}}.summary();
{{/configEvaluationCounter}}
{{^configEvaluationCounter}}
String message = "Option --evaluationCounter was not set. No Summary available";
{{logWarn}}(message);
return message;
{{/configEvaluationCounter}}
}
{{#configEvaluationCounter}}
static EvaluationCounter ASTNode.{{evaluationCounterVariable}} = new EvaluationCounter();
public class EvaluationCounter {
private java.util.Map<String, java.util.Map<String, {{evaluationCounterInnerClass}}>> counters = new java.util.HashMap<>();
private final java.util.function.Function<? super String, ? extends java.util.Map<String, {{evaluationCounterInnerClass}}>> parentAbsent = key -> {
return new java.util.HashMap<>();
};
private final java.util.function.Function<? super String, ? extends {{evaluationCounterInnerClass}}> entityAbsent = key -> {
return new {{evaluationCounterInnerClass}}();
};
public void incrementReceive(String parentTypeName, String entityName) {
getCounter(parentTypeName, entityName).receive += 1;
}
public void incrementSend(String parentTypeName, String entityName) {
getCounter(parentTypeName, entityName).send += 1;
}
public void incrementCall(String parentTypeName, String entityName) { {{> EvaluationCounter}}
getCounter(parentTypeName, entityName).call += 1;
}
public void incrementFirstNull(String parentTypeName, String entityName) {
getCounter(parentTypeName, entityName).firstNull += 1;
}
public void incrementSkip(String parentTypeName, String entityName) {
getCounter(parentTypeName, entityName).skip += 1;
}
public void incrementException(String parentTypeName, String entityName) {
getCounter(parentTypeName, entityName).exception += 1;
}
public void incrementReject(String parentTypeName, String entityName) {
getCounter(parentTypeName, entityName).reject += 1;
}
public String summary() {
StringBuilder sb = new StringBuilder();
// header
sb.append("parentTypeName,entityName,receive,send,call,firstNull,skip,exception,reject").append("\n");
// values
java.util.Set<String> sortedParentTypes = new java.util.TreeSet<>(counters.keySet());
for (String parentType : sortedParentTypes) {
java.util.Set<String> sortedEntityNames = new java.util.TreeSet<>(counters.get(parentType).keySet());
for (String entityName : sortedEntityNames) {
{{evaluationCounterInnerClass}} count = getCounter(parentType, entityName);
java.util.StringJoiner sj = new java.util.StringJoiner(",", "", "\n");
sj.add(parentType)
.add(entityName)
.add(Integer.toString(count.receive))
.add(Integer.toString(count.send))
.add(Integer.toString(count.call))
.add(Integer.toString(count.firstNull))
.add(Integer.toString(count.skip))
.add(Integer.toString(count.exception))
.add(Integer.toString(count.reject))
;
sb.append(sj);
}
}
return sb.toString();
}
private {{evaluationCounterInnerClass}} getCounter(String parentTypeName, String entityName) {
return counters.computeIfAbsent(parentTypeName, parentAbsent).computeIfAbsent(entityName, entityAbsent);
}
}
class {{evaluationCounterInnerClass}} {
int receive = 0;
int send = 0;
int call = 0;
int firstNull = 0;
int skip = 0;
int exception = 0;
int reject = 0;
}
{{/configEvaluationCounter}}
}
...@@ -12,7 +12,7 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) { ...@@ -12,7 +12,7 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) {
{{/typeIsList}} {{/typeIsList}}
/** /**
* Connects the receive endpoint {{entityName}}. * Connects the receive port {{entityName}}.
{{#typeIsList}}{{#WithAdd}} {{#typeIsList}}{{#WithAdd}}
* New values are appended to the end of the list. * New values are appended to the end of the list.
{{/WithAdd}}{{/typeIsList}} {{/WithAdd}}{{/typeIsList}}
...@@ -25,14 +25,11 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) { ...@@ -25,14 +25,11 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) {
*/ */
public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParameterName}}{{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}}, int index{{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}) throws java.io.IOException { public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParameterName}}{{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}}, int index{{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}) throws java.io.IOException {
java.util.function.BiConsumer<String, byte[]> consumer = (topic, message) -> { java.util.function.BiConsumer<String, byte[]> consumer = (topic, message) -> {
{{#configEvaluationCounter}}
{{evaluationCounterVariable}}.incrementReceive("{{parentTypeName}}", "{{entityName}}");
{{/configEvaluationCounter}}
{{> mappingApplication}} {{> mappingApplication}}
{{#configLoggingEnabledForReads}} {{#configLoggingEnabledForReads}}
{{logDebug}}("[Receive] {{log_}} -> {{entityName}} = {{log_}}", {{connectParameterName}}, {{lastResult}}); {{logDebug}}("[Receive] {{log_}} -> {{entityName}} = {{log_}}", {{connectParameterName}}, {{lastResult}});
{{/configLoggingEnabledForReads}} {{/configLoggingEnabledForReads}}
{{#hasTypeEndpointTarget}} {{#hasTypePortTarget}}
{{lastResult}}.treeResolveAll(); {{lastResult}}.treeResolveAll();
{{#typeIsList}} {{#typeIsList}}
{{^IndexBasedListAccess}} {{^IndexBasedListAccess}}
...@@ -56,17 +53,20 @@ public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParamete ...@@ -56,17 +53,20 @@ public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParamete
{{^typeIsList}} {{^typeIsList}}
set{{entityName}}({{lastResult}}); set{{entityName}}({{lastResult}});
{{/typeIsList}} {{/typeIsList}}
{{/hasTypeEndpointTarget}} {{/hasTypePortTarget}}
{{^hasTypeEndpointTarget}} {{^hasTypePortTarget}}
set{{entityName}}({{lastResult}}); set{{entityName}}({{lastResult}});
{{/hasTypeEndpointTarget}} {{/hasTypePortTarget}}
{{#configEvaluationCounter}}
{{evaluationCounterVariable}}.incrementReceive("{{parentTypeName}}", "{{entityName}}");
{{/configEvaluationCounter}}
}; };
return {{internalConnectMethodName}}({{connectParameterName}}, consumer); return {{internalConnectMethodName}}({{connectParameterName}}, consumer);
} }
{{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}} {{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}}
/** /**
* Connects the receive endpoint {{entityName}} using a "wildcard" URI (if supported by the chosen protocol). * Connects the receive port {{entityName}} using a "wildcard" URI (if supported by the chosen protocol).
* @param {{connectParameterName}} string describing protocol and path as an URI * @param {{connectParameterName}} string describing protocol and path as an URI
* @return true if connect was successful, false otherwise * @return true if connect was successful, false otherwise
* @throws java.io.IOException if connect failed * @throws java.io.IOException if connect failed
......
...@@ -159,21 +159,21 @@ protected void {{parentTypeName}}.{{writeMethodName}}({{#IndexBasedListAccess}}i ...@@ -159,21 +159,21 @@ protected void {{parentTypeName}}.{{writeMethodName}}({{#IndexBasedListAccess}}i
{{senderName}}.run({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}token); {{senderName}}.run({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}token);
} }
{{#needForwardingNTA}} {{#needForwarding}}
syn {{{forwardingNTA_Type}}} {{parentTypeName}}.{{forwardingNTA_Name}}({{#IndexBasedListAccess}}int index{{/IndexBasedListAccess}}) { syn {{{forwardingType}}} {{parentTypeName}}.{{forwardingName}}({{#IndexBasedListAccess}}int index{{/IndexBasedListAccess}}) {
{{#relationEndpointWithListRole}} {{#relationPortWithListRole}}
// for (var element : {{realGetterMethodCall}}) { // for (var element : {{realGetterMethodCall}}) {
// element.{{touchedTerminalsMethodName}}(); // element.{{touchedTerminalsMethodName}}();
// } // }
{{realGetterMethodCall}}.stream().forEach(element -> element.{{touchedTerminalsMethodName}}()); {{realGetterMethodCall}}.stream().forEach(element -> element.{{touchedTerminalsMethodName}}());
return {{realGetterMethodCall}}; return {{realGetterMethodCall}};
{{/relationEndpointWithListRole}} {{/relationPortWithListRole}}
{{^relationEndpointWithListRole}} {{^relationPortWithListRole}}
{{{forwardingNTA_Type}}} result = {{realGetterMethodCall}}; {{{forwardingType}}} result = {{realGetterMethodCall}};
if (result == null) { if (result == null) {
return null; return null;
} }
return result.{{touchedTerminalsMethodName}}(); return result.{{touchedTerminalsMethodName}}();
{{/relationEndpointWithListRole}} {{/relationPortWithListRole}}
} }
{{/needForwardingNTA}} {{/needForwarding}}
...@@ -2,11 +2,11 @@ public {{parentTypeName}} {{parentTypeName}}.set{{Name}}({{javaType}} value) { ...@@ -2,11 +2,11 @@ public {{parentTypeName}} {{parentTypeName}}.set{{Name}}({{javaType}} value) {
set{{internalName}}(value); set{{internalName}}(value);
{{#DependencySourceDefinitions}} {{#DependencySourceDefinitions}}
for ({{targetParentTypeName}} target : get{{internalRelationPrefix}}TargetList()) { for ({{targetParentTypeName}} target : get{{internalRelationPrefix}}TargetList()) {
{{#targetEndpointDefinition}} {{#targetPortDefinition}}
if (target.{{updateMethodName}}()) { if (target.{{updateMethodName}}()) {
target.{{writeMethodName}}(); target.{{writeMethodName}}();
} }
{{/targetEndpointDefinition}} {{/targetPortDefinition}}
} }
{{/DependencySourceDefinitions}} {{/DependencySourceDefinitions}}
{{#normalTokenSendDef}} {{#normalTokenSendDef}}
......
...@@ -14,11 +14,11 @@ inh int {{Name}}._ragconnect_myIndexInList(); ...@@ -14,11 +14,11 @@ inh int {{Name}}._ragconnect_myIndexInList();
{{/isListComponent}} {{/isListComponent}}
{{/occurencesInProductionRules}} {{/occurencesInProductionRules}}
{{#ContextFreeTypeEndpointTargets}}{{#containingEndpointDefinition}} {{#ContextFreeTypePortTargets}}{{#containingPortDefinition}}
public boolean {{Name}}.{{connectMethodName}}(String {{connectParameterName}}{{#Send}}, boolean writeCurrentValue{{/Send}}) throws java.io.IOException { public boolean {{Name}}.{{connectMethodName}}(String {{connectParameterName}}{{#Send}}, boolean writeCurrentValue{{/Send}}) throws java.io.IOException {
switch (_ragconnect_myContext()) { switch (_ragconnect_myContext()) {
{{#occurencesInProductionRules}} {{#occurencesInProductionRules}}
{{!TODO only using "connectMethodName" is not correct, since the actual name might be different, e.g., if both send and receive are defined. need a reference to the actual endpoint-definition here}} {{!TODO only using "connectMethodName" is not correct, since the actual name might be different, e.g., if both send and receive are defined. need a reference to the actual port-definition here}}
{{^isListComponent}} {{^isListComponent}}
case "{{parentTypeName}}.{{Name}}": return (({{parentTypeName}}) _ragconnect_myParent()).{{connectMethodName}}{{Name}}({{connectParameterName}}{{#Send}}, writeCurrentValue{{/Send}}); case "{{parentTypeName}}.{{Name}}": return (({{parentTypeName}}) _ragconnect_myParent()).{{connectMethodName}}{{Name}}({{connectParameterName}}{{#Send}}, writeCurrentValue{{/Send}});
{{/isListComponent}} {{/isListComponent}}
...@@ -42,4 +42,4 @@ public boolean {{Name}}.{{disconnectMethodName}}(String {{connectParameterName}} ...@@ -42,4 +42,4 @@ public boolean {{Name}}.{{disconnectMethodName}}(String {{connectParameterName}}
return false; return false;
} }
} }
{{/containingEndpointDefinition}}{{/ContextFreeTypeEndpointTargets}} {{/containingPortDefinition}}{{/ContextFreeTypePortTargets}}
...@@ -47,7 +47,7 @@ dependencies { ...@@ -47,7 +47,7 @@ dependencies {
testImplementation project(':ragconnect.base') testImplementation project(':ragconnect.base')
implementation group: 'org.jastadd', name: 'jastadd2', version: '2.3.5-dresden-7' implementation group: 'org.jastadd', name: 'jastadd2', version: '2.3.5-dresden-7'
relast group: 'org.jastadd', name: 'relast', version: "0.3.0-137" relast group: 'org.jastadd', name: 'relast', version: "${relast_version}"
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.0' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.9.0' testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.9.0'
...@@ -64,7 +64,7 @@ dependencies { ...@@ -64,7 +64,7 @@ dependencies {
// rest and client // rest and client
testImplementation group: 'com.sparkjava', name: 'spark-core', version: '2.9.3' testImplementation group: 'com.sparkjava', name: 'spark-core', version: '2.9.3'
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.1' testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4j_version}"
testImplementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.31' testImplementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.31'
testImplementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.31' testImplementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.31'
testImplementation group: 'javax.activation', name: 'activation', version: '1.1.1' testImplementation group: 'javax.activation', name: 'activation', version: '1.1.1'
...@@ -72,7 +72,7 @@ dependencies { ...@@ -72,7 +72,7 @@ dependencies {
testImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' testImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
api group: 'com.google.protobuf', name: 'protobuf-java', version: '3.0.0' api group: 'com.google.protobuf', name: 'protobuf-java', version: '3.0.0'
implementation group: 'de.tudresden.inf.st', name: 'dumpAst', version: "1.0.2-68" implementation group: 'de.tudresden.inf.st', name: 'dumpAst', version: "${dumpAst_version}"
} }
// --- Preprocessors --- // --- Preprocessors ---
......
...@@ -14,5 +14,5 @@ D ::= <SourceNonExistingTarget> ...@@ -14,5 +14,5 @@ D ::= <SourceNonExistingTarget>
<SourceDoubledValue> /<TargetDoubledValue>/ <SourceDoubledValue> /<TargetDoubledValue>/
MyList:D* ; MyList:D* ;
// context-free endpoints // context-free ports
E ::= ; E ::= ;
Part1.connect Line 3, column 1: Endpoint definition already defined for B.DoubledValue Part1.connect Line 3, column 1: Port definition already defined for B.DoubledValue
Part1.connect Line 4, column 1: Endpoint definition already defined for B.DoubledValue Part1.connect Line 4, column 1: Port definition already defined for B.DoubledValue
Part1.connect Line 10, column 1: Receiving target token must not be an NTA token! Part1.connect Line 10, column 1: Receiving target token must not be an NTA token!
Part1.connect Line 13, column 1: No suitable default mapping found for type java.util.List<String> Part1.connect Line 13, column 1: No suitable default mapping found for type java.util.List<String>
Part1.connect Line 16, column 1: to-type of last mapping (java.util.List<String>) not assignable to type of the token (String)! Part1.connect Line 16, column 1: to-type of last mapping (java.util.List<String>) not assignable to type of the token (String)!
Part1.connect Line 19, column 1: to-type of last mapping (int) not assignable to type of the token (String)! Part1.connect Line 19, column 1: to-type of last mapping (int) not assignable to type of the token (String)!
Part1.connect Line 26, column 6: Could not resolve endpoint target C.ErrorNotResolved Part1.connect Line 26, column 6: Could not resolve port target C.ErrorNotResolved
Part2.connect Line 5, column 1: Endpoint definition already defined for C.DoubledValue Part2.connect Line 5, column 1: Port definition already defined for C.DoubledValue
Part2.connect Line 6, column 1: Endpoint definition already defined for C.DoubledValue Part2.connect Line 6, column 1: Port definition already defined for C.DoubledValue
Part2.connect Line 17, column 1: The name of a dependency definition must not be equal to a list-node on the source Part2.connect Line 17, column 1: The name of a dependency definition must not be equal to a list-node on the source
Part2.connect Line 22, column 1: Dependency definition already defined for D with name DoubledValue Part2.connect Line 22, column 1: Dependency definition already defined for D with name DoubledValue
...@@ -18,10 +18,10 @@ receive B.ErrorTypeOfLastMapping using StringToString, StringToList ; ...@@ -18,10 +18,10 @@ receive B.ErrorTypeOfLastMapping using StringToString, StringToList ;
// Error: types of mappings must match (modulo inheritance) // Error: types of mappings must match (modulo inheritance)
receive B.ErrorTypeMismatch using StringToList, IntToInt ; receive B.ErrorTypeMismatch using StringToList, IntToInt ;
// Error: Context-Free endpoint not allowed for root nodes // Error: Context-Free port not allowed for root nodes
receive A; receive A;
// Error: Clash with implied endpoint definition of context-free endpoint // Error: Clash with implied port definition of context-free port
receive E; receive E;
receive A.E; receive A.E;
...@@ -63,7 +63,7 @@ send D.TargetDoubledValue; ...@@ -63,7 +63,7 @@ send D.TargetDoubledValue;
// non-existence of attributes is not checked by RagConnect // non-existence of attributes is not checked by RagConnect
send A.nonExistingAttribute(int); send A.nonExistingAttribute(int);
// Already defined endpoints for attributes will be reported, however // Already defined ports for attributes will be reported, however
send A.nonExistingAttribute(int); send A.nonExistingAttribute(int);
// mappings are not checked, here string would not match // mappings are not checked, here string would not match
......
Standard.connect Line 3, column 1: Endpoint definition already defined for B.DoubledValue Standard.connect Line 3, column 1: Port definition already defined for B.DoubledValue
Standard.connect Line 4, column 1: Endpoint definition already defined for B.DoubledValue Standard.connect Line 4, column 1: Port definition already defined for B.DoubledValue
Standard.connect Line 10, column 1: Receiving target token must not be an NTA token! Standard.connect Line 10, column 1: Receiving target token must not be an NTA token!
Standard.connect Line 13, column 1: No suitable default mapping found for type java.util.List<String> Standard.connect Line 13, column 1: No suitable default mapping found for type java.util.List<String>
Standard.connect Line 16, column 1: to-type of last mapping (java.util.List<String>) not assignable to type of the token (String)! Standard.connect Line 16, column 1: to-type of last mapping (java.util.List<String>) not assignable to type of the token (String)!
Standard.connect Line 19, column 1: to-type of last mapping (int) not assignable to type of the token (String)! Standard.connect Line 19, column 1: to-type of last mapping (int) not assignable to type of the token (String)!
Standard.connect Line 22, column 9: Context-Free endpoint not allowed for root node A! Standard.connect Line 22, column 9: Context-Free port not allowed for root node A!
Standard.connect Line 26, column 1: Clash with implied, indexed endpoint definition of context-free endpoint in line 25! Standard.connect Line 26, column 1: Clash with implied, indexed port definition of context-free port in line 25!
Standard.connect Line 30, column 9: Could not resolve endpoint target C.NonExisting Standard.connect Line 30, column 9: Could not resolve port target C.NonExisting
Standard.connect Line 43, column 1: Endpoint definition already defined for C.DoubledValue Standard.connect Line 43, column 1: Port definition already defined for C.DoubledValue
Standard.connect Line 44, column 1: Endpoint definition already defined for C.DoubledValue Standard.connect Line 44, column 1: Port definition already defined for C.DoubledValue
Standard.connect Line 55, column 1: The name of a dependency definition must not be equal to a list-node on the source Standard.connect Line 55, column 1: The name of a dependency definition must not be equal to a list-node on the source
Standard.connect Line 60, column 1: Dependency definition already defined for D with name DoubledValue Standard.connect Line 60, column 1: Dependency definition already defined for D with name DoubledValue
Standard.connect Line 64, column 1: Endpoint definition already defined for A.nonExistingAttribute Standard.connect Line 64, column 1: Port definition already defined for A.nonExistingAttribute
Standard.connect Line 67, column 1: Endpoint definition already defined for A.nonExistingAttribute Standard.connect Line 67, column 1: Port definition already defined for A.nonExistingAttribute
# Forwarding # Forwarding
Idea: Use send definitions targeting only non-NTAs (thus, requiring the creation of implicit NTAs). Idea: Use send definitions targeting only non-NTAs (thus, requiring the creation of implicit NTAs).
Also test context-free endpoint definitions targeting non-NTAs to test compatibility of those two features. Also test context-free port definitions targeting non-NTAs to test compatibility of those two features.
Note: When a type occurs in a list, the context-free endpoint definition will force an (implicit) indexed send for that context. Note: When a type occurs in a list, the context-free port definition will force an (implicit) indexed send for that context.
// endpoint definitions // port definitions
receive A.Input ; receive A.Input ;
send A.OutputOnA ; send A.OutputOnA ;
send B.OutputOnB using Transformation ; send B.OutputOnB using Transformation ;
......
...@@ -23,12 +23,12 @@ A _n_ = Input _n_ + _n_, e.g., A1 = Input1 + 1 and A3 = Input3 + 3 ...@@ -23,12 +23,12 @@ A _n_ = Input _n_ + _n_, e.g., A1 = Input1 + 1 and A3 = Input3 + 3
## Execution-Trace (SendInitialValue) ## Execution-Trace (SendInitialValue)
| Input | [A1,A2,A3,A4,IO] | # | A* | UsingWcA | WithAddA | UsingWcWithAddA:A | | Input | [A1,A2,A3,A4,IO] | # | A* | UsingWcA | WithAddA | UsingWcWithAddA:A |
|---|---|---|---|---|---|---| |-------|------------------|-----|-------------|-------------|---------------------|---------------------|
| * | [1,2,3,4,0] | 5 | [1,2,3,4,0] | [1,2,3,4,0] | [1,2,3,4,0] | [1,2,3,4,0] | | * | [1,2,3,4,0] | 5 | [1,2,3,4,0] | [1,2,3,4,0] | [1,2,3,4,0] | [1,2,3,4,0] |
| I1:1 | [2,2,3,4,0] | 6 | [2,2,3,4,0] | [2,2,3,4,0] | [1,2,3,4,0,2] | [1,2,3,4,0,2] | | I1:1 | [2,2,3,4,0] | 6 | [2,2,3,4,0] | [2,2,3,4,0] | [1,2,3,4,0,2] | [1,2,3,4,0,2] |
| I1:1 | [2,2,3,4,0] | 6 | [2,2,3,4,0] | [2,2,3,4,0] | [1,2,3,4,0,2] | [1,2,3,4,0,2] | | I1:1 | [2,2,3,4,0] | 6 | [2,2,3,4,0] | [2,2,3,4,0] | [1,2,3,4,0,2] | [1,2,3,4,0,2] |
| I1:2 | [3,2,3,4,0] | 7 | [3,2,3,4,0] | [3,2,3,4,0] | [1,2,3,4,0,2,3] | [1,2,3,4,0,2,3] | | I1:2 | [3,2,3,4,0] | 7 | [3,2,3,4,0] | [3,2,3,4,0] | [1,2,3,4,0,2,3] | [1,2,3,4,0,2,3] |
| IO:5 | [3,2,3,4,5] | 8 | [3,2,3,4,5] | [3,2,3,4,5] | [1,2,3,4,0,2,3,5] | [1,2,3,4,0,2,3,5] | IO:5 | [3,2,3,4,5] | 8 | [3,2,3,4,5] | [3,2,3,4,5] | [1,2,3,4,0,2,3,5] | [1,2,3,4,0,2,3,5] |
| I3:4 | [3,2,7,4,5] | 9 | [3,2,7,4,5] | [3,2,7,4,5] | [1,2,3,4,0,2,3,5,7] | [1,2,3,4,0,2,3,5,7] | | I3:4 | [3,2,7,4,5] | 9 | [3,2,7,4,5] | [3,2,7,4,5] | [1,2,3,4,0,2,3,5,7] | [1,2,3,4,0,2,3,5,7] |
*: (1:0, 2:0, 3:0, 4:0, 5:0) *: (1:0, 2:0, 3:0, 4:0, 5:0)
...@@ -36,12 +36,12 @@ A _n_ = Input _n_ + _n_, e.g., A1 = Input1 + 1 and A3 = Input3 + 3 ...@@ -36,12 +36,12 @@ A _n_ = Input _n_ + _n_, e.g., A1 = Input1 + 1 and A3 = Input3 + 3
## Execution-Trace (OnlyUpdate) ## Execution-Trace (OnlyUpdate)
| Input | [A1,A2,A3,A4,IO] | # | A* | UsingWcA | WithAddA | UsingWcWithAddA:A | | Input | [A1,A2,A3,A4,IO] | # | A* | UsingWcA | WithAddA | UsingWcWithAddA:A |
|---|---|---|---|---|---|---| |-------|------------------|-----|-------------|----------|-----------|-------------------|
| * | [-,-,-,-,-] | 0 | [0,0,0,0,0] | [] | [] | [] | | * | [-,-,-,-,-] | 0 | [0,0,0,0,0] | [] | [] | [] |
| I1:1 | [2,-,-,-,-] | 1 | [2,0,0,0,0] | [2] | [2] | [2] | | I1:1 | [2,-,-,-,-] | 1 | [2,0,0,0,0] | [2] | [2] | [2] |
| I1:1 | [2,-,-,-,-] | 1 | [2,0,0,0,0] | [2] | [2] | [2] | | I1:1 | [2,-,-,-,-] | 1 | [2,0,0,0,0] | [2] | [2] | [2] |
| I1:2 | [3,-,-,-,-] | 2 | [3,0,0,0,0] | [3] | [2,3] | [2,3] | | I1:2 | [3,-,-,-,-] | 2 | [3,0,0,0,0] | [3] | [2,3] | [2,3] |
| IO:5 | [2,-,-,-,5] | 3 | [3,0,0,0,5] | [3,5] | [2,3,5] | [2,3,5] | IO:5 | [2,-,-,-,5] | 3 | [3,0,0,0,5] | [3,5] | [2,3,5] | [2,3,5] |
| I3:4 | [2,-,7,-,5] | 4 | [3,0,7,0,5] | [3,5,7] | [2,3,5,7] | [2,3,5,7] | | I3:4 | [2,-,7,-,5] | 4 | [3,0,7,0,5] | [3,5,7] | [2,3,5,7] | [2,3,5,7] |
*: (1:0, 2:0, 3:0, 4:0, 5:0) *: (1:0, 2:0, 3:0, 4:0, 5:0)
// endpoint definitions // port definitions
receive A.Input ; receive A.Input ;
send A.OutputOnA ; send A.OutputOnA ;
send B.OutputOnB using Transformation ; send B.OutputOnB using Transformation ;
......
...@@ -2,9 +2,8 @@ package org.jastadd.ragconnect.tests; ...@@ -2,9 +2,8 @@ package org.jastadd.ragconnect.tests;
import defaultOnlyRead.ast.MqttHandler; import defaultOnlyRead.ast.MqttHandler;
import io.github.artsok.RepeatedIfExceptionsTest; import io.github.artsok.RepeatedIfExceptionsTest;
import org.jastadd.ragconnect.tests.utils.TestUtils;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
......
package org.jastadd.ragconnect.tests; package org.jastadd.ragconnect.tests;
import attributeInc.ast.*; import attributeInc.ast.*;
import de.tudresden.inf.st.jastadd.dumpAst.ast.Dumper;
import org.jastadd.ragconnect.tests.utils.TestUtils;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.jastadd.ragconnect.tests.utils.TestChecker;
import static java.util.function.Predicate.isEqual; import static java.util.function.Predicate.isEqual;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.jastadd.ragconnect.tests.TestUtils.*; import static org.jastadd.ragconnect.tests.utils.TestUtils.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
/** /**
...@@ -22,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.*; ...@@ -22,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.*;
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
@Tag("Incremental") @Tag("Incremental")
@Tag("New")
public class AttributeTest extends AbstractMqttTest { public class AttributeTest extends AbstractMqttTest {
private static final String TOPIC_WILDCARD = "attr/#"; private static final String TOPIC_WILDCARD = "attr/#";
...@@ -84,7 +89,7 @@ public class AttributeTest extends AbstractMqttTest { ...@@ -84,7 +89,7 @@ public class AttributeTest extends AbstractMqttTest {
data = new ReceiverData(); data = new ReceiverData();
assertTrue(handler.newConnection(TOPIC_WILDCARD, bytes -> data.numberOfValues += 1)); assertTrue(handler.newConnection(TOPIC_WILDCARD, bytes -> data.numberOfValues += 1));
checker = new TestUtils.TestChecker(); checker = new TestChecker();
checker.setActualNumberOfValues(() -> data.numberOfValues) checker.setActualNumberOfValues(() -> data.numberOfValues)
.setCheckForString(CHECK_BASIC, this::checkBasic) .setCheckForString(CHECK_BASIC, this::checkBasic)
.setCheckForString(CHECK_SIMPLE, this::checkSimple) .setCheckForString(CHECK_SIMPLE, this::checkSimple)
...@@ -147,6 +152,35 @@ public class AttributeTest extends AbstractMqttTest { ...@@ -147,6 +152,35 @@ public class AttributeTest extends AbstractMqttTest {
.put(CHECK_CIRCULAR, INITIAL_STRING_FOR_INT_PLUS_2) .put(CHECK_CIRCULAR, INITIAL_STRING_FOR_INT_PLUS_2)
.put(CHECK_COLLECTION, "[" + INITIAL_STRING + "]"); .put(CHECK_COLLECTION, "[" + INITIAL_STRING + "]");
if (!TestUtils.isCi()) {
Dumper.read(model)
.includeAttributeWhen((node, attributeName, isNTA, value) -> {
switch (attributeName) {
case "basic":
case "simple":
case "collectionAttribute":
return node.equals(senderString);
case "transformed":
case "circularAttribute":
return node.equals(senderInt);
case "toReferenceType":
case "toNTA":
return node.equals(senderA);
}
return false;
})
.includeChildWhen((parentNode, childNode, contextName) -> !contextName.equals("Inner"))
.setNameMethod(node -> {
if (node instanceof SenderRoot) {
String suffix = node.equals(senderString) ? "(String)" :
node.equals(senderInt) ? "(int)" : "(reference type)";
return "SenderRoot " + suffix;
}
return node.getClass().getSimpleName();
})
.dumpAsPNG(Paths.get("attribute.png"));
}
communicateBoth(); communicateBoth();
} }
......
...@@ -4,13 +4,16 @@ import contextFreeSimpleInc.ast.A; ...@@ -4,13 +4,16 @@ import contextFreeSimpleInc.ast.A;
import contextFreeSimpleInc.ast.MqttHandler; import contextFreeSimpleInc.ast.MqttHandler;
import contextFreeSimpleInc.ast.Root; import contextFreeSimpleInc.ast.Root;
import contextFreeSimpleInc.ast.SerializationException; import contextFreeSimpleInc.ast.SerializationException;
import org.jastadd.ragconnect.tests.utils.DefaultMappings;
import org.jastadd.ragconnect.tests.utils.TestChecker;
import org.jastadd.ragconnect.tests.utils.TestUtils;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.jastadd.ragconnect.tests.TestUtils.mqttUri; import static org.jastadd.ragconnect.tests.utils.TestUtils.mqttUri;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
/** /**
...@@ -41,7 +44,7 @@ public class ContextFreeSimpleTest extends AbstractMqttTest { ...@@ -41,7 +44,7 @@ public class ContextFreeSimpleTest extends AbstractMqttTest {
private ReceiverData data; private ReceiverData data;
private MqttHandler handler; private MqttHandler handler;
private TestUtils.TestChecker checker; private TestChecker checker;
@Override @Override
protected void createModel() { protected void createModel() {
...@@ -70,7 +73,7 @@ public class ContextFreeSimpleTest extends AbstractMqttTest { ...@@ -70,7 +73,7 @@ public class ContextFreeSimpleTest extends AbstractMqttTest {
handler.newConnection(TOPIC_WILDCARD, (topic, bytes) -> data.valuesSent += 1); handler.newConnection(TOPIC_WILDCARD, (topic, bytes) -> data.valuesSent += 1);
checker = new TestUtils.TestChecker(); checker = new TestChecker();
checker.alwaysWait() checker.alwaysWait()
.setCheckForString(TOPIC_UNNAMED, (name, expected) -> this.check(name, expected, model.getA(), unnamedA)) .setCheckForString(TOPIC_UNNAMED, (name, expected) -> this.check(name, expected, model.getA(), unnamedA))
.setCheckForString(TOPIC_SINGLE, (name, expected) -> this.check(name, expected, model.getSingleA(), singleA)) .setCheckForString(TOPIC_SINGLE, (name, expected) -> this.check(name, expected, model.getSingleA(), singleA))
...@@ -143,7 +146,7 @@ public class ContextFreeSimpleTest extends AbstractMqttTest { ...@@ -143,7 +146,7 @@ public class ContextFreeSimpleTest extends AbstractMqttTest {
private void send(String topic, String value) throws IOException { private void send(String topic, String value) throws IOException {
A a = new A().setValue(value); A a = new A().setValue(value);
try { try {
publisher.publish(topic, TestUtils.DefaultMappings.TreeToBytes(a::serialize)); publisher.publish(topic, DefaultMappings.TreeToBytes(a::serialize));
} catch (SerializationException e) { } catch (SerializationException e) {
throw new IOException(e); throw new IOException(e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment