Author: stliu
Date: 2010-05-12 07:03:46 -0400 (Wed, 12 May 2010)
New Revision: 19474
Added:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/MockIndexReader.java
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestManipulatorPerDP.java
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/SharingBufferIndexProviderTest.java
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestableSharingBufferReaderProvider.java
Log:
JBPAPP-2289 HSEARCH unit test failure:
org.hibernate.search.test.reader.functionality.TestableSharingBufferReaderProvider
Added:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/MockIndexReader.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/MockIndexReader.java
(rev 0)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/MockIndexReader.java 2010-05-12
11:03:46 UTC (rev 19474)
@@ -0,0 +1,209 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.search.test.reader.functionality;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Vector;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldSelector;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
+import org.apache.lucene.index.TermEnum;
+import org.apache.lucene.index.TermFreqVector;
+import org.apache.lucene.index.TermPositions;
+import org.apache.lucene.index.TermVectorMapper;
+
+
+/**
+ *
+ * @author stliu
+ */
+public class MockIndexReader extends IndexReader {
+
+ private final AtomicBoolean closed = new AtomicBoolean( false );
+ private final AtomicBoolean hasAlreadyBeenReOpened = new AtomicBoolean( false );
+ private final AtomicBoolean isIndexReaderCurrent;
+ private Vector<MockIndexReader> createdReadersHistory;
+ MockIndexReader(AtomicBoolean isIndexReaderCurrent,Vector<MockIndexReader>
createdReadersHistory) {
+ this.isIndexReaderCurrent = isIndexReaderCurrent;
+ if ( !isIndexReaderCurrent.compareAndSet( false, true ) ) {
+ throw new IllegalStateException( "Unnecessarily reopened" );
+ }
+ createdReadersHistory.add( this );
+ this.createdReadersHistory=createdReadersHistory;
+ }
+
+ MockIndexReader(AtomicBoolean isIndexReaderCurrent) {
+ this.isIndexReaderCurrent = isIndexReaderCurrent;
+ if ( !isIndexReaderCurrent.compareAndSet( false, true ) ) {
+ throw new IllegalStateException( "Unnecessarily reopened" );
+ }
+ }
+
+
+ public final boolean isClosed() {
+ return closed.get();
+ }
+
+ @Override
+ protected void doClose() throws IOException {
+ boolean okToClose = closed.compareAndSet( false, true );
+ if ( !okToClose ) {
+ throw new IllegalStateException( "Attempt to close a closed IndexReader" );
+ }
+ if ( !hasAlreadyBeenReOpened.get() ) {
+ throw new IllegalStateException( "Attempt to close the most current
IndexReader" );
+ }
+ }
+
+ @Override
+ public synchronized IndexReader reopen() {
+ if ( isIndexReaderCurrent.get() ) {
+ return this;
+ }
+ else {
+ if ( hasAlreadyBeenReOpened.compareAndSet( false, true ) ) {
+ MockIndexReader mockIndexReader = new MockIndexReader( isIndexReaderCurrent );
+ if (createdReadersHistory!=null){
+ createdReadersHistory.add( mockIndexReader );
+ }
+ return mockIndexReader;
+ }
+ else {
+ throw new IllegalStateException( "Attempt to reopen an old IndexReader more than
once" );
+ }
+ }
+ }
+
+ @Override
+ protected void doCommit() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void doDelete(int docNum) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void doSetNorm(int doc, String field, byte value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void doUndeleteAll() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int docFreq(Term t) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Document document(int n, FieldSelector fieldSelector) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection getFieldNames(FieldOption fldOption) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TermFreqVector getTermFreqVector(int docNumber, String field) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getTermFreqVector(int docNumber, String field, TermVectorMapper mapper) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getTermFreqVector(int docNumber, TermVectorMapper mapper) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TermFreqVector[] getTermFreqVectors(int docNumber) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasDeletions() {
+ return false;//just something to make MultiReader constructor happy
+ }
+
+ @Override
+ public boolean isDeleted(int n) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int maxDoc() {
+ return 10;//just something to make MultiReader constructor happy
+ }
+
+ @Override
+ public byte[] norms(String field) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void norms(String field, byte[] bytes, int offset) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int numDocs() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TermDocs termDocs() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TermPositions termPositions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TermEnum terms() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TermEnum terms(Term t) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/SharingBufferIndexProviderTest.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/SharingBufferIndexProviderTest.java 2010-05-12
06:25:42 UTC (rev 19473)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/SharingBufferIndexProviderTest.java 2010-05-12
11:03:46 UTC (rev 19474)
@@ -12,8 +12,6 @@
import org.apache.lucene.index.IndexReader;
import org.hibernate.search.store.DirectoryProvider;
-import
org.hibernate.search.test.reader.functionality.TestableSharingBufferReaderProvider.MockIndexReader;
-import
org.hibernate.search.test.reader.functionality.TestableSharingBufferReaderProvider.TestManipulatorPerDP;
import junit.framework.TestCase;
Added:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestManipulatorPerDP.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestManipulatorPerDP.java
(rev 0)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestManipulatorPerDP.java 2010-05-12
11:03:46 UTC (rev 19474)
@@ -0,0 +1,49 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.search.test.reader.functionality;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.store.RAMDirectoryProvider;
+
+/**
+ *
+ * @author stliu
+ */
+public class TestManipulatorPerDP {
+ final AtomicBoolean isIndexReaderCurrent = new AtomicBoolean( false );//starts at true,
see MockIndexReader contructor
+ final AtomicBoolean isReaderCreated = new AtomicBoolean( false );
+ final DirectoryProvider dp = new RAMDirectoryProvider();
+
+ public TestManipulatorPerDP(int seed) {
+ dp.initialize( "dp" + seed, null, null );
+ dp.start();
+ }
+
+ public void setIndexChanged() {
+ isIndexReaderCurrent.set( false );
+ }
+}
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestableSharingBufferReaderProvider.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestableSharingBufferReaderProvider.java 2010-05-12
06:25:42 UTC (rev 19473)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/reader/functionality/TestableSharingBufferReaderProvider.java 2010-05-12
11:03:46 UTC (rev 19474)
@@ -2,34 +2,22 @@
package org.hibernate.search.test.reader.functionality;
import java.io.IOException;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.FieldSelector;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.index.TermEnum;
-import org.apache.lucene.index.TermFreqVector;
-import org.apache.lucene.index.TermPositions;
-import org.apache.lucene.index.TermVectorMapper;
import org.apache.lucene.store.Directory;
-
import org.hibernate.search.SearchException;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.reader.ReaderProviderHelper;
import org.hibernate.search.reader.SharingBufferReaderProvider;
import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.search.store.RAMDirectoryProvider;
/**
* @author Sanne Grinovero
@@ -49,22 +37,6 @@
}
}
- public static class TestManipulatorPerDP {
- private final AtomicBoolean isIndexReaderCurrent = new AtomicBoolean( false );//starts
at true, see MockIndexReader contructor
- private final AtomicBoolean isReaderCreated = new AtomicBoolean( false );
- private final DirectoryProvider dp = new RAMDirectoryProvider();
-
- public TestManipulatorPerDP(int seed) {
- dp.initialize( "dp" + seed, null, null );
- dp.start();
- }
-
- public void setIndexChanged() {
- isIndexReaderCurrent.set( false );
- }
-
- }
-
public boolean isReaderCurrent(MockIndexReader reader) {
//avoid usage of allReaders or test would be useless
for ( PerDirectoryLatestReader latest : currentReaders.values() ) {
@@ -83,7 +55,7 @@
throw new IllegalStateException( "IndexReader1 created twice" );
}
else {
- return new MockIndexReader( manipulatorPerDP.isIndexReaderCurrent );
+ return new MockIndexReader( manipulatorPerDP.isIndexReaderCurrent,
createdReadersHistory );
}
}
@@ -121,155 +93,6 @@
return ( MockIndexReader ) indexReaders[0];
}
- public class MockIndexReader extends IndexReader {
+
- private final AtomicBoolean closed = new AtomicBoolean( false );
- private final AtomicBoolean hasAlreadyBeenReOpened = new AtomicBoolean( false );
- private final AtomicBoolean isIndexReaderCurrent;
-
- MockIndexReader(AtomicBoolean isIndexReaderCurrent) {
- this.isIndexReaderCurrent = isIndexReaderCurrent;
- if ( !isIndexReaderCurrent.compareAndSet( false, true ) ) {
- throw new IllegalStateException( "Unnecessarily reopened" );
- }
- createdReadersHistory.add( this );
- }
-
- public final boolean isClosed() {
- return closed.get();
- }
-
- @Override
- protected void doClose() throws IOException {
- boolean okToClose = closed.compareAndSet( false, true );
- if ( !okToClose ) {
- throw new IllegalStateException( "Attempt to close a closed IndexReader"
);
- }
- if ( !hasAlreadyBeenReOpened.get() ) {
- throw new IllegalStateException( "Attempt to close the most current
IndexReader" );
- }
- }
-
- @Override
- public synchronized IndexReader reopen() {
- if ( isIndexReaderCurrent.get() ) {
- return this;
- }
- else {
- if ( hasAlreadyBeenReOpened.compareAndSet( false, true ) ) {
- return new MockIndexReader( isIndexReaderCurrent );
- }
- else {
- throw new IllegalStateException( "Attempt to reopen an old IndexReader more
than once" );
- }
- }
- }
-
- @Override
- protected void doCommit() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected void doDelete(int docNum) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected void doSetNorm(int doc, String field, byte value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected void doUndeleteAll() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int docFreq(Term t) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Document document(int n, FieldSelector fieldSelector) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Collection getFieldNames(FieldOption fldOption) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TermFreqVector getTermFreqVector(int docNumber, String field) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void getTermFreqVector(int docNumber, String field, TermVectorMapper mapper) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void getTermFreqVector(int docNumber, TermVectorMapper mapper) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TermFreqVector[] getTermFreqVectors(int docNumber) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean hasDeletions() {
- return false;//just something to make MultiReader constructor happy
- }
-
- @Override
- public boolean isDeleted(int n) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int maxDoc() {
- return 10;//just something to make MultiReader constructor happy
- }
-
- @Override
- public byte[] norms(String field) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void norms(String field, byte[] bytes, int offset) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int numDocs() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TermDocs termDocs() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TermPositions termPositions() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TermEnum terms() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TermEnum terms(Term t) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- }
-
}