writeThreads[t] = new Thread(new Runnable() {
@Override
public void run() {
for (int r = 0; r < rounds; r++) {
TitanTransaction tx = graph.newTransaction();
TitanVertex previous = null;
for (int c = 0; c < commitSize; c++) {
TitanVertex v = tx.addVertex();
long uid = uidCounter.incrementAndGet();
v.setProperty("uid", uid);
v.setProperty("name", "user" + uid);
if (previous != null) {
v.addEdge("friend", previous).setProperty("time", Math.abs(random.nextInt()));
}
previous = v;
}
tx.commit();
}
}
});
writeThreads[t].start();
}
for (int t = 0; t < writeThreads.length; t++) {
writeThreads[t].join();
}
System.out.println("Write time for " + (rounds * commitSize * writeThreads.length) + " vertices & edges: " + (System.currentTimeMillis() - start));
final int maxUID = uidCounter.get();
final int trials = 1000;
final String fixedName = "john";
Thread[] readThreads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
start = System.currentTimeMillis();
for (int t = 0; t < readThreads.length; t++) {
readThreads[t] = new Thread(new Runnable() {
@Override
public void run() {
TitanTransaction tx = graph.newTransaction();
long ruid = random.nextInt(maxUID) + 1;
tx.getVertex("uid", ruid).setProperty("name", fixedName);
for (int t = 1; t <= trials; t++) {
TitanVertex v = tx.getVertex("uid", random.nextInt(maxUID) + 1);
assertEquals(2, Iterables.size(v.getProperties()));
int count = 0;
for (TitanEdge e : v.getEdges()) {
count++;
assertTrue(((Number) e.getProperty("time")).longValue() >= 0);
}
assertTrue(count <= 2);
// if (t%(trials/10)==0) System.out.println(t);