Package org.objectweb.speedo.stress

Source Code of org.objectweb.speedo.stress.TestRelationN_M

/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package org.objectweb.speedo.stress;

import org.objectweb.speedo.pobjects.relations.A;
import org.objectweb.speedo.pobjects.relations.B;

import javax.jdo.JDOFatalException;
import javax.jdo.PersistenceManager;

/**
* Stress the relation many-many implementation by Speedo.
*
* @author M. Guillemin
*/
public class TestRelationN_M extends StressHelper {

  public TestRelationN_M(String s) {
    super(s);
  }

  protected String[] getClassNamesToInit() {
    return new String[]{
      org.objectweb.speedo.pobjects.relations.A.class.getName(),
      org.objectweb.speedo.pobjects.relations.B.class.getName()
    };
  }

  protected String getLoggerName() {
    return STRESS_LOG_NAME + ".TestRelation1_1";
  }


  protected void perform(StressHelper.Task task,
                         int threadId,
                         int txId,
                         Object ctx,
                         StressHelper.PerformResult res) {
    PersistenceManager pm = getPM(task, threadId, txId);
    try {
      res.beginTest();
      int oid = txId * 3;
      beginTx(pm, task, threadId, txId);
      // Execute first transaction (makePersistent)
      A a1 = new A("a" + oid);
      A a2 = new A("a" + oid + 1);
      A a3 = new A("a" + oid + 2);
      B b1 = new B("b" + oid);
      B b2 = new B("b" + oid + 1);
      B b3 = new B("b" + oid + 2);
      pm.makePersistent(a1);
      pm.makePersistent(a2);
      pm.makePersistent(a3);
      pm.makePersistent(b1);
      pm.makePersistent(b2);
      pm.makePersistent(b3);
      Object oida1 = pm.getObjectId(a1);
      Object oida2 = pm.getObjectId(a2);
      Object oida3 = pm.getObjectId(a3);
      Object oidb1 = pm.getObjectId(b1);
      Object oidb2 = pm.getObjectId(b2);
      Object oidb3 = pm.getObjectId(b3);
      commitTx(pm, task, threadId, txId);
      closePM(pm, threadId, txId, task, res);

      pm = getPM(task, threadId, txId);
      a1.getBs().add(b1);
      assertTrue(b1.getAs().contains(a1));
      a1.getBs().add(b2);
      assertTrue(b2.getAs().contains(a1));

      a2.getBs().add(b1);
      assertTrue(b1.getAs().contains(a2));
      a2.getBs().add(b2);
      assertTrue(b2.getAs().contains(a2));
      a2.getBs().add(b3);
      assertTrue(b3.getAs().contains(a2));

      a3.getBs().add(b2);
      assertTrue(b2.getAs().contains(a3));
      a3.getBs().add(b3);
      assertTrue(b3.getAs().contains(a3));

      a1.getBs().add(b3);
      assertTrue(b3.getAs().contains(a1));

      a1.getBs().remove(b1);
      assertTrue(!b1.getAs().contains(a1));

      b2.getAs().remove(a2);
      assertTrue(!a2.getBs().contains(b2));

      a1.setBs(a2.getBs());
      // reload objects before testing effects of the above assignement
      closePM(pm, threadId, txId, task, res);

      pm = getPM(task, threadId, txId);
      assertTrue(a1.getBs().contains(b1));
      assertTrue(!a1.getBs().contains(b2));
      assertTrue(a1.getBs().contains(b3));

      assertTrue(a2.getBs().contains(b1));
      assertTrue(!a2.getBs().contains(b2));
      assertTrue(a2.getBs().contains(b3));

      assertTrue(!a3.getBs().contains(b1));
      assertTrue(a3.getBs().contains(b2));
      assertTrue(a3.getBs().contains(b3));

      assertTrue(b1.getAs().contains(a1));
      assertTrue(b1.getAs().contains(a2));
      assertTrue(!b1.getAs().contains(a3));

      assertTrue(!b2.getAs().contains(a1));
      assertTrue(!b2.getAs().contains(a2));
      assertTrue(b2.getAs().contains(a3));

      assertTrue(b3.getAs().contains(a1));
      assertTrue(b3.getAs().contains(a2));
      assertTrue(b3.getAs().contains(a3));
      closePM(pm, threadId, txId, task, res);
      pm = getPM(task, threadId, txId);
      beginTx(pm, task, threadId, txId);
      pm.deletePersistent(pm.getObjectById(oidb3, false));
      commitTx(pm, task, threadId, txId);
      closePM(pm, threadId, txId, task, res);
      pm = getPM(task, threadId, txId);

      assertTrue(a1.getBs().size() == 1);
      assertTrue(a1.getBs().contains(b1));
      assertTrue(a2.getBs().size() == 1);
      assertTrue(a2.getBs().contains(b1));
      assertTrue(a3.getBs().size() == 1);
      assertTrue(a3.getBs().contains(b2));

      assertTrue(b1.getAs().contains(a1));
      assertTrue(b1.getAs().contains(a2));
      assertTrue(!b1.getAs().contains(a3));
      assertTrue(!b2.getAs().contains(a1));
      assertTrue(!b2.getAs().contains(a2));
      assertTrue(b2.getAs().contains(a3));

      beginTx(pm, task, threadId, txId);
      pm.deletePersistent(pm.getObjectById(oida1, false));
      pm.deletePersistent(pm.getObjectById(oida2, false));
      pm.deletePersistent(pm.getObjectById(oida3, false));
      pm.deletePersistent(pm.getObjectById(oidb1, false));
      pm.deletePersistent(pm.getObjectById(oidb2, false));
      commitTx(pm, task, threadId, txId);

      res.endTest();
    } catch (JDOFatalException e) {
      rollbackOnException(pm, e, res, task, threadId, txId);
    } catch (Throwable e) {
      stopOnError(pm, e, res, task, threadId, txId);
    } finally {
      closePM(pm, threadId, txId, task, res);
    }
  }


  /**
   * Tests the read of a lot of persistent objects, with interactive setting
   * of test parameteres (see file userconf/project.properties).
   */
  public void testRelationN_M() {
    if (interactive) {
      perform(Integer.getInteger(THREAD, 1).intValue(),
              Integer.getInteger(TX, 1).intValue(),
              Integer.getInteger(TIMEOUT, 1).intValue(), null);
    }
  }

  /**
   * Tests 100 transactions where each of them stress 1 persistent object using 1 thread.
   */
  public void testRelationN_MTh1Tx100() {
    if (!interactive) {
      perform(1, 100, 1000000, null);
    }
  }

  /**
   * Tests 1000 transactions where each of them stress 1 persistent object using 1 thread.
   */
  public void testRelationN_MTh1Tx1000() {
    if (!interactive) {
      perform(1, 1000, 1000000, null);
    }
  }

  /**
   * Tests 10000 transactions where each of them stress 1 persistent object using 1 thread.
   */
  public void testRelationN_MTh1Tx10000() {
    if (!interactive) {
      perform(1, 10000, 1000000, null);
    }
  }

  /**
   * Tests 100 transactions where each of them stress 1 persistent object using 2 thread.
   */
  public void testRelationN_MTh2Tx100() {
    if (!interactive) {
      perform(2, 100, 1000000, null);
    }
  }

  /**
   * Tests 1000 transactions where each of them stress 1 persistent object using 2 thread.
   */
  public void testRelationN_MTh2Tx1000() {
    if (!interactive) {
      perform(2, 1000, 1000000, null);
    }
  }

  /**
   * Tests 10000 transactions where each of them stress 1 persistent object using 2 thread.
   */
  public void testRelationN_MTh2Tx10000() {
    if (!interactive) {
      perform(2, 10000, 1000000, null);
    }
  }

  /**
   * Tests 100 transactions where each of them stress 1 persistent object using 10 thread.
   */
  public void testRelationN_MTh10Tx100() {
    if (!interactive) {
      perform(10, 100, 1000000, null);
    }
  }

  /**
   * Tests 1000 transactions where each of them stress 1 persistent object using 10 thread.
   */
  public void testRelationN_MTh10Tx1000() {
    if (!interactive) {
      perform(10, 1000, 1000000, null);
    }
  }

  /**
   * Tests 10000 transactions where each of them stress 1 persistent object using 10 thread.
   */
  public void testRelationN_MTh10Tx10000() {
    if (!interactive) {
      perform(10, 10000, 1000000, null);
    }
  }
}
TOP

Related Classes of org.objectweb.speedo.stress.TestRelationN_M

TOP
Copyright © 2018 www.massapi.com. 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.