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

moved test to SpScPipeTest and removed old Classes

Changed type of pipe to InterThreadPipe to get method getSignal
parent de7cab4c
No related branches found
No related tags found
No related merge requests found
package teetime.examples.pipe;
import teetime.framework.AnalysisConfiguration;
import teetime.framework.ConsumerStage;
import teetime.framework.ProducerStage;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
import teetime.framework.pipe.SpScPipe;
import teetime.stage.Cache;
import teetime.stage.Clock;
public class SignalQueueConfiguration extends AnalysisConfiguration {
public SpScPipe pipe;
public SignalQueueConfiguration() {
ProducerStage<Long> first = new Clock();
ConsumerStage<Long> second = new Cache<Long>();
pipe = (SpScPipe) PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTER, PipeOrdering.QUEUE_BASED, false)
.create(first.getOutputPort(), second.getInputPort());
}
}
package teetime.examples.pipe;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Test;
import teetime.framework.pipe.SpScPipe;
import teetime.framework.signal.ISignal;
import teetime.framework.signal.StartingSignal;
import teetime.framework.signal.TerminatingSignal;
import teetime.framework.signal.ValidatingSignal;
public class SignalQueueTest {
@Test
public void executeTest() {
ArrayList<ISignal> list = new ArrayList<ISignal>();
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
SpScPipe pipe = new SignalQueueConfiguration().pipe;
for (ISignal s : list) {
pipe.sendSignal(s);
}
ArrayList<ISignal> secondList = new ArrayList<ISignal>();
while (true) {
ISignal temp = pipe.getSignal();
if (temp == null) {
break;
}
secondList.add(temp);
}
Assert.assertEquals(list, secondList);
}
}
package teetime.framework.pipe; package teetime.framework.pipe;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import teetime.framework.InputPort; import teetime.framework.InputPort;
import teetime.framework.OutputPort; import teetime.framework.OutputPort;
import teetime.framework.signal.ISignal;
import teetime.framework.signal.StartingSignal;
import teetime.framework.signal.TerminatingSignal;
import teetime.framework.signal.ValidatingSignal;
public class SpScPipeTest { public class SpScPipeTest {
...@@ -11,11 +19,31 @@ public class SpScPipeTest { ...@@ -11,11 +19,31 @@ public class SpScPipeTest {
public void testSignalOrdering() throws Exception { public void testSignalOrdering() throws Exception {
OutputPort<? extends Object> sourcePort = null; OutputPort<? extends Object> sourcePort = null;
InputPort<Object> targetPort = null; InputPort<Object> targetPort = null;
IPipe pipe = new SpScPipe(sourcePort, targetPort, 1); InterThreadPipe pipe = new SpScPipe(sourcePort, targetPort, 1); // IPipe does not provide getSignal method
List<ISignal> list = new ArrayList<ISignal>();
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
// TODO implement test for (ISignal s : list) {
// pipe.sendSignal(signal); pipe.sendSignal(s);
}
// pipe.getSignal(); List<ISignal> secondList = new ArrayList<ISignal>();
while (true) {
ISignal temp = pipe.getSignal();
if (temp == null) {
break;
}
secondList.add(temp);
}
Assert.assertEquals(list, secondList);
} }
} }
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