Search in sources :

Example 16 with StaticGasProvider

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);
    }
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) RateLimiter(com.google.common.util.concurrent.RateLimiter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Random(java.util.Random) BigInteger(java.math.BigInteger) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Aggregations

StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)16 BigInteger (java.math.BigInteger)10 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)6 ContractGasProvider (org.fisco.bcos.web3j.tx.gas.ContractGasProvider)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Resource (org.springframework.core.io.Resource)6 Service (org.fisco.bcos.channel.client.Service)5 Credentials (org.fisco.bcos.web3j.crypto.Credentials)5 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)5 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 Web3j (org.fisco.bcos.web3j.protocol.Web3j)4 ApplicationContext (org.springframework.context.ApplicationContext)4 Random (java.util.Random)3 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)3 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)3 RateLimiter (com.google.common.util.concurrent.RateLimiter)2 Date (java.util.Date)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2