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
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import teetime.variant.methodcallWithPorts.framework.core.signal.StartingSignal;
import teetime.variant.methodcallWithPorts.framework.core.signal.TerminatingSignal;
import teetime.variant.methodcallWithPorts.framework.core.signal.ValidatingSignal;
import teetime.variant.methodcallWithPorts.framework.core.validation.AnalysisNotValidException;
public class RunnableStage implements Runnable {
......@@ -26,8 +27,7 @@ public class RunnableStage implements Runnable {
ValidatingSignal validatingSignal = new ValidatingSignal();
this.stage.onSignal(validatingSignal, null);
if (validatingSignal.getInvalidPortConnections().size() > 0) {
// throw new RuntimeException(message);
// TODO implement what to do on validation messages
throw new AnalysisNotValidException(validatingSignal.getInvalidPortConnections());
}
}
......
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;
public class InvalidPortConnection {
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();
this.sourcePort = sourcePort;
this.inputPort = inputPort;
this.targetPort = targetPort;
}
public OutputPort<?> getSourcePort() {
return sourcePort;
return this.sourcePort;
}
public InputPort<?> getInputPort() {
return inputPort;
public InputPort<?> getTargetPort() {
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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.TypeVariable;
import org.junit.Test;
import teetime.util.ConstructorClosure;
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.PipeFactory;
import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory.ThreadCommunication;
......@@ -21,6 +21,8 @@ import teetime.variant.methodcallWithPorts.stage.basic.Sink;
public class ConnectionTypeTest {
// tests for load-time validation
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDynamicPortConnection() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException,
......@@ -36,6 +38,8 @@ public class ConnectionTypeTest {
Constructor<ObjectProducer> constructor = ObjectProducer.class.getConstructor(long.class, ConstructorClosure.class);
ObjectProducer objectProducer = constructor.newInstance(1, constructorClosure);
// PortTypeConfiguration.setPortTypes(objectProducer, Class.forName("teetime.variant.explicitScheduling.examples.throughput.TimestampObject"));
StartTimestampFilter startTimestampFilter = StartTimestampFilter.class.newInstance();
StopTimestampFilter stopTimestampFilter = StopTimestampFilter.class.newInstance();
Sink sink = Sink.class.newInstance();
......@@ -49,61 +53,38 @@ public class ConnectionTypeTest {
pipe = pipeFactory.create(ThreadCommunication.INTRA);
pipe.connectPorts(stopTimestampFilter.getOutputPort(), sink.getInputPort());
/*
* requirements:
* <ul>
* <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
// 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.framework.core.OutputPort
// System.out.println(typeVariable.getGenericDeclaration()); // ->class teetime.variant.methodcallWithPorts.stage.ObjectProducer
// }
//
// TypeVariable<?>[] startTimestampFilterOutputPortTypeParameters = startTimestampFilter.getOutputPort().getClass().getTypeParameters();
// for (TypeVariable<?> typeVariable : startTimestampFilterOutputPortTypeParameters) {
// System.out.println(typeVariable.getBounds()); // ->[Ljava.lang.reflect.Type;@7b365f02
// 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.framework.core.OutputPort
// Class<?> currentClass = objectProducer.getClass();
// while (currentClass.getSuperclass() != null) { // we don't want to process Object.class
// Field[] fields = currentClass.getDeclaredFields();
// 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();
// }
Class<?> currentClass = objectProducer.getClass();
while (currentClass.getSuperclass() != null) { // we don't want to process Object.class
Field[] fields = currentClass.getDeclaredFields();
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();
}
assertNull(objectProducer.getOutputPort().getType());
PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName()));
assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType());
System.out.println(objectProducer.getOutputPort().getType());
PortTypeConfiguration.setPortTypes(objectProducer, Class.forName("teetime.variant.explicitScheduling.examples.throughput.TimestampObject"));
System.out.println(objectProducer.getOutputPort().getType());
assertNull(startTimestampFilter.getOutputPort().getType());
PortTypeConfiguration.setPortTypes(startTimestampFilter);
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