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

Test finally correct

parent 93296b5b
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,9 @@ import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import org.junit.Test;
import teetime.stage.InitialElementProducer;
import teetime.stage.basic.Sink;
public class TerminationTest {
......@@ -27,16 +26,20 @@ public class TerminationTest {
execution.executeNonBlocking();
Thread.sleep(100);
execution.abortEventually();
assertThat(configuration.sinkStage.time - 450, is(greaterThan(configuration.init.time)));
assertThat(configuration.finalProp.time - 450, is(greaterThan(configuration.firstProp.time)));
}
private class TerminationConfig extends Configuration {
InitialElementProducer<Integer> init = new InitialElementProducer<Integer>(1, 2, 3, 4, 5, 6);
Propagator firstProp = new Propagator();
DoesNotRetrieveElements sinkStage = new DoesNotRetrieveElements();
Propagator finalProp = new Propagator();
public TerminationConfig(final int capacity) {
if (capacity == 1) {
connectPorts(init.getOutputPort(), sinkStage.getInputPort(), capacity);
connectPorts(init.getOutputPort(), firstProp.getInputPort());
connectPorts(firstProp.getOutputPort(), sinkStage.getInputPort(), capacity);
connectPorts(sinkStage.getOutputPort(), finalProp.getInputPort());
addThreadableStage(sinkStage);
} else {
Sink<Integer> sink = new Sink<Integer>();
......@@ -47,34 +50,9 @@ public class TerminationTest {
}
private final class InitialElementProducer<T> extends AbstractProducerStage<T> {
private final Iterable<T> elements;
public long time;
public InitialElementProducer(final T... elements) {
this.elements = Arrays.asList(elements);
}
@Override
protected void execute() {
for (final T element : this.elements) {
this.outputPort.send(element);
}
this.terminate();
}
@Override
protected void terminate() {
time = System.currentTimeMillis();
super.terminate();
}
}
private class DoesNotRetrieveElements extends AbstractConsumerStage<Integer> {
public long time;
private final OutputPort<Integer> output = createOutputPort();
@Override
protected void execute(final Integer element) {
......@@ -87,17 +65,41 @@ public class TerminationTest {
// First sleep will throw this
}
if (i > 1) {
Thread.currentThread().interrupt();
time = System.currentTimeMillis();
super.terminate();
break;
}
}
}
public OutputPort<? extends Integer> getOutputPort() {
return output;
}
@Override
protected void terminate() {}
}
private class Propagator extends AbstractConsumerStage<Integer> {
public long time;
private final OutputPort<Integer> output = createOutputPort();
@Override
protected void execute(final Integer element) {
output.send(element);
}
public OutputPort<? extends Integer> getOutputPort() {
return output;
}
@Override
public void onTerminating() throws Exception {
time = System.currentTimeMillis();
super.onTerminating();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment