public void reset() { // Remove the transport added for this test DatabaseSession session = (DatabaseSession) getSession(); UnitOfWork uow = session.acquireUnitOfWork(); ExpressionBuilder transport = new ExpressionBuilder(); Expression expression = transport.get("id").equal(transportId); uow.deleteAllObjects(uow.readAllObjects(Transport.class, expression)); uow.commit(); }
protected void verify() { // Check to see that aCountry was not deleted from the database. ExpressionBuilder xBuilder = new ExpressionBuilder(); Expression exp = xBuilder.get("name").equal(aCountry.name); Country dbCountry = (Country) getSession().readObject(Country.class, exp); if (dbCountry != null) { throw new TestErrorException( "The Country object was illegally updated! It should not have been!"); } }
public void test() { transport = Transport.example6(); UnitOfWork uow = getSession().acquireUnitOfWork(); uow.registerObject(transport); uow.commit(); transportId = transport.getId(); DatabaseSession session = (DatabaseSession) getSession(); ExpressionBuilder exp = new ExpressionBuilder(); Expression expression = exp.get("id").equal(transportId); transport = (Transport) session.readObject(Transport.class, expression); }
private void createEmployeeAndSearchExpression() { // Create the example employee employee = (org.eclipse.persistence.testing.models.employee.domain.Employee) new org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator() .basicEmployeeExample1(); employee.setFirstName("Timugen"); employee.setLastName("Singaera"); employee.addResponsibility("Answer the phones."); // Create an expression to retreive the employee from the database ExpressionBuilder expressionBuilder = new ExpressionBuilder(); Expression exp1; Expression exp2; Expression expression; exp1 = expressionBuilder.get("firstName").equal(employee.getFirstName()); exp2 = expressionBuilder.get("lastName").equal(employee.getLastName()); searchExpression = exp1.or(exp2); }
public void run() { try { ExpressionBuilder builder = new ExpressionBuilder(); Expression exp = builder.anyOf("policies").get("policyNumber").equal(200); for (int i = 0; i < 1; i++) { PolicyHolder holder = (PolicyHolder) this.clientSession.readObject( org.eclipse.persistence.testing.models.insurance.PolicyHolder.class, exp); if ((holder == null) || (holder.getFirstName() == "") || (holder.getPolicies() == null) || (holder.getAddress() == null) || (holder.getAddress().getCity() == null)) { throw new TestWarningException("Client/Server dead lock test fails as null is returned."); } } } catch (Exception exception) { this.server.errorOccured = true; exception.printStackTrace(System.out); } }
/** * Load the last test result from the test result database. Find only the results run on the same * machine and database. Compare the current test run result with the previous results do * determine if the test passes or fails. */ public static void verify(PerformanceRegressionTest test) { // Ensures all tests pass to reset baseline, // Required when tests or environment change to be slower to avoid failures. if (reset) { throw new TestWarningException("Reseting baseline."); } Session session = LoadBuildSystem.getSystem().getSession(); // Query all previous successful test results for this test on the same machine and database. // Find only the baseline version, or last version run different than current version. // If you need to compare results against the current version you must change the TopLink // version string. ReadAllQuery query = new ReadAllQuery(TestResult.class); ExpressionBuilder result = new ExpressionBuilder(); query.setSelectionCriteria( result .get("name") .equal(test.getName()) .and( result .get("loadBuildSummary") .get("machine") .equal(LoadBuildSystem.getSummary().getMachine())) .and( result .get("loadBuildSummary") .get("loginChoice") .equal(LoadBuildSystem.getSummary().getLoginChoice()))); // Allow comparing to a set version through a system property. String currentVersion = LoadBuildSystem.getSummary().getToplinkVersion(); String baselineVersion = null; if (System.getProperties().containsKey("toplink.loadbuild.baseline-version")) { baselineVersion = System.getProperties().getProperty("toplink.loadbuild.baseline-version"); // System properties cannot store spaces so need to replace them from \b. baselineVersion = baselineVersion.replace('_', ' '); ((PerformanceComparisonTestResult) ((TestCase) test).getTestResult()).baselineVersion = baselineVersion; } else { // Compare against the last successful version. ReportQuery reportQuery = new ReportQuery(TestResult.class, query.getExpressionBuilder()); reportQuery.useDistinct(); reportQuery.returnSingleValue(); reportQuery.addAttribute("version", result.get("loadBuildSummary").get("toplinkVersion")); reportQuery.setSelectionCriteria( query .getSelectionCriteria() .and( (result.get("outcome").equal(TestResult.PASSED)) .or(result.get("outcome").equal(TestResult.WARNING))) .and(result.get("loadBuildSummary").get("toplinkVersion").notEqual(currentVersion))); reportQuery.addOrdering(result.get("loadBuildSummary").get("timestamp").descending()); baselineVersion = (String) session.executeQuery(reportQuery); } query.setSelectionCriteria( query .getSelectionCriteria() .and(result.get("loadBuildSummary").get("toplinkVersion").equal(baselineVersion))); query.addOrdering(result.get("loadBuildSummary").get("timestamp").descending()); query.setMaxRows(10); query.useCursoredStream(1, 1); CursoredStream stream = (CursoredStream) session.executeQuery(query); if (!stream.hasMoreElements()) { throw new TestWarningException("No previous test result to compare performance with."); } TestResult lastResult = (TestResult) stream.nextElement(); double lastCount = lastResult.getTestTime(); PerformanceComparisonTestResult testResult = (PerformanceComparisonTestResult) ((TestCase) test).getTestResult(); testResult.getBaselineVersionResults().add(new Double(lastCount)); // Average last 5 runs. int numberOfRuns = 0; while (stream.hasMoreElements() && (numberOfRuns < 4)) { TestResult nextResult = (TestResult) stream.nextElement(); testResult.getBaselineVersionResults().add(new Double(nextResult.getTestTime())); numberOfRuns++; } stream.close(); double baselineAverage = PerformanceComparisonTestResult.averageResults(testResult.getBaselineVersionResults()); double currentCount = ((TestCase) test).getTestResult().getTestTime(); testResult.baselineVersion = lastResult.getLoadBuildSummary().getToplinkVersion(); testResult.percentageDifferenceLastRun = PerformanceComparisonTestResult.percentageDifference(currentCount, lastCount); // Query the current version last 5 runs for averaging. query = new ReadAllQuery(TestResult.class); result = new ExpressionBuilder(); query.setSelectionCriteria( result .get("name") .equal(((TestCase) test).getName()) .and( result .get("loadBuildSummary") .get("machine") .equal(LoadBuildSystem.getSummary().getMachine())) .and( result .get("loadBuildSummary") .get("loginChoice") .equal(LoadBuildSystem.getSummary().getLoginChoice())) .and(result.get("loadBuildSummary").get("toplinkVersion").equal(currentVersion))); query.addOrdering(result.get("loadBuildSummary").get("timestamp").descending()); query.useCursoredStream(1, 1); stream = (CursoredStream) session.executeQuery(query); // Average last 5 runs. testResult.getCurrentVersionResults().add(new Double(currentCount)); numberOfRuns = 0; while (stream.hasMoreElements() && (numberOfRuns < 4)) { TestResult nextResult = (TestResult) stream.nextElement(); testResult.getCurrentVersionResults().add(new Double(nextResult.getTestTime())); numberOfRuns++; } stream.close(); double currentAverage = PerformanceComparisonTestResult.averageResults(testResult.getCurrentVersionResults()); testResult.percentageDifferenceAverage = PerformanceComparisonTestResult.percentageDifference(currentAverage, baselineAverage); testResult.baselineStandardDeviation = PerformanceComparisonTestResult.standardDeviationResults( testResult.getBaselineVersionResults()); testResult.currentStandardDeviation = PerformanceComparisonTestResult.standardDeviationResults( testResult.getCurrentVersionResults()); if (testResult.percentageDifferenceAverage < test.getAllowableDecrease()) { throw new TestErrorException( "Test is " + ((long) testResult.percentageDifferenceAverage) + "% slower than last successful execution."); } }