public void run() {
   try {
     txnStart = System.currentTimeMillis();
     createTxn();
     for (int i = 0; i < operations; i++) {
       if (i % 1000 == 0) {
         System.err.println(this + ": Operation " + i);
       }
       while (true) {
         try {
           op(i);
           break;
         } catch (TransactionAbortedException e) {
           if (logger.isLoggable(Level.FINE)) {
             logger.log(Level.FINE, "{0}: {1}", this, e);
           }
           aborts++;
           createTxn();
         }
       }
     }
     txn.abort(null);
     threadDone(aborts, maxTxnTime, maxTxnTimeOps);
   } catch (Throwable t) {
     try {
       txn.abort(null);
     } catch (RuntimeException e) {
     }
     threadFailed(t);
   }
 }
Esempio n. 2
0
 public void abort(Throwable cause) {
   if (txn.getState() == DummyTransaction.State.ACTIVE) {
     txn.abort(cause);
   } else {
     // TODO: Maybe chaeck the exception that caused the
     // abort in order to throw an exception with the right
     // retry status.
     throw new TransactionNotActiveException("Transaction is not active");
   }
 }
 public void testConcurrency() throws Throwable {
   DummyComponentRegistry componentRegistry = new DummyComponentRegistry();
   service = getDataService(props, componentRegistry);
   if (service instanceof ProfileProducer) {
     DummyProfileCoordinator.startProfiling(((ProfileProducer) service));
   }
   DummyTransaction txn = new DummyTransaction();
   txnProxy.setCurrentTransaction(txn);
   service.configure(componentRegistry, txnProxy);
   componentRegistry.setComponent(DataManager.class, service);
   componentRegistry.registerAppContext();
   txn.commit();
   int perThread = objects + objectsBuffer;
   /* Create objects */
   for (int t = 0; t < maxThreads; t++) {
     long startTime = System.currentTimeMillis();
     txn = new DummyTransaction();
     txnProxy.setCurrentTransaction(txn);
     int start = t * perThread;
     BigInteger block = null;
     for (int i = 0; i < perThread; i++) {
       if (startTime + 100 < System.currentTimeMillis()) {
         txn.commit();
         txn = new DummyTransaction();
         txnProxy.setCurrentTransaction(txn);
         if (i > 0) {
           service.getBinding(getObjectName(start), ModifiableObject.class);
         }
       }
       ModifiableObject object = new ModifiableObject();
       if (i == 0) {
         service.manageInNewArea(object);
       }
       service.setBinding(getObjectName(start + i), object);
       BigInteger oidBlock = service.createReference(object).getId().shiftRight(32);
       if (block == null || !block.equals(oidBlock)) {
         block = oidBlock;
         System.err.println("Thread " + t + ": init block " + block);
       }
     }
     txn.commit();
   }
   /* Warm up */
   if (repeat != 1) {
     System.err.println("Warmup:");
     runOperations(1);
   }
   /* Test */
   for (int t = threads; t <= maxThreads; t++) {
     System.err.println("Threads: " + t);
     for (int r = 0; r < repeat; r++) {
       runOperations(t);
     }
   }
 }
 private void op(int i) throws Exception {
   if (random.nextInt(5) == 0) {
     DummyTransaction t = txn;
     txn = null;
     t.commit();
     long time = System.currentTimeMillis() - txnStart;
     if (time > maxTxnTime) {
       maxTxnTime = time;
       maxTxnTimeOps = txnOps;
     }
     txnStart = System.currentTimeMillis();
     txnOps = 0;
     createTxn();
   }
   txnOps++;
   int start = id * (objects + objectsBuffer);
   String name = getObjectName(start + random.nextInt(objects));
   switch (random.nextInt(whichOperations.value)) {
     case 0:
       /* Get binding */
       service.getBinding(name, Object.class);
       break;
     case 1:
       /* Set bindings */
       ModifiableObject obj = service.getBinding(name, ModifiableObject.class);
       String name2 = getObjectName(start + random.nextInt(objects));
       ModifiableObject obj2 = service.getBinding(name2, ModifiableObject.class);
       service.setBinding(name, obj2);
       service.setBinding(name2, obj);
       break;
     case 2:
       /* Modify object */
       service.getBinding(name, ModifiableObject.class).incrementNumber(service);
       break;
     case 3:
       /* Create object */
       /*
        * Get the binding first, so the new object is created with
        * proper locality.
        */
       ModifiableObject object = service.getBinding(name, ModifiableObject.class);
       service.removeObject(object);
       object = new ModifiableObject();
       service.setBinding(name, object);
       BigInteger oidBlock = service.createReference(object).getId().shiftRight(32);
       if (block == null || !block.equals(oidBlock)) {
         block = oidBlock;
         System.err.println("Thread " + id + ": create block " + block);
       }
       break;
     default:
       throw new AssertionError();
   }
 }
Esempio n. 5
0
 public Transaction getTransaction() {
   if (txn.getState() == DummyTransaction.State.ACTIVE) {
     return txn;
   } else {
     throw new TransactionNotActiveException("Transaction is not active");
   }
 }
 /** Stores fields, if they are not null, into bindings and commits the current transaction. */
 private void endTransaction() throws Exception {
   if (set != null) {
     try {
       dataService.setBinding("set", set);
     } catch (ObjectNotFoundException e) {
     }
   }
   if (one != null) {
     try {
       dataService.setBinding("one", one);
     } catch (ObjectNotFoundException e) {
     }
   }
   txn.commit();
   txn = null;
 }
 /** Teardown. */
 @After
 public void tearDown() {
   if (txn != null) {
     txn.abort(null);
   }
 }
Esempio n. 8
0
 public void commit() throws Exception {
   txn.commit();
 }