Search in sources :

Example 36 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class LimitHashMapTest method test1.

@Test
public void test1() throws IOException {
    CacheMap<NulsDigestData, Transaction> map = new CacheMap<>("a-test", 128, NulsDigestData.class, Transaction.class);
    long use = 0;
    List<NulsDigestData> hashList = new ArrayList<>();
    for (int i = 0; i < 200000; i++) {
        Transaction transaction = new TransferTransaction();
        transaction.setTime(System.currentTimeMillis());
        transaction.setHash(NulsDigestData.calcDigestData(transaction.serializeForHash()));
        hashList.add(transaction.getHash());
        long start = System.nanoTime();
        map.put(transaction.getHash(), transaction);
        use += (System.nanoTime() - start);
    }
    System.out.println("插入20万条累计用时:" + use + "纳秒");
    long start = System.currentTimeMillis();
    for (NulsDigestData key : hashList) {
        map.get(key);
    }
    System.out.println("查询200000次用时:" + (System.currentTimeMillis() - start) + "ms");
    start = System.currentTimeMillis();
    for (NulsDigestData key : hashList) {
        map.containsKey(key);
    }
    System.out.println("判断是否包含200000次用时:" + (System.currentTimeMillis() - start) + "ms");
    start = System.currentTimeMillis();
    for (NulsDigestData key : hashList) {
        map.remove(key);
    }
    System.out.println("删除200000次用时:" + (System.currentTimeMillis() - start) + "ms");
    assertTrue(true);
}
Also used : Transaction(io.nuls.kernel.model.Transaction) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.kernel.model.NulsDigestData) CacheMap(io.nuls.cache.CacheMap) TransferTransaction(io.nuls.protocol.model.tx.TransferTransaction) Test(org.junit.Test)

Example 37 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class LimitHashMapTest method testSet.

@Test
public void testSet() {
    List<NulsDigestData> list = new ArrayList<>();
    for (int i = 0; i < 1000000; i++) {
        list.add(NulsDigestData.calcDigestData((i + "").getBytes()));
    }
    Set<NulsDigestData> set = new HashSet<>();
    long start = System.nanoTime();
    for (NulsDigestData hash : list) {
        set.add(hash);
    }
    System.out.println("放入set中100万条用时:" + (System.nanoTime() - start) / 1000000 + "ms");
    Set<NulsDigestData> set2 = new HashSet<>();
    start = System.nanoTime();
    set2.addAll(set);
    System.out.println("addAll 100万条用时:" + (System.nanoTime() - start) / 1000000 + "ms");
    start = System.nanoTime();
    for (NulsDigestData hash : list) {
        set2.remove(hash);
    }
    System.out.println("remove100万条用时:" + (System.nanoTime() - start) / 1000000 + "ms");
    start = System.nanoTime();
    for (NulsDigestData hash : list) {
        set.contains(hash);
    }
    System.out.println("contains100万条用时:" + (System.nanoTime() - start) / 1000000 + "ms");
    start = System.nanoTime();
    set.clear();
    System.out.println("clear100万条用时:" + (System.nanoTime() - start) / 1000000 + "ms");
}
Also used : ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.kernel.model.NulsDigestData) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class TemporaryCacheManagerTest method cacheSmallBlock.

/**
 * 测试小区快的缓存处理流程:
 * 1. 先测试放入缓存,不出现异常视为成功
 * 2. 测试获取刚放入的小区快,获取的结果不能为空且和刚仿佛的是相同内容
 * 3. 测试删除之前放入的小区快,删除后再获取应该得到null
 * 4. 重新把小区快放回缓存中,调用清理方法,清理后缓存中应该没有任何小区块或者交易
 * test the cache processing process of the smallblock:
 * 1. The first test is put into the cache, and no exceptions are deemed to be successful.
 * 2. Test to get the newly inserted smallblock fast, the results can not be empty and the same content as if it is just as if.
 * 3. Before the test is deleted, the cells should be put into the smallblock quickly. After deleting, it should be null.
 * 4. Reattach the smallblock to the cache, call the cleaning method, and there should be no blocks or transactions in the cache.
 */
@Test
public void cacheSmallBlock() {
    SmallBlock smallBlock = new SmallBlock();
    BlockHeader header = new BlockHeader();
    NulsDigestData hash = NulsDigestData.calcDigestData("abcdefg".getBytes());
    header.setHash(hash);
    manager.cacheSmallBlock(smallBlock);
    assertTrue(true);
    this.getSmallBlock(hash, smallBlock);
    this.removeSmallBlock(hash);
    manager.cacheSmallBlock(smallBlock);
    this.clear();
}
Also used : SmallBlock(io.nuls.protocol.model.SmallBlock) NulsDigestData(io.nuls.kernel.model.NulsDigestData) BlockHeader(io.nuls.kernel.model.BlockHeader) Test(org.junit.Test)

Example 39 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class TxMemoryPool method addInFirst.

public boolean addInFirst(Transaction tx, boolean isOrphan) {
    try {
        if (tx == null) {
            return false;
        }
        // check Repeatability
        if (isOrphan) {
            NulsDigestData hash = tx.getHash();
            orphanContainer.put(hash, tx);
        } else {
            ((LinkedBlockingDeque) txQueue).addFirst(tx);
        }
        return true;
    } finally {
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Example 40 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class RoundManager method getDepositListMap.

private Map<NulsDigestData, List<Deposit>> getDepositListMap(long startBlockHeight) {
    List<Deposit> depositList = chain.getDepositList();
    Map<NulsDigestData, List<Deposit>> map = new HashMap<>();
    for (int i = depositList.size() - 1; i >= 0; i--) {
        Deposit deposit = depositList.get(i);
        if (deposit.getDelHeight() != -1L && deposit.getDelHeight() <= startBlockHeight) {
            continue;
        }
        if (deposit.getBlockHeight() > startBlockHeight || deposit.getBlockHeight() < 0L) {
            continue;
        }
        List<Deposit> list = map.get(deposit.getAgentHash());
        if (null == list) {
            list = new ArrayList<>();
            map.put(deposit.getAgentHash(), list);
        }
        list.add(deposit);
    }
    return map;
}
Also used : Deposit(io.nuls.consensus.poc.protocol.entity.Deposit) NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Aggregations

NulsDigestData (io.nuls.kernel.model.NulsDigestData)54 ArrayList (java.util.ArrayList)16 Transaction (io.nuls.kernel.model.Transaction)12 Test (org.junit.Test)12 Block (io.nuls.kernel.model.Block)9 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)8 NulsException (io.nuls.kernel.exception.NulsException)8 BlockHeader (io.nuls.kernel.model.BlockHeader)7 IOException (java.io.IOException)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)5 Result (io.nuls.kernel.model.Result)5 BaseTest (io.nuls.consensus.poc.storage.BaseTest)4 HashSet (java.util.HashSet)4 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)3 MicroKernelBootstrap (io.nuls.kernel.MicroKernelBootstrap)3 BlockSignature (io.nuls.kernel.script.BlockSignature)3 ValidateResult (io.nuls.kernel.validate.ValidateResult)3 Node (io.nuls.network.model.Node)3 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)3 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)2