List:Commits« Previous MessageNext Message »
From:Craig L Russell Date:September 20 2010 8:56pm
Subject:bzr push into clusterj branch (Craig.Russell:326 to 327)
View as plain text  
  327 Craig L Russell	2010-09-20
      Add tests for blind update, update all, and update all autocommit

    modified:
      clusterj-test/src/main/java/testsuite/clusterj/UpdateTest.java
  326 Craig L Russell	2010-09-20
      Add a little debugging/logging for startTransaction

    modified:
      clusterj-tie/src/main/java/com/mysql/clusterj/tie/DbImpl.java
      clusterj-tie/src/main/resources/com/mysql/clusterj/tie/Bundle.properties
=== modified file 'clusterj-test/src/main/java/testsuite/clusterj/UpdateTest.java'
--- a/clusterj-test/src/main/java/testsuite/clusterj/UpdateTest.java	2009-12-11 21:19:31 +0000
+++ b/clusterj-test/src/main/java/testsuite/clusterj/UpdateTest.java	2010-09-20 20:36:08 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2009 Sun Microsystems Inc.
+   Copyright (C) 2009-2010 Sun Microsystems Inc.
    All rights reserved. Use is subject to license terms.
 
    This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,9 @@
 
 package testsuite.clusterj;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import testsuite.clusterj.model.Employee;
 
 public class UpdateTest extends AbstractClusterJModelTest {
@@ -66,4 +69,155 @@ public class UpdateTest extends Abstract
         tx.commit();
         failOnError();
     }
+
+    public void testBlindUpdate() {
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.newInstance(Employee.class);
+            // set primary key (required for blind update)
+            e.setId(i);
+            // change age 
+            e.setAge(NUMBER_TO_INSERT - i);
+            // send the change to the database
+            session.updatePersistent(e);
+        }
+        tx.commit();
+        
+        // now verify that the changes were committed
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // verify age 
+            int expected = NUMBER_TO_INSERT - i;
+            int actual = e.getAge();
+            if (expected != actual) {
+                error("Failed update: for employee " + i
+                        + " expected age " + expected
+                        + " actual age " + actual);
+            }
+        }
+        tx.commit();
+        failOnError();
+    }
+
+    public void testUpdateAll() {
+        List<Employee> employees = new ArrayList<Employee>();
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // change age 
+            e.setAge(NUMBER_TO_INSERT - i);
+            employees.add(e);
+        }
+        // send the changes to the database
+        session.updatePersistentAll(employees);
+        tx.commit();
+        
+        // now verify that the changes were committed
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // verify age 
+            int expected = NUMBER_TO_INSERT - i;
+            int actual = e.getAge();
+            if (expected != actual) {
+                error("Failed update: for employee " + i
+                        + " expected age " + expected
+                        + " actual age " + actual);
+            }
+        }
+        tx.commit();
+        failOnError();
+    }
+
+    public void testBlindUpdateAll() {
+        List<Employee> employees = new ArrayList<Employee>();
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.newInstance(Employee.class);
+            // set primary key (required for blind update)
+            e.setId(i);
+            // change age 
+            e.setAge(NUMBER_TO_INSERT - i);
+            employees.add(e);
+        }
+        // send the changes to the database
+        session.updatePersistentAll(employees);
+        tx.commit();
+        
+        // now verify that the changes were committed
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // verify age 
+            int expected = NUMBER_TO_INSERT - i;
+            int actual = e.getAge();
+            if (expected != actual) {
+                error("Failed update: for employee " + i
+                        + " expected age " + expected
+                        + " actual age " + actual);
+            }
+        }
+        tx.commit();
+        failOnError();
+    }
+
+    public void testUpdateAllAutocommit() {
+        List<Employee> employees = new ArrayList<Employee>();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // change age 
+            e.setAge(NUMBER_TO_INSERT - i);
+            employees.add(e);
+        }
+        // send the changes to the database in a single autocommit transaction
+        session.updatePersistentAll(employees);
+        
+        // now verify that the changes were committed
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // verify age 
+            int expected = NUMBER_TO_INSERT - i;
+            int actual = e.getAge();
+            if (expected != actual) {
+                error("Failed update: for employee " + i
+                        + " expected age " + expected
+                        + " actual age " + actual);
+            }
+        }
+        tx.commit();
+        failOnError();
+    }
+
+    public void testBlindUpdateAllAutocommit() {
+        List<Employee> employees = new ArrayList<Employee>();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.newInstance(Employee.class);
+            // set primary key (required for blind update)
+            e.setId(i);
+            // change age 
+            e.setAge(NUMBER_TO_INSERT - i);
+            employees.add(e);
+        }
+        // send the changes to the database in a single autocommit transaction
+        session.updatePersistentAll(employees);
+        
+        // now verify that the changes were committed
+        tx.begin();
+        for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
+            Employee e = session.find(Employee.class, i);
+            // verify age 
+            int expected = NUMBER_TO_INSERT - i;
+            int actual = e.getAge();
+            if (expected != actual) {
+                error("Failed update: for employee " + i
+                        + " expected age " + expected
+                        + " actual age " + actual);
+            }
+        }
+        tx.commit();
+        failOnError();
+    }
+
 }


Attachment: [text/bzr-bundle] bzr/craig.russell@oracle.com-20100920203608-gb4max8sxbi9zhk2.bundle
Thread
bzr push into clusterj branch (Craig.Russell:326 to 327)Craig L Russell20 Sep