Skip to content
Snippets Groups Projects
Commit cdc72e42 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

Validation works now, but not sure if type check is correct

parent c32b1a52
No related branches found
No related tags found
No related merge requests found
...@@ -310,7 +310,7 @@ public abstract class AbstractStage { ...@@ -310,7 +310,7 @@ public abstract class AbstractStage {
Class<?> targetType = port.getType(); Class<?> targetType = port.getType();
Class<?> sourceType = port.pipe.getSourcePort().getType(); Class<?> sourceType = port.pipe.getSourcePort().getType();
if (targetType != null && sourceType != null) { if (targetType != null && sourceType != null) {
if (targetType.isAssignableFrom(sourceType)) { // kinda instanceof, but for Class class if (!targetType.isAssignableFrom(sourceType)) { // TODO: Is this correct? // kinda instanceof, but for Class class
invalidPortConnections.add(new InvalidPortConnection(port.pipe.getSourcePort(), port)); invalidPortConnections.add(new InvalidPortConnection(port.pipe.getSourcePort(), port));
// throw new IllegalStateException("2002 - Invalid pipe at " + port.toString() + ": " + targetType + " is not a superclass/type of " + // throw new IllegalStateException("2002 - Invalid pipe at " + port.toString() + ": " + targetType + " is not a superclass/type of " +
// sourceType); // sourceType);
......
...@@ -25,6 +25,7 @@ import org.jctools.queues.spec.Preference; ...@@ -25,6 +25,7 @@ import org.jctools.queues.spec.Preference;
import teetime.framework.signal.ISignal; import teetime.framework.signal.ISignal;
import teetime.framework.signal.StartingSignal; import teetime.framework.signal.StartingSignal;
import teetime.framework.signal.ValidatingSignal;
import teetime.util.framework.concurrent.queue.PCBlockingQueue; import teetime.util.framework.concurrent.queue.PCBlockingQueue;
import teetime.util.framework.concurrent.queue.putstrategy.PutStrategy; import teetime.util.framework.concurrent.queue.putstrategy.PutStrategy;
import teetime.util.framework.concurrent.queue.putstrategy.YieldPutStrategy; import teetime.util.framework.concurrent.queue.putstrategy.YieldPutStrategy;
...@@ -67,6 +68,10 @@ public abstract class AbstractSynchedPipe<T> extends AbstractPipe<T> { ...@@ -67,6 +68,10 @@ public abstract class AbstractSynchedPipe<T> extends AbstractPipe<T> {
@Override @Override
public final void waitForStartSignal() throws InterruptedException { public final void waitForStartSignal() throws InterruptedException {
final ISignal signal = signalQueue.take(); final ISignal signal = signalQueue.take();
if (signal instanceof ValidatingSignal) {
this.waitForStartSignal();
return;
}
if (!(signal instanceof StartingSignal)) { if (!(signal instanceof StartingSignal)) {
throw new IllegalStateException( throw new IllegalStateException(
"2001 - Expected StartingSignal, but was " + signal.getClass().getSimpleName() + " in " + getTargetPort().getOwningStage().getId()); "2001 - Expected StartingSignal, but was " + signal.getClass().getSimpleName() + " in " + getTargetPort().getOwningStage().getId());
......
...@@ -56,7 +56,7 @@ public final class Execution<T extends Configuration> { ...@@ -56,7 +56,7 @@ public final class Execution<T extends Configuration> {
* to be used for the analysis * to be used for the analysis
*/ */
public Execution(final T configuration) { public Execution(final T configuration) {
this(configuration, false); this(configuration, true);
} }
/** /**
...@@ -74,10 +74,10 @@ public final class Execution<T extends Configuration> { ...@@ -74,10 +74,10 @@ public final class Execution<T extends Configuration> {
throw new IllegalStateException("3001 - Configuration has already been used."); throw new IllegalStateException("3001 - Configuration has already been used.");
} }
configuration.setInitialized(true); configuration.setInitialized(true);
init();
if (validationEnabled) { if (validationEnabled) {
validateStages(); validateStages();
} }
init();
} }
// BETTER validate concurrently // BETTER validate concurrently
......
...@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; ...@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -28,6 +29,7 @@ import org.junit.Test; ...@@ -28,6 +29,7 @@ import org.junit.Test;
import teetime.framework.signal.StartingSignal; import teetime.framework.signal.StartingSignal;
import teetime.framework.signal.TerminatingSignal; import teetime.framework.signal.TerminatingSignal;
import teetime.framework.validation.AnalysisNotValidException;
import teetime.stage.Cache; import teetime.stage.Cache;
import teetime.stage.Counter; import teetime.stage.Counter;
import teetime.stage.InitialElementProducer; import teetime.stage.InitialElementProducer;
...@@ -98,19 +100,26 @@ public class AbstractStageTest { ...@@ -98,19 +100,26 @@ public class AbstractStageTest {
} }
@Test @Test(expected = AnalysisNotValidException.class)
public void testCheckTypeCompliance() throws Exception { public void testCheckTypeCompliance() throws Exception {
new Execution<Configuration>(new TestConnectionsConfig(false), true); try {
new Execution<Configuration>(new TestConnectionsConfig(false), true).executeBlocking();
} catch (AnalysisNotValidException e) {
fail();
}
new Execution<Configuration>(new TestConnectionsConfig(true), true).executeBlocking();
} }
private class TestConnectionsConfig extends Configuration { private class TestConnectionsConfig extends Configuration {
TestConnectionsConfig(final boolean fails) { TestConnectionsConfig(final boolean fails) {
EmptyStage stage = new EmptyStage();
if (fails) { if (fails) {
// Can not be tested in Eclipse connectPorts((OutputPort) new EmptyStage().createOutputPort(Object.class), new EmptyStage().createInputPort(Integer.class));
} else { } else {
connectPorts(new EmptyStage().createOutputPort(Integer.class), new EmptyStage().createInputPort(Object.class)); connectPorts(stage.createOutputPort(Integer.class), new EmptyStage().createInputPort(Object.class));
} }
stage.declareActive();
} }
} }
...@@ -119,8 +128,7 @@ public class AbstractStageTest { ...@@ -119,8 +128,7 @@ public class AbstractStageTest {
@Override @Override
protected void execute() { protected void execute() {
// TODO Auto-generated method stub terminate();
} }
} }
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment