/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.stests.manac;

import java.rmi.RemoteException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.transaction.RollbackException;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.objectweb.jonas.stests.util.JTestCase;

/**
 * This TestCase is a set of multithreaded clients accessing concurrently
 * the set of accounts.
 */
public class F_multi extends A_manac {

    public F_multi(String name) {
	super(name);
    }

    /*
     * Simplest test with 2 threads : 1 loop, 2 thread, no rollback, no delay
     */
    public void test_a4_d0_l1_m10_t2() throws Exception {
	manac(4, 0, 1, 10, 2);
    }

    /*
     * 2 threads with possible rollback
     */
    public void test_a6_d0_l20_m400_t2() throws Exception {
	manac(6, 0, 20, 400, 2);
    }

    /*
     * add a delay
     */
    public void test_a4_d3_l2_m10_t2() throws Exception {
	manac(4, 3, 2, 10, 2);
    }

    /*
     * 4 threads 
     */
    public void test_amax_d0_l5_m10_t4() throws Exception {
	manac(maxAccounts, 0, 5, 10, 4);
    }

    /*
     * 4 threads with delay
     */
    public void test_amax_d2_l5_m20_t4() throws Exception {
	manac(maxAccounts, 2, 5, 10, 4);
    }

    /*
     * 6 threads 
     */
    public void test_amax_d0_l5_m10_t6() throws Exception {
	manac(maxAccounts, 0, 5, 10, 6);
    }

    /*
     * 6 threads with collisions
     */
    public void _test_a4_d0_l10_m20_t6() throws Exception {
	manac(4, 0, 10, 20, 6);
    }

    /*
     * 4 threads with many collisions
     */
    public void test_a4_d0_l20_m100_t4() throws Exception {
	manac(4, 0, 20, 100, 4);
    }

    /*
     * 8 threads 
     */
    public void test_amax_d0_l2_m1_t8() throws Exception {
	manac(maxAccounts, 0, 2, 1, 8);
    }

    /*
     * 8 threads more loops
     */
    public void _test_a10_d0_l20_m2_t8() throws Exception {
	manac(10, 0, 20, 2, 8);
    }

    /*
     * 8 threads with many collisions
     */
    public void _test_a4_d0_l5_m10_t8() throws Exception {
	manac(4, 0, 5, 10, 8);
    }

    /*
     * more threads 
     */
    public void _test_amax_d0_l2_m5_t12() throws Exception {
	manac(maxAccounts, 0, 2, 1, 12);
    }

    /*
     * more threads again
     */
    public void _test_amax_d0_l1_m1_t30() throws Exception {
	manac(maxAccounts, 0, 2, 1, 12);
    }

    public static Test suite() {
	return new TestSuite(F_multi.class);
    }

    public static void main (String args[]) {
	String testtorun = null;
	// Get args
	for (int argn = 0; argn < args.length; argn++) {
	    String s_arg = args[argn];
	    Integer i_arg;
	    if (s_arg.equals("-n")) {
		testtorun = args[++argn];
	    }
	}
	if (testtorun == null) {
	    junit.textui.TestRunner.run(suite());
	} else {
	    junit.textui.TestRunner.run(new F_multi(testtorun));
	}
    }
}
