public void setup() {
    ConcurrentTestRefreshWithOptimisticLocking.execute = true;
    try {
      getSession().getLog().write("WARNING, some tests may take 3 minutes or more");
      getSession().getLog().flush();
    } catch (java.io.IOException e) {
    }

    try {
      DatabaseLogin login = (DatabaseLogin) getSession().getLogin().clone();
      ConcurrentTestRefreshWithOptimisticLocking.server =
          new Server(login, numThreads, numThreads + 2);
      ConcurrentTestRefreshWithOptimisticLocking.server.serverSession.setSessionLog(
          getSession().getSessionLog());
      ConcurrentTestRefreshWithOptimisticLocking.server.login();
      ConcurrentTestRefreshWithOptimisticLocking.server.copyDescriptors(getSession());
      ClassDescriptor empDesc =
          this.server.serverSession.getClassDescriptor(DeadLockEmployee.class);
      this.oldVersionRefresh = empDesc.shouldOnlyRefreshCacheIfNewerVersion();
      empDesc.onlyRefreshCacheIfNewerVersion();

    } catch (ValidationException ex) {
      this.verify();
    }

    for (int count = 0; count < numThreads; ++count) {
      ConcurrentTestRefreshWithOptimisticLocking.threadList[count] =
          new Thread(new ConcurrentTestRefreshWithOptimisticLocking(false, count).runnable());
      ConcurrentTestRefreshWithOptimisticLocking.timeList[count] = System.currentTimeMillis();
    }
  }
 /** Log the results to the session's log (System.out). */
 public void dumpResults() {
   this.lastDumpTime = System.currentTimeMillis();
   StringWriter writer = new StringWriter();
   writer.write("\nPerformance Monitor:");
   writer.write(String.valueOf(this.lastDumpTime));
   writer.write("\nOperation\tValue (ns)\n");
   Set<String> operations = new TreeSet<String>(this.operationTimings.keySet());
   NumberFormat formater = NumberFormat.getInstance();
   for (String operation : operations) {
     Object value = this.operationTimings.get(operation);
     if (value == null) {
       value = Long.valueOf(0);
     }
     writer.write(operation);
     writer.write("\t");
     if (value instanceof Long) {
       writer.write(formater.format(value));
     } else {
       writer.write(value.toString());
     }
     writer.write("\n");
   }
   try {
     this.session.getLog().write(writer.toString());
     this.session.getLog().flush();
   } catch (IOException error) {
     // ignore
   }
 }
 /**
  * PUBLIC: Create a new profiler. The profiler can be registered with a session to log performance
  * information on queries.
  */
 public PerformanceMonitor() {
   this.operationTimings = new Hashtable();
   this.operationStartTimesByThread = new Hashtable();
   this.lastDumpTime = System.currentTimeMillis();
   this.dumpTime = 60000; // 1 minute
   this.profileWeight = SessionProfiler.ALL;
 }
 public void watchOtherThreads() {
   long startTime = System.currentTimeMillis();
   while (((System.currentTimeMillis() - startTime) < (runTime + 30000))
       && ConcurrentTestRefreshWithOptimisticLocking.execute) {
     for (int localIdex = 0; localIdex < numThreads; ++localIdex) {
       if ((System.currentTimeMillis()
               - ConcurrentTestRefreshWithOptimisticLocking.timeList[localIdex])
           > 30000) {
         // System.out.println(" Number: " + localIdex + " time: " + (System.currentTimeMillis() -
         // this.timeList[localIdex]));
         execute = false;
         break;
       }
     }
     try {
       Thread.sleep(30000);
     } catch (InterruptedException ex) {
       throw new TestProblemException("Test thread was interrupted.  Test failed to run properly");
     }
   }
 }
 public void executeUntilStopped() {
   Session session =
       ConcurrentTestRefreshWithOptimisticLocking.server.serverSession.acquireClientSession();
   DeadLockAddress address =
       (DeadLockAddress)
           session.readObject(
               org.eclipse.persistence.testing.tests.clientserver.DeadLockAddress.class);
   DeadLockEmployee employee = (DeadLockEmployee) session.readObject(DeadLockEmployee.class);
   ReadObjectQuery query;
   if ((this.index % 2) != 0) {
     query = new ReadObjectQuery(address);
     query.refreshIdentityMapResult();
     query.setCascadePolicy(DatabaseQuery.CascadeAllParts);
   } else {
     query = new ReadObjectQuery(employee);
     query.refreshIdentityMapResult();
     query.setCascadePolicy(DatabaseQuery.CascadeAllParts);
   }
   while (ConcurrentTestRefreshWithOptimisticLocking.execute) {
     ConcurrentTestRefreshWithOptimisticLocking.timeList[this.index] = System.currentTimeMillis();
     session.executeQuery(query);
   }
   // System.out.println("BeingShutDown");
 }
  public void populate(DatabaseSession session) {
    PopulationManager manager = PopulationManager.getDefaultManager();

    Cat cat = Cat.example1();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample1");

    Dog dog = Dog.example1();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample1");

    cat = Cat.example2();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample2");

    dog = Dog.example2();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample2");

    cat = Cat.example3();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample3");

    dog = Dog.example3();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample3");

    Company company = Company.example1();
    session.writeObject(company);
    manager.registerObject(company, "example1");

    manager.registerObject(((Vector) company.getVehicles().getValue()).firstElement(), "example1");

    company = Company.example2();
    session.writeObject(company);
    manager.registerObject(company, "example2");

    company = Company.example3();
    session.writeObject(company);
    manager.registerObject(company, "example3");

    Person person = Person.example1();
    session.writeObject(person);
    manager.registerObject(person, "example1");

    // populate the data for duplicate field testing
    session.writeObject(A_King2.exp1());
    session.writeObject(A_King2.exp2());
    session.writeObject(A_1_King2.exp3());
    session.writeObject(A_2_King2.exp4());
    session.writeObject(A_2_1_King2.exp5());

    UnitOfWork unitOfWork = session.acquireUnitOfWork();
    person = Person.example2();
    unitOfWork.registerObject(person);
    unitOfWork.commit();
    manager.registerObject(person, "example2");
    manager.registerObject(person.bestFriend, "example5");
    manager.registerObject(person.representitive, "example4");

    person = Person.example3();
    session.writeObject(person);
    manager.registerObject(person, "example3");

    Computer computer = Computer.example1();
    session.writeObject(computer);
    manager.registerObject(computer, "example1");

    computer = Computer.example2();
    session.writeObject(computer);
    manager.registerObject(computer, "example2");

    computer = Computer.example3();
    session.writeObject(computer);
    manager.registerObject(computer, "example3");

    computer = Computer.example4();
    session.writeObject(computer);
    manager.registerObject(computer, "example4");

    computer = Computer.example5();
    session.writeObject(computer);
    manager.registerObject(computer, "example5");

    JavaProgrammer JP = JavaProgrammer.example1();
    session.writeObject(JP);
    manager.registerObject(JP, "example1");

    JP = JavaProgrammer.example2();
    session.writeObject(JP);
    manager.registerObject(JP, "example2");

    // Added to test bug 3019934.
    unitOfWork = session.acquireUnitOfWork();
    Alligator alligator = new Alligator();
    alligator.setFavoriteSwamp("Florida");
    alligator.setLatestVictim(JavaProgrammer.steve());
    unitOfWork.registerObject(alligator);
    manager.registerObject(alligator, "example1");
    unitOfWork.commit();

    // Added to test bug 6111278

    unitOfWork = session.acquireUnitOfWork();
    Entomologist bugguy = new Entomologist();
    bugguy.setId((int) System.currentTimeMillis());
    bugguy.setName("Gary");
    bugguy = (Entomologist) unitOfWork.registerObject(bugguy);
    Insect insect = new GrassHopper();
    insect.setIn_numberOfLegs(4);
    insect.setEntomologist(bugguy);
    bugguy.getInsectCollection().add(insect);
    unitOfWork.commit();
  }
 /** Log the results after a set amount of time has passed. */
 public void checkDumpTime() {
   if ((System.currentTimeMillis() - this.lastDumpTime) > this.dumpTime) {
     dumpResults();
   }
 }