vinayc 2003/08/28 11:19:51
Added: integrationtests/src/test/org/apache/altrmi/test/clientcontext
Account.java AccountImpl.java AccountListener.java
AccountManager.java AccountManagerImpl.java
ClientContextTestCase.java CreditBarfed.java
DebitBarfed.java TestClientContext.java
TestClientContextFactory.java TransferBarfed.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/clientcontext/Account.java
Index: Account.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.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface Account
{
String getSymbolicKey();
void debit( int amt ) throws DebitBarfed;
void credit( int amt ) throws CreditBarfed;
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/AccountImpl.java
Index: AccountImpl.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.clientcontext;
import org.apache.altrmi.common.ClientContext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class AccountImpl implements Account {
private ServerSideClientContextFactory m_clientContextFactory;
String m_symbolicKey;
private int m_balance = 123;
private AccountListener m_accountListener;
public AccountImpl(ServerSideClientContextFactory clientContextFactory,
String symbolicKey, AccountListener accountListener) {
m_clientContextFactory = clientContextFactory;
m_symbolicKey = symbolicKey;
m_accountListener = accountListener;
}
public String getSymbolicKey() {
return m_symbolicKey;
}
public int getBalance() {
return m_balance;
}
public void debit(int amt) throws DebitBarfed
{
ClientContext cc = m_clientContextFactory.get();
m_balance = m_balance - amt;
m_accountListener.record(getSymbolicKey() + ":debit:" + amt, cc);
}
public void credit(int amt) throws CreditBarfed
{
ClientContext cc = m_clientContextFactory.get();
m_balance = m_balance + amt;
m_accountListener.record(getSymbolicKey() + ":credit:" + amt, cc);
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/AccountListener.java
Index: AccountListener.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.clientcontext;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface AccountListener
{
void record( String event, ClientContext clientContext );
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/AccountManager.java
Index: AccountManager.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.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface AccountManager
{
void transferAmount( String acct1, String acct2, int amt ) throws
TransferBarfed;
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/AccountManagerImpl.java
Index: AccountManagerImpl.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.clientcontext;
import org.apache.altrmi.common.ClientContext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import java.util.HashMap;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class AccountManagerImpl implements AccountManager
{
private HashMap m_accounts = new HashMap();
private ServerSideClientContextFactory m_clientContextFactory;
public AccountManagerImpl( ServerSideClientContextFactory
clientContextFactory, Account one, Account two )
{
m_clientContextFactory = clientContextFactory;
m_accounts.put( one.getSymbolicKey(), one );
m_accounts.put( two.getSymbolicKey(), two );
}
public void transferAmount( String acct1, String acct2, int amt ) throws
TransferBarfed
{
Account from = ( Account ) m_accounts.get( acct1 );
Account to = ( Account ) m_accounts.get( acct2 );
ClientContext cc = m_clientContextFactory.get();
try
{
from.debit( amt );
to.credit( amt );
}
catch ( DebitBarfed debitBarfed )
{
throw new TransferBarfed();
}
catch ( CreditBarfed creditBarfed )
{
throw new TransferBarfed();
}
finally
{
// ?
}
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/ClientContextTestCase.java
Index: ClientContextTestCase.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.clientcontext;
import junit.framework.TestCase;
import org.apache.altrmi.client.Factory;
import org.apache.altrmi.client.impl.ClientSideClassFactory;
import org.apache.altrmi.client.impl.socket.SocketCustomStreamHostContext;
import org.apache.altrmi.common.ClientContext;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.DefaultThreadPool;
import org.apache.altrmi.server.PublicationDescription;
import org.apache.altrmi.server.PublicationException;
import org.apache.altrmi.server.Server;
import org.apache.altrmi.server.ServerException;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import org.apache.altrmi.server.impl.DefaultAuthenticator;
import org.apache.altrmi.server.impl.DefaultServerSideClientContext;
import org.apache.altrmi.server.impl.DefaultServerSideClientContextFactory;
import org.apache.altrmi.server.impl.NullServerMonitor;
import org.apache.altrmi.server.impl.classretrievers.PlainClassRetriever;
import org.apache.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
import java.util.HashMap;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class ClientContextTestCase extends TestCase
{
public ClientContextTestCase( String name )
{
super( name );
}
public void testSimple()
{
AccountListener al = new AccountListener()
{
public void record( String event, ClientContext clientContext )
{
}
};
ServerSideClientContextFactory clientContextFactory = new
DefaultServerSideClientContextFactory();
AccountImpl one = new AccountImpl( clientContextFactory, "one", al );
AccountImpl two = new AccountImpl( clientContextFactory, "two", al );
final AccountManager accountManager = new AccountManagerImpl(
clientContextFactory, one, two );
try
{
accountManager.transferAmount( "one", "two", 23 );
}
catch ( TransferBarfed transferBarfed )
{
fail( "Transfer should have worked" );
}
assertEquals( one.getBalance(), 100 );
assertEquals( two.getBalance(), 146 );
}
public void testWithCustomContextWithoutRPC() throws InterruptedException
{
final HashMap hashMap = new HashMap();
AccountListener al = makeAccountListener( hashMap );
ServerSideClientContextFactory clientContextFactory = new
TestClientContextFactory();
AccountImpl one = new AccountImpl( clientContextFactory, "one", al );
AccountImpl two = new AccountImpl( clientContextFactory, "two", al );
final AccountManager accountManager = new AccountManagerImpl(
clientContextFactory, one, two );
Thread threadOne = makeThread( accountManager, 11 );
Thread threadTwo = makeThread( accountManager, 22 );
threadOne.start();
threadTwo.start();
Thread.sleep( 2000 );
ClientContext debit11 = ( ClientContext ) hashMap.get( "one:debit:11"
);
ClientContext credit11 = ( ClientContext ) hashMap.get(
"two:credit:11" );
basicAsserts( debit11, credit11 );
ClientContext debit22 = ( ClientContext ) hashMap.get( "one:debit:22"
);
ClientContext credit22 = ( ClientContext ) hashMap.get(
"two:credit:22" );
basicAsserts( debit22, credit22 );
assertFalse( debit11 == credit22 );
}
public void testWithCustomContextWithRPC() throws InterruptedException,
ServerException,
PublicationException, ConnectionException
{
final HashMap hashMap = new HashMap();
AccountListener al = makeAccountListener( hashMap );
ServerSideClientContextFactory ccf
= new DefaultServerSideClientContextFactory();
AccountImpl one = new AccountImpl( ccf, "one", al );
AccountImpl two = new AccountImpl( ccf, "two", al );
final AccountManager accountManager
= new AccountManagerImpl( ccf, one, two );
Server server = new CompleteSocketCustomStreamServer( new
PlainClassRetriever(), new DefaultAuthenticator(), new NullServerMonitor(), new
DefaultThreadPool(), ccf, 13333 );
PublicationDescription pd = new PublicationDescription(
AccountManager.class );
server.publish( accountManager, "OurAccountManager", pd );
server.start();
Factory factory = new ClientSideClassFactory( new
SocketCustomStreamHostContext.WithSimpleDefaults( "127.0.0.1", 13333 ), false );
final AccountManager clientSideAccountManager = ( AccountManager )
factory.lookup( "OurAccountManager" );
Thread threadOne = makeThread( clientSideAccountManager, 11 );
Thread threadTwo = makeThread( clientSideAccountManager, 22 );
threadOne.start();
threadTwo.start();
Thread.sleep( 2000 );
ClientContext debit11 = ( ClientContext ) hashMap.get( "one:debit:11"
);
ClientContext credit11 = ( ClientContext ) hashMap.get(
"two:credit:11" );
basicAsserts( debit11, credit11 );
assertTrue( "Wrong type of ClientContext", credit11 instanceof
DefaultServerSideClientContext );
ClientContext debit22 = ( ClientContext ) hashMap.get( "one:debit:22"
);
ClientContext credit22 = ( ClientContext ) hashMap.get(
"two:credit:22" );
basicAsserts( debit22, credit22 );
assertFalse( debit11 == credit22 );
}
private void basicAsserts( ClientContext debitContext, ClientContext
creditContext )
{
assertNotNull( "Debit should have been registered on server side",
debitContext );
assertNotNull( "Credit should have been registered on server side",
creditContext );
assertEquals( "Debit Context and Credit Context should be .equals()",
debitContext, creditContext );
}
private AccountListener makeAccountListener( final HashMap hashMap )
{
AccountListener al = new AccountListener()
{
public void record( String event, ClientContext clientContext )
{
//System.out.println("EVENT-" + event + " " + clientContext);
hashMap.put( event, clientContext );
}
};
return al;
}
private Thread makeThread( final AccountManager accountManager, final int
amount )
{
Thread thread = new Thread( new Runnable()
{
public void run()
{
try
{
accountManager.transferAmount( "one", "two", amount );
}
catch ( TransferBarfed transferBarfed )
{
fail( "Transfer should have worked" );
}
}
} );
return thread;
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/CreditBarfed.java
Index: CreditBarfed.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.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class CreditBarfed extends Exception
{
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/DebitBarfed.java
Index: DebitBarfed.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.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class DebitBarfed extends Exception
{
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/TestClientContext.java
Index: TestClientContext.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.clientcontext;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class TestClientContext implements ClientContext
{
private String ctx;
public TestClientContext()
{
ctx = "TestCCF:" + System.identityHashCode(Thread.currentThread());
}
public int hashCode()
{
return ctx.hashCode();
}
public String toString()
{
return ctx;
}
public boolean equals( Object obj )
{
return ctx.equals(((TestClientContext) obj).ctx);
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/TestClientContextFactory.java
Index: TestClientContextFactory.java
===================================================================
package org.apache.altrmi.test.clientcontext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class TestClientContextFactory implements
ServerSideClientContextFactory
{
public TestClientContextFactory()
{
}
public ClientContext get()
{
return new TestClientContext();
}
//return "TestCCF:" + System.identityHashCode(Thread.currentThread());
public void set( Long session, ClientContext clientContext )
{
}
public boolean isSet()
{
return false;
}
}
1.1
incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/clientcontext/TransferBarfed.java
Index: TransferBarfed.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.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class TransferBarfed extends Exception
{
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]