Thread: [Batchserver-cvs] batchserver/test/org/jmonks/batchserver/framework/repository/jdbc MySQLJdbcRepos
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-13 04:51:54
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/framework/repository/jdbc In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21674/framework/repository/jdbc Modified Files: MySQLJdbcRepositoryTest.java OracleJdbcRepositoryTest.java Log Message: no message Index: OracleJdbcRepositoryTest.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/framework/repository/jdbc/OracleJdbcRepositoryTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OracleJdbcRepositoryTest.java 12 Sep 2006 23:25:23 -0000 1.1 --- OracleJdbcRepositoryTest.java 13 Sep 2006 04:51:14 -0000 1.2 *************** *** 8,13 **** --- 8,20 ---- package org.jmonks.batchserver.framework.repository.jdbc; + import java.io.InputStream; + import java.sql.Connection; + import java.sql.PreparedStatement; + import java.sql.ResultSet; + import java.sql.SQLException; + import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; + import java.util.List; import java.util.Map; import junit.framework.*; *************** *** 43,49 **** { TestSuite suite = new TestSuite(); ! //suite.addTest(new OracleJdbcRepositoryTest("testInit")); ! //suite.addTest(new OracleJdbcRepositoryTest("testJobDataTransfer")); suite.addTest(new OracleJdbcRepositoryTest("testLogStatistics")); return suite; } --- 50,57 ---- { TestSuite suite = new TestSuite(); ! suite.addTest(new OracleJdbcRepositoryTest("testInit")); ! suite.addTest(new OracleJdbcRepositoryTest("testJobDataTransfer")); suite.addTest(new OracleJdbcRepositoryTest("testLogStatistics")); + suite.addTest(new OracleJdbcRepositoryTest("testJobMgmtMntrInfo")); return suite; } *************** *** 120,123 **** --- 128,135 ---- boolean logged=repository1.logStatistics(stats); assertTrue(logged); + + JobStatistics[] loggedStats=repository1.getStatistics(); + assertNotNull(loggedStats); + assertTrue(loggedStats.length>=1); } catch(Exception exception) *************** *** 133,136 **** --- 145,174 ---- public void testJobMgmtMntrInfo() { + try + { + OracleJdbcRepository repository1=new OracleJdbcRepository(); + repository1.init(getOracleConfigMap()); + repository1.setJobName("process_file_abc"); + List list=new ArrayList(); + list.add(0, "Suresh"); + boolean registered=repository1.registerJobMgmtMntrInfo(list); + assertTrue(registered); + + Object registeredInfo=repository1.lookupJobMgmtMntrInfo(); + assertNotNull(registeredInfo); + List retrievedList=(List)registeredInfo; + assertTrue(retrievedList.size()>=1); + String savedValue=(String)retrievedList.get(0); + assertEquals("Suresh",savedValue); + + boolean unregistered=repository1.unregisterJobMgmtMntrInfo(); + assertTrue(unregistered); + registeredInfo=repository1.lookupJobMgmtMntrInfo(); + assertNull(registeredInfo); + } + catch(Exception exception) + { + fail("Oracle Jdbc Repository testLogStatistics was failed."); + } } *************** *** 166,169 **** --- 204,309 ---- this.jobName=jobName; } + public JobStatistics[] getStatistics() + { + // logger.trace("Entering getStatistics"); + // logger.debug("getStatistics :: job name = " + jobName); + // + // if(jobName==null) + // throw new IllegalArgumentException("job name cannot be null for querying the job statistics."); + + JobStatistics[] statistics=null; + List jobStatisticsList=null; + Connection connection=JdbcConnectionHelper.getConnection(this.jdbcConfigMap); + if(connection==null) + statistics=new JobStatistics[]{}; + else + { + try + { + PreparedStatement statement=connection.prepareStatement("select job_start_time,job_end_time,job_exit_code,job_exit_reason,records_processed,memory_usage from job_statistics where job_name=?"); + statement.setString(1, this.jobName); + ResultSet rs=statement.executeQuery(); + jobStatisticsList=new ArrayList(); + while(rs.next()) + { + JobStatistics statistic=new JobStatistics(jobName); + statistic.setStartTime(new java.util.Date(rs.getTimestamp(1).getTime())); + statistic.setEndTime(new java.util.Date(rs.getTimestamp(2).getTime())); + int exitCode=rs.getInt(3); + String exitReason=rs.getString(4); + ErrorCode errorCode=ErrorCode.createErrorCode(exitCode, exitReason==null?"":exitReason); + statistic.setExitCode(errorCode); + statistic.setRecordsProcessed(rs.getLong(5)); + statistic.setMaxMemeoryUsage(rs.getLong(6)); + jobStatisticsList.add(statistic); + } + rs.close(); + statement.close(); + } + catch(SQLException exception) + { + exception.printStackTrace(); + //logger.error("Exception while trying to get the job statistics for the job = " + this.jobName + ". Message = " + exception.getMessage(), exception); + } + finally + { + JdbcConnectionHelper.closeConnection(connection); + if(jobStatisticsList!=null) + { + statistics=new JobStatistics[jobStatisticsList.size()]; + jobStatisticsList.toArray(statistics); + } + else + statistics=new JobStatistics[]{}; + } + } + //logger.trace("Exiting getStatistics"); + return statistics; + } + + public Object lookupJobMgmtMntrInfo() + { + //logger.trace("Entering lookupJobMgmtMntrInfo"); + //logger.debug("lookupJobMgmtMntrInfo :: job name = " + jobName); + + //if(jobName==null) + //throw new IllegalArgumentException("jobName cannot be null to lookup the mgmt and mntr information."); + + Object registredInfo=null; + Connection connection=JdbcConnectionHelper.getConnection(this.jdbcConfigMap); + if(connection==null) + registredInfo=null; + else + { + try + { + PreparedStatement statement=connection.prepareStatement("select job_info from job_mgmt_mntr_info where job_name=?"); + statement.setString(1, this.jobName); + ResultSet rs=statement.executeQuery(); + if(rs.next()) + { + InputStream inputStream=rs.getBinaryStream(1); + registredInfo=deserializeObjectFromInputStream(inputStream); + } + else + registredInfo=null; + rs.close(); + statement.close(); + } + catch(SQLException exception) + { + exception.printStackTrace(); + //logger.error("Exception while trying to lookup mgmt and mntr info = " + this.jobName); + registredInfo=null; + } + finally + { + JdbcConnectionHelper.closeConnection(connection); + } + } + //logger.trace("Exiting lookupJobMgmtMntrInfo"); + return registredInfo; + } + } } Index: MySQLJdbcRepositoryTest.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/framework/repository/jdbc/MySQLJdbcRepositoryTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MySQLJdbcRepositoryTest.java 12 Sep 2006 23:25:23 -0000 1.2 --- MySQLJdbcRepositoryTest.java 13 Sep 2006 04:51:14 -0000 1.3 *************** *** 8,14 **** --- 8,24 ---- package org.jmonks.batchserver.framework.repository.jdbc; + import java.io.InputStream; + import java.sql.Connection; + import java.sql.PreparedStatement; + import java.sql.ResultSet; + import java.sql.SQLException; + import java.util.ArrayList; + import java.util.Calendar; import java.util.HashMap; + import java.util.List; import java.util.Map; import junit.framework.*; + import org.jmonks.batchserver.framework.ErrorCode; + import org.jmonks.batchserver.framework.JobStatistics; import org.jmonks.batchserver.framework.util.JdbcConnectionHelper; *************** *** 39,43 **** TestSuite suite = new TestSuite(); suite.addTest(new MySQLJdbcRepositoryTest("testInit")); ! suite.addTest(new MySQLJdbcRepositoryTest("testSendDataToNextJob")); return suite; } --- 49,55 ---- TestSuite suite = new TestSuite(); suite.addTest(new MySQLJdbcRepositoryTest("testInit")); ! suite.addTest(new MySQLJdbcRepositoryTest("testJobDataTransfer")); ! suite.addTest(new MySQLJdbcRepositoryTest("testLogStatistics")); ! suite.addTest(new MySQLJdbcRepositoryTest("testJobMgmtMntrInfo")); return suite; } *************** *** 60,101 **** /** ! * Test of clearDataTransferredFromThisJob method, of class org.jmonks.batchserver.framework.repository.jdbc.JdbcRepository. ! */ ! public void testClearDataTransferredFromThisJob() ! { ! } ! ! /** ! * Test of sendDataToNextJob method, of class org.jmonks.batchserver.framework.repository.jdbc.JdbcRepository. */ ! public void testSendDataToNextJob() { try { ! MySQLJdbcRepository repository=new MySQLJdbcRepository(); ! repository.init(getMySQLConfigMap()); ! repository.setJobName("process_file_abc"); Map dataGoingToBeSend=new HashMap(); dataGoingToBeSend.put("author","suresh"); ! boolean sendStatus=repository.sendDataToNextJob("ID1", "process_file_xyz", dataGoingToBeSend); assertEquals(true, sendStatus); ! Object dataSent=repository.getDataFromPreviousJob("ID1", "process_file_xyz"); assertNotNull(dataSent); Map dataSentMap=(Map)dataSent; String author=(String)dataSentMap.get("author"); assertEquals("suresh",author); } catch(Exception exception) { ! fail("MySQL Jdbc Repository testSendDataToNextJob was failed."); } } - /** - * Test of getDataFromPreviousJob method, of class org.jmonks.batchserver.framework.repository.jdbc.JdbcRepository. - */ - public void testGetDataFromPreviousJob() - { - } /** --- 72,108 ---- /** ! * Test of testJobDataTransfer covers all the cases for the job data transfer. */ ! public void testJobDataTransfer() { try { ! MySQLJdbcRepository repository1=new MySQLJdbcRepository(); ! repository1.init(getMySQLConfigMap()); ! repository1.setJobName("process_file_abc"); Map dataGoingToBeSend=new HashMap(); dataGoingToBeSend.put("author","suresh"); ! boolean sendStatus=repository1.sendDataToNextJob("ID1", "process_file_xyz", dataGoingToBeSend); assertEquals(true, sendStatus); ! ! MySQLJdbcRepository repository2=new MySQLJdbcRepository(); ! repository2.init(getMySQLConfigMap()); ! repository2.setJobName("process_file_xyz"); ! Object dataSent=repository2.getDataFromPreviousJob("ID1", "process_file_abc"); assertNotNull(dataSent); Map dataSentMap=(Map)dataSent; String author=(String)dataSentMap.get("author"); assertEquals("suresh",author); + + repository1.clearDataTransferredFromThisJob(); + Object clearedDataSent=repository2.getDataFromPreviousJob("ID1", "process_file_abc"); + assertNull(clearedDataSent); } catch(Exception exception) { ! fail("MySQL Jdbc Repository testJobDataTransfer was failed."); } } /** *************** *** 104,122 **** public void testLogStatistics() { } /** ! * Test of unregisterJobMgmtMntrInfo method, of class org.jmonks.batchserver.framework.repository.jdbc.JdbcRepository. ! */ ! public void testUnregisterJobMgmtMntrInfo() ! { ! } ! ! /** ! * Test of registerJobMgmtMntrInfo method, of class org.jmonks.batchserver.framework.repository.jdbc.JdbcRepository. */ ! public void testRegisterJobMgmtMntrInfo() { } --- 111,172 ---- public void testLogStatistics() { + try + { + MySQLJdbcRepository repository1=new MySQLJdbcRepository(); + repository1.init(getMySQLConfigMap()); + repository1.setJobName("process_file_abc"); + + JobStatistics stats=new JobStatistics("process_file_abc"); + stats.setStartTime(Calendar.getInstance().getTime()); + stats.setEndTime(Calendar.getInstance().getTime()); + stats.setExitCode(ErrorCode.createErrorCode(10001, "This is my error code.")); + stats.setMaxMemeoryUsage(123456); + stats.setRecordsProcessed(123456); + + boolean logged=repository1.logStatistics(stats); + assertTrue(logged); + + JobStatistics[] loggedStats=repository1.getStatistics(); + assertNotNull(loggedStats); + assertTrue(loggedStats.length>=1); + } + catch(Exception exception) + { + fail("MySQL Jdbc Repository testLogStatistics was failed."); + } } /** ! * Test of testJobMgmtMntrInfo covers all the cases for the job mgmt and mntr updates. */ ! public void testJobMgmtMntrInfo() { + try + { + MySQLJdbcRepository repository1=new MySQLJdbcRepository(); + repository1.init(getMySQLConfigMap()); + repository1.setJobName("process_file_abc"); + List list=new ArrayList(); + list.add(0, "Suresh"); + boolean registered=repository1.registerJobMgmtMntrInfo(list); + assertTrue(registered); + + Object registeredInfo=repository1.lookupJobMgmtMntrInfo(); + assertNotNull(registeredInfo); + List retrievedList=(List)registeredInfo; + assertTrue(retrievedList.size()>=1); + String savedValue=(String)retrievedList.get(0); + assertEquals("Suresh",savedValue); + + boolean unregistered=repository1.unregisterJobMgmtMntrInfo(); + assertTrue(unregistered); + registeredInfo=repository1.lookupJobMgmtMntrInfo(); + assertNull(registeredInfo); + } + catch(Exception exception) + { + fail("MySQL Jdbc Repository testLogStatistics was failed."); + } } *************** *** 134,141 **** class MySQLJdbcRepository extends JdbcRepository { - - /** - * Creates a new instance of MySQLJdbcRepository - */ public MySQLJdbcRepository() { --- 184,187 ---- *************** *** 151,154 **** --- 197,303 ---- this.jobName=jobName; } + + public JobStatistics[] getStatistics() + { + // logger.trace("Entering getStatistics"); + // logger.debug("getStatistics :: job name = " + jobName); + // + // if(jobName==null) + // throw new IllegalArgumentException("job name cannot be null for querying the job statistics."); + + JobStatistics[] statistics=null; + List jobStatisticsList=null; + Connection connection=JdbcConnectionHelper.getConnection(this.jdbcConfigMap); + if(connection==null) + statistics=new JobStatistics[]{}; + else + { + try + { + PreparedStatement statement=connection.prepareStatement("select job_start_time,job_end_time,job_exit_code,job_exit_reason,records_processed,memory_usage from job_statistics where job_name=?"); + statement.setString(1, this.jobName); + ResultSet rs=statement.executeQuery(); + jobStatisticsList=new ArrayList(); + while(rs.next()) + { + JobStatistics statistic=new JobStatistics(jobName); + statistic.setStartTime(new java.util.Date(rs.getTimestamp(1).getTime())); + statistic.setEndTime(new java.util.Date(rs.getTimestamp(2).getTime())); + int exitCode=rs.getInt(3); + String exitReason=rs.getString(4); + ErrorCode errorCode=ErrorCode.createErrorCode(exitCode, exitReason==null?"":exitReason); + statistic.setExitCode(errorCode); + statistic.setRecordsProcessed(rs.getLong(5)); + statistic.setMaxMemeoryUsage(rs.getLong(6)); + jobStatisticsList.add(statistic); + } + rs.close(); + statement.close(); + } + catch(SQLException exception) + { + exception.printStackTrace(); + //logger.error("Exception while trying to get the job statistics for the job = " + this.jobName + ". Message = " + exception.getMessage(), exception); + } + finally + { + JdbcConnectionHelper.closeConnection(connection); + if(jobStatisticsList!=null) + { + statistics=new JobStatistics[jobStatisticsList.size()]; + jobStatisticsList.toArray(statistics); + } + else + statistics=new JobStatistics[]{}; + } + } + //logger.trace("Exiting getStatistics"); + return statistics; + } + + public Object lookupJobMgmtMntrInfo() + { + //logger.trace("Entering lookupJobMgmtMntrInfo"); + //logger.debug("lookupJobMgmtMntrInfo :: job name = " + jobName); + + //if(jobName==null) + //throw new IllegalArgumentException("jobName cannot be null to lookup the mgmt and mntr information."); + + Object registredInfo=null; + Connection connection=JdbcConnectionHelper.getConnection(this.jdbcConfigMap); + if(connection==null) + registredInfo=null; + else + { + try + { + PreparedStatement statement=connection.prepareStatement("select job_info from job_mgmt_mntr_info where job_name=?"); + statement.setString(1, this.jobName); + ResultSet rs=statement.executeQuery(); + if(rs.next()) + { + InputStream inputStream=rs.getBinaryStream(1); + registredInfo=deserializeObjectFromInputStream(inputStream); + } + else + registredInfo=null; + rs.close(); + statement.close(); + } + catch(SQLException exception) + { + exception.printStackTrace(); + //logger.error("Exception while trying to lookup mgmt and mntr info = " + this.jobName); + registredInfo=null; + } + finally + { + JdbcConnectionHelper.closeConnection(connection); + } + } + //logger.trace("Exiting lookupJobMgmtMntrInfo"); + return registredInfo; + } + } } |