public T doWork(T context, int niters, Result<T> opts) { opts.setErrorCount(0); ActionRecord record = new ActionRecord(); ActionRecord logRecord = new ActionRecord(); final int transactionSize = ThreadLocalRandom.current().nextInt(this.maxTransactionSize) + this.minTransactionSize; List<String> keysToUse = keys.getRandomKeyList(transactionSize, true); // If this is a logger if (writeToLogs > 0 && ThreadLocalRandom.current().nextInt(1000) < 1) { System.out.println("Log Reader"); record = machine.readLog(3, millisBetweenActions); workTimeMillis = System.currentTimeMillis(); return null; } if (keysToUse.size() < 2) { System.out.println("whoa there..."); } // Get Random number to assign task final int rand1 = ThreadLocalRandom.current().nextInt(1000); if (rand1 < chanceOfRead) { // Reader record = machine.read(keysToUse, millisBetweenActions); } else if (rand1 < chanceOfWrite) { // Writer record = machine.update(keysToUse, millisBetweenActions); } else if (rand1 < chanceOfReadModifyWrite) { // Reader + Writer record = machine.readModifyWrite(keysToUse, millisBetweenActions); } else if (rand1 < chanceOfBalanceTransfer) { record = machine.balanceTransfer(keysToUse.get(0), keysToUse.get(1), millisBetweenActions); } else if (rand1 < chanceOfIncrementalUpdate) { record = machine.incrementalUpdate(keysToUse, millisBetweenActions); } // Write the logs (if there are any to write) if (writeToLogs > 0) logRecord = machine.writeLog(writeToLogs, millisBetweenActions); // Check for success if (record == null || !record.isSuccess() || (writeToLogs > 0 && (logRecord == null || !logRecord.isSuccess()))) { opts.incrementErrorCount(); } workTimeMillis = System.currentTimeMillis(); return null; }