/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/
package org.codehaus.activemq.util;

import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
import junit.framework.TestCase;

/**
 * @version $Revision: 1.1 $
 */
public class AsyncProxyTest extends TestCase {

    public void testAsyncProxy() throws Exception {
        ExampleServer service = new ExampleServerImpl();
        
        // thread pool to execute tasks in
        PooledExecutor executor = new PooledExecutor(1);
        
        // async proxy
        ExampleServer proxy = (ExampleServer) AsyncProxy.createProxy(ExampleServer.class, service, executor);

        // lets make an async call
        System.out.println("Making an async call from thread: " + Thread.currentThread());
        proxy.foo();
        
        // wait a moment for async stuff
        Thread.sleep(1000);

        assertEquals("Should have invoked foo by now", 1, service.getFooCount());

        ExecutorHelper.stopExecutor(executor);
    }
}
