/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* 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 of the License, or (at your option) 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
*/
package org.objectweb.speedo.stress;
import java.util.ArrayList;
import java.util.List;
import javax.jdo.JDOFatalException;
import javax.jdo.PersistenceManager;
import junit.framework.Assert;
import org.objectweb.speedo.Alea;
import org.objectweb.speedo.pobjects.collection.AllCollection;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* Stress the collection access function of Speedo.
*
* @author M.Guillemin
*/
public class TestCollectionConcurrency extends AllCollectionHelper {
public TestCollectionConcurrency(String s) {
super(s);
logger.log(BasicLevel.INFO, "TestCollectionConcurrency");
}
protected String[] getClassNamesToInit() {
return new String[]{AllCollection.class.getName()};
}
protected String getLoggerName() {
return STRESS_LOG_NAME + ".TestCollectionConcurrency";
}
protected void perform(Task task, int threadId, int txId, Object ctx, PerformResult res) {
long _oids = (txId * 6);
ACCtx acctx = (ACCtx) ctx;
PersistenceManager pm = getPM(task, threadId,txId);
try {
res.beginTest();
long[] reverse = new long[]{_oids + 5, _oids + 4, _oids + 3, _oids + 2, _oids + 1, _oids};
// Reverse a persistent Collections at random
int oid = Alea.rand(0, acctx.dbSize - 1);
beginTx(pm, task, threadId, txId);
AllCollection ac = (AllCollection) pm.getObjectById(acctx.oids[oid], false);
// Reverse the data
logger.log(BasicLevel.DEBUG, "reverse data of "+ac.getId());
ac.setLongs(reverse);
ac.setRefs(new Object[]{ac});
// Verify result
List expectedLong = new ArrayList(reverse.length);
for (int i = 0; i < reverse.length; i++) {
expectedLong.add(new Long(reverse[i]));
}
List expectedRef = new ArrayList(1);
expectedRef.add(ac);
//Collection
Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long());
Assert.assertNotNull("The collection of reference is null", ac.getCol_ref());
assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref());
//HashSet
Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long());
assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long());
Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref());
assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref());
//List
Assert.assertNotNull("The list of Long is null", ac.getList_Long());
assertSameList("The list of Long", expectedLong, ac.getList_Long());
Assert.assertNotNull("The list of reference is null", ac.getList_ref());
assertSameList("The list of reference", expectedRef, ac.getList_ref());
//Set
Assert.assertNotNull("The set of Long is null", ac.getSet_Long());
assertSameCollection("The set of Long", expectedLong, ac.getSet_Long());
Assert.assertNotNull("The set of reference is null", ac.getSet_ref());
assertSameCollection("The set of ref", expectedRef, ac.getSet_ref());
commitTx(pm, task, threadId, txId);
res.endTest();
} catch (JDOFatalException e) {
rollbackOnException(pm, e, res, task, threadId, txId);
} catch (Throwable e) {
stopOnError(pm, e, res, task, threadId, txId);
} finally {
closePM(pm, threadId, txId, task, res);
}
}
/**
* Methode d'aiguillage
*/
private void perform(
int nbThread,
int dbSize,
int nbTx,
int threadTimeout) {
perform(nbThread, nbTx, threadTimeout, new ACCtx(dbSize));
}
/**
* Tests the modification of a lot of persistent Collection objects, with interactive
* setting of test parameteres (see file userconf/project.properties).
*/
public void testInteractive (){
if (interactive) {
logger.log(BasicLevel.INFO, "testInteractive");
perform(Integer.getInteger(THREAD, 1).intValue(),
Integer.getInteger(TX, 9).intValue(),
Integer.getInteger(TIMEOUT, 200000).intValue(),
new ACCtx(Integer.getInteger(DBSIZE, 1000).intValue())
);
} else {
logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
}
}
/**
* Tests 100 transactions which stress collections using 1 thread.
*/
public void testCollectionConcurrencyTh1Tx100() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx100");
perform(1, 10000, 100, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx100");
}
}
/**
* Tests 1.000 transactions which stress collections using 1 thread.
*/
public void testCollectionConcurrencyTh1Tx1000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx1000");
perform(1, 10000, 1000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx1000");
}
}
/**
* Tests 10.000 transactions which stress collections using 1 thread.
*/
public void testCollectionConcurrencyTh1Tx10000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx10000");
perform(1, 10000, 10000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx10000");
}
}
/**
* Tests 100.000 transactions which stress collections using 1 thread.
*/
public void _testCollectionConcurrencyTh1Tx100000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx100000");
perform(1, 10000, 100000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx100000");
}
}
/**
* Tests 100 transactions which stress collections using 2 thread.
*/
public void testCollectionConcurrencyTh2Tx100() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx100");
perform(2, 10000, 100, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx100");
}
}
/**
* Tests 1000 transactions which stress collections using 2 thread.
*/
public void testCollectionConcurrencyTh2Tx1000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx1000");
perform(2, 10000, 1000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx1000");
}
}
/**
* Tests 10.000 transactions which stress collections using 2 thread.
*/
public void testCollectionConcurrencyTh2Tx10000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx10000");
perform(2, 10000, 10000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx10000");
}
}
/**
* Tests 100.000 transactions which stress collections using 2 thread.
*/
public void _testCollectionConcurrencyTh2Tx100000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx100000");
perform(2, 10000, 100000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx100000");
}
}
/**
* Tests 1000 transactions which stress collections using 10 thread.
*/
public void testCollectionConcurrencyTh10Tx1000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx1000");
perform(10, 10000, 1000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx1000");
}
}
/**
* Tests 10.000 transactions which stress collections using 10 thread.
*/
public void testCollectionConcurrencyTh10Tx10000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx10000");
perform(10, 10000, 10000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx10000");
}
}
/**
* Tests 100.000 transactions which stress collections using 10 thread.
*/
public void _testCollectionConcurrencyTh10Tx100000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx100000");
perform(10, 10000, 100000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx100000");
}
}
/**
* Tests 100 transactions which stress collections using 100 thread.
*/
public void testCollectionConcurrencyTh100Tx100() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh100Tx100");
perform(100, 10000, 100, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh100Tx100");
}
}
/**
* Tests 1000 transactions which stress collections using 1000 thread.
*/
public void testCollectionConcurrencyTh1000Tx1000() {
if (!interactive) {
logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1000Tx1000");
perform(1000, 10000, 1000, 1000000);
} else {
logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1000Tx1000");
}
}
}