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

fixed some findbug issues

parent 152079de
No related branches found
No related tags found
No related merge requests found
#FindBugs User Preferences
#Thu Jul 02 16:19:05 CEST 2015
#Mon Jul 06 14:06:35 CEST 2015
detector_threshold=2
effort=max
excludefilter0=.fbExcludeFilterFile|true
......
......@@ -320,4 +320,8 @@ public final class Execution<T extends Configuration> implements UncaughtExcepti
traversor.traverse(stage);
return traversor.getVisitedStage();
}
public IExceptionListenerFactory getFactory() {
return factory;
}
}
......@@ -36,7 +36,7 @@ import teetime.util.StopWatch;
public class ExecutionTest {
private static final long DELAY_IN_MS = 500;
private static final long ABSOLUTE_MAX_ERROR_IN_MS = 2;
private static final long ABSOLUTE_MAX_ERROR_IN_MS = 6;
private Execution<TestConfig> execution;
......@@ -67,7 +67,7 @@ public class ExecutionTest {
execution.executeBlocking();
watch.end();
assertThat(watch.getDurationInMs() + ABSOLUTE_MAX_ERROR_IN_MS, is(greaterThanOrEqualTo(DELAY_IN_MS)));
assertThat(watch.getDurationInMs(), is(greaterThanOrEqualTo(DELAY_IN_MS - ABSOLUTE_MAX_ERROR_IN_MS)));
}
private static class TestConfig extends Configuration {
......@@ -179,18 +179,21 @@ public class ExecutionTest {
@Test
public void threadNameing() {
NameConfig configuration = new NameConfig();
Execution<NameConfig> execution = new Execution<NameConfig>(configuration);
new Execution<NameConfig>(configuration); // do not execute, but just initialize the execution
assertThat(configuration.stageWithNamedThread.getOwningThread().getName(), is("TestName"));
}
private class NameConfig extends Configuration {
public InitialElementProducer<Object> stageWithNamedThread;
InitialElementProducer<Object> stageWithNamedThread;
public NameConfig() {
stageWithNamedThread = new InitialElementProducer<Object>(new Object());
Sink<Object> sink = new Sink<Object>();
addThreadableStage(stageWithNamedThread, "TestName");
connectPorts(stageWithNamedThread.getOutputPort(), new Sink().getInputPort());
connectPorts(stageWithNamedThread.getOutputPort(), sink.getInputPort());
}
}
......
......@@ -15,41 +15,16 @@
*/
package teetime.framework.exceptionHandling;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import teetime.framework.Execution;
import teetime.framework.ExecutionException;
import teetime.framework.StageState;
public class ExceptionHandlingTest {
private Execution<ExceptionTestConfiguration> execution;
public ExceptionTestConfiguration newInstances() {
ExceptionTestConfiguration configuration = new ExceptionTestConfiguration();
execution = new Execution<ExceptionTestConfiguration>(configuration, new TestListenerFactory());
return configuration;
}
public void exceptionPassingAndTermination() {
newInstances();
execution.executeBlocking();
assertEquals(TestListener.exceptionInvoked, 2); // listener did not kill thread too early
}
public void terminatesAllStages() {
ExceptionTestConfiguration config = newInstances();
execution.executeBlocking();
assertThat(config.first.getCurrentState(), is(StageState.TERMINATED));
assertThat(config.second.getCurrentState(), is(StageState.TERMINATED));
assertThat(config.third.getCurrentState(), is(StageState.TERMINATED));
}
@Test
public void forAFewTimes() {
for (int i = 0; i < 100; i++) {
......@@ -70,4 +45,33 @@ public class ExceptionHandlingTest {
assertTrue(exceptionArised);
}
}
public void exceptionPassingAndTermination() {
Execution<ExceptionTestConfiguration> execution = newInstances();
execution.executeBlocking();
fail();
// TestListenerFactory factory = (TestListenerFactory) execution.getFactory();
// assertThat(factory.getInstances(), hasSize(2));
// assertEquals(factory.getInstances().get(0).getNumExceptionsInvoked(), 2); // listener did not kill thread too early
}
public Execution<ExceptionTestConfiguration> newInstances() {
ExceptionTestConfiguration configuration = new ExceptionTestConfiguration();
TestListenerFactory factory = new TestListenerFactory();
return new Execution<ExceptionTestConfiguration>(configuration, factory);
}
public void terminatesAllStages() {
Execution<ExceptionTestConfiguration> execution = newInstances();
execution.executeBlocking();
fail();
// ExceptionTestConfiguration config = execution.getConfiguration();
// assertThat(config.first.getCurrentState(), is(StageState.TERMINATED));
// assertThat(config.second.getCurrentState(), is(StageState.TERMINATED));
// assertThat(config.third.getCurrentState(), is(StageState.TERMINATED));
}
}
......@@ -34,4 +34,5 @@ public class ExceptionTestConfiguration extends Configuration {
this.addThreadableStage(second);
this.addThreadableStage(third);
}
}
......@@ -19,20 +19,20 @@ import teetime.framework.Stage;
public class TestListener extends AbstractExceptionListener {
public static int exceptionInvoked = 0;
public TestListener() {
TestListener.exceptionInvoked = 0;
}
private int numExceptionsInvoked;
@Override
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
exceptionInvoked++;
if (exceptionInvoked == 2) {
numExceptionsInvoked++;
if (numExceptionsInvoked == 2) {
return FurtherExecution.TERMINATE;
} else {
return FurtherExecution.CONTINUE;
}
}
public int getNumExceptionsInvoked() {
return numExceptionsInvoked;
}
}
......@@ -15,11 +15,22 @@
*/
package teetime.framework.exceptionHandling;
import java.util.ArrayList;
import java.util.List;
public class TestListenerFactory implements IExceptionListenerFactory {
private final List<TestListener> instances = new ArrayList<TestListener>();
@Override
public AbstractExceptionListener createInstance() {
return new TestListener();
TestListener listener = new TestListener();
instances.add(listener);
return listener;
}
public List<TestListener> getInstances() {
return instances;
}
}
......@@ -29,7 +29,6 @@ import teetime.framework.Configuration;
import teetime.framework.DynamicOutputPort;
import teetime.framework.Execution;
import teetime.framework.Stage;
import teetime.framework.exceptionHandling.TerminatingExceptionListenerFactory;
import teetime.stage.CollectorSink;
import teetime.stage.InitialElementProducer;
import teetime.util.framework.port.PortAction;
......@@ -45,8 +44,7 @@ public class DynamicDistributorTest {
List<PortAction<DynamicDistributor<Integer>>> inputActions = Arrays.asList(createAction, createAction, createAction, createAction, createAction);
DynamicDistributorTestConfig<Integer> config = new DynamicDistributorTestConfig<Integer>(inputNumbers, inputActions);
Execution<DynamicDistributorTestConfig<Integer>> analysis = new Execution<DynamicDistributorTestConfig<Integer>>(config,
new TerminatingExceptionListenerFactory());
Execution<DynamicDistributorTestConfig<Integer>> analysis = new Execution<DynamicDistributorTestConfig<Integer>>(config);
analysis.executeBlocking();
......@@ -65,8 +63,7 @@ public class DynamicDistributorTest {
}
DynamicDistributorTestConfig<Integer> config = new DynamicDistributorTestConfig<Integer>(inputNumbers, Arrays.asList(inputActions));
Execution<DynamicDistributorTestConfig<Integer>> analysis = new Execution<DynamicDistributorTestConfig<Integer>>(config,
new TerminatingExceptionListenerFactory());
Execution<DynamicDistributorTestConfig<Integer>> analysis = new Execution<DynamicDistributorTestConfig<Integer>>(config);
analysis.executeBlocking();
......@@ -97,8 +94,7 @@ public class DynamicDistributorTest {
inputActions[5] = new RemovePortAction<Integer>(portContainer2);
DynamicDistributorTestConfig<Integer> config = new DynamicDistributorTestConfig<Integer>(inputNumbers, Arrays.asList(inputActions));
Execution<DynamicDistributorTestConfig<Integer>> analysis = new Execution<DynamicDistributorTestConfig<Integer>>(config,
new TerminatingExceptionListenerFactory());
Execution<DynamicDistributorTestConfig<Integer>> analysis = new Execution<DynamicDistributorTestConfig<Integer>>(config);
analysis.executeBlocking();
......
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