1 23 24 package org.objectweb.jorm.runtime.pnameiterator; 25 26 import org.objectweb.jorm.runtime.TestRuntimeHelper; 27 import org.objectweb.jorm.runtime.namedef.NameDefAccessor; 28 import org.objectweb.jorm.naming.api.PBinder; 29 import org.objectweb.jorm.naming.api.PNameCoder; 30 import org.objectweb.jorm.naming.api.PName; 31 import org.objectweb.jorm.type.api.PType; 32 import org.objectweb.jorm.type.api.PTypeSpace; 33 import org.objectweb.jorm.facility.naming.basidir.BasidBinder; 34 import org.objectweb.jorm.api.PClassMapping; 35 import org.objectweb.jorm.api.PBinding; 36 import org.objectweb.util.monolog.api.BasicLevel; 37 38 import java.util.Iterator ; 39 40 44 public class TestSingleNameIterator extends TestRuntimeHelper { 45 46 private final static String LOGGER_NAME 47 = "test.org.objectweb.jorm.singlename"; 48 49 public TestSingleNameIterator(String name) throws Exception { 50 super(name); 51 } 52 53 protected String getLoggerName() { 54 return LOGGER_NAME; 55 } 56 57 protected PBinder getBinder(String className) throws Exception { 58 int idx = className.lastIndexOf('.'); 59 String cn = className.substring(idx + 1); 60 PType type = null; 61 int ct = -1; 62 Object nullvalue = null; 63 if (cn.equals("ASingleIntId")) { 64 type = PTypeSpace.INT; 65 ct = PNameCoder.CTINT; 66 nullvalue = new Integer (-1); 67 } else { 68 throw new Exception ( 69 "Unable to find the type of the binder for the class: " 70 + className); 71 } 72 logger.log(BasicLevel.DEBUG, "Allocate a BasidBinder to manage " 73 + type.getJormName()); 74 PBinder binder = new BasidBinder(); 75 binder.setNullPName(nullvalue); 76 ((BasidBinder) binder).setCodingType(ct); 77 return binder; 78 } 79 80 private final static String CNINT = "org.objectweb.jorm.pobject.singlename.ASingleIntId"; 81 82 public void trueTester(int NBOBJ, boolean prefetch) throws Exception { 83 PClassMapping pcm = getMapping(CNINT); 84 Object conn = mapper.getConnection(); 85 for (int i = 0; i < NBOBJ; i++) { 86 PBinding pb = export(CNINT, new Integer (i)); 87 NameDefAccessor accwrite = new NameDefAccessor(i, pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 88 pb.write(conn, accwrite); 89 } 90 Iterator it = pcm.getPNameIterator(conn, false, prefetch, conn); 91 int nbiter = 0; 92 PBinding[] pb = new PBinding[NBOBJ]; 93 NameDefAccessor accread = new NameDefAccessor(); 94 while (it.hasNext()) { 95 PName pn = (PName) it.next(); 96 pb[nbiter] = bind(CNINT, pn); 97 pb[nbiter].read(conn, accread, conn); 98 assertEquals("Bad object pname and F1 should be equal", accread.f1, pn.encodeInt()); 99 nbiter++; 100 } 101 assertEquals("Wrong number of objects iterated", NBOBJ, nbiter); 102 mapper.getPrefetchCache().invalidatePrefetchBuffer(conn); 103 mapper.closeConnection(conn); 104 mapper.getPMapCluster(CNINT).deleteData(); 105 } 106 107 public void testIntNameIteratorNoPrefetchNoElem() throws Exception { 108 int NBOBJ = 0; 109 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 110 trueTester(NBOBJ, false); 111 logger.log(BasicLevel.DEBUG, "testInt end"); 112 } 113 114 public void testIntNameIteratorNoPrefetchOneElem() throws Exception { 115 int NBOBJ = 1; 116 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 117 trueTester(NBOBJ, false); 118 logger.log(BasicLevel.DEBUG, "testInt end"); 119 } 120 121 public void testIntNameIteratorNoPrefetch10Elem() throws Exception { 122 int NBOBJ = 10; 123 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 124 trueTester(NBOBJ, false); 125 logger.log(BasicLevel.DEBUG, "testInt end"); 126 } 127 128 public void testIntNameIteratorNoPrefetch100Elem() throws Exception { 129 int NBOBJ = 100; 130 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 131 trueTester(NBOBJ, false); 132 logger.log(BasicLevel.DEBUG, "testInt end"); 133 } 134 135 public void testIntNameIteratorNoPrefetch1000Elem() throws Exception { 136 int NBOBJ = 1000; 137 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 138 trueTester(NBOBJ, false); 139 logger.log(BasicLevel.DEBUG, "testInt end"); 140 } 141 142 public void testIntNameIteratorPrefetchNoElem() throws Exception { 143 int NBOBJ = 0; 144 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 145 trueTester(NBOBJ, true); 146 logger.log(BasicLevel.DEBUG, "testInt end"); 147 } 148 149 public void testIntNameIteratorPrefetchOneElem() throws Exception { 150 int NBOBJ = 1; 151 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 152 trueTester(NBOBJ, true); 153 logger.log(BasicLevel.DEBUG, "testInt end"); 154 } 155 156 public void testIntNameIteratorPrefetch10Elem() throws Exception { 157 int NBOBJ = 10; 158 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 159 trueTester(NBOBJ, true); 160 logger.log(BasicLevel.DEBUG, "testInt end"); 161 } 162 163 public void testIntNameIteratorPrefetch100Elem() throws Exception { 164 int NBOBJ = 100; 165 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 166 trueTester(NBOBJ, true); 167 logger.log(BasicLevel.DEBUG, "testInt end"); 168 } 169 170 public void testIntNameIteratorPrefetch1000Elem() throws Exception { 171 int NBOBJ = 1000; 172 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 173 trueTester(NBOBJ, true); 174 logger.log(BasicLevel.DEBUG, "testInt end"); 175 } 176 } 177 | Popular Tags |