Skip to content

Commit

Permalink
Fixed unit tests for Continuations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodzga committed Mar 8, 2017
1 parent 0a0bf44 commit c8bd4d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/com/linkedin/parseq/internal/Continuations.java
Expand Up @@ -41,12 +41,16 @@ protected Continuation initialValue() {

public void submit(final Runnable action) {
if (ParSeqGlobalConfiguration.isTrampolineEnabled()) {
CONTINUATION.get().submit(action);
doSubmit(action);
} else {
action.run();
}
}

void doSubmit(final Runnable action) {
CONTINUATION.get().submit(action);
}

private static final class Continuation {
// contains sibling actions in reverse order of submission
// sibling actions are actions submitted by the same parent action
Expand Down
1 change: 0 additions & 1 deletion src/com/linkedin/parseq/promise/SettablePromiseImpl.java
Expand Up @@ -24,7 +24,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.linkedin.parseq.ParSeqGlobalConfiguration;
import com.linkedin.parseq.internal.Continuations;


Expand Down
32 changes: 16 additions & 16 deletions test/com/linkedin/parseq/internal/TestContinuations.java
Expand Up @@ -16,7 +16,7 @@ public class TestContinuations {
public void testActionCalled() {
final AtomicBoolean action = new AtomicBoolean(false);
Continuations CONT = new Continuations();
CONT.submit(() -> {
CONT.doSubmit(() -> {
action.set(true);
});
assertTrue(action.get());
Expand All @@ -28,10 +28,10 @@ public void testOnSuccessCalled() {
final AtomicInteger action = new AtomicInteger();
final AtomicInteger onSuccess = new AtomicInteger();
Continuations CONT = new Continuations();
CONT.submit(() -> {
CONT.doSubmit(() -> {
action.set(sequence.incrementAndGet());
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
onSuccess.set(sequence.incrementAndGet());
});
assertEquals(action.get(), 1);
Expand All @@ -44,10 +44,10 @@ public void testOnSuccessNotCalledWhenException() {
final AtomicInteger onSuccess = new AtomicInteger();
Continuations CONT = new Continuations();
try {
CONT.submit(() -> {
CONT.doSubmit(() -> {
throw new RuntimeException("test");
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
onSuccess.set(sequence.incrementAndGet());
});
fail("should have thrown exception");
Expand All @@ -61,11 +61,11 @@ public void testOnSuccessNotCalledWhenException() {
public void testRecursiveOrder() {
final Continuations CONT = new Continuations();
final StringBuilder result = new StringBuilder();
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.append("BEGIN{");
recursivePostOrder(CONT, result, "root", 0);
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.append("}END");
});
assertEquals(result.toString(),
Expand All @@ -74,13 +74,13 @@ public void testRecursiveOrder() {

private void recursivePostOrder(final Continuations CONT, final StringBuilder result, final String branch,
final int depth) {
CONT.submit(() -> {
CONT.doSubmit(() -> {
if (depth < 2) {
recursivePostOrder(CONT, result, branch + "L", depth + 1);
recursivePostOrder(CONT, result, branch + "R", depth + 1);
}
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.append("[done(" + branch + ":" + depth + ")]");
});
}
Expand All @@ -90,11 +90,11 @@ public void testRecursiveOrderWithException() {
final Continuations CONT = new Continuations();
final StringBuilder result = new StringBuilder();
try {
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.append("BEGIN{");
recursivePostOrderWithException(CONT, result, "root", 0);
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.append("}END");
});
fail("should have thrown exception");
Expand All @@ -106,7 +106,7 @@ public void testRecursiveOrderWithException() {

private void recursivePostOrderWithException(final Continuations CONT, final StringBuilder result,
final String branch, final int depth) {
CONT.submit(() -> {
CONT.doSubmit(() -> {
if (depth < 2) {
recursivePostOrderWithException(CONT, result, branch + "L", depth + 1);
recursivePostOrderWithException(CONT, result, branch + "R", depth + 1);
Expand All @@ -116,7 +116,7 @@ private void recursivePostOrderWithException(final Continuations CONT, final Str
}
}
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.append("[done(" + branch + ":" + depth + ")]");
});
}
Expand All @@ -125,19 +125,19 @@ private void recursivePostOrderWithException(final Continuations CONT, final Str
public void testDeepRecursion() {
final Continuations CONT = new Continuations();
final AtomicInteger result = new AtomicInteger();
CONT.submit(() -> {
CONT.doSubmit(() -> {
deepRecursion(CONT, result, 0);
});
assertEquals(result.get(), 1000001);
}

private void deepRecursion(final Continuations CONT, final AtomicInteger result, final int depth) {
CONT.submit(() -> {
CONT.doSubmit(() -> {
if (depth < 1000000) {
deepRecursion(CONT, result, depth + 1);
}
});
CONT.submit(() -> {
CONT.doSubmit(() -> {
result.incrementAndGet();
});
}
Expand Down

0 comments on commit c8bd4d1

Please sign in to comment.