use of org.fisco.bcos.web3j.tx.gas.StaticGasProvider in project web3sdk by FISCO-BCOS.
the class PerformanceDTTest method userTransferRevertTest.
public void userTransferRevertTest(BigInteger count, BigInteger qps, BigInteger deci, BigInteger queryAccountQPS) {
try {
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(200);
threadPool.setMaxPoolSize(500);
threadPool.setQueueCapacity(count.intValue());
threadPool.initialize();
RateLimiter limiter = RateLimiter.create(qps.intValue());
Integer area = count.intValue() / 10;
parallelokAddr = dagUserMgr.getContractAddr();
parallelok = ParallelOk.load(parallelokAddr, web3, credentials, new StaticGasProvider(new BigInteger("30000000"), new BigInteger("30000000")));
System.out.println("ParallelOk address: " + parallelokAddr);
// query all account balance info
List<DagTransferUser> allUser = dagUserMgr.getUserList();
for (int i = 0; i < allUser.size(); ++i) {
BigInteger result = parallelok.balanceOf(allUser.get(i).getUser()).send();
allUser.get(i).setAmount(result);
logger.debug(" query user " + allUser.get(i).getUser() + " amount " + result);
}
System.out.println("Start UserTransferRevert test...");
System.out.println("===================================================================");
long startTime = System.currentTimeMillis();
this.collector.setStartTimestamp(startTime);
for (Integer i = 0; i < 2 * count.intValue(); i += 2) {
final int index = i;
threadPool.execute(new Runnable() {
@Override
public void run() {
boolean success = false;
while (!success) {
limiter.acquire();
DagTransferUser from = dagUserMgr.getFrom(index);
DagTransferUser to = dagUserMgr.getNext(index);
Random random = new Random();
int value = random.nextInt(101);
int prob = random.nextInt(10);
if (prob < deci.intValue()) {
value += 101;
}
BigInteger amount = BigInteger.valueOf(value);
PerformanceDTCallback callback = new PerformanceDTCallback();
callback.setCallBackType("transferRevert");
callback.setCollector(collector);
callback.setDagUserMgr(getDagUserMgr());
callback.setFromUser(from);
callback.setToUser(to);
callback.setAmount(amount);
String info = "[RevertTest-SendTx]" + "\t[From]=" + from.getUser() + "\t[FromBalance]=" + from.getAmount() + "\t[To]=" + to.getUser() + "\t[ToBalance]=" + to.getAmount() + "\t[Amount]=" + amount;
System.out.println(info);
try {
callback.recordStartTime();
parallelok.transferWithRevert(from.getUser(), to.getUser(), amount, callback);
success = true;
} catch (Exception e) {
success = false;
continue;
}
}
}
});
}
// end or not
while (!collector.isEnd()) {
Thread.sleep(3000);
logger.info(" received: {}, total: {}", collector.getReceived().intValue(), collector.getTotal());
}
veryTransferData(threadPool, queryAccountQPS);
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
Aggregations