コード例 #1
0
 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);
     }
   }
 }
コード例 #2
0
 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();
   }
 }
コード例 #3
0
 /** 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;
 }
コード例 #4
0
 public void commit() throws Exception {
   txn.commit();
 }