vinayc 2003/08/28 11:18:40
Added: integrationtests/src/test/org/apache/altrmi/test/async
AbstractSimpleAsyncTestCase.java AsyncTest.java
AsyncTestImpl.java BcelSimpleAsyncTestCase.java
JavacSimpleAsyncTestCase.java
SimpleAsync2TestCase.java
Log:
Refactorize (includes modularize,mavenize & rest of the nice's)
Revision Changes Path
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/async/AbstractSimpleAsyncTestCase.java
Index: AbstractSimpleAsyncTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.test.async;
import junit.framework.TestCase;
import org.apache.altrmi.client.Factory;
import org.apache.altrmi.client.impl.ServerSideClassFactory;
import org.apache.altrmi.client.impl.socket.SocketCustomStreamHostContext;
import org.apache.altrmi.common.DefaultThreadPool;
import org.apache.altrmi.server.PublicationDescription;
import org.apache.altrmi.server.PublicationDescriptionItem;
import org.apache.altrmi.server.impl.DefaultAuthenticator;
import org.apache.altrmi.server.impl.DefaultServerSideClientContextFactory;
import org.apache.altrmi.server.impl.NullServerMonitor;
import
org.apache.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
import org.apache.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
public abstract class AbstractSimpleAsyncTestCase extends TestCase
{
AsyncTestImpl asyncTestImpl;
AsyncTest testClient;
Factory factory;
CompleteSocketCustomStreamServer server;
public AbstractSimpleAsyncTestCase(String name)
{
super(name);
}
protected abstract AbstractDynamicGeneratorClassRetriever
getAbstractDynamicGeneratorClassRetriever(ClassLoader cl);
protected void setUp() throws Exception
{
super.setUp();
// server side setup.
// JavacDynamicGeneratorClassRetriever cr = new
JavacDynamicGeneratorClassRetriever(
// this.getClass().getClassLoader());
AbstractDynamicGeneratorClassRetriever cr =
getAbstractDynamicGeneratorClassRetriever(
this.getClass().getClassLoader());
cr.setClassGenDir(".");
cr.setClasspath("..\\build\\classes;%JAVA_HOME%\\lib\\tools.jar");
cr.setSrcGenDir(".");
DefaultServerSideClientContextFactory ccf = new
DefaultServerSideClientContextFactory();
server = new CompleteSocketCustomStreamServer(cr,
new DefaultAuthenticator(),
new NullServerMonitor(), new DefaultThreadPool(), ccf, 11003);
asyncTestImpl = new AsyncTestImpl();
PublicationDescription pd = new PublicationDescription();
pd.addInterfaceToExpose(
new PublicationDescriptionItem(AsyncTest.class,
new String[]{"setOne(java.lang.String)",
"setTwo(java.lang.String)",
"setThree(java.lang.String)",
},
new String[]{"fire()"},
new String[]{"whoa()"}
)
);
cr.generate("AsyncTest", pd, this.getClass().getClassLoader());
server.publish(asyncTestImpl, "AsyncTest", pd);
server.start();
// Client side setup
factory = new ServerSideClassFactory(
new
SocketCustomStreamHostContext.WithSimpleDefaults("127.0.0.1", 11003), false);
testClient = (AsyncTest) factory.lookup("AsyncTest");
// just a kludge for unit testing given we are intrinsically dealing
with
// threads, AltRMI being a client/server thing
Thread.yield();
}
public void testSimpleAsync() throws Exception
{
testClient.setOne("one");
testClient.setTwo("two");
testClient.setThree("three");
assertNull("Field 'One' should be null", asyncTestImpl.one);
assertNull("Field 'Two' should be null", asyncTestImpl.two);
assertNull("Field 'Tree' should be null", asyncTestImpl.three);
assertFalse("Field 'Fire' should be false", asyncTestImpl.fired);
testClient.fire();
assertNotNull("Field 'One' should not be null", asyncTestImpl.one);
assertNotNull("Field 'Two' should not be null", asyncTestImpl.two);
assertNotNull("Field 'Tree' should not be null", asyncTestImpl.three);
assertTrue("Field 'Fire' should not be false", asyncTestImpl.fired);
}
public void testRollback() throws Exception
{
testClient.setOne("111");
assertNull("Field 'One' should be null #1", asyncTestImpl.one);
testClient.whoa();
testClient.fire();
assertNull("Field 'One' should be null #2", asyncTestImpl.one);
assertTrue("Field 'Whoa' should not be false", asyncTestImpl.whoa);
assertTrue("Field 'Fire' should not be false", asyncTestImpl.fired);
testClient.setOne("222");
testClient.fire();
assertNotNull("Field 'One' should not be null", asyncTestImpl.one);
}
protected void tearDown() throws Exception
{
testClient = null;
System.gc();
Thread.yield();
factory.close();
Thread.yield();
server.stop();
Thread.yield();
server = null;
asyncTestImpl = null;
super.tearDown();
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/async/AsyncTest.java
Index: AsyncTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.test.async;
/**
* @altrmi:facade async-mode1
*/
public interface AsyncTest
{
/**
* @altrmi:method async
*/
void setOne(String one);
/**
* @altrmi:method async
*/
void setTwo(String two);
/**
* @altrmi:method async
*/
void setThree(String three);
/**
* @altrmi:method commit
*/
void fire();
/**
* @altrmi:method rollback
*/
void whoa();
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/async/AsyncTestImpl.java
Index: AsyncTestImpl.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.test.async;
public class AsyncTestImpl implements AsyncTest
{
public String one;
public String two;
public String three;
public boolean fired;
public boolean whoa;
public void setOne(String one)
{
this.one = one;
}
public void setTwo(String two)
{
this.two = two;
}
public void setThree(String three)
{
this.three = three;
}
public void fire()
{
fired = true;
}
public void whoa()
{
whoa = true;
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/async/BcelSimpleAsyncTestCase.java
Index: BcelSimpleAsyncTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.test.async;
import
org.apache.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
import
org.apache.altrmi.server.impl.classretrievers.BcelDynamicGeneratorClassRetriever;
public class BcelSimpleAsyncTestCase extends AbstractSimpleAsyncTestCase {
public BcelSimpleAsyncTestCase(String name) {
super(name);
}
protected AbstractDynamicGeneratorClassRetriever
getAbstractDynamicGeneratorClassRetriever(ClassLoader cl) {
return new BcelDynamicGeneratorClassRetriever(cl);
}
public static void main(String[] args) throws Exception
{
AbstractSimpleAsyncTestCase simp = new
BcelSimpleAsyncTestCase("testSimpleAsync");
simp.setUp();
simp.testSimpleAsync();
simp.tearDown();
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/async/JavacSimpleAsyncTestCase.java
Index: JavacSimpleAsyncTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.test.async;
import
org.apache.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
import
org.apache.altrmi.server.impl.classretrievers.JavacDynamicGeneratorClassRetriever;
public class JavacSimpleAsyncTestCase extends AbstractSimpleAsyncTestCase {
public JavacSimpleAsyncTestCase(String name) {
super(name);
}
protected AbstractDynamicGeneratorClassRetriever
getAbstractDynamicGeneratorClassRetriever(ClassLoader cl) {
return new JavacDynamicGeneratorClassRetriever(cl);
}
public static void main(String[] args) throws Exception
{
AbstractSimpleAsyncTestCase simp = new
JavacSimpleAsyncTestCase("testSimpleAsync");
simp.setUp();
simp.testSimpleAsync();
simp.tearDown();
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/async/SimpleAsync2TestCase.java
Index: SimpleAsync2TestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "AltRMI", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.test.async;
import junit.framework.TestCase;
import org.apache.altrmi.client.Factory;
import org.apache.altrmi.client.impl.ServerSideClassFactory;
import org.apache.altrmi.client.impl.socket.SocketCustomStreamHostContext;
import org.apache.altrmi.common.DefaultThreadPool;
import org.apache.altrmi.server.PublicationDescription;
import org.apache.altrmi.server.impl.DefaultAuthenticator;
import org.apache.altrmi.server.impl.DefaultServerSideClientContextFactory;
import org.apache.altrmi.server.impl.NullServerMonitor;
import
org.apache.altrmi.server.impl.classretrievers.JavacDynamicGeneratorClassRetriever;
import org.apache.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
import java.io.File;
public class SimpleAsync2TestCase extends TestCase
{
AsyncTestImpl asyncTestImpl;
AsyncTest testClient;
Factory factory;
CompleteSocketCustomStreamServer server;
public SimpleAsync2TestCase(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
// server side setup.
JavacDynamicGeneratorClassRetriever cr = new
JavacDynamicGeneratorClassRetriever(
this.getClass().getClassLoader());
cr.setClassGenDir(".");
String FS = File.separator;
String PS = File.pathSeparator;
String javaHomeString = System.getProperty("java.home");
File javaHome = new File(javaHomeString);
if (javaHomeString.endsWith(FS + "jre"))
{
javaHome = javaHome.getParentFile();
}
System.out.println("javaHome=" + javaHome.getAbsolutePath());
cr.setClasspath(".." + FS + "build" + FS + "classes" + PS +
javaHome.getAbsolutePath() + FS + "lib" + FS + "tools.jar");
cr.setSrcGenDir(".");
server = new CompleteSocketCustomStreamServer(cr, new
DefaultAuthenticator(), new NullServerMonitor(), new DefaultThreadPool(), new
DefaultServerSideClientContextFactory(), 11004);
asyncTestImpl = new AsyncTestImpl();
// automatic determination of async elements.
PublicationDescription pd = new
PublicationDescription(AsyncTest.class);
cr.generate("AsyncTestB", pd, this.getClass().getClassLoader());
server.publish(asyncTestImpl, "AsyncTestB", pd);
server.start();
// Client side setup
factory = new ServerSideClassFactory(new
SocketCustomStreamHostContext.WithSimpleDefaults("127.0.0.1", 11004), false);
testClient = (AsyncTest) factory.lookup("AsyncTestB");
// just a kludge for unit testing given we are intrinsically dealing
with
// threads, AltRMI being a client/server thing
Thread.yield();
}
public void testSimpleAsync() throws Exception
{
testClient.setOne("one");
testClient.setTwo("two");
testClient.setThree("three");
assertNull("Field 'One' should be null", asyncTestImpl.one);
assertNull("Field 'Two' should be null", asyncTestImpl.two);
assertNull("Field 'Tree' should be null", asyncTestImpl.three);
assertFalse("Field 'Fire' should be false", asyncTestImpl.fired);
testClient.fire();
assertNotNull("Field 'One' should not be null", asyncTestImpl.one);
assertNotNull("Field 'Two' should not be null", asyncTestImpl.two);
assertNotNull("Field 'Tree' should not be null", asyncTestImpl.three);
assertTrue("Field 'Fire' should not be false", asyncTestImpl.fired);
}
public void testRollback() throws Exception
{
testClient.setOne("111");
assertNull("Field 'One' should be null #1", asyncTestImpl.one);
testClient.whoa();
testClient.fire();
assertNull("Field 'One' should be null #2", asyncTestImpl.one);
assertTrue("Field 'Whoa' should not be false", asyncTestImpl.whoa);
assertTrue("Field 'Fire' should not be false", asyncTestImpl.fired);
testClient.setOne("222");
testClient.fire();
assertNotNull("Field 'One' should not be null", asyncTestImpl.one);
}
protected void tearDown() throws Exception
{
testClient = null;
System.gc();
Thread.yield();
factory.close();
Thread.yield();
server.stop();
Thread.yield();
server = null;
asyncTestImpl = null;
super.tearDown();
}
public static void main(String[] args) throws Exception
{
SimpleAsync2TestCase simp = new
SimpleAsync2TestCase("testSimpleAsync");
simp.setUp();
simp.testSimpleAsync();
simp.tearDown();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]