1 24 25 package org.objectweb.cjdbc.scenario.raidb1.cache; 26 27 import java.sql.Connection ; 28 29 import org.objectweb.cjdbc.controller.cache.result.AbstractResultCache; 30 import org.objectweb.cjdbc.scenario.templates.Raidb1Template; 31 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 32 import org.objectweb.cjdbc.scenario.tools.util.MemoryProfiler; 33 34 40 public class OutOfMemoryCacheScenario extends Raidb1Template 41 { 42 43 int NUMBER_ROUND = 5000; 44 45 boolean cleanTables = true; 46 47 public void testMultipleAdd() throws Exception 48 { 49 Connection con = getCJDBCConnection(); 50 51 MemoryProfiler memProp = new MemoryProfiler(); 52 memProp.start(); 53 54 for (int i = 0; i < NUMBER_ROUND; i++) 55 round(con); 56 57 memProp.quit(); 58 memProp.join(); 59 } 60 61 private void round(Connection con) throws Exception 62 { 63 64 batchAdd(con, "DOCUMENT"); 65 batchAdd(con, "ADDRESS"); 66 batchAdd(con, "PRODUCT"); 67 68 AbstractResultCache cache = mainVdb.getRequestManager().getResultCache(); 69 70 if (cleanTables) 71 { 72 cleanTableCache(con, "DOCUMENT", "TOTAL"); 73 cleanTableCache(con, "ADDRESS", "FIRSTNAME"); 74 cleanTableCache(con, "PRODUCT", "NAME"); 75 } 76 77 } 78 79 private void cleanTableCache(Connection con, String table, String column) 80 throws Exception 81 { 82 con.createStatement().executeUpdate( 83 "update " + table + " set " + column + "=0"); 84 } 85 86 private void batchAdd(Connection con, String table) throws Exception 87 { 88 for (int i = 0; i < 50; i++) 89 ScenarioUtility.getSingleQueryResult("select * from " + table 90 + " where ID=" + i, con, true); 91 } 92 } | Popular Tags |