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);
}
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");
}
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();
}
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 {
}
}
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;
}
Aggregations