diff options
Diffstat (limited to 'java/sca/itest/scopes/src/test')
-rw-r--r-- | java/sca/itest/scopes/src/test/java/org/apache/tuscany/sca/test/ScopeTestCase.java | 97 |
1 files changed, 51 insertions, 46 deletions
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(); } - + } |