protected void verify() { Session session = getSession(); // Read the object from the database Employee databaseEmployee = (Employee) session.readObject(Employee.class, getSearchExpression()); // If the employee object IS NOT in the database then there is a problem. if (databaseEmployee == null) { throw new TestErrorException( "Employee object should not have been deleted after transaction rollback"); } }
protected void resetVerify() { Session session = getSession(); // Read the object from the database Employee databaseEmployee = (Employee) session.readObject(Employee.class, getSearchExpression()); // If the employee object IS in the database then there is a problem. if (databaseEmployee != null) { throw new TestErrorException( "The example employee object should have been deleted from the database."); } }
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"); }
protected void verify() { Session session = getSession(); // Read the object from the database Employee databaseEmployee = (Employee) session.readObject(Employee.class, getSearchExpression()); // If the employee object is NOT in the database then there is a problem. if (databaseEmployee == null) { throw new TestErrorException( "Employee object should have been inserted into database after commit transaction"); } // Check that the employee read from the database is the same as the one in memory. if (!compareObjects(getEmployee(), databaseEmployee)) { throw new TestErrorException( "The object read from the database, '" + databaseEmployee + "' does not match the originial, '" + getEmployee() + "."); } }
public void run() { try { counter = 0; while (!experienceError && counter < numOftries) { if (thread == 1) { session.getIdentityMapAccessor().initializeIdentityMap(BigBadObject.class); readObject = (BigBadObject) session.readObject(referenceObject); } else { readObject = (BigBadObject) session.getIdentityMapAccessor().getFromIdentityMap(referenceObject); } if ((readObject != null) && ((readObject.number02 == null) || (!readObject.number02.equals(referenceObject.number02)))) { this.experienceError = true; } counter++; } } catch (RuntimeException ex) { this.experienceError = true; this.exception = ex; } }
/* * This test creates an object and registers it with a unit of work. It then serializes that * object and deserializes it. Adds an object onto the origional then performs serialization * sequence again. Then deepMergeClone is attempted and the results are compared to verify that * the merge worked. */ public void test() { try { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(byteStream); // create the phoneNumber object Session session = getSession(); UnitOfWork uow = session.acquireUnitOfWork(); this.deptObject = (Dept) session.readObject( Dept.class, new org.eclipse.persistence.expressions.ExpressionBuilder() .get("deptno") .equal(5.0)); Dept deptClone = (Dept) uow.registerObject(this.deptObject); // force instantiations of value holders before serialization deptClone.getEmpCollection().size(); Emp empClone = null; if ((deptClone.getEmpCollection() != null) && (deptClone.getEmpCollection().size() > 1)) { empClone = (Emp) deptClone.getEmpCollection().iterator().next(); deptClone.getEmpCollection().remove(empClone); empClone.setDeptno(null); } // serialize object by writing to a stream stream.writeObject(deptClone); stream.writeObject(empClone); stream.flush(); byte[] arr = byteStream.toByteArray(); ByteArrayInputStream inByteStream = new ByteArrayInputStream(arr); ObjectInputStream inObjStream = new ObjectInputStream(inByteStream); Dept deserialDept; Emp deserialEmp = null; // deserialize the object try { deserialDept = (Dept) inObjStream.readObject(); deserialEmp = (Emp) inObjStream.readObject(); } catch (ClassNotFoundException e) { throw new TestErrorException("Could not deserialize object " + e.toString()); } // add a new manager, test 1-m's /* if (deserialDept.getEmpCollection() != null && deserialDept.getEmpCollection().size() > 1) { deserialEmp = (Emp)deserialDept.getEmpCollection().iterator().next(); deserialDept.getEmpCollection().remove(deserialEmp); deserialEmp.setDeptno(null); } */ deserialDept.getEmpCollection().add(deserialEmp); deserialEmp.setDeptno(deserialDept); int collectionSize = deserialDept.getEmpCollection().size(); byteStream = new ByteArrayOutputStream(); stream = new ObjectOutputStream(byteStream); // send the ammended object back through the serialization process stream.writeObject(deserialDept); stream.flush(); arr = byteStream.toByteArray(); inByteStream = new ByteArrayInputStream(arr); inObjStream = new ObjectInputStream(inByteStream); try { deserialDept = (Dept) inObjStream.readObject(); } catch (ClassNotFoundException e) { throw new TestErrorException("Could not deserialize object " + e.toString()); } // merge the ammended clone with the unit of work deptClone = (Dept) uow.deepMergeClone(deserialDept); if (deptClone.getEmpCollection().size() != collectionSize) { throw new TestErrorException("Failed to merge the collection correctly not enough Emps"); } for (Iterator iterator = deptClone.getEmpCollection().iterator(); iterator.hasNext(); ) { Emp emp = (Emp) iterator.next(); if (emp.getDeptno() != deptClone) { throw new TestErrorException("Failed to merge the back pointer"); } } uow.commit(); } catch (IOException e) { throw new TestErrorException("Error running Test " + e.toString()); } }