1 21 package com.db4o.test.cluster; 22 23 import java.io.*; 24 25 import com.db4o.*; 26 import com.db4o.cluster.*; 27 import com.db4o.query.*; 28 import com.db4o.test.*; 29 30 import db4ounit.Assert; 31 32 33 public class BasicClusterTest { 34 35 public String _name; 36 37 public static final String SECOND_FILE = "second.yap"; 38 39 public BasicClusterTest(){ 40 41 } 42 43 public BasicClusterTest(String name){ 44 _name = name; 45 } 46 47 public void store(){ 48 new File(SECOND_FILE).delete(); 49 Test.store(new BasicClusterTest("inOne")); 50 Test.store(new BasicClusterTest("inBoth")); 51 ObjectContainer second = Db4o.openFile(SECOND_FILE); 52 second.set(new BasicClusterTest("inBoth")); 53 second.set(new BasicClusterTest("inTwo")); 54 second.close(); 55 } 56 57 public void testConstrained(){ 58 ObjectContainer second = Db4o.openFile(SECOND_FILE); 59 Cluster cluster = new Cluster(new ObjectContainer[]{ 60 Test.objectContainer(), 61 second 62 }); 63 tQuery(cluster, "inOne", 1); 64 tQuery(cluster, "inTwo", 1); 65 tQuery(cluster, "inBoth", 2); 66 second.close(); 67 } 68 69 public void testPlain(){ 70 ObjectContainer second = Db4o.openFile(SECOND_FILE); 71 Cluster cluster = new Cluster(new ObjectContainer[]{ 72 Test.objectContainer(), 73 second 74 }); 75 Query q = cluster.query(); 76 q.constrain(this.getClass()); 77 ObjectSet result=q.execute(); 78 Test.ensure(result.size() == 4); 79 while(result.hasNext()) { 80 Test.ensure(result.next() instanceof BasicClusterTest); 81 } 82 second.close(); 83 } 84 85 private void tQuery(Cluster cluster, String name, int expected){ 86 Query q = cluster.query(); 87 q.constrain(this.getClass()); 88 q.descend("_name").constrain(name); 89 ObjectSet result=q.execute(); 90 Assert.areEqual(expected, result.size()); 91 while(result.hasNext()) { 92 Test.ensure(result.next() instanceof BasicClusterTest); 93 } 94 } 95 96 97 98 } 99 | Popular Tags |