/*
 * 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;


/**
 * This TestCase is a set of multithreaded clients accessing concurrently
 * the set of accounts. For each test, an indicative Time (in millisec) is
 * given, to have a rough idea of the relative time of the test case.
 * (first value = CMP1, second value = CMP2)
 */
public abstract class A_multi extends A_manac {

    // default values
    int accounts = 20;          // 20 accounts (nb of pre-created accounts)
    int delay = 0;              // no delay added
    int loops = 1;              // 1 loop
    int amount = 10;            // withdraw value : 10 (initial value is 1000)
    int threads = 2;            // 2 threads
    int checklevel = 2;         // check accounts after every test
    int timeout = 12;           // 12 seconds

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

    public int getAccounts() {
        return accounts;
    }

    /*
     * Simplest test with 2 threads : 1 loop, 2 threads, no rollback, no delay
     * Time: 
     */
    public void testBasic() throws Exception {
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 2 threads with possible rollback
     * Time: 
     */
    public void testRb() throws Exception {
        int accounts = 6;
        int loops = 10;
        int amount = 400;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * add a delay
     * Time: 
     */
    public void testD3T3() throws Exception {
        int accounts = 4;
        int delay = 3;
        int loops = 6;
        int threads = 3;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 4 threads 
     * Time: 
     */
    public void testT4() throws Exception {
        int loops = 12;
        int threads = 4;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 6 threads 
     * Time: 3,449 20,143 (or possible failure)
     */
    public void testT6() throws Exception {
        int loops = 8;
        int threads = 6;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 6 threads with collisions
     * Time: 27,967 52,204
     */
    public void testCollT6() throws Exception {
        int accounts = 4;
        int threads = 6;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 8 threads
     * Time: 73,842 failure
     */
    public void testT8() throws Exception {
        int loops = 6;
        int threads = 8;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 8 threads with many collisions
     * Time: 42,465 42,846
     */
    public void testCollT8() throws Exception {
        int accounts = 4;
        int threads = 8;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 16 threads
     * Time: 33,22 failure
     */
    public void testT16() throws Exception {
        int threads = 16;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }


    /*
     * more threads again
     * failure failure
     */
    public void testT30() throws Exception {
        int threads = 30;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }


    /*
     * 4 threads and possible create
     * Time: 3,706 3,227
     */
    public void testCreateT4() throws Exception {
        int accounts = 200;
        int loops = 12;
        int threads = 4;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 2 threads with possible rollback and create
     * Time: 3,601 7,146
     */
    public void testCreateRbT2() throws Exception {
        int accounts = 100;
        int loops = 10;
        int amount = 444;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 4 threads with delay and possible create
     * Time: 
     */
    public void testCreateD2T4() throws Exception {
        int accounts = 200;
        int delay = 2;
        int threads = 4;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 6 threads and possible create
     * Time: 
     */
    public void testCreateT6() throws Exception {
        int accounts = 400;
        int loops = 8;
        int threads = 6;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 8 threads and possible create
     * Time: 
     */
    public void testCreateT8() throws Exception {
        int accounts = 400;
        int loops = 6;
        int threads = 8;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 16 threads and possible create
     * Time: 5,381 15,261
     */
    public void testCreateT16() throws Exception {
        int accounts = 800;
        int threads = 16;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * 16 threads more loops
     * Time: 14,431 14,239
     */
    public void testCreateD1T16() throws Exception {
        int accounts = 300;
        int delay = 1;
        int threads = 16;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

    /*
     * Test many create in parallell
     */
    public void testConcurrentCreate() throws Exception {
        int accounts = 40;
        int threads = 30;
        int loops = 1;
        int timeout = 18;
        manac(accounts, delay, loops, amount, threads, checklevel, timeout);
    }

}
