Tag: cws_src680_rowsetdel User: fs Date: 06/01/18 23:13:54 Modified: /dba/dbaccess/qa/complex/dbaccess/ RowSet.java
Log: #i55731# more tests. Some of the currently fail and have to be fixed separately File Changes: Directory: /dba/dbaccess/qa/complex/dbaccess/ ============================================= File [changed]: RowSet.java Url: http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/RowSet.java?r1=1.4.68.2&r2=1.4.68.3 Delta lines: +148 -99 ---------------------- --- RowSet.java 18 Jan 2006 15:25:42 -0000 1.4.68.2 +++ RowSet.java 19 Jan 2006 07:13:51 -0000 1.4.68.3 @@ -4,9 +4,9 @@ * * $RCSfile: RowSet.java,v $ * - * $Revision: 1.4.68.2 $ + * $Revision: 1.4.68.3 $ * - * last change: $Author: fs $ $Date: 2006/01/18 15:25:42 $ + * last change: $Author: fs $ $Date: 2006/01/19 07:13:51 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -71,37 +71,51 @@ XPropertySet m_rowSetProperties; // -------------------------------------------------------------------------------------------------------- - class CloneThread implements Runnable + class ResultSetMovementStress implements Runnable { - XResultSet clone; - XRow row; - int id; - public CloneThread(XResultSet _clone,int _id) throws java.lang.Exception { - clone = _clone; - row = (XRow)UnoRuntime.queryInterface(XRow.class,clone); - id = _id; + XResultSet m_resultSet; + XRow m_row; + int m_id; + public ResultSetMovementStress(XResultSet _resultSet,int _id) throws java.lang.Exception { + m_resultSet = _resultSet; + m_row = (XRow)UnoRuntime.queryInterface(XRow.class,m_resultSet); + m_id = _id; } public void run() { - try{ - clone.beforeFirst(); - for ( int i = 0; i < MAX_TABLE_ROWS && !clone.isAfterLast(); ++i ){ - boolean move = clone.next(); - if ( move ){ - int pos = clone.getRow(); - int val = row.getInt(1); - log.println("Clone Move(" + id +") Pos: " + pos + " Val: " + val); - testPosition(clone,row,"Clone Move(" + id +")"); - int pos2 = clone.getRow(); - log.println("Clone GetR(" + id +") Pos: " + pos2 + " Val: " + val); - assure("CloneThread wrong position: " + i + " Pos1: " + pos + " Pos2: " + pos2,pos == pos2); - } + try + { + m_resultSet.beforeFirst(); + for ( int i = 0; m_resultSet.next(); ++i ) + { + int pos = m_resultSet.getRow(); + int val = m_row.getInt(1); + testPosition( m_resultSet, m_row, i + 1, "clone move(" + m_id +")" ); + int pos2 = m_resultSet.getRow(); + assure("ResultSetMovementStress wrong position: " + i + " Pos1: " + pos + " Pos2: " + pos2,pos == pos2); } }catch(AssureException e){ }catch(Exception e){ - assure("CloneThread(" + id + ") failed: " + e,false); + assure("ResultSetMovementStress(" + m_id + ") failed: " + e,false); + } + } } + + // -------------------------------------------------------------------------------------------------------- + public String[] getTestMethodNames() { + return new String[] + { + "testRowSet", + "testRowSetEvents", + "testDeleteBehavior", + "testCloneMovesPlusDeletions", + "testCloneMovesPlusInsertions" + }; } + + // -------------------------------------------------------------------------------------------------------- + public String getTestObjectName() { + return "RowSet"; } // -------------------------------------------------------------------------------------------------------- @@ -145,22 +159,6 @@ // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() { - return new String[] - { - "testRowSet", - "testRowSetEvents", - "testDeleteBehavior", - "testCloneMovesPlusDeletions" - }; - } - - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() { - return "RowSet"; - } - - // -------------------------------------------------------------------------------------------------------- private XMultiServiceFactory getFactory() { return (XMultiServiceFactory)param.getMSF(); @@ -192,11 +190,11 @@ log.println("testing testRowSet"); createTestCase(); - // 1st test + // sequential postioning m_resultSet.beforeFirst(); - testValueAndPosition(m_resultSet,m_row); + testSequentialPositining(m_resultSet,m_row); - // 2nd test + // absolute positioning testAbsolutePositioning(m_resultSet,m_row); // 3rd test @@ -204,7 +202,8 @@ // 4th test test4(m_resultSet); - // test5(m_resultSet); + // concurrent (multi threaded) access to the row set and its clones + testConcurrentAccess(m_resultSet); } // -------------------------------------------------------------------------------------------------------- @@ -231,37 +230,43 @@ } // -------------------------------------------------------------------------------------------------------- - void testPosition(XResultSet m_resultSet,XRow m_row,String errorMsg) throws java.lang.Exception { + void testPosition(XResultSet m_resultSet,XRow m_row,int expectedValue,String location) throws SQLException + { int val = m_row.getInt(1); int pos = m_resultSet.getRow(); - assure(errorMsg + " Value is not identical: " + pos + " (Pos) != " + val + " (Val)",val == pos); + assure( location + ": value/position do not match: " + pos + " (pos) != " + val + " (val)", val == pos ); + assure( location + ": value/position are not as expected: " + pos + " (pos) != " + expectedValue + " (expected)", val == expectedValue ); } // -------------------------------------------------------------------------------------------------------- - void testValueAndPosition(XResultSet m_resultSet,XRow m_row){ - try{ + void testSequentialPositining(XResultSet _resultSet,XRow _row) + { + try + { // 1st test int i=1; - while(m_resultSet.next()){ - int val = m_row.getInt(1); - int pos = m_resultSet.getRow(); - assure("Value is not identical: " + i + " != " + val,val == i); - assure("Row is not identical: " + i + " != " + pos,pos == i); + while(_resultSet.next()) + { + testPosition( _resultSet, _row, i, "testSequentialPositining" ); ++i; } - }catch(AssureException e){ - }catch(Exception e){ - assure("testValueAndPosition failed: " + e,false); + } + catch(AssureException e) + { + } + catch(Exception e) + { + assure("testSequentialPositining failed: " + e,false); } } // -------------------------------------------------------------------------------------------------------- - void testAbsolutePositioning(XResultSet m_resultSet,XRow m_row){ + void testAbsolutePositioning(XResultSet _resultSet,XRow _row){ try{ for(int i = 1 ; i <= MAX_FETCH_ROWS ; ++i){ int calcPos = (MAX_TABLE_ROWS % i) + 1; - assure( "testAbsolutePositioning failed", m_resultSet.absolute(calcPos) ); - testPosition(m_resultSet,m_row,"testAbsolutePositioning"); + assure( "testAbsolutePositioning failed", _resultSet.absolute(calcPos) ); + testPosition( _resultSet, _row, calcPos, "testAbsolutePositioning" ); } }catch(AssureException e){ }catch(Exception e){ @@ -270,17 +275,16 @@ } // -------------------------------------------------------------------------------------------------------- - void test3(XResultSet clone,XResultSet m_resultSet){ + void test3(XResultSet clone,XResultSet _resultSet){ try{ - XRow m_row = (XRow)UnoRuntime.queryInterface(XRow.class,m_resultSet); + XRow _row = (XRow)UnoRuntime.queryInterface(XRow.class,_resultSet); XRow cloneRow = (XRow)UnoRuntime.queryInterface(XRow.class,clone); for(int i = 1 ; i <= MAX_FETCH_ROWS ; ++i){ int calcPos = (MAX_TABLE_ROWS % i) + 1; - if ( clone.absolute(calcPos) ){ - int val = cloneRow.getInt(1); - int pos = clone.getRow(); - assure("Value is not identical: " + pos + " != " + val,val == pos); - testAbsolutePositioning(m_resultSet,m_row); + if ( clone.absolute(calcPos) ) + { + testPosition( clone, cloneRow, calcPos, "test3" ); + testAbsolutePositioning(_resultSet,_row); testAbsolutePositioning(clone,cloneRow); } } @@ -291,23 +295,20 @@ } // -------------------------------------------------------------------------------------------------------- - void test4(XResultSet m_resultSet){ + void test4(XResultSet _resultSet){ try{ - XRow m_row = (XRow)UnoRuntime.queryInterface(XRow.class,m_resultSet); - m_resultSet.beforeFirst(); + XRow _row = (XRow)UnoRuntime.queryInterface(XRow.class,_resultSet); + _resultSet.beforeFirst(); for(int i = 1 ; i <= MAX_TABLE_ROWS ; ++i){ - m_resultSet.next(); + _resultSet.next(); XResultSet clone = createClone(); XRow cloneRow = (XRow)UnoRuntime.queryInterface(XRow.class,clone); int calcPos = MAX_TABLE_ROWS - 1; - if ( calcPos != 0 && clone.absolute(calcPos) ){ - int val = cloneRow.getInt(1); - int pos = clone.getRow(); - assure("Value is not identical: " + pos + " != " + val,val == pos); - val = m_row.getInt(1); - pos = m_resultSet.getRow(); - assure("Value is not identical: " + pos + " != " + val,val == pos && val == i); + if ( calcPos != 0 && clone.absolute(calcPos) ) + { + testPosition( clone, cloneRow, calcPos, "test4: clone" ); + testPosition( _resultSet, _row, i, "test4: rowset" ); } } }catch(AssureException e){ @@ -317,29 +318,34 @@ } // -------------------------------------------------------------------------------------------------------- - void test5(XResultSet m_resultSet){ + void testConcurrentAccess(XResultSet _resultSet) + { log.println("testing Thread"); - try{ - XRow m_row = (XRow)UnoRuntime.queryInterface(XRow.class,m_resultSet); - m_resultSet.beforeFirst(); - Thread t1 = new Thread(new CloneThread( createClone(),1)); - t1.start(); - System.out.println("Start Thread 1"); -/* - Thread t2 = new Thread(new CloneThread( createClone(),2)); - t2.start(); - System.out.println("Start Thread 2"); - */ - Thread t3 = new Thread(new CloneThread( m_resultSet,3)); - t3.start(); - System.out.println("Start Thread 3"); - t1.join(); -// t2.join(); - t3.join(); - }catch(AssureException e){ - }catch(Exception e){ + try + { + XRow _row = (XRow)UnoRuntime.queryInterface(XRow.class,_resultSet); + _resultSet.beforeFirst(); + + final int numberOfThreads = 2; + + Thread threads[] = new Thread[numberOfThreads]; + for ( int i=0; i<numberOfThreads; ++i ) + { + threads[i] = new Thread( new ResultSetMovementStress( createClone(), i ) ); + System.out.println( "starting thread " + String.valueOf(i+1) + " of " + String.valueOf( numberOfThreads ) ); + threads[i].start(); + } + + for ( int i=0; i<numberOfThreads; ++i ) + threads[i].join(); + } + catch(AssureException e) + { + } + catch(Exception e) + { e.printStackTrace(); - assure("test5 failed: " + e,false); + assure("testConcurrentAccess failed: " + e,false); } } // -------------------------------------------------------------------------------------------------------- @@ -726,5 +732,48 @@ assure( "moving to the next record after |deleteRow| and clone moves failed", m_resultSet.next() ); assure( "wrong position after |deleteRow| and clone movement", !m_resultSet.isAfterLast() && !m_resultSet.isBeforeFirst() ); assure( "wrong absolute position after |deleteRow| and clone movement", m_resultSet.getRow() == positionBefore ); + } + + // -------------------------------------------------------------------------------------------------------- + /** checks whether insertions on the main RowSet properly interfere (or don't interfere) with the movement + * on a clone of the RowSet + */ + public void testCloneMovesPlusInsertions() throws SQLException, UnknownPropertyException, WrappedTargetException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException + { + createTestCase(); + // ensure that all records are known + m_rowSetProperties.setPropertyValue( "FetchSize", new Integer( 10 ) ); + + XResultSet clone = createClone(); + XRow cloneRow = (XRow)UnoRuntime.queryInterface( XRow.class, clone ); + + // ..................................................................................................... + // first check the basic scenario without the |moveToInsertRow| |moveToCurrentRow|, to ensure that + // really those are broken, if at all + m_resultSet.last(); + clone.first(); + clone.absolute( 11 ); + clone.first(); + + int rowValue1 = m_row.getInt(1); + int rowPos = m_resultSet.getRow(); + int rowValue2 = m_row.getInt(1); + assure( "repeated query for the same column value delivers different values (" + rowValue1 + " and " + rowValue2 + ")", + rowValue1 == rowValue2 ); + + testPosition( clone, cloneRow, 1, "mixed clone/rowset move: clone check" ); + testPosition( m_resultSet, m_row, MAX_TABLE_ROWS, "mixed clone/rowset move: rowset check" ); + + // ..................................................................................................... + // now the complete scenario + m_resultSet.last(); + m_resultSetUpdate.moveToInsertRow(); + clone.first(); + clone.absolute( 11 ); + clone.first(); + m_resultSetUpdate.moveToCurrentRow(); + + testPosition( clone, cloneRow, 1, "mixed clone/rowset move/insertion: clone check" ); + testPosition( m_resultSet, m_row, 1, "mixed clone/rowset move/insertion: rowset check" ); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
