/** * Initialize the workload. Called once, in the main client thread, before any operations are * started. * * @throws IOException * @throws ClassNotFoundException */ public void init(Props props) throws IOException { CmdProvider cmdProvider; int readPercent = props.getInt(Benchmark.SELECT, 0); int writePercent = props.getInt(Benchmark.INSERT, 0); double readProportion = (double) readPercent / (double) 100; double writeProportion = (double) writePercent / (double) 100; if (readProportion + writeProportion > 0) { double sum = readProportion + writeProportion; readProportion = readProportion / sum; writeProportion = writeProportion / sum; } if (readProportion > 0) { cmdProvider = new QueryProvider(props); operationChooser.addValue(readProportion, cmdProvider.getName()); operations.put(cmdProvider.getName(), cmdProvider); } if (writeProportion > 0) { cmdProvider = new InsertProvider(props); operationChooser.addValue(writeProportion, cmdProvider.getName()); operations.put(cmdProvider.getName(), cmdProvider); } if (props.containsKey(Benchmark.RECORD_FILE)) { String cmd = props.getString(Benchmark.CMD_PROVIDER, ""); if (StringUtils.startsWith(cmd, "ctu_minisearch")) { cmdProvider = new CtuMiniSearchProvider(props); } else { cmdProvider = new SqlFileProvider(props); } operationChooser.addValue(1.0, cmdProvider.getName()); operations.put(cmdProvider.getName(), cmdProvider); } }
public boolean doTransaction(ClientWrapper db) { String op = operationChooser.nextString(); boolean result = false; for (Entry<String, CmdProvider> entry : operations.entrySet()) { if (StringUtils.equals(entry.getKey(), op)) { result = db.execute(entry.getValue()); break; } } return result; }