Author: dr Date: Tue Feb 26 13:23:39 2008 New Revision: 7451 Log: - Added in-transaction detection and some test cases.
Modified: trunk/Search/design/class_diagram.png trunk/Search/src/handlers/solr.php trunk/Search/src/search_autoload.php trunk/Search/src/search_session.php trunk/Search/tests/handlers/solr_test.php Modified: trunk/Search/design/class_diagram.png ============================================================================== Binary files - no diff available. Modified: trunk/Search/src/handlers/solr.php ============================================================================== --- trunk/Search/src/handlers/solr.php [iso-8859-1] (original) +++ trunk/Search/src/handlers/solr.php [iso-8859-1] Tue Feb 26 13:23:39 2008 @@ -72,9 +72,15 @@ * * As transactions can be nested, this method will only call commit when * all the nested transactions have been ended. + * + * @throws ezcSearchTransactionException if no transaction is active. */ public function commit() { + if ( $this->inTransaction < 1 ) + { + throw new ezcSearchTransactionException( 'Cannot commit without a transaction.' ); + } $this->inTransaction--; if ( $this->inTransaction == 0 ) Modified: trunk/Search/src/search_autoload.php ============================================================================== --- trunk/Search/src/search_autoload.php [iso-8859-1] (original) +++ trunk/Search/src/search_autoload.php [iso-8859-1] Tue Feb 26 13:23:39 2008 @@ -15,6 +15,7 @@ 'ezcSearchDefinitionInvalidException' => 'Search/exceptions/definition_invalid.php', 'ezcSearchDefinitionMissingIdPropertyException' => 'Search/exceptions/missing_id.php', 'ezcSearchDefinitionNotFoundException' => 'Search/exceptions/definition_not_found.php', + 'ezcSearchTransactionException' => 'Search/exceptions/transaction.php', 'ezcSearchDefinitionManager' => 'Search/interfaces/definition_manager.php', 'ezcSearchHandler' => 'Search/interfaces/handler.php', 'ezcSearchIndexHandler' => 'Search/interfaces/index_handler.php', Modified: trunk/Search/src/search_session.php ============================================================================== --- trunk/Search/src/search_session.php [iso-8859-1] (original) +++ trunk/Search/src/search_session.php [iso-8859-1] Tue Feb 26 13:23:39 2008 @@ -153,6 +153,8 @@ * * As transactions can be nested, this method will only call commit when * all the nested transactions have been ended. + * + * @throws ezcSearchTransactionException if no transaction is active. */ public function commit() { Modified: trunk/Search/tests/handlers/solr_test.php ============================================================================== --- trunk/Search/tests/handlers/solr_test.php [iso-8859-1] (original) +++ trunk/Search/tests/handlers/solr_test.php [iso-8859-1] Tue Feb 26 13:23:39 2008 @@ -94,6 +94,87 @@ self::assertEquals( 0, $r->response->numFound ); } + function testCommit() + { + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<add><doc><field name="id">cfe5cc06-9b07-4e4b-930e-7e99f5202570</field><field name="name_s">solr</field></doc></add>' ); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<commit/>' ); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 1, $r->response->numFound ); + } + + function testTransaction() + { + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->beginTransaction(); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<add><doc><field name="id">cfe5cc06-9b07-4e4b-930e-7e99f5202570</field><field name="name_s">solr</field></doc></add>' ); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->commit(); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 1, $r->response->numFound ); + } + + function testNestedTransaction() + { + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->beginTransaction(); + $r = $this->solr->beginTransaction(); + + $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '<add><doc><field name="id">cfe5cc06-9b07-4e4b-930e-7e99f5202570</field><field name="name_s">solr</field></doc></add>' ); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->commit(); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 0, $r->response->numFound ); + + $r = $this->solr->commit(); + + $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); + $r = json_decode( $r ); + self::assertEquals( 1, $r->response->numFound ); + } + + function testCommitWithoutBegin() + { + try + { + $r = $this->solr->commit(); + self::fail( "Expected exception not thrown." ); + } + catch ( ezcSearchTransactionException $e ) + { + self::assertEquals( 'Cannot commit without a transaction.', $e->getMessage() ); + } + } + function testSimpleIndexWithSearch() { $r = $this->solr->search( 'solr', 'name_s' ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components