Package org.objectweb.speedo.pobjects.basic

Examples of org.objectweb.speedo.pobjects.basic.BasicA


    public void testSimpleDelete() {
        final int NB_OBJ = 50;
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        for (int i = 0; i < NB_OBJ; i++) {
            pm.makePersistent(new BasicA("testSimpleDelete_" + i, i));
        }
        pm.currentTransaction().commit();
        pm.evictAll();
        pm.currentTransaction().begin();
        Query q = pm.newQuery(BasicA.class);
View Full Code Here


    logger.log(BasicLevel.INFO, "testLotOfQuery(" + withclose
        + ", pm:" + NB_PM + ", query: "+ NB_QUERY +") is running ...");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    for(int i=0; i<20; i++) {
      BasicA ba = new BasicA();
      ba.writeF1("testBillionQuery_" + i);
      pm.makePersistent(ba);
    }
    pm.currentTransaction().commit();
    pm.close();
    for(int i=0; i<NB_PM; i++) {
View Full Code Here

  public void testAccess(final int nbThread , final int[] actions) {
    final int initialValue = 0;
    rollbackExceptions.clear();
    errors.clear();
    Thread[] ts = new Thread[nbThread];
    BasicA ba = new BasicA();
    ba.writeF1("1");
    ba.writeF2(initialValue);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(ba);
    final BasicA a = ba;
    Object id = pm.getObjectId(ba);
    pm.currentTransaction().commit();
    pm.close();
    for (int i = 0; i < nbThread; i++) {
      final int _i = i;
      ts[i] = new Thread(
          new Runnable() {
            public void run() {
                int action = (_i % 2 == 0 ? W_ACTION : R_W_ACTION);
                for(int j=0; j<actions.length; j++) {
              PersistenceManager pm = pmf.getPersistenceManager();
              boolean rollback = false;
              try {
                pm.currentTransaction().begin();
                logger.log(BasicLevel.DEBUG, _i + "," + j + " begin tx");
                switch(actions[j]) {
                case W_ACTION:
                  a.incF2();
                  break;
                case R_W_ACTION:
                  a.writeF2(a.readF2() + 1);
                  break;
                case MIXED_ACTION:
                    if (action == W_ACTION) {
                        a.incF2();
                        action = R_W_ACTION;
                    } else if (action == R_W_ACTION) {
                        a.writeF2(a.readF2() + 1);
                        action = W_ACTION;
                    }
                  break;
                }
                pm.currentTransaction().commit();
View Full Code Here

 
  public void create(final int threadId) {
      again();
      PersistenceManager pm = pmf.getPersistenceManager();
      pm.currentTransaction().begin();
      BasicA po = new BasicA();
      pm.makePersistent(po);
      po.setUndeclaredField(pm.getObjectId(po).toString());
      pm.currentTransaction().commit();
      pm.close();
      try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
View Full Code Here

      }
  }
 
  public void delete(final int threadId) {
      again();
      BasicA po = null;
      synchronized (pos) {
          while(pos.size() == 0) {
              try {
                    pos.wait();
                } catch (InterruptedException e) {
                }
          }
          po = (BasicA) pos.remove(0);
      }
      if (po != null) {
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        po.writeF1();
        Object oid = pm.getObjectId(po);
        pm.deletePersistent(po);
        synchronized (removed) {
            removed.add(oid);
        }
View Full Code Here

        p.setProperty(SpeedoProperties.MAPPING_STRUCTURE, SpeedoProperties.MAPPING_STRUCTURE_DD);
        return p;
    }
    public void test2thread1PMNoTx() {
        final PersistenceManager pm = pmf.getPersistenceManager();
        BasicA ba = new BasicA();
        ba.writeF1("test2thread1PMNoTx.thread1");
        ba.writeF2(2);
        pm.makePersistent(ba);
        final Object oid = pm.getObjectId(ba);
        Thread t = new Thread(
                new Runnable() {
                    public void run() {
                        try {
                            BasicA _ba = ((BasicA) pm.getObjectById(oid, false));
                            _ba.readF1_F2();
                            _ba.writeF1("test2thread1PMNoTx.thread2");
                        } catch (Exception e) {
                            e.printStackTrace();
                            fail(e.getMessage());
                        }
                    }
View Full Code Here

    }


    public void test2thread1PMTx() {
        final PersistenceManager pm = pmf.getPersistenceManager();
        BasicA ba = new BasicA();
        ba.writeF1("test2thread1PM.thread1");
        ba.writeF2(1);
        pm.currentTransaction().begin();
        pm.makePersistent(ba);
        final Object oid = pm.getObjectId(ba);
        Thread t = new Thread(
                new Runnable() {
                    public void run() {
                        try {
                            BasicA _ba = ((BasicA) pm.getObjectById(oid, false));
                            _ba.readF1_F2();
                            _ba.writeF1("test2thread1PM.thread2");
                            _ba.writeF2(2);
                            pm.currentTransaction().commit();
                        } catch (Exception e) {
                            e.printStackTrace();
                            fail(e.getMessage());
                        }
View Full Code Here

        final PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        final Object[] oids = new Object[NB_OBJECT];
        final Semaphore[] s = new Semaphore[NB_OBJECT];
        for(int i=0; i<NB_OBJECT; i++) {
            BasicA ba = new BasicA();
            ba.writeF1("testManyThreadConcurrentData_" + i);
            ba.writeF2(i);
            pm.makePersistent(ba);
            oids[i] = pm.getObjectId(ba);
            s[i] = new Semaphore();
        }
        pm.currentTransaction().commit();
View Full Code Here

        }
    }

    private void execute() {
        //test concurrent loading in the same transaction
        BasicA ba = ((BasicA) pm.getObjectById(oids[NB_OBJECT-1], false));
        ba.readF1_F2();
       
        ba = ((BasicA) pm.getObjectById(oids[threadId], false));
        ba.writeF1(ba.readF1() + "modifiedBy" + threadId);
       
        for(int j=0; j<NB_MODIF; j++) {
            // Choose an object: alternativly on each side
            // of the threadId
            int id = j;
            if (j % 2 == 0) {
                id = Math.min(NB_OBJECT-1, threadId + j);
            } else {
                id = Math.max(0, threadId - j);
            }
            ba = ((BasicA) pm.getObjectById(oids[id], false));
            s[id].P();
            try {
                ba.writeF1(ba.readF1() + "modifiedBy" + threadId);
            } finally {
                s[id].V();
            }
        }
       
        for(int j=0; j<NB_QUERY; j++) {
            final int min = Math.max(0, threadId - (INTERVAL/2));
            final int max = Math.min(NB_OBJECT-1, threadId + (INTERVAL/2));
            Query q = pm.newQuery(BasicA.class);
            q.declareParameters("int pmin, int pmax");
            q.setFilter("(f2 >= pmin) && (f2 <= pmax)");
            Collection c = (Collection) q.execute(
                    new Integer(min), new Integer(max));
            Collection expected = new ArrayList();
            for(int id=min; id<=max; id++) {
                expected.add(new Integer(id));
            }
            st.getLogger().log(BasicLevel.DEBUG, "Thread " + threadId + " expect: " + expected);
            Collection found = new ArrayList();
            for (Iterator iter = c.iterator(); iter.hasNext();) {
                ba = (BasicA) iter.next();
                int f2 = ba.readF2();
                found.add(new Integer(f2));
            }
            q.closeAll();
            st.getLogger().log(BasicLevel.DEBUG, "Thread " + threadId + " found: " + found);
            st.assertSameCollection("Bad query result"
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.basic.BasicA

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.