[hibernate-commits] Hibernate SVN: r15555 - in search/trunk/src: test/org/hibernate/search/test/configuration and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Nov 12 13:27:38 EST 2008


Author: sannegrinovero
Date: 2008-11-12 13:27:38 -0500 (Wed, 12 Nov 2008)
New Revision: 15555

Modified:
   search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java
   search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
   search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java
Log:
HSEARCH-298 Warn for dangerous IndexWriter settings

Modified: search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java	2008-11-12 16:37:50 UTC (rev 15554)
+++ search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java	2008-11-12 18:27:38 UTC (rev 15555)
@@ -12,6 +12,7 @@
 import org.hibernate.search.SearchException;
 import org.hibernate.search.backend.configuration.IndexWriterSetting;
 import static org.hibernate.search.backend.configuration.IndexWriterSetting.MAX_FIELD_LENGTH;
+import static org.hibernate.search.backend.configuration.IndexWriterSetting.USE_COMPOUND_FILE;
 import org.hibernate.search.backend.configuration.MaskedProperty;
 import org.hibernate.search.util.LoggerFactory;
 
@@ -46,19 +47,26 @@
 		Properties transactionProps = new MaskedProperty( indexingParameters, TRANSACTION );
 		//get keys for "batch" (defaulting to transaction)
 		Properties batchProps = new MaskedProperty( indexingParameters, BATCH, transactionProps ); //TODO to close HSEARCH-201 just remove 3° parameter
-		transactionIndexParameters = new ParameterSet( transactionProps, TRANSACTION);
-		batchIndexParameters = new ParameterSet( batchProps, BATCH);
-		doSanityChecks( transactionIndexParameters, batchIndexParameters);
+		transactionIndexParameters = new ParameterSet( transactionProps, TRANSACTION );
+		batchIndexParameters = new ParameterSet( batchProps, BATCH );
+		doSanityChecks( transactionIndexParameters, batchIndexParameters );
 	}
 
 	private void doSanityChecks(ParameterSet transParams, ParameterSet batchParams) {
 		if ( log.isWarnEnabled() ) {
 			Integer maxFieldLengthTransaction = transParams.parameters.get( MAX_FIELD_LENGTH );
-			Integer maxFieldLengthBatch = transParams.parameters.get( MAX_FIELD_LENGTH );
+			Integer maxFieldLengthBatch = batchParams.parameters.get( MAX_FIELD_LENGTH );
 			if ( notEquals( maxFieldLengthTransaction, maxFieldLengthBatch ) ) {
-				log.warn( "The max_field_length value configured for transaction is different than the value configured for batch." );
+				log.warn( "The max_field_length value configured for transaction is "
+						+ "different than the value configured for batch." );
 			}
 		}
+		Integer useCompoundTransaction = transParams.parameters.get( USE_COMPOUND_FILE );
+		Integer useCompoundBatch = batchParams.parameters.get( USE_COMPOUND_FILE );
+		if ( notEquals( useCompoundTransaction, useCompoundBatch ) ) {
+			throw new SearchException( "The IndexWriter setting \"use_compound_file\" for batch "+
+					"mode can't be different from the transaction setting." );
+		}
 	}
 
 	private boolean notEquals(Integer a, Integer b) {

Modified: search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java	2008-11-12 16:37:50 UTC (rev 15554)
+++ search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java	2008-11-12 18:27:38 UTC (rev 15555)
@@ -1,11 +1,15 @@
 // $Id$
 package org.hibernate.search.test.configuration;
 
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.AnnotationConfiguration;
 import org.hibernate.search.FullTextSession;
 import org.hibernate.search.Search;
+import org.hibernate.search.SearchException;
 import org.hibernate.search.backend.configuration.IndexWriterSetting;
 import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.store.RAMDirectoryProvider;
 import org.hibernate.search.test.SearchTestCase;
 import org.hibernate.search.util.FileHelper;
 
@@ -87,5 +91,20 @@
 		super.tearDown();
 		FileHelper.delete( getBaseIndexDir() );
 	}
+	
+	public static void assertCfgIsInvalid(AnnotationConfiguration configuration, Class[] mapping) {
+		try {
+			for ( Class annotated : mapping ) {
+				( configuration ).addAnnotatedClass( annotated );
+			}
+			configuration.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+			configuration.buildSessionFactory();
+			fail();
+		} catch (HibernateException e) {
+			//thrown exceptions means the test is ok when cause by a SearchException
+			Throwable cause = e.getCause();
+			assertTrue( cause instanceof SearchException );
+		}
+	}
 
 }

Modified: search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java	2008-11-12 16:37:50 UTC (rev 15554)
+++ search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java	2008-11-12 18:27:38 UTC (rev 15555)
@@ -4,6 +4,7 @@
 import java.io.IOException;
 import java.util.Properties;
 
+import org.hibernate.cfg.AnnotationConfiguration;
 import org.hibernate.search.backend.LuceneIndexingParameters;
 import org.hibernate.search.test.Document;
 import org.hibernate.search.test.SerializationTestHelper;
@@ -15,6 +16,7 @@
 import static org.hibernate.search.backend.configuration.IndexWriterSetting.MERGE_FACTOR;
 import static org.hibernate.search.backend.configuration.IndexWriterSetting.RAM_BUFFER_SIZE;
 import static org.hibernate.search.backend.configuration.IndexWriterSetting.USE_COMPOUND_FILE;
+import static org.hibernate.search.backend.configuration.IndexWriterSetting.MAX_FIELD_LENGTH;
 import static org.hibernate.search.test.configuration.ConfigurationReadTestCase.TransactionType.TRANSACTION;
 import static org.hibernate.search.test.configuration.ConfigurationReadTestCase.TransactionType.BATCH;
 
@@ -27,7 +29,7 @@
 		super.configure( cfg );
 		
 		cfg.setProperty( "hibernate.search.default.batch.ram_buffer_size", "1" );
-		cfg.setProperty( "hibernate.search.default.batch.use_compound_file", "true" );
+		cfg.setProperty( "hibernate.search.default.transaction.use_compound_file", "true" );
 //set by super : cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
 		
 		cfg.setProperty( "hibernate.search.default.transaction.ram_buffer_size", "2" );
@@ -51,12 +53,12 @@
 		cfg.setProperty( "hibernate.search.Documents.transaction.merge_factor", "6" );
 		cfg.setProperty( "hibernate.search.Documents.transaction.max_buffered_docs", "7" );
 		cfg.setProperty( "hibernate.search.Documents.batch.max_merge_docs", "9" );
-		
+		cfg.setProperty( "hibernate.search.Documents.transaction.max_field_length", "7" );
+		cfg.setProperty( "hibernate.search.Documents.batch.max_field_length", "9" );
 	}
 	
 	public void testDefaultIndexProviderParameters() throws Exception {
 		assertValueIsSet( Author.class, BATCH, USE_COMPOUND_FILE, 1 );
-		assertValueIsDefault( Author.class, TRANSACTION, USE_COMPOUND_FILE );
 		assertValueIsSet( Author.class, TRANSACTION, RAM_BUFFER_SIZE, 2 );
 		assertValueIsSet( Author.class, TRANSACTION, MAX_MERGE_DOCS, 9 );
 		assertValueIsSet( Author.class, TRANSACTION, MAX_BUFFERED_DOCS,  11 );
@@ -75,6 +77,12 @@
 		assertValueIsSet( Document.class, BATCH, MAX_BUFFERED_DOCS, 1000 );
 	}
 	
+	public void testMaxFieldLength() throws Exception {
+		// there should also be logged a warning being logged about these:
+		assertValueIsSet( Document.class, TRANSACTION, MAX_FIELD_LENGTH, 7 );
+		assertValueIsSet( Document.class, BATCH, MAX_FIELD_LENGTH, 9 );
+	}
+	
 	public void testExplicitBatchParameters() throws Exception {
 		assertValueIsSet( Book.class, BATCH, MAX_MERGE_DOCS, 12 );
 		assertValueIsSet( Book.class, BATCH, MAX_BUFFERED_DOCS, 14 );
@@ -106,6 +114,13 @@
 		assertEquals( param.getTransactionIndexParameters(), paramCopy.getTransactionIndexParameters() );
 	}
 	
+	public void testInvalidConfiguration() {
+		AnnotationConfiguration configuration = new AnnotationConfiguration();
+		configuration.setProperty( "hibernate.search.default.transaction.use_compound_file", "true" );
+		configuration.setProperty( "hibernate.search.default.batch.use_compound_file", "false" );
+		assertCfgIsInvalid( configuration, getMappings() );
+	}
+	
 	protected Class[] getMappings() {
 		return new Class[] {
 				Book.class,




More information about the hibernate-commits mailing list