1 21 22 package org.apache.derbyTesting.unitTests.store; 23 24 import org.apache.derbyTesting.unitTests.harness.T_MultiThreadedIterations; 25 import org.apache.derbyTesting.unitTests.harness.T_Fail; 26 27 import org.apache.derby.impl.store.raw.data.*; 28 29 import org.apache.derby.iapi.services.context.ContextService; 30 import org.apache.derby.iapi.services.context.ContextManager; 31 import org.apache.derby.iapi.services.locks.*; 32 import org.apache.derby.iapi.services.property.PropertyUtil; 33 import org.apache.derby.iapi.services.monitor.Monitor; 34 import org.apache.derby.iapi.services.sanity.SanityManager; 35 import org.apache.derby.iapi.services.io.Storable; 36 import org.apache.derby.iapi.services.io.FormatIdOutputStream; 37 38 import org.apache.derby.iapi.error.StandardException; 39 import org.apache.derby.iapi.store.raw.*; 40 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 41 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 42 43 import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo; 44 45 import org.apache.derby.iapi.types.DataValueDescriptor; 46 47 import org.apache.derby.iapi.reference.Property; 48 49 import org.apache.derby.iapi.services.io.FormatableBitSet; 50 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream; 51 52 import java.io.*; 53 import java.util.Properties ; 54 55 58 59 public class T_StreamFile extends T_MultiThreadedIterations { 60 61 private static final String testService = "streamFileTest"; 62 63 static final String REC_001 = "McLaren"; 64 static final String REC_002 = "Ferrari"; 65 static final String REC_003 = "Benetton"; 66 static final String REC_004 = "Prost"; 67 static final String REC_005 = "Tyrell"; 68 static final String REC_006 = "Derby, Natscape, Goatscape, the popular names"; 69 static final String REC_007 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; 70 71 static final String SP1 = "savepoint1"; 72 static final String SP2 = "savepoint2"; 73 74 75 static RawStoreFactory factory; 76 static LockFactory lf; 77 static long commonContainer = -1; 78 79 static boolean testRollback; static final String TEST_ROLLBACK_OFF = "derby.RawStore.RollbackTestOff"; 81 82 private static ContextService contextService; 83 private T_Util t_util; 84 85 public T_StreamFile() { 86 super(); 87 } 88 89 92 public void boot(boolean create, Properties startParams) 93 throws StandardException { 94 super.boot(create, startParams); 95 contextService = ContextService.getFactory(); 96 } 97 98 99 102 103 protected String getModuleToTestProtocolName() { 104 return RawStoreFactory.MODULE; 105 } 106 107 108 113 protected void setupTest() throws T_Fail { 114 String rollbackOff = PropertyUtil.getSystemProperty(TEST_ROLLBACK_OFF); 115 testRollback = !Boolean.valueOf(rollbackOff).booleanValue(); 116 117 if (startParams == null) { 119 startParams = new Properties (); 120 } 121 122 startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString()); 123 startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString()); 125 126 startParams = T_Util.setEncryptionParam(startParams); 128 129 try { 130 factory = (RawStoreFactory) Monitor.createPersistentService(getModuleToTestProtocolName(), 131 testService, startParams); 132 if (factory == null) { 133 throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " service not started."); 134 } 135 136 lf = factory.getLockFactory(); 137 if (lf == null) { 138 throw T_Fail.testFailMsg("LockFactory.MODULE not found"); 139 } 140 } catch (StandardException mse) { 141 throw T_Fail.exceptionFail(mse); 142 } 143 144 t_util = new T_Util(factory, lf, contextService); 145 commonContainer = commonContainer(); 146 147 return; 148 } 149 150 151 156 protected void joinSetupTest() throws T_Fail { 157 158 T_Fail.T_ASSERT(factory != null, "raw store factory not setup "); 159 T_Fail.T_ASSERT(contextService != null, "Context service not setup "); 160 T_Fail.T_ASSERT(commonContainer != -1, "common container not setup "); 161 162 t_util = new T_Util(factory, lf, contextService); 163 164 } 165 166 protected T_MultiThreadedIterations newTestObject() { 167 return new T_StreamFile(); 168 } 169 170 175 protected void runTestSet() throws T_Fail { 176 177 179 ContextManager cm1 = contextService.newContextManager(); 180 contextService.setCurrentContextManager(cm1); 181 182 try { 183 184 SF001(1, 13, T_RowSource.STRING_ROW_TYPE, false); 186 187 SF001(1, 1, T_RowSource.STRING_ROW_TYPE, false); 189 190 SF001(1000, 1, T_RowSource.STRING_ROW_TYPE, false); 192 193 SF001(1000, 2, T_RowSource.STRING_ROW_TYPE, false); 195 196 SF001(500, 9, T_RowSource.STRING_ROW_TYPE, false); 198 199 SF001(500, 13, T_RowSource.STRING_ROW_TYPE, false); 201 202 SF001(1000, 2, T_RowSource.STRING_ROW_TYPE, true); 204 205 212 217 } catch (StandardException se) { 218 219 cm1.cleanupOnError(se); 220 throw T_Fail.exceptionFail(se); 221 } 222 finally { 223 contextService.resetCurrentContextManager(cm1); 224 } 225 } 226 227 230 private long commonContainer() throws T_Fail { 231 232 ContextManager cm1 = contextService.newContextManager(); 233 contextService.setCurrentContextManager(cm1); 234 long cid; 235 236 try { 237 Transaction t = t_util.t_startTransaction(); 238 cid = t_util.t_addContainer(t, 0); 239 t_util.t_commit(t); 240 t.close(); 241 } 242 catch (StandardException se) { 243 244 cm1.cleanupOnError(se); 245 throw T_Fail.exceptionFail(se); 246 } 247 finally { 248 contextService.resetCurrentContextManager(cm1); 249 } 250 return cid; 251 } 252 253 257 protected void SF001(int rowCount, int columnCount, int columnType, boolean forceAbort) 258 throws StandardException, T_Fail { 259 260 Transaction t = t_util.t_startTransaction(); 261 262 int segmentId = StreamContainerHandle.TEMPORARY_SEGMENT; 263 Properties properties = new Properties (); 264 properties.put(RawStoreFactory.STREAM_FILE_BUFFER_SIZE_PARAMETER, "16384"); 265 266 T_RowSource testRowSource = null; 268 if (forceAbort) 269 testRowSource = new T_RowSource(rowCount, columnCount, columnType, forceAbort, t); 270 else 271 testRowSource = new T_RowSource(rowCount, columnCount, columnType, forceAbort, null); 272 273 long startms = System.currentTimeMillis(); 274 275 long containerId = t.addAndLoadStreamContainer(segmentId, properties, testRowSource); 276 277 long endms = System.currentTimeMillis(); 278 long time = endms - startms; 279 REPORT("SF001 - write: " + time + "ms"); 280 281 StreamContainerHandle scHandle = 283 t.openStreamContainer(segmentId, containerId, false); 284 285 DataValueDescriptor template[] = null; 287 template = testRowSource.getTemplate(); 288 289 DataValueDescriptor readRow[] = null; 290 readRow = testRowSource.getTemplate(); 291 segmentId = StreamContainerHandle.TEMPORARY_SEGMENT; 292 int fetchCount = 0; 293 startms = System.currentTimeMillis(); 294 while (scHandle.fetchNext(readRow)) { 295 fetchCount++; 296 if (!readRow.toString().equals(template.toString())) 299 throw T_Fail.testFailMsg("Record's value incorrect, expected :" 300 + template.toString() + ": - got :" + readRow.toString()); 301 } 302 endms = System.currentTimeMillis(); 303 time = endms - startms; 304 if (fetchCount != rowCount) 306 throw T_Fail.testFailMsg("incorrect number of row fetched. Expecting " + rowCount 307 + " rows, got " + fetchCount + ", rows instead."); 308 REPORT("SF001 - fetch: " + time + "ms"); 309 310 scHandle.close(); 311 312 t_util.t_commit(t); 313 t.close(); 314 315 PASS("SF001, rowCount = " + rowCount + ", columnCount = " + columnCount + ", clumn type: " + columnType); 316 } 317 318 protected void SF002(int param) throws StandardException, T_Fail { 321 322 T_RowSource rowSource = new T_RowSource(500000, 13, 2, false, null); 323 324 DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream(16384); 325 FormatIdOutputStream logicalDataOut = new FormatIdOutputStream(out); 326 327 long startms = System.currentTimeMillis(); 328 System.out.println("starting rowSource test, time: " + startms); 329 try { 330 331 FormatableBitSet validColumns = rowSource.getValidColumns(); 332 333 int numberFields = 0; 334 if (validColumns != null) { 335 for (int i = validColumns.size() - 1; i >= 0; i--) { 336 if (validColumns.get(i)) { 337 numberFields = i + 1; 338 break; 339 } 340 } 341 } 342 343 DataValueDescriptor[] row = rowSource.getNextRowFromRowSource(); 344 while (row != null) { 345 if (SanityManager.DEBUG) { 346 SanityManager.ASSERT(row != null, 347 "RowSource returned null"); 348 } 349 350 int arrayPosition = -1; 351 for (int i = 0; i < numberFields; i++) { 352 if (validColumns.get(i)) { 354 arrayPosition++; 355 DataValueDescriptor column = row[arrayPosition]; 356 357 if (param == 1) { 358 try { 359 Storable sColumn = (Storable) column; 360 if (!sColumn.isNull()) { 361 sColumn.writeExternal(logicalDataOut); 362 out.reset(); 363 } 364 } catch (IOException ioe) { 365 throw T_Fail.exceptionFail(ioe); 366 } 367 } 368 369 } 370 } 371 372 row = rowSource.getNextRowFromRowSource(); 373 } 374 375 } finally { 376 377 } 378 379 long endms = System.currentTimeMillis(); 380 long time2 = endms - startms; 381 if (param != 1) 382 System.out.println("ended rowSource test, time: " + endms 383 + ", time spent = " + time2); 384 else 385 System.out.println("------ writeExternal called....\n ended rowSource test, time: " + endms 386 + ", time spent = " + time2); 387 388 PASS("SF002"); 389 } 390 } 391 | Popular Tags |