/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.db.testing.base; import gnu.trove.list.array.TLongArrayList; import org.apache.commons.math3.stat.regression.SimpleRegression; import org.junit.Test; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.db.testing.cases.FreshDatabaseTest; import org.simantics.db.testing.common.Command; import org.simantics.db.testing.common.CommandSequenceEnvironment; import org.simantics.db.testing.common.CommandSpec; /** * * @author Antti Villberg * */ abstract public class CommandSequenceTest extends FreshDatabaseTest implements CommandSequenceEnvironment { private static final boolean TRACE = true; protected TLongArrayList executionTimes = new TLongArrayList(); protected double getSlowdown() { SimpleRegression regression = new SimpleRegression(); for(int i=0;i[] getFactories() { return null; } @Override public Session getSession() { return super.getSession(); } public int randomNatural() { return (int)(Math.random() * Integer.MAX_VALUE); } protected Command[] newSequence() throws Exception { int size = getSequenceSize(); CommandSpec[] classes = getFactories(); int index = 0; Command[] result = new Command[size]; double totalWeight = 0; for(CommandSpec p : classes) totalWeight += p.weight; double[] wts = new double[classes.length]; index=0; double previous = 0; for(CommandSpec p : classes) { double weight = p.weight/totalWeight; wts[index++] = previous + weight; previous += weight; } for(int i=0;i lastProgress) { System.err.println("[" + counter + "/" + sequence.length + "]: " + progress + "%"); lastProgress = progress; } } for(Command command : afterSequence(environment)) { command.run(environment); } analyse(environment); } public void invoke(CommandSequenceEnvironment environment, Command command) { try { command.run(environment); } catch (Throwable t) { if(!isAllowed(t)) { throw new AssertionError(t); } } } boolean isAllowed(Throwable t) { if(t instanceof AllowedThrowable) return true; if(t instanceof DatabaseException) { DatabaseException d = (DatabaseException)t; if(d.getCause() instanceof AllowedThrowable) return true; } return false; } }