use of com.iota.iri.model.Hash in project iri by iotaledger.
the class TransactionViewModelTest method updateHeightPrefilledSlotShouldFail.
@Test
public void updateHeightPrefilledSlotShouldFail() throws Exception {
int count = 4;
TransactionViewModel[] transactionViewModels = new TransactionViewModel[count];
Hash hash = getRandomTransactionHash();
for (int i = 0; ++i < count; ) {
transactionViewModels[i] = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hash, Hash.NULL_HASH), hash = getRandomTransactionHash());
transactionViewModels[i].store(tangle);
}
transactionViewModels[count - 1].updateHeights(tangle);
for (int i = count; i > 1; ) {
assertEquals(0, TransactionViewModel.fromHash(tangle, transactionViewModels[--i].getHash()).getHeight());
}
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class TransactionViewModelTest method testManyTXInDB.
// @Test
public void testManyTXInDB() throws Exception {
int i, j;
LinkedList<Hash> hashes = new LinkedList<>();
Hash hash;
hash = getRandomTransactionHash();
hashes.add(hash);
long start, diff, diffget;
long subSumDiff = 0, maxdiff = 0, sumdiff = 0;
int max = 990 * 1000;
int interval1 = 50;
int interval = interval1 * 10;
log.info("Starting Test. #TX: {}", TransactionViewModel.getNumberOfStoredTransactions(tangle));
new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(Hash.NULL_HASH, Hash.NULL_HASH), hash).store(tangle);
TransactionViewModel transactionViewModel;
boolean pop = false;
for (i = 0; i++ < max; ) {
hash = getRandomTransactionHash();
j = hashes.size();
transactionViewModel = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hashes.get(seed.nextInt(j)), hashes.get(seed.nextInt(j))), hash);
start = System.nanoTime();
transactionViewModel.store(tangle);
diff = System.nanoTime() - start;
subSumDiff += diff;
if (diff > maxdiff) {
maxdiff = diff;
}
hash = hashes.get(seed.nextInt(j));
start = System.nanoTime();
TransactionViewModel.fromHash(tangle, hash);
diffget = System.nanoTime() - start;
hashes.add(hash);
if (pop || i > 1000) {
hashes.removeFirst();
}
// log.info("{}", new String(new char[(int) ((diff/ 10000))]).replace('\0', '|'));
if (i % interval1 == 0) {
// log.info("{}", new String(new char[(int) (diff / 50000)]).replace('\0', '-'));
// log.info("{}", new String(new char[(int) ((subSumDiff / interval1 / 100000))]).replace('\0', '|'));
sumdiff += subSumDiff;
subSumDiff = 0;
}
if (i % interval == 0) {
log.info("Save time for {}: {} us.\tGet Time: {} us.\tMax time: {} us. Average: {}", i, (diff / 1000), diffget / 1000, (maxdiff / 1000), sumdiff / interval / 1000);
sumdiff = 0;
maxdiff = 0;
}
}
log.info("Done. #TX: {}", TransactionViewModel.getNumberOfStoredTransactions(tangle));
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class TransactionViewModelTest method updateHeightShouldWork.
@Test
public void updateHeightShouldWork() throws Exception {
int count = 4;
TransactionViewModel[] transactionViewModels = new TransactionViewModel[count];
Hash hash = getRandomTransactionHash();
transactionViewModels[0] = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(Hash.NULL_HASH, Hash.NULL_HASH), hash);
transactionViewModels[0].store(tangle);
for (int i = 0; ++i < count; ) {
transactionViewModels[i] = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hash, Hash.NULL_HASH), hash = getRandomTransactionHash());
transactionViewModels[i].store(tangle);
}
transactionViewModels[count - 1].updateHeights(tangle);
for (int i = count; i > 1; ) {
assertEquals(i, TransactionViewModel.fromHash(tangle, transactionViewModels[--i].getHash()).getHeight());
}
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class TipsViewModel method getRandomSolidTipHash.
public Hash getRandomSolidTipHash() {
synchronized (sync) {
int size = solidTips.size();
if (size == 0) {
return getRandomNonSolidTipHash();
}
int index = seed.nextInt(size);
Iterator<Hash> hashIterator;
hashIterator = solidTips.iterator();
Hash hash = null;
while (index-- >= 0 && hashIterator.hasNext()) {
hash = hashIterator.next();
}
return hash;
// return solidTips.size() != 0 ? solidTips.get(seed.nextInt(solidTips.size())) : getRandomNonSolidTipHash();
}
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class Node method weightQueueHashPair.
// TODO generalize these weightQueues
private static ConcurrentSkipListSet<Pair<Hash, Neighbor>> weightQueueHashPair() {
return new ConcurrentSkipListSet<Pair<Hash, Neighbor>>((transaction1, transaction2) -> {
Hash tx1 = transaction1.getLeft();
Hash tx2 = transaction2.getLeft();
for (int i = Hash.SIZE_IN_BYTES; i-- > 0; ) {
if (tx1.bytes()[i] != tx2.bytes()[i]) {
return tx2.bytes()[i] - tx1.bytes()[i];
}
}
return 0;
});
}
Aggregations