/*
 * 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 org.objectweb.jonas.stests.util.JTestCase;


public abstract class A_manac extends JTestCase {

    static final int initialValue = 1000;
    public static boolean threadfail;

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

    public abstract String getManagerHomeName();
    public abstract Manager getManager();
 
   


    /**
     * Run a multithreaded client test
     * Each "transaction" uses 4 accounts.
     * @param accounts nb of accounts used to choose the 4 accounts
     * @param delay nb of seconds added inside the "transaction".
     * @param loops nb of loops done (each loop is a transaction)
     * @param amount amount withdrawn in the transaction
     * @param threads nb of threads executing a transaction concurrently.
     * @param cl checking level
     * @param tt transaction timeout
     */
    public void manac(int accounts, int delay, int loops, int amount, int threads, int cl, int tt) throws Exception {

        // Set the transaction timeout
        if (tt > 0) {
            stopTxAt(tt);
        }

        // Create and start all threads
        A_thread[] t_thr = new A_thread[threads];
        for (int i = 0; i < threads; i++) {
            t_thr[i] = new A_thread(getManagerHomeName(), i, ictx, accounts, delay, loops, amount, cl);
            t_thr[i].start();
        }

        // Wait end of all threads
        for (int p = 0; p < threads; p++) {
            t_thr[p].join();
        }

        // Check if all threads run ok
        if (threadfail) {
            fail("Error in a thread");
        }

        // Check Accounts after each test
        if (cl != 0 && ! getManager().checkAll()) {
            fail("bad accounts");
        }
    }


}
