| 22 | import org.junit.Assert; |
| 23 | |
| 24 | public final class Tasks { |
| 25 | public static final boolean debugTradeSum = false; |
| 26 | private static final ConcurrentHashMap<String, LongConcurrentHashMap<LongAdder>> CounterKey = new ConcurrentHashMap<>(); |
| 27 | private static final ConcurrentHashMap<String, LongAdder> CounterRun = new ConcurrentHashMap<>(); |
| 28 | private static final ConcurrentHashMap<String, LongAdder> CounterSuccess = new ConcurrentHashMap<>(); |
| 29 | |
| 30 | static LongConcurrentHashMap<LongAdder> getKeyCounters(String name) { |
| 31 | return CounterKey.computeIfAbsent(name, __ -> new LongConcurrentHashMap<>()); |
| 32 | } |
| 33 | |
| 34 | static LongAdder getKeyCounter(String name, long key) { |
| 35 | return getKeyCounters(name).computeIfAbsent(key, __ -> new LongAdder()); |
| 36 | } |
| 37 | |
| 38 | static LongAdder getRunCounter(String name) { |
| 39 | return CounterRun.computeIfAbsent(name, __ -> new LongAdder()); |
| 40 | } |
| 41 | |
| 42 | static LongAdder getSuccessCounter(String name) { |
| 43 | return CounterSuccess.computeIfAbsent(name, __ -> new LongAdder()); |
| 44 | } |
| 45 | |
| 46 | static void clearAllCounters() { |
| 47 | CounterKey.clear(); |
| 48 | CounterRun.clear(); |
| 49 | CounterSuccess.clear(); |
| 50 | Table1Long2Add1.commitCount.reset(); |
| 51 | tflushInt1TradeConcurrentVerify.keys = null; |
| 52 | } |
| 53 | |
| 54 | // 所有以long为key的记录访问可以使用这个基类。 |
| 55 | // 其他类型的key需要再定义新的基类。 |
| 56 | static abstract class Task implements FuncLong { |
| 57 | final Set<Long> Keys = new HashSet<>(); |
| 58 | demo.App App; |
| 59 | |
| 60 | int getKeyNumber() { |
| 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | int getKeyBound() { |
| 65 | return Simulate.AccessKeyBound; |
| 66 | } |
| 67 | |
| 68 | boolean IsProcedure() { |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | App Run() throws ExecutionException, InterruptedException { |
| 73 | var app = Simulate.getInstance().randApp(); |
| 74 | app.Run(this); |
| 75 | return app; |
| 76 | } |
| 77 | |
| 78 | void prepare() throws Exception { |
| 79 | } |
| 80 | |
| 81 | abstract long process(); |