summaryrefslogtreecommitdiffstats
path: root/java/sca/itest/scopes
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-12-05 00:48:31 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-12-05 00:48:31 +0000
commitf44c07576a61f6f4915ea8fd2aa5af9fee71745f (patch)
treeda023390d4bb97f353cdff9e6ca11a3f2eb9236b /java/sca/itest/scopes
parent10a9f2e5c0be26d6a44f1f90b677b9c5b7f985a9 (diff)
Convert, clean and bring up a set of itests
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@723537 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/itest/scopes')
-rw-r--r--java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/CompositeScopeStateVerifierImpl.java6
-rw-r--r--java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/RequestScopeStateVerifierImpl.java13
-rw-r--r--java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/StateVerifier.java2
-rw-r--r--java/sca/itest/scopes/src/test/java/org/apache/tuscany/sca/test/ScopeTestCase.java97
4 files changed, 62 insertions, 56 deletions
diff --git a/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/CompositeScopeStateVerifierImpl.java b/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/CompositeScopeStateVerifierImpl.java
index 4aa414be8e..f4ef805644 100644
--- a/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/CompositeScopeStateVerifierImpl.java
+++ b/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/CompositeScopeStateVerifierImpl.java
@@ -32,15 +32,15 @@ public class CompositeScopeStateVerifierImpl implements StateVerifier {
ThreadLocal<Integer> moduleState;
public CompositeScopeStateVerifierImpl() {
- moduleState = new ThreadLocal<Integer>();
+ moduleState = new ThreadLocal<Integer>();
}
public void setState(int i) {
- moduleState.set(i);
+ moduleState.set(i);
}
public boolean checkState(int i) {
- return (moduleState.get() == i);
+ return (moduleState.get() == i);
}
}
diff --git a/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/RequestScopeStateVerifierImpl.java b/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/RequestScopeStateVerifierImpl.java
index fae4dcd586..7e19a15cb1 100644
--- a/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/RequestScopeStateVerifierImpl.java
+++ b/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/RequestScopeStateVerifierImpl.java
@@ -17,6 +17,7 @@
* under the License.
*/
package org.apache.tuscany.sca.itest.scopes;
+
import org.osoa.sca.annotations.Destroy;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Scope;
@@ -30,21 +31,21 @@ public class RequestScopeStateVerifierImpl implements StateVerifier {
int requestState;
public void setState(int i) {
- requestState = i;
+ requestState = i;
}
public boolean checkState(int i) {
- return (requestState == i);
+ return (requestState == i);
}
-
+
@Init
public void init() {
requestState = 0;
}
-
+
@Destroy
public void destroy() {
- requestState = -1;
+ requestState = -1;
}
-} \ No newline at end of file
+}
diff --git a/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/StateVerifier.java b/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/StateVerifier.java
index 878f7e4cc6..e6bf08ccf2 100644
--- a/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/StateVerifier.java
+++ b/java/sca/itest/scopes/src/main/java/org/apache/tuscany/sca/itest/scopes/StateVerifier.java
@@ -20,6 +20,6 @@ package org.apache.tuscany.sca.itest.scopes;
public interface StateVerifier {
void setState(int i);
+
boolean checkState(int i);
}
-
diff --git a/java/sca/itest/scopes/src/test/java/org/apache/tuscany/sca/test/ScopeTestCase.java b/java/sca/itest/scopes/src/test/java/org/apache/tuscany/sca/test/ScopeTestCase.java
index ce2519cbc0..028cea6304 100644
--- a/java/sca/itest/scopes/src/test/java/org/apache/tuscany/sca/test/ScopeTestCase.java
+++ b/java/sca/itest/scopes/src/test/java/org/apache/tuscany/sca/test/ScopeTestCase.java
@@ -18,76 +18,81 @@
*/
package org.apache.tuscany.sca.test;
-import junit.framework.TestCase;
+import static org.junit.Assert.fail;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.itest.scopes.StateVerifier;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public class ScopeTestCase extends TestCase {
+public class ScopeTestCase {
final static int numThreads = 4; // number of threads to drive each scope container
final static int iterations = 200; // number of iterations per thread
- private SCADomain domain;
+ private Node node;
// Test scope containers.
// The request scope container isn't hooked up for some reason so the code below
// that tests request scope is commented out.
// Code could be added to test session scope once it is supported in a standalone environment.
-
+ @Test
public void testScopes() throws InterruptedException {
- Thread[] moduleScopeThreadTable = new Thread[numThreads];
- Thread[] requestScopeThreadTable = new Thread[numThreads];
+ Thread[] moduleScopeThreadTable = new Thread[numThreads];
+ Thread[] requestScopeThreadTable = new Thread[numThreads];
- for(int i=0; i<numThreads; i++)
- {
- moduleScopeThreadTable[i] = new ModuleScopeTestThread();
- requestScopeThreadTable[i] = new RequestScopeTestThread();
- }
- for(int j=0; j<numThreads; j++)
- {
- moduleScopeThreadTable[j].start();
- requestScopeThreadTable[j].start();
- }
- for(int k=0; k<numThreads; k++)
- {
- moduleScopeThreadTable[k].join();
- requestScopeThreadTable[k].join();
- }
+ for (int i = 0; i < numThreads; i++) {
+ moduleScopeThreadTable[i] = new ModuleScopeTestThread();
+ requestScopeThreadTable[i] = new RequestScopeTestThread();
+ }
+ for (int j = 0; j < numThreads; j++) {
+ moduleScopeThreadTable[j].start();
+ requestScopeThreadTable[j].start();
+ }
+ for (int k = 0; k < numThreads; k++) {
+ moduleScopeThreadTable[k].join();
+ requestScopeThreadTable[k].join();
+ }
}
- private class ModuleScopeTestThread extends Thread {
- @Override
- public void run() {
- StateVerifier moduleScopeService = domain.getService(StateVerifier.class, "ModuleScopeComponent");
- for(int i=1; i<=iterations; i++) {
- moduleScopeService.setState(i);
- if (!moduleScopeService.checkState(i))
- fail("The module scope service lost its state on iteration " + i);
+ private class ModuleScopeTestThread extends Thread {
+
+ public void run() {
+ StateVerifier moduleScopeService = node.getService(StateVerifier.class, "ModuleScopeComponent");
+ for (int i = 1; i <= iterations; i++) {
+ moduleScopeService.setState(i);
+ if (!moduleScopeService.checkState(i))
+ fail("The module scope service lost its state on iteration " + i);
+ }
}
- }
}
private class RequestScopeTestThread extends Thread {
- @Override
- public void run() {
- StateVerifier requestScopeService = domain.getService(StateVerifier.class, "RequestScopeComponent");
- for(int i=1; i<=iterations; i++) {
- requestScopeService.setState(i);
- if (!requestScopeService.checkState(i))
- fail("The request scope service lost its state on iteration " + i);
+
+ public void run() {
+ StateVerifier requestScopeService = node.getService(StateVerifier.class, "RequestScopeComponent");
+ for (int i = 1; i <= iterations; i++) {
+ requestScopeService.setState(i);
+ if (!requestScopeService.checkState(i))
+ fail("The request scope service lost its state on iteration " + i);
+ }
}
- }
}
- @Override
- protected void setUp() throws Exception {
- domain = SCADomain.newInstance("scopes.composite");
+ @Before
+ public void setUp() throws Exception {
+ String location = ContributionLocationHelper.getContributionLocation("scopes.composite");
+ node = NodeFactory.newInstance().createNode("scopes.composite", new Contribution("c1", location));
+ node.start();
}
- @Override
- protected void tearDown() throws Exception {
- domain.close();
+ @After
+ public void tearDown() throws Exception {
+ node.stop();
}
-
+
}