Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2008-12-19 16:30:56 +0000
committerbvosburgh2008-12-19 16:30:56 +0000
commit6333d08a6739f26e3bafb9a3e906877f17832aef (patch)
treed26dbf6514fc0dfd672165958dca71d20002eb0c /jpa/tests/org.eclipse.jpt.utility.tests/src
parent1318d978885709acb55d37ea8e18490c6a80d6ac (diff)
downloadwebtools.dali-6333d08a6739f26e3bafb9a3e906877f17832aef.tar.gz
webtools.dali-6333d08a6739f26e3bafb9a3e906877f17832aef.tar.xz
webtools.dali-6333d08a6739f26e3bafb9a3e906877f17832aef.zip
added ThreadLocalCommand and other minor clean-up on CommandExecutor
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.utility.tests/src')
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java2
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandTests.java57
2 files changed, 52 insertions, 7 deletions
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java
index eeef9623fe..f27f8830ba 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java
@@ -75,7 +75,7 @@ public class CommandExecutorTests extends TestCase {
this.executionCount = executionCount;
}
public void run() {
- this.threadLocalCommandExecutor.setThreadLocalCommandExecutor(this.testCommandExecutor);
+ this.threadLocalCommandExecutor.set(this.testCommandExecutor);
for (int i = 0; i < this.executionCount; i++) {
this.threadLocalCommandExecutor.execute(this.testCommand);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandTests.java
index 04879f20f1..160c77f3c2 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandTests.java
@@ -12,8 +12,10 @@ package org.eclipse.jpt.utility.tests.internal;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.Command;
+import org.eclipse.jpt.utility.CommandExecutor;
import org.eclipse.jpt.utility.internal.CommandRunnable;
import org.eclipse.jpt.utility.internal.RunnableCommand;
+import org.eclipse.jpt.utility.internal.ThreadLocalCommand;
public class CommandTests extends TestCase {
@@ -39,14 +41,14 @@ public class CommandTests extends TestCase {
}
public void testRunnableCommand() {
- TestRunnable testRunnable = new TestRunnable();
+ SimpleTestRunnable testRunnable = new SimpleTestRunnable();
assertFalse(testRunnable.ran);
Command command = new RunnableCommand(testRunnable);
command.execute();
assertTrue(testRunnable.ran);
}
- static class TestRunnable implements Runnable {
+ static class SimpleTestRunnable implements Runnable {
boolean ran = false;
public void run() {
this.ran = true;
@@ -55,16 +57,59 @@ public class CommandTests extends TestCase {
public void testCommandRunnable() {
TestCommand testCommand = new TestCommand();
- assertFalse(testCommand.executed);
+ assertEquals(0, testCommand.count);
Runnable runnable = new CommandRunnable(testCommand);
runnable.run();
- assertTrue(testCommand.executed);
+ assertEquals(1, testCommand.count);
}
static class TestCommand implements Command {
- boolean executed = false;
+ int count = 0;
public void execute() {
- this.executed = true;
+ this.count++;
+ }
+ }
+
+ public void testThreadLocalCommand() throws Exception {
+ ThreadLocalCommand threadLocalCommand = new ThreadLocalCommand();
+ TestRunnable testRunnable1 = new TestRunnable(threadLocalCommand, 1);
+ Thread thread1 = new Thread(testRunnable1);
+ thread1.run();
+
+ TestRunnable testRunnable2 = new TestRunnable(threadLocalCommand, 2);
+ Thread thread2 = new Thread(testRunnable2);
+ thread2.run();
+
+ thread1.join();
+ thread2.join();
+
+ assertEquals(1, testRunnable1.testCommand.count);
+
+ assertEquals(2, testRunnable2.testCommand.count);
+ }
+
+ static class TestCommandExecutor implements CommandExecutor {
+ int count = 0;
+ public void execute(Command command) {
+ this.count++;
+ command.execute();
+ }
+ }
+
+ static class TestRunnable implements Runnable {
+ final ThreadLocalCommand threadLocalCommand;
+ final int executionCount;
+ final TestCommand testCommand = new TestCommand();
+ TestRunnable(ThreadLocalCommand threadLocalCommand, int executionCount) {
+ super();
+ this.threadLocalCommand = threadLocalCommand;
+ this.executionCount = executionCount;
+ }
+ public void run() {
+ this.threadLocalCommand.set(this.testCommand);
+ for (int i = 0; i < this.executionCount; i++) {
+ this.threadLocalCommand.execute();
+ }
}
}

Back to the top