Skip to content
Snippets Groups Projects
Commit bd7eccd6 authored by Christian Wulf's avatar Christian Wulf
Browse files

RunnableStage throws an AnalysisNotValidException now if validation is

enabled
parent 5d9b47e3
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; ...@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import teetime.variant.methodcallWithPorts.framework.core.signal.StartingSignal; import teetime.variant.methodcallWithPorts.framework.core.signal.StartingSignal;
import teetime.variant.methodcallWithPorts.framework.core.signal.TerminatingSignal; import teetime.variant.methodcallWithPorts.framework.core.signal.TerminatingSignal;
import teetime.variant.methodcallWithPorts.framework.core.signal.ValidatingSignal; import teetime.variant.methodcallWithPorts.framework.core.signal.ValidatingSignal;
import teetime.variant.methodcallWithPorts.framework.core.validation.AnalysisNotValidException;
public class RunnableStage implements Runnable { public class RunnableStage implements Runnable {
...@@ -26,8 +27,7 @@ public class RunnableStage implements Runnable { ...@@ -26,8 +27,7 @@ public class RunnableStage implements Runnable {
ValidatingSignal validatingSignal = new ValidatingSignal(); ValidatingSignal validatingSignal = new ValidatingSignal();
this.stage.onSignal(validatingSignal, null); this.stage.onSignal(validatingSignal, null);
if (validatingSignal.getInvalidPortConnections().size() > 0) { if (validatingSignal.getInvalidPortConnections().size() > 0) {
// throw new RuntimeException(message); throw new AnalysisNotValidException(validatingSignal.getInvalidPortConnections());
// TODO implement what to do on validation messages
} }
} }
......
package teetime.variant.methodcallWithPorts.framework.core.validation;
import java.util.List;
import com.google.common.base.Joiner;
public class AnalysisNotValidException extends RuntimeException {
private static final long serialVersionUID = 455596493924684318L;
private final List<InvalidPortConnection> invalidPortConnections;
public AnalysisNotValidException(final List<InvalidPortConnection> invalidPortConnections) {
super();
this.invalidPortConnections = invalidPortConnections;
}
@Override
public String getMessage() {
StringBuilder builder = new StringBuilder(this.invalidPortConnections.size() * 40);
builder.append(this.invalidPortConnections.size());
builder.append(" invalid port connections were detected.\n");
Joiner.on("\n").appendTo(builder, this.invalidPortConnections);
return builder.toString();
}
}
...@@ -6,20 +6,27 @@ import teetime.variant.methodcallWithPorts.framework.core.OutputPort; ...@@ -6,20 +6,27 @@ import teetime.variant.methodcallWithPorts.framework.core.OutputPort;
public class InvalidPortConnection { public class InvalidPortConnection {
private final OutputPort<?> sourcePort; private final OutputPort<?> sourcePort;
private final InputPort<?> inputPort; private final InputPort<?> targetPort;
public InvalidPortConnection(final OutputPort<?> sourcePort, final InputPort<?> inputPort) { public InvalidPortConnection(final OutputPort<?> sourcePort, final InputPort<?> targetPort) {
super(); super();
this.sourcePort = sourcePort; this.sourcePort = sourcePort;
this.inputPort = inputPort; this.targetPort = targetPort;
} }
public OutputPort<?> getSourcePort() { public OutputPort<?> getSourcePort() {
return sourcePort; return this.sourcePort;
} }
public InputPort<?> getInputPort() { public InputPort<?> getTargetPort() {
return inputPort; return this.targetPort;
}
@Override
public String toString() {
String sourcePortTypeName = (this.sourcePort.getType() == null) ? null : this.sourcePort.getType().getName();
String targetPortTypeName = (this.targetPort.getType() == null) ? null : this.targetPort.getType().getName();
return sourcePortTypeName + " != " + targetPortTypeName;
} }
} }
package teetime.variant.methodcallWithPorts.runtime.typeCheck; package teetime.variant.methodcallWithPorts.runtime.typeCheck;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.TypeVariable;
import org.junit.Test; import org.junit.Test;
import teetime.util.ConstructorClosure; import teetime.util.ConstructorClosure;
import teetime.variant.explicitScheduling.examples.throughput.TimestampObject; import teetime.variant.explicitScheduling.examples.throughput.TimestampObject;
import teetime.variant.methodcallWithPorts.framework.core.OutputPort;
import teetime.variant.methodcallWithPorts.framework.core.pipe.IPipe; import teetime.variant.methodcallWithPorts.framework.core.pipe.IPipe;
import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory; import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory;
import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory.ThreadCommunication; import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory.ThreadCommunication;
...@@ -21,6 +21,8 @@ import teetime.variant.methodcallWithPorts.stage.basic.Sink; ...@@ -21,6 +21,8 @@ import teetime.variant.methodcallWithPorts.stage.basic.Sink;
public class ConnectionTypeTest { public class ConnectionTypeTest {
// tests for load-time validation
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testDynamicPortConnection() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, public void testDynamicPortConnection() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException,
...@@ -36,6 +38,8 @@ public class ConnectionTypeTest { ...@@ -36,6 +38,8 @@ public class ConnectionTypeTest {
Constructor<ObjectProducer> constructor = ObjectProducer.class.getConstructor(long.class, ConstructorClosure.class); Constructor<ObjectProducer> constructor = ObjectProducer.class.getConstructor(long.class, ConstructorClosure.class);
ObjectProducer objectProducer = constructor.newInstance(1, constructorClosure); ObjectProducer objectProducer = constructor.newInstance(1, constructorClosure);
// PortTypeConfiguration.setPortTypes(objectProducer, Class.forName("teetime.variant.explicitScheduling.examples.throughput.TimestampObject"));
StartTimestampFilter startTimestampFilter = StartTimestampFilter.class.newInstance(); StartTimestampFilter startTimestampFilter = StartTimestampFilter.class.newInstance();
StopTimestampFilter stopTimestampFilter = StopTimestampFilter.class.newInstance(); StopTimestampFilter stopTimestampFilter = StopTimestampFilter.class.newInstance();
Sink sink = Sink.class.newInstance(); Sink sink = Sink.class.newInstance();
...@@ -49,61 +53,38 @@ public class ConnectionTypeTest { ...@@ -49,61 +53,38 @@ public class ConnectionTypeTest {
pipe = pipeFactory.create(ThreadCommunication.INTRA); pipe = pipeFactory.create(ThreadCommunication.INTRA);
pipe.connectPorts(stopTimestampFilter.getOutputPort(), sink.getInputPort()); pipe.connectPorts(stopTimestampFilter.getOutputPort(), sink.getInputPort());
/* // TypeVariable<Class<ObjectProducer>>[] objectProducerTypeParameters = ObjectProducer.class.getTypeParameters();
* requirements: // for (TypeVariable<Class<ObjectProducer>> typeVariable : objectProducerTypeParameters) {
* <ul> // System.out.println(typeVariable.getBounds()); // ->[Ljava.lang.reflect.Type;@13a65d1f
* <li>when selecting a stage class to create one instance, the user is prompted to declare each type argument
* <li>
* </ul>
*/
TypeVariable<Class<ObjectProducer>>[] objectProducerTypeParameters = ObjectProducer.class.getTypeParameters();
for (TypeVariable<Class<ObjectProducer>> typeVariable : objectProducerTypeParameters) {
System.out.println(typeVariable.getBounds()); // ->[Ljava.lang.reflect.Type;@13a65d1f
System.out.println(typeVariable.getBounds().length); // ->1
System.out.println(typeVariable.getBounds()[0]); // ->class java.lang.Object
System.out.println(typeVariable.getName()); // ->T
System.out.println(typeVariable.getClass()); // ->class sun.reflect.generics.reflectiveObjects.TypeVariableImpl
System.out.println(typeVariable.getGenericDeclaration()); // ->class teetime.variant.methodcallWithPorts.stage.ObjectProducer
}
// TypeVariable<?>[] objectProducerOutputPortTypeParameters = objectProducer.getOutputPort().getClass().getTypeParameters();
// for (TypeVariable<?> typeVariable : objectProducerOutputPortTypeParameters) {
// System.out.println(typeVariable.getBounds()); // ->[Ljava.lang.reflect.Type;@20a12d8f
// System.out.println(typeVariable.getBounds().length); // ->1 // System.out.println(typeVariable.getBounds().length); // ->1
// System.out.println(typeVariable.getBounds()[0]); // ->class java.lang.Object // System.out.println(typeVariable.getBounds()[0]); // ->class java.lang.Object
// System.out.println(typeVariable.getName()); // ->T // System.out.println(typeVariable.getName()); // ->T
// System.out.println(typeVariable.getClass()); // ->class sun.reflect.generics.reflectiveObjects.TypeVariableImpl // System.out.println(typeVariable.getClass()); // ->class sun.reflect.generics.reflectiveObjects.TypeVariableImpl
// System.out.println(typeVariable.getGenericDeclaration()); // ->class teetime.variant.methodcallWithPorts.framework.core.OutputPort // System.out.println(typeVariable.getGenericDeclaration()); // ->class teetime.variant.methodcallWithPorts.stage.ObjectProducer
// } // }
// //
// TypeVariable<?>[] startTimestampFilterOutputPortTypeParameters = startTimestampFilter.getOutputPort().getClass().getTypeParameters(); // Class<?> currentClass = objectProducer.getClass();
// for (TypeVariable<?> typeVariable : startTimestampFilterOutputPortTypeParameters) { // while (currentClass.getSuperclass() != null) { // we don't want to process Object.class
// System.out.println(typeVariable.getBounds()); // ->[Ljava.lang.reflect.Type;@7b365f02 // Field[] fields = currentClass.getDeclaredFields();
// System.out.println(typeVariable.getBounds().length); // ->1 // for (Field field : fields) {
// System.out.println(typeVariable.getBounds()[0]); // ->class java.lang.Object // // System.out.println("Field: " + field.getType());
// System.out.println(typeVariable.getName()); // ->T // if (OutputPort.class.equals(field.getType())) {
// System.out.println(typeVariable.getClass()); // ->class sun.reflect.generics.reflectiveObjects.TypeVariableImpl // System.out.println("Field.name: " + field.getName());
// System.out.println(typeVariable.getGenericDeclaration()); // ->class teetime.variant.methodcallWithPorts.framework.core.OutputPort // System.out.println("Field.type: " + field.getType());
// // field.getType()
// }
// }
//
// currentClass = currentClass.getSuperclass();
// } // }
Class<?> currentClass = objectProducer.getClass(); assertNull(objectProducer.getOutputPort().getType());
while (currentClass.getSuperclass() != null) { // we don't want to process Object.class PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName()));
Field[] fields = currentClass.getDeclaredFields(); assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType());
for (Field field : fields) {
// System.out.println("Field: " + field.getType());
if (OutputPort.class.equals(field.getType())) {
System.out.println("Field.name: " + field.getName());
System.out.println("Field.type: " + field.getType());
// field.getType()
}
}
currentClass = currentClass.getSuperclass();
}
System.out.println(objectProducer.getOutputPort().getType()); assertNull(startTimestampFilter.getOutputPort().getType());
PortTypeConfiguration.setPortTypes(objectProducer, Class.forName("teetime.variant.explicitScheduling.examples.throughput.TimestampObject")); PortTypeConfiguration.setPortTypes(startTimestampFilter);
System.out.println(objectProducer.getOutputPort().getType()); assertEquals(TimestampObject.class, startTimestampFilter.getInputPort().getType());
assertEquals(TimestampObject.class, startTimestampFilter.getOutputPort().getType());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment