Package org.objectweb.speedo.stress

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

/**
* 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 javax.jdo.JDOFatalException;
import javax.jdo.PersistenceManager;

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

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

  public TestRelation1_1(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 * 2;
      beginTx(pm, task, threadId, txId);
      // Execute first transaction (makePersistent)
      A a1 = new A("a" + oid);
      A a2 = new A("a" + oid + 1);
      B b1 = new B("b" + oid);
      B b2 = new B("b" + oid + 1);
      pm.makePersistent(a1);
      pm.makePersistent(a2);
      pm.makePersistent(b1);
      pm.makePersistent(b2);
      commitTx(pm, task, threadId, txId);

      a1.setB(b1);
      assertTrue(b1.getA() == a1);
      a2.setB(b2);
      assertTrue(b2.getA() == a2);
      a1.setB(b2);
      assertTrue(b1.getA() == null);
      assertTrue(b2.getA() == a1);
      assertTrue(a2.getB() == null);
      b1.setA(a2);
      assertTrue(a2.getB() == b1);
      b1.setA(a1);
      assertTrue(a1.getB() == b1);
      assertTrue(b2.getA() == null);
      assertTrue(a2.getB() == null);

      // Delete persistent (speedoproxy)
      beginTx(pm, task, threadId, txId);
      pm.deletePersistent(a1);
      pm.deletePersistent(a2);
      pm.deletePersistent(b1);
      pm.deletePersistent(b2);
      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 testRelation1_1() {
    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_1 linked persistents objects using 1 thread.
   */
  public void testRelation1_1Th1Tx100() {
    if (!interactive) {
      perform(1, 100, 1000000, null);
    }
  }

  /**
   * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
   */
  public void testRelation1_1Th1Tx1000() {
    if (!interactive) {
      perform(1, 1000, 1000000, null);
    }
  }

  /**
   * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
   */
  public void testRelation1_1Th1Tx10000() {
    if (!interactive) {
      perform(1, 10000, 1000000, null);
    }
  }

  /**
   * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
   */
  public void testRelation1_1Th2Tx100() {
    if (!interactive) {
      perform(2, 100, 1000000, null);
    }
  }

  /**
   * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
   */
  public void testRelation1_1Th2Tx1000() {
    if (!interactive) {
      perform(2, 1000, 1000000, null);
    }
  }

  /**
   * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
   */
  public void testRelation1_1Th2Tx10000() {
    if (!interactive) {
      perform(2, 10000, 1000000, null);
    }
  }

  /**
   * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
   */
  public void testRelation1_1Th10Tx100() {
    if (!interactive) {
      perform(10, 100, 1000000, null);
    }
  }

  /**
   * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
   */
  public void testRelation1_1Th10Tx1000() {
    if (!interactive) {
      perform(10, 1000, 1000000, null);
    }
  }

  /**
   * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
   */
  public void testRelation1_1Th10Tx10000() {
    if (!interactive) {
      perform(10, 10000, 1000000, null);
    }
  }
}
TOP

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

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.