1 21 package com.db4o.test; 22 23 import com.db4o.*; 24 import com.db4o.ext.*; 25 import com.db4o.query.*; 26 27 public class TwoClients extends AllTestsConfAll{ 28 29 public void test(){ 30 if(Test.clientServer){ 31 Test.deleteAllInstances(new Atom()); 32 Test.commit(); 33 34 ExtObjectContainer client1 = Test.objectContainer(); 35 ExtObjectContainer client2 = Test.openClient(); 36 Atom a_1_1 = new Atom("One"); 37 Atom a_1_2 = new Atom("Two"); 38 Atom a_1_3 = new Atom("Three"); 39 client1.set(a_1_1); 40 client1.set(a_1_2); 41 client1.set(a_1_3); 42 ensureAtomCount(client2,null, 0); 43 Test.commitSync(client1, client2); 44 ensureAtomCount(client2,null, 3); 45 Atom a_2_1 = (Atom)client2.get(new Atom("One")).next(); 46 a_1_1.child = new Atom("OneChild"); 47 client1.set(a_1_1); 48 ensureAtomCount(client2,null, 3); 49 Test.commitSync(client1, client2); 50 ensureAtomCount(client2,null, 4); 51 client2.deactivate(a_2_1, Integer.MAX_VALUE); 52 client2.activate(a_2_1, Integer.MAX_VALUE); 53 Test.ensure(a_2_1.child.name.equals("OneChild")); 54 a_2_1.name = "Zulu"; 55 client2.set(a_2_1); 56 57 Atom a_1_4 = new Atom("Zorro"); 58 client1.set(a_1_4); 59 Atom a_1_5 = new Atom("Zzerk"); 60 client1.set(a_1_5); 61 62 ensureAtomCount(client1, "Zulu", 0); 63 64 Test.commitSync(client2, client1); 65 66 ensureAtomCount(client1, "Zulu", 1); 67 68 69 Query q = client1.query(); 70 q.constrain(Atom.class); 71 q.descend("name").constrain("Zulu"); 72 ObjectSet os = q.execute(); 73 Atom q_1_1 = (Atom)os.next(); 74 75 Test.ensure(a_1_1 == q_1_1); 76 a_1_1.name = "Bozo"; 77 client1.set(a_1_1); 78 a_1_1.child.name = "BozoChild"; 79 client1.set(a_1_1.child); 80 a_1_4.name = "Bozo"; 81 client1.set(a_1_4); 82 a_1_5.name = "Cue"; 83 client1.set(a_1_5); 84 85 client2.refresh(a_2_1, Integer.MAX_VALUE); 86 Test.ensure(a_2_1.name.equals("Zulu")); 87 Test.ensure(a_2_1.child.name.equals("OneChild")); 88 ensureAtomCount(client2, "Bozo", 0); 89 90 Test.commitSync(client1, client2); 91 92 client2.refresh(a_2_1, Integer.MAX_VALUE); 93 Test.ensure(a_2_1.name.equals("Bozo")); 94 Test.ensure(a_2_1.child.name.equals("BozoChild")); 95 ensureAtomCount(client2, "Bozo", 2); 96 ensureAtomCount(client2, "Cue", 1); 97 ensureAtomCount(client2, "BozoChild", 1); 98 99 client2.close(); 100 } 101 } 102 103 private void ensureAtomCount(ObjectContainer con, String name, int count){ 104 105 for (int i = 0; i < 5; i++) { 108 Query q = con.query(); 109 q.constrain(Atom.class); 110 if(name != null){ 111 q.descend("name").constrain(name); 112 } 113 if(q.execute().size() == count){ 114 Test.assertionCount ++; 115 return; 116 } 117 } 118 Test.error(); 119 } 120 121 122 123 124 125 } 126 | Popular Tags |