Пример #1
0
  public void testMultipleDetachCopyAndFetchPlanModification() {
    try {
      Properties multiProps = new Properties();
      multiProps.setProperty("datanucleus.Multithreaded", "true");
      pmf = TestHelper.getPMF(1, multiProps);

      int THREAD_SIZE = 1000;
      Thread[] threads = new Thread[THREAD_SIZE];
      Runnable[] runner = new Runnable[THREAD_SIZE];

      PersistenceManager pm = pmf.getPersistenceManager();
      pm.currentTransaction().begin();
      Employee woody =
          new Employee(
              1, "Woody", "Woodpecker", "*****@*****.**", 13, "serial 1", new Integer(10));
      Manager bart = new Manager(2, "Bart", "Simpson", "*****@*****.**", 2, "serial 2");
      woody.setManager(bart);
      pm.makePersistent(woody);
      pm.currentTransaction().commit();

      pm.currentTransaction().begin();
      try {
        for (int i = 0; i < THREAD_SIZE; i++) {
          if (i % 2 == 0) {
            runner[i] = new MultithreadDetachRunner(pm, woody);
          } else {
            runner[i] = new MultithreadFetchPlanRunner(pm);
          }
          threads[i] = new Thread(runner[i]);
          threads[i].start();
        }
        for (int i = 0; i < THREAD_SIZE; i++) {
          threads[i].join();

          Exception e = null;
          if (runner[i] instanceof MultithreadDetachRunner) {
            e = ((MultithreadDetachRunner) runner[i]).getException();
          } else if (runner[i] instanceof MultithreadFetchPlanRunner) {
            e = ((MultithreadFetchPlanRunner) runner[i]).getException();
          }
          if (e != null) {
            LOG.error("Exception during test", e);
            fail("Exception thrown during test : " + e);
          }
        }
      } catch (Exception e) {
        fail(e.getMessage());
      } finally {
        if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
        }
        pm.close();
      }
    } finally {
      CompanyHelper.clearCompanyData(pmf);
    }
  }
Пример #2
0
  /** Test changing the state */
  public void testMultipleNonTransitionWrite() {
    try {
      Properties multiProps = new Properties();
      multiProps.setProperty("datanucleus.Multithreaded", "true");
      pmf = TestHelper.getPMF(1, multiProps);

      int THREAD_SIZE = 1000;
      Thread[] threads = new Thread[THREAD_SIZE];

      PersistenceManager pm = pmf.getPersistenceManager();
      pm.currentTransaction().begin();
      final Employee woody =
          new Employee(
              1, "Woody", "Woodpecker", "*****@*****.**", 13, "serial 1", new Integer(10));
      Manager bart = new Manager(2, "Bart", "Simpson", "*****@*****.**", 2, "serial 2");
      final Manager boss = new Manager(3, "Boss", "WakesUp", "*****@*****.**", 4, "serial 3");
      woody.setManager(bart);
      pm.makePersistent(woody);
      pm.currentTransaction().commit();
      pm.currentTransaction().setNontransactionalWrite(true);
      try {
        for (int i = 0; i < THREAD_SIZE; i++) {
          threads[i] =
              new Thread(
                  new Runnable() {
                    public void run() {
                      woody.setLastName("name");
                      woody.setManager(boss);
                    }
                  });
        }
        for (int i = 0; i < THREAD_SIZE; i++) {
          threads[i].start();
        }
        for (int i = 0; i < THREAD_SIZE; i++) {
          try {
            threads[i].join();
          } catch (InterruptedException e) {
            fail(e.getMessage());
          }
        }
      } finally {
        if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
        }
        pm.close();
      }
    } finally {
      CompanyHelper.clearCompanyData(pmf);
    }
  }