use of com.icodici.universa.HashId in project universa by UniversaBlockchain.
the class HashIdTest method init.
@Before
public void init() {
idA = new HashId(new byte[] { 1, 2, 3 });
idB = new HashId(new byte[] { 1, 2, 4 });
idA1 = new HashId(new byte[] { 1, 2, 3 });
}
use of com.icodici.universa.HashId in project universa by UniversaBlockchain.
the class PostgresLedgerTest method create.
@Test
public void create() throws Exception {
// System.out.println("" + ledger.getDb().getIntParam("version"));
HashId id = HashId.createRandom();
assertNull(ledger.getRecord(id));
StateRecord r = ledger.findOrCreate(id);
System.out.println(r);
System.out.println(ledger.countRecords());
}
use of com.icodici.universa.HashId in project universa by UniversaBlockchain.
the class PostgresLedgerTest method findOrCreateAndGet.
@Test
public void findOrCreateAndGet() throws Exception {
// Atomic new record creation
HashId id = HashId.createRandom();
StateRecord r = ledger.findOrCreate(id);
assertNotNull(r);
assertEquals(id, r.getId());
assertEquals(ItemState.PENDING, r.getState());
assertAlmostSame(ZonedDateTime.now(), r.getCreatedAt());
// returning existing record
StateRecord r1 = ledger.findOrCreate(id);
assertSameRecords(r, r1);
StateRecord r2 = ledger.getRecord(id);
assertSameRecords(r, r2);
StateRecord r3 = ledger.getRecord(HashId.createRandom());
assert (r3 == null);
}
use of com.icodici.universa.HashId in project universa by UniversaBlockchain.
the class PostgresLedgerTest method ledgerBenchmark.
// @Test
public void ledgerBenchmark() throws Exception {
ExecutorService es = Executors.newCachedThreadPool();
List<Future<?>> ff = new ArrayList<>();
int nMax = 32;
int nIds = 4000;
long t = StopWatch.measure(true, () -> {
for (int n = 0; n < nMax; n++) {
final int x = n;
ff.add(es.submit(() -> {
HashId[] ids = new HashId[nIds];
for (int i = 0; i < ids.length; i++) ids[i] = HashId.createRandom();
System.out.println(x);
StopWatch.measure(true, () -> {
for (HashId i : ids) {
try {
ledger.findOrCreate(i);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
});
System.out.println("end-" + x);
return null;
}));
}
ff.forEach(f -> {
try {
f.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
});
System.out.println("total");
});
System.out.println("TPS: " + (nMax * nIds * 1000 / t));
System.out.println("" + ledger.getDb().queryOne("SELECT count(*) from ledger"));
}
use of com.icodici.universa.HashId in project universa by UniversaBlockchain.
the class PostgresLedgerTest method recordExpiration.
@Test
public void recordExpiration() throws Exception {
// todo: expired can't be get - it should be dropped by the database
HashId hashId = HashId.createRandom();
StateRecord r = ledger.findOrCreate(hashId);
assertNotNull(r.getExpiresAt());
assert (r.getExpiresAt().isAfter(ZonedDateTime.now()));
long recordId = r.getRecordId();
ZonedDateTime inFuture = ZonedDateTime.now().plusHours(2);
r.setExpiresAt(inFuture);
StateRecord r1 = ledger.getRecord(hashId);
assertNotEquals(r1.getExpiresAt(), inFuture);
r.save();
r1 = ledger.getRecord(hashId);
assertAlmostSame(r.getExpiresAt(), r1.getExpiresAt());
r.setExpiresAt(ZonedDateTime.now().minusHours(1));
r.save();
r1 = ledger.getRecord(hashId);
assertNull(r1);
}
Aggregations