-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
moves dispatching functionality out of Fixture class into a Dispatcher class #281
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6ef4646
separates dispatcher and fixture functionality of Fixture class
MartinGijsen 20d7ef4
corrects indentation and removes a line of commented code
MartinGijsen 33d5e65
reintroduced public members of Fixture class for compatibility
MartinGijsen ecd0b8d
Introduced parent class for Fixture named BaseFixture.
MartinGijsen a569f16
using doTable i.s.o. doTables where possible
MartinGijsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package fit; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import fit.exception.FitFailureException; | ||
|
||
|
||
public final class Dispatcher { | ||
public Counts counts; | ||
public final Map<String, Object> summary; | ||
|
||
private final FixtureListener listener; | ||
|
||
private static boolean forcedAbort = false; //Semaphores | ||
|
||
|
||
public static class RunTime { | ||
long start = System.currentTimeMillis(); | ||
long elapsed = 0; | ||
|
||
public String toString() { | ||
elapsed = System.currentTimeMillis() - start; | ||
if (elapsed > 600000) { | ||
return d(3600000) + ":" + d(600000) + d(60000) + ":" + d(10000) + d(1000); | ||
} else { | ||
return d(60000) + ":" + d(10000) + d(1000) + "." + d(100) + d(10); | ||
} | ||
} | ||
|
||
String d(long scale) { | ||
long report = elapsed / scale; | ||
elapsed -= report * scale; | ||
return Long.toString(report); | ||
} | ||
} | ||
|
||
public Dispatcher(FixtureListener listener) { | ||
counts = new Counts(); | ||
summary = new HashMap<String, Object>(); | ||
this.listener = listener; | ||
} | ||
|
||
public Dispatcher() { | ||
this(new NullFixtureListener()); | ||
} | ||
|
||
public static void setForcedAbort(boolean state) { | ||
forcedAbort = state; | ||
} //Semaphores | ||
|
||
public void doTables(Parse tables) { | ||
summary.put("run date", new Date()); | ||
summary.put("run elapsed time", new RunTime()); | ||
counts = new Counts(); | ||
while (tables != null) { | ||
processTable(tables); | ||
tables = tables.more; | ||
} | ||
listener.tablesFinished(counts); | ||
cleanup(); | ||
} | ||
|
||
protected void cleanup() { | ||
Fixture.ClearSymbols(); | ||
SemaphoreFixture.ClearSemaphores(); //Semaphores: clear all at end | ||
} | ||
|
||
private void processTable(Parse table) { | ||
Parse heading = table.at(0, 0, 0); | ||
if (forcedAbort) { | ||
ignore(heading); //Semaphores: ignore on failed lock | ||
} else if (heading != null) { | ||
try { | ||
Fixture fixture = getLinkedFixtureWithArgs(table); | ||
fixture.doTable(table); | ||
} catch (Throwable e) { | ||
exception(heading, e); | ||
} finally { | ||
listener.tableFinished(table); | ||
} | ||
} | ||
} | ||
|
||
private void ignore(Parse cell) { | ||
cell.addToTag(" class=\"ignore\""); | ||
counts.ignores++; | ||
} | ||
|
||
private Fixture getLinkedFixtureWithArgs(Parse tables) throws Throwable { | ||
Parse header = tables.at(0, 0, 0); | ||
Fixture fixture = Fixture.loadFixture(header.text()); | ||
fixture.counts = counts; | ||
fixture.summary = summary; | ||
fixture.getArgsForTable(tables); | ||
return fixture; | ||
} | ||
|
||
public void exception(Parse cell, Throwable exception) { | ||
while (exception.getClass().equals(InvocationTargetException.class)) { | ||
exception = ((InvocationTargetException) exception).getTargetException(); | ||
} | ||
if (isFriendlyException(exception)) { | ||
cell.addToBody("<hr/>" + Fixture.label(exception.getMessage())); | ||
} else { | ||
final StringWriter buf = new StringWriter(); | ||
exception.printStackTrace(new PrintWriter(buf)); | ||
cell.addToBody("<hr><pre><div class=\"fit_stacktrace\">" + (buf.toString()) + "</div></pre>"); | ||
} | ||
cell.addToTag(" class=\"error\""); | ||
counts.exceptions++; | ||
} | ||
|
||
private boolean isFriendlyException(Throwable exception) { | ||
return exception instanceof FitFailureException; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation issue here