You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/08/23 19:00:47 UTC

svn commit: r988206 [4/4] - in /lucene/dev/trunk: ./ lucene/ lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/ lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/ lucene/contrib/instantiated/src/test/org/...

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java Mon Aug 23 17:00:43 2010
@@ -32,7 +32,6 @@ import org.apache.lucene.index.RandomInd
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.*;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.MockRAMDirectory;
 
 /*******************************************************************************
  * Tests the span query bug in Lucene. It demonstrates that SpanTermQuerys don't

Copied: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java (from r988190, lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java?p2=lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java&p1=lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.java&r1=988190&r2=988206&rev=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Mon Aug 23 17:00:43 2010
@@ -31,11 +31,12 @@ import java.util.ArrayList;
 import java.util.Arrays;
 
 /**
- * This is a subclass of RAMDirectory that adds methods
+ * This is a Directory Wrapper that adds methods
  * intended to be used only by unit tests.
  */
 
-public class MockRAMDirectory extends RAMDirectory {
+public class MockDirectoryWrapper extends Directory {
+  final Directory delegate;
   long maxSize;
 
   // Max actual bytes used. This is set by MockRAMOutputStream:
@@ -63,12 +64,8 @@ public class MockRAMDirectory extends RA
       unSyncedFiles = new HashSet<String>();
   }
 
-  public MockRAMDirectory() {
-    super();
-    init();
-  }
-  public MockRAMDirectory(Directory dir) throws IOException {
-    super(dir);
+  public MockDirectoryWrapper(Directory delegate) {
+    this.delegate = delegate;
     init();
   }
 
@@ -81,7 +78,11 @@ public class MockRAMDirectory extends RA
   @Deprecated
   @Override
   public void sync(String name) throws IOException {
-    sync(Collections.singleton(name));
+    maybeThrowDeterministicException();
+    if (crashed)
+      throw new IOException("cannot sync after crash");
+    unSyncedFiles.remove(name);
+    delegate.sync(name);
   }
 
   @Override
@@ -91,6 +92,19 @@ public class MockRAMDirectory extends RA
     if (crashed)
       throw new IOException("cannot sync after crash");
     unSyncedFiles.removeAll(names);
+    delegate.sync(names);
+  }
+  
+  public synchronized final long sizeInBytes() throws IOException {
+    if (delegate instanceof RAMDirectory)
+      return ((RAMDirectory) delegate).sizeInBytes();
+    else {
+      // hack
+      long size = 0;
+      for (String file : delegate.listAll())
+        size += delegate.fileLength(file);
+      return size;
+    }
   }
 
   /** Simulates a crash of OS or machine by overwriting
@@ -101,23 +115,52 @@ public class MockRAMDirectory extends RA
     Iterator<String> it = unSyncedFiles.iterator();
     unSyncedFiles = new HashSet<String>();
     int count = 0;
-    while(it.hasNext()) {
-      String name = it.next();
-      RAMFile file = fileMap.get(name);
-      if (count % 3 == 0) {
-        deleteFile(name, true);
-      } else if (count % 3 == 1) {
-        // Zero out file entirely
-        final int numBuffers = file.numBuffers();
-        for(int i=0;i<numBuffers;i++) {
-          byte[] buffer = file.getBuffer(i);
-          Arrays.fill(buffer, (byte) 0);
+    if (!(delegate instanceof RAMDirectory)) {
+      while(it.hasNext()) {
+        String name = it.next();
+        if (count % 3 == 0) {
+          deleteFile(name, true);
+        } else if (count % 3 == 1) {
+          // Zero out file entirely
+          long length = fileLength(name);
+          byte[] zeroes = new byte[256];
+          long upto = 0;
+          IndexOutput out = delegate.createOutput(name);
+          while(upto < length) {
+            final int limit = (int) Math.min(length-upto, zeroes.length);
+            out.writeBytes(zeroes, 0, limit);
+            upto += limit;
+          }
+          out.close();
+        } else if (count % 3 == 2) {
+          // Truncate the file:
+          IndexOutput out = delegate.createOutput(name);
+          out.setLength(fileLength(name)/2);
+          out.close();
+        }
+        count++;
+      }
+    } else {
+
+      RAMDirectory ramDir = (RAMDirectory) delegate;
+      while(it.hasNext()) {
+        String name = it.next();
+        RAMFile file = ramDir.fileMap.get(name);
+        if (count % 3 == 0) {
+          deleteFile(name, true);
+        } else if (count % 3 == 1) {
+          // Zero out file entirely
+          final int numBuffers = file.numBuffers();
+          for(int i=0;i<numBuffers;i++) {
+            byte[] buffer = file.getBuffer(i);
+            Arrays.fill(buffer, (byte) 0);
+          }
+        } else if (count % 3 == 2) {
+          // Truncate the file:
+          file.setLength(file.getLength()/2);
         }
-      } else if (count % 3 == 2) {
-        // Truncate the file:
-        file.setLength(file.getLength()/2);
+        count++;
       }
-      count++;
     }
   }
 
@@ -139,7 +182,7 @@ public class MockRAMDirectory extends RA
   public long getMaxUsedSizeInBytes() {
     return this.maxUsedSize;
   }
-  public void resetMaxUsedSizeInBytes() {
+  public void resetMaxUsedSizeInBytes() throws IOException {
     this.maxUsedSize = getRecomputedActualSizeInBytes();
   }
 
@@ -194,10 +237,10 @@ public class MockRAMDirectory extends RA
       unSyncedFiles.remove(name);
     if (!forced) {
       if (noDeleteOpenFile && openFiles.containsKey(name)) {
-        throw new IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot delete");
+        throw new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot delete");
       }
     }
-    super.deleteFile(name);
+    delegate.deleteFile(name);
   }
 
   @Override
@@ -210,32 +253,35 @@ public class MockRAMDirectory extends RA
         throw new IOException("file \"" + name + "\" was already written to");
     }
     if (noDeleteOpenFile && openFiles.containsKey(name))
-      throw new IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot overwrite");
-    RAMFile file = new RAMFile(this);
+      throw new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite");
+    
     if (crashed)
       throw new IOException("cannot createOutput after crash");
     unSyncedFiles.add(name);
     createdFiles.add(name);
-    RAMFile existing = fileMap.get(name);
-    // Enforce write once:
-    if (existing!=null && !name.equals("segments.gen") && preventDoubleWrite)
-      throw new IOException("file " + name + " already exists");
-    else {
-      if (existing!=null) {
-        sizeInBytes.getAndAdd(-existing.sizeInBytes);
-        existing.directory = null;
+    
+   if (delegate instanceof RAMDirectory) {
+      RAMDirectory ramdir = (RAMDirectory) delegate;
+      RAMFile file = new RAMFile(ramdir);
+      RAMFile existing = ramdir.fileMap.get(name);
+    
+      // Enforce write once:
+      if (existing!=null && !name.equals("segments.gen") && preventDoubleWrite)
+        throw new IOException("file " + name + " already exists");
+      else {
+        if (existing!=null) {
+          ramdir.sizeInBytes.getAndAdd(-existing.sizeInBytes);
+          existing.directory = null;
+        }
+        ramdir.fileMap.put(name, file);
       }
-
-      fileMap.put(name, file);
     }
-
-    return new MockRAMOutputStream(this, file, name);
+    return new MockIndexOutputWrapper(this, delegate.createOutput(name), name);
   }
 
   @Override
   public synchronized IndexInput openInput(String name) throws IOException {
-    RAMFile file = fileMap.get(name);
-    if (file == null)
+    if (!delegate.fileExists(name))
       throw new FileNotFoundException(name);
     else {
       if (openFiles.containsKey(name)) {
@@ -246,13 +292,16 @@ public class MockRAMDirectory extends RA
          openFiles.put(name, Integer.valueOf(1));
       }
     }
-    return new MockRAMInputStream(this, name, file);
+
+    return new MockIndexInputWrapper(this, name, delegate.openInput(name));
   }
 
   /** Provided for testing purposes.  Use sizeInBytes() instead. */
-  public synchronized final long getRecomputedSizeInBytes() {
+  public synchronized final long getRecomputedSizeInBytes() throws IOException {
+    if (!(delegate instanceof RAMDirectory))
+      return sizeInBytes();
     long size = 0;
-    for(final RAMFile file: fileMap.values()) {
+    for(final RAMFile file: ((RAMDirectory)delegate).fileMap.values()) {
       size += file.getSizeInBytes();
     }
     return size;
@@ -264,15 +313,17 @@ public class MockRAMDirectory extends RA
    * RAMOutputStream.BUFFER_SIZE (now 1024) bytes.
    */
 
-  public final synchronized long getRecomputedActualSizeInBytes() {
+  public final synchronized long getRecomputedActualSizeInBytes() throws IOException {
+    if (!(delegate instanceof RAMDirectory))
+      return sizeInBytes();
     long size = 0;
-    for (final RAMFile file : fileMap.values())
+    for (final RAMFile file : ((RAMDirectory)delegate).fileMap.values())
       size += file.length;
     return size;
   }
 
   @Override
-  public synchronized void close() {
+  public synchronized void close() throws IOException {
     if (openFiles == null) {
       openFiles = new HashMap<String,Integer>();
     }
@@ -282,6 +333,7 @@ public class MockRAMDirectory extends RA
       throw new RuntimeException("MockRAMDirectory: cannot close: there are still open files: " + openFiles);
     }
     open = false;
+    delegate.close();
   }
 
   boolean open = true;
@@ -300,7 +352,7 @@ public class MockRAMDirectory extends RA
     /**
      * eval is called on the first write of every new file.
      */
-    public void eval(MockRAMDirectory dir) throws IOException { }
+    public void eval(MockDirectoryWrapper dir) throws IOException { }
 
     /**
      * reset should set the state of the failure to its default
@@ -353,5 +405,58 @@ public class MockRAMDirectory extends RA
     }
   }
 
+  @Override
+  public synchronized String[] listAll() throws IOException {
+    return delegate.listAll();
+  }
+
+  @Override
+  public synchronized boolean fileExists(String name) throws IOException {
+    return delegate.fileExists(name);
+  }
+
+  @Override
+  public synchronized long fileModified(String name) throws IOException {
+    return delegate.fileModified(name);
+  }
+
+  @Override
+  public synchronized void touchFile(String name) throws IOException {
+    delegate.touchFile(name);
+  }
+
+  @Override
+  public synchronized long fileLength(String name) throws IOException {
+    return delegate.fileLength(name);
+  }
+
+  @Override
+  public synchronized Lock makeLock(String name) {
+    return delegate.makeLock(name);
+  }
+
+  @Override
+  public synchronized void clearLock(String name) throws IOException {
+    delegate.clearLock(name);
+  }
+
+  @Override
+  public synchronized void setLockFactory(LockFactory lockFactory) {
+    delegate.setLockFactory(lockFactory);
+  }
+
+  @Override
+  public synchronized LockFactory getLockFactory() {
+    return delegate.getLockFactory();
+  }
+
+  @Override
+  public synchronized String getLockID() {
+    return delegate.getLockID();
+  }
 
+  @Override
+  public synchronized void copy(Directory to, String src, String dest) throws IOException {
+    delegate.copy(to, src, dest);
+  }
 }

Copied: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexInputWrapper.java (from r988190, lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMInputStream.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexInputWrapper.java?p2=lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexInputWrapper.java&p1=lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMInputStream.java&r1=988190&r2=988206&rev=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMInputStream.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexInputWrapper.java Mon Aug 23 17:00:43 2010
@@ -1,6 +1,7 @@
 package org.apache.lucene.store;
 
 import java.io.IOException;
+import java.util.Map;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,26 +21,27 @@ import java.io.IOException;
  */
 
 /**
- * Used by MockRAMDirectory to create an input stream that
+ * Used by MockDirectoryWrapper to create an input stream that
  * keeps track of when it's been closed.
  */
 
-public class MockRAMInputStream extends RAMInputStream {
-  private MockRAMDirectory dir;
+public class MockIndexInputWrapper extends IndexInput {
+  private MockDirectoryWrapper dir;
   private String name;
+  private IndexInput delegate;
   private boolean isClone;
 
   /** Construct an empty output buffer. 
    * @throws IOException */
-  public MockRAMInputStream(MockRAMDirectory dir, String name, RAMFile f) throws IOException {
-    super(f);
+  public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
     this.name = name;
     this.dir = dir;
+    this.delegate = delegate;
   }
 
   @Override
-  public void close() {
-    super.close();
+  public void close() throws IOException {
+    delegate.close();
     // Pending resolution on LUCENE-686 we may want to
     // remove the conditional check so we also track that
     // all clones get closed:
@@ -61,7 +63,8 @@ public class MockRAMInputStream extends 
 
   @Override
   public Object clone() {
-    MockRAMInputStream clone = (MockRAMInputStream) super.clone();
+    IndexInput iiclone = (IndexInput) delegate.clone();
+    MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone);
     clone.isClone = true;
     // Pending resolution on LUCENE-686 we may want to
     // uncomment this code so that we also track that all
@@ -79,4 +82,75 @@ public class MockRAMInputStream extends 
     */
     return clone;
   }
+
+  @Override
+  public long getFilePointer() {
+    return delegate.getFilePointer();
+  }
+
+  @Override
+  public void seek(long pos) throws IOException {
+    delegate.seek(pos);
+  }
+
+  @Override
+  public long length() {
+    return delegate.length();
+  }
+
+  @Override
+  public byte readByte() throws IOException {
+    return delegate.readByte();
+  }
+
+  @Override
+  public void readBytes(byte[] b, int offset, int len) throws IOException {
+    delegate.readBytes(b, offset, len);
+  }
+
+  @Override
+  public void copyBytes(IndexOutput out, long numBytes) throws IOException {
+    delegate.copyBytes(out, numBytes);
+  }
+
+  @Override
+  public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
+      throws IOException {
+    delegate.readBytes(b, offset, len, useBuffer);
+  }
+
+  @Override
+  public short readShort() throws IOException {
+    return delegate.readShort();
+  }
+
+  @Override
+  public int readInt() throws IOException {
+    return delegate.readInt();
+  }
+
+  @Override
+  public int readVInt() throws IOException {
+    return delegate.readVInt();
+  }
+
+  @Override
+  public long readLong() throws IOException {
+    return delegate.readLong();
+  }
+
+  @Override
+  public long readVLong() throws IOException {
+    return delegate.readVLong();
+  }
+
+  @Override
+  public String readString() throws IOException {
+    return delegate.readString();
+  }
+
+  @Override
+  public Map<String,String> readStringStringMap() throws IOException {
+    return delegate.readStringStringMap();
+  }
 }

Copied: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java (from r988190, lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMOutputStream.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java?p2=lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java&p1=lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMOutputStream.java&r1=988190&r2=988206&rev=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockRAMOutputStream.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java Mon Aug 23 17:00:43 2010
@@ -18,6 +18,7 @@ package org.apache.lucene.store;
  */
 
 import java.io.IOException;
+import java.util.Map;
 
 /**
  * Used by MockRAMDirectory to create an output stream that
@@ -26,26 +27,27 @@ import java.io.IOException;
  * IOExceptions.
  */
 
-public class MockRAMOutputStream extends RAMOutputStream {
-  private MockRAMDirectory dir;
+public class MockIndexOutputWrapper extends IndexOutput {
+  private MockDirectoryWrapper dir;
+  private final IndexOutput delegate;
   private boolean first=true;
   private final String name;
   
   byte[] singleByte = new byte[1];
 
   /** Construct an empty output buffer. */
-  public MockRAMOutputStream(MockRAMDirectory dir, RAMFile f, String name) {
-    super(f);
+  public MockIndexOutputWrapper(MockDirectoryWrapper dir, IndexOutput delegate, String name) {
     this.dir = dir;
     this.name = name;
+    this.delegate = delegate;
   }
 
   @Override
   public void close() throws IOException {
-    super.close();
-
+    dir.maybeThrowDeterministicException();
+    delegate.close();
     // Now compute actual disk usage & track the maxUsedSize
-    // in the MockRAMDirectory:
+    // in the MockDirectoryWrapper:
     long size = dir.getRecomputedActualSizeInBytes();
     if (size > dir.maxUsedSize) {
       dir.maxUsedSize = size;
@@ -55,7 +57,7 @@ public class MockRAMOutputStream extends
   @Override
   public void flush() throws IOException {
     dir.maybeThrowDeterministicException();
-    super.flush();
+    delegate.flush();
   }
 
   @Override
@@ -66,7 +68,7 @@ public class MockRAMOutputStream extends
   
   @Override
   public void writeBytes(byte[] b, int offset, int len) throws IOException {
-    long freeSpace = dir.maxSize - dir.sizeInBytes();
+    long freeSpace = dir.maxSize == 0 ? 0 : dir.maxSize - dir.sizeInBytes();
     long realUsage = 0;
 
     // If MockRAMDir crashed since we were opened, then
@@ -85,14 +87,14 @@ public class MockRAMOutputStream extends
     if (dir.maxSize != 0 && freeSpace <= len) {
       if (freeSpace > 0 && freeSpace < len) {
         realUsage += freeSpace;
-        super.writeBytes(b, offset, (int) freeSpace);
+        delegate.writeBytes(b, offset, (int) freeSpace);
       }
       if (realUsage > dir.maxUsedSize) {
         dir.maxUsedSize = realUsage;
       }
       throw new IOException("fake disk full at " + dir.getRecomputedActualSizeInBytes() + " bytes when writing " + name);
     } else {
-      super.writeBytes(b, offset, len);
+      delegate.writeBytes(b, offset, len);
     }
 
     dir.maybeThrowDeterministicException();
@@ -104,4 +106,78 @@ public class MockRAMOutputStream extends
       dir.maybeThrowIOException();
     }
   }
+
+  @Override
+  public long getFilePointer() {
+    return delegate.getFilePointer();
+  }
+
+  @Override
+  public void seek(long pos) throws IOException {
+    delegate.seek(pos);
+  }
+
+  @Override
+  public long length() throws IOException {
+    return delegate.length();
+  }
+
+  @Override
+  public void setLength(long length) throws IOException {
+    delegate.setLength(length);
+  }
+
+  /*
+  @Override
+  public void writeBytes(byte[] b, int length) throws IOException {
+    delegate.writeBytes(b, length);
+  }
+
+  @Override
+  public void writeInt(int i) throws IOException {
+    delegate.writeInt(i);
+  }
+
+  @Override
+  public void writeVInt(int i) throws IOException {
+    delegate.writeVInt(i);
+  }
+
+  @Override
+  public void writeLong(long i) throws IOException {
+    delegate.writeLong(i);
+  }
+
+  @Override
+  public void writeVLong(long i) throws IOException {
+    delegate.writeVLong(i);
+  }
+
+  @Override
+  public void writeString(String s) throws IOException {
+    delegate.writeString(s);
+  }
+
+  @Override
+  public void writeChars(String s, int start, int length) throws IOException {
+    delegate.writeChars(s, start, length);
+  }
+
+  @Override
+  public void writeChars(char[] s, int start, int length) throws IOException {
+    delegate.writeChars(s, start, length);
+  }
+
+  @Override
+  public void writeStringStringMap(Map<String,String> map) throws IOException {
+    delegate.writeStringStringMap(map);
+  }
+  */
+
+  @Override
+  public void copyBytes(DataInput input, long numBytes) throws IOException {
+    delegate.copyBytes(input, numBytes);
+    // TODO: we may need to check disk full here as well
+    dir.maybeThrowDeterministicException();
+  }
 }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java Mon Aug 23 17:00:43 2010
@@ -40,8 +40,8 @@ public class TestFileSwitchDirectory ext
     fileExtensions.add(IndexFileNames.FIELDS_EXTENSION);
     fileExtensions.add(IndexFileNames.FIELDS_INDEX_EXTENSION);
     
-    Directory primaryDir = new MockRAMDirectory();
-    RAMDirectory secondaryDir = new MockRAMDirectory();
+    Directory primaryDir = new MockDirectoryWrapper(new RAMDirectory());
+    Directory secondaryDir = new MockDirectoryWrapper(new RAMDirectory());
     
     FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
     IndexWriter writer = new IndexWriter(fsd, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestLockFactory.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestLockFactory.java Mon Aug 23 17:00:43 2010
@@ -42,7 +42,7 @@ public class TestLockFactory extends Luc
     // methods are called at the right time, locks are created, etc.
 
     public void testCustomLockFactory() throws IOException {
-        Directory dir = new MockRAMDirectory();
+        Directory dir = new MockDirectoryWrapper(new RAMDirectory());
         MockLockFactory lf = new MockLockFactory();
         dir.setLockFactory(lf);
 
@@ -75,7 +75,7 @@ public class TestLockFactory extends Luc
     // exceptions raised:
     // Verify: NoLockFactory allows two IndexWriters
     public void testRAMDirectoryNoLocking() throws IOException {
-        Directory dir = new MockRAMDirectory();
+        Directory dir = new MockDirectoryWrapper(new RAMDirectory());
         dir.setLockFactory(NoLockFactory.getNoLockFactory());
 
         assertTrue("RAMDirectory.setLockFactory did not take",
@@ -102,7 +102,7 @@ public class TestLockFactory extends Luc
     // Verify: SingleInstanceLockFactory is the default lock for RAMDirectory
     // Verify: RAMDirectory does basic locking correctly (can't create two IndexWriters)
     public void testDefaultRAMDirectory() throws IOException {
-        Directory dir = new MockRAMDirectory();
+        Directory dir = new RAMDirectory();
 
         assertTrue("RAMDirectory did not use correct LockFactory: got " + dir.getLockFactory(),
                    SingleInstanceLockFactory.class.isInstance(dir.getLockFactory()));

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java Mon Aug 23 17:00:43 2010
@@ -69,7 +69,7 @@ public class TestRAMDirectory extends Lu
   public void testRAMDirectory () throws IOException {
     
     Directory dir = FSDirectory.open(indexDir);
-    MockRAMDirectory ramDir = new MockRAMDirectory(dir);
+    MockDirectoryWrapper ramDir = new MockDirectoryWrapper(new RAMDirectory(dir));
     
     // close the underlaying directory
     dir.close();
@@ -101,7 +101,7 @@ public class TestRAMDirectory extends Lu
   public void testRAMDirectorySize() throws IOException, InterruptedException {
       
     Directory dir = FSDirectory.open(indexDir);
-    final MockRAMDirectory ramDir = new MockRAMDirectory(dir);
+    final MockDirectoryWrapper ramDir = new MockDirectoryWrapper(new RAMDirectory(dir));
     dir.close();
     
     final IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Mon Aug 23 17:00:43 2010
@@ -42,7 +42,9 @@ import org.apache.lucene.search.BooleanQ
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.FieldCache.CacheEntry;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
 
 /** 
@@ -84,6 +86,8 @@ public abstract class LuceneTestCase ext
   static final String TEST_LOCALE = LuceneTestCaseJ4.TEST_LOCALE;
   /** Gets the timezone to run tests with */
   static final String TEST_TIMEZONE = LuceneTestCaseJ4.TEST_TIMEZONE;
+  /** Gets the directory to run tests with */
+  static final String TEST_DIRECTORY = LuceneTestCaseJ4.TEST_DIRECTORY;
   
   /**
    * A random multiplier which you should use when writing random tests:
@@ -102,7 +106,7 @@ public abstract class LuceneTestCase ext
   private TimeZone timeZone;
   private TimeZone savedTimeZone;
 
-  private Map<MockRAMDirectory,StackTraceElement[]> stores;
+  private Map<MockDirectoryWrapper,StackTraceElement[]> stores;
 
   /** Used to track if setUp and tearDown are called correctly from subclasses */
   private boolean setup;
@@ -131,7 +135,7 @@ public abstract class LuceneTestCase ext
     super.setUp();
     assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup);
     setup = true;
-    stores = new IdentityHashMap<MockRAMDirectory,StackTraceElement[]>();
+    stores = new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>();
     savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
     Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
       public void uncaughtException(Thread t, Throwable e) {
@@ -211,7 +215,7 @@ public abstract class LuceneTestCase ext
     }
 
     // now look for unclosed resources
-    for (MockRAMDirectory d : stores.keySet()) {
+    for (MockDirectoryWrapper d : stores.keySet()) {
       if (d.isOpen()) {
         StackTraceElement elements[] = stores.get(d);
         StackTraceElement element = (elements.length > 1) ? elements[1] : null;
@@ -329,16 +333,17 @@ public abstract class LuceneTestCase ext
     return LuceneTestCaseJ4.newIndexWriterConfig(r, v, a);
   }
 
-  public MockRAMDirectory newDirectory(Random r) throws IOException {
+  public MockDirectoryWrapper newDirectory(Random r) throws IOException {
     StackTraceElement[] stack = new Exception().getStackTrace();
-    MockRAMDirectory dir = new MockRAMDirectory();
+    Directory impl = LuceneTestCaseJ4.newDirectoryImpl(TEST_DIRECTORY);
+    MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
     stores.put(dir, stack);
     return dir;
   }
   
-  public MockRAMDirectory newDirectory(Random r, Directory d) throws IOException {
+  public MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
     StackTraceElement[] stack = new Exception().getStackTrace();
-    MockRAMDirectory dir = new MockRAMDirectory(d);
+    MockDirectoryWrapper dir = new MockDirectoryWrapper(new RAMDirectory(d));
     stores.put(dir, stack);
     return dir;
   }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java Mon Aug 23 17:00:43 2010
@@ -27,7 +27,8 @@ import org.apache.lucene.search.BooleanQ
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.FieldCache.CacheEntry;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
 import org.apache.lucene.index.codecs.CodecProvider;
 import org.apache.lucene.index.codecs.Codec;
@@ -70,6 +71,7 @@ import java.util.WeakHashMap;
 import java.util.Collections;
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 
 import static org.junit.Assert.assertEquals;
@@ -149,6 +151,8 @@ public class LuceneTestCaseJ4 {
   static final String TEST_LOCALE = System.getProperty("tests.locale", "random");
   /** Gets the timezone to run tests with */
   static final String TEST_TIMEZONE = System.getProperty("tests.timezone", "random");
+  /** Gets the directory to run tests with */
+  static final String TEST_DIRECTORY = System.getProperty("tests.directory", "RAMDirectory");
   
   private static final Pattern codecWithParam = Pattern.compile("(.*)\\(\\s*(\\d+)\\s*\\)");
 
@@ -190,7 +194,7 @@ public class LuceneTestCaseJ4 {
   private static TimeZone timeZone;
   private static TimeZone savedTimeZone;
   
-  private static Map<MockRAMDirectory,StackTraceElement[]> stores;
+  private static Map<MockDirectoryWrapper,StackTraceElement[]> stores;
   
   private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock", "MockVariableIntBlock"};
 
@@ -279,7 +283,7 @@ public class LuceneTestCaseJ4 {
 
   @BeforeClass
   public static void beforeClassLuceneTestCaseJ4() {
-    stores = Collections.synchronizedMap(new IdentityHashMap<MockRAMDirectory,StackTraceElement[]>());
+    stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
     codec = installTestCodecs();
     savedLocale = Locale.getDefault();
     locale = TEST_LOCALE.equals("random") ? randomLocale(seedRnd) : localeForName(TEST_LOCALE);
@@ -295,7 +299,7 @@ public class LuceneTestCaseJ4 {
     Locale.setDefault(savedLocale);
     TimeZone.setDefault(savedTimeZone);
     // now look for unclosed resources
-    for (MockRAMDirectory d : stores.keySet()) {
+    for (MockDirectoryWrapper d : stores.keySet()) {
       if (d.isOpen()) {
         StackTraceElement elements[] = stores.get(d);
         StackTraceElement element = (elements.length > 1) ? elements[1] : null;
@@ -582,16 +586,17 @@ public class LuceneTestCaseJ4 {
     return c;
   }
 
-  public static MockRAMDirectory newDirectory(Random r) throws IOException {
+  public static MockDirectoryWrapper newDirectory(Random r) throws IOException {
     StackTraceElement[] stack = new Exception().getStackTrace();
-    MockRAMDirectory dir = new MockRAMDirectory();
+    Directory impl = newDirectoryImpl(TEST_DIRECTORY);
+    MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
     stores.put(dir, stack);
     return dir;
   }
   
-  public static MockRAMDirectory newDirectory(Random r, Directory d) throws IOException {
+  public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
     StackTraceElement[] stack = new Exception().getStackTrace();
-    MockRAMDirectory dir = new MockRAMDirectory(d);
+    MockDirectoryWrapper dir = new MockDirectoryWrapper(new RAMDirectory(d));
     stores.put(dir, stack);
     return dir;
   }
@@ -619,6 +624,32 @@ public class LuceneTestCaseJ4 {
     }
   }
 
+  static Directory newDirectoryImpl(String clazzName) {
+    if (clazzName.indexOf(".") == -1) // if not fully qualified, assume .store
+      clazzName = "org.apache.lucene.store." + clazzName;
+    try {
+      final Class<? extends Directory> clazz = Class.forName(clazzName).asSubclass(Directory.class);
+      try {
+        // try empty ctor
+        return clazz.newInstance();
+      } catch (Exception e) {
+        final File tmpFile = File.createTempFile("test", "tmp", TEMP_DIR);
+        tmpFile.delete();
+        tmpFile.mkdir();
+        try {
+          Constructor<? extends Directory> ctor = clazz.getConstructor(File.class);
+          return ctor.newInstance(tmpFile);
+        } catch (Exception e2) {
+          // try .open(File)
+          Method method = clazz.getMethod("open", new Class[] { File.class });
+          return (Directory) method.invoke(null, tmpFile);
+        }
+      }
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    } 
+  }
+  
   public String getName() {
     return this.name;
   }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestBitVector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestBitVector.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestBitVector.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestBitVector.java Mon Aug 23 17:00:43 2010
@@ -20,8 +20,8 @@ package org.apache.lucene.util;
 import java.io.IOException;
 
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.store.RAMDirectory;
 
 /**
  * <code>TestBitVector</code> tests the <code>BitVector</code>, obviously.
@@ -140,7 +140,7 @@ public class TestBitVector extends Lucen
     }
 
     private void doTestWriteRead(int n) throws Exception {
-        MockRAMDirectory d = new  MockRAMDirectory();
+        MockDirectoryWrapper d = new  MockDirectoryWrapper(new RAMDirectory());
         d.setPreventDoubleWrite(false);
         BitVector bv = new BitVector(n);
         // test count when incrementally setting bits
@@ -171,7 +171,7 @@ public class TestBitVector extends Lucen
     }
     
     private void doTestDgaps(int size, int count1, int count2) throws IOException {
-      MockRAMDirectory d = new  MockRAMDirectory();
+      MockDirectoryWrapper d = new  MockDirectoryWrapper(new RAMDirectory());
       d.setPreventDoubleWrite(false);
       BitVector bv = new BitVector(size);
       for (int i=0; i<count1; i++) {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java Mon Aug 23 17:00:43 2010
@@ -24,7 +24,7 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
 import org.apache.lucene.util.FieldCacheSanityChecker.InsanityType;
 
@@ -36,7 +36,7 @@ public class TestFieldCacheSanityChecker
   protected IndexReader readerA;
   protected IndexReader readerB;
   protected IndexReader readerX;
-  protected MockRAMDirectory dirA, dirB;
+  protected Directory dirA, dirB;
   private static final int NUM_DOCS = 1000;
 
   @Override

Modified: lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java (original)
+++ lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java Mon Aug 23 17:00:43 2010
@@ -32,10 +32,9 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.TermPositionVector;
 import org.apache.lucene.index.TermVectorOffsetInfo;
-import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.AttributeSource;
 import org.apache.lucene.util.English;
 import java.io.IOException;
@@ -94,7 +93,7 @@ public class TestTeeSinkTokenFilter exte
   // with BaseTokenStreamTestCase now...
   public void testEndOffsetPositionWithTeeSinkTokenFilter() throws Exception {
     Random random = newRandom();
-    MockRAMDirectory dir = newDirectory(random);
+    Directory dir = newDirectory(random);
     Analyzer analyzer = new WhitespaceAnalyzer(TEST_VERSION_CURRENT);
     IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
     Document doc = new Document();

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/search/TestSort.java?rev=988206&r1=988205&r2=988206&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/search/TestSort.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/search/TestSort.java Mon Aug 23 17:00:43 2010
@@ -23,7 +23,7 @@ import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.search.*;
-import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.OpenBitSet;
 import org.apache.solr.util.AbstractSolrTestCase;
 
@@ -49,7 +49,7 @@ public class TestSort extends AbstractSo
 
   public void testSort() throws Exception {
     Random random = newRandom();
-    MockRAMDirectory dir = newDirectory(random);
+    Directory dir = newDirectory(random);
     Document smallDoc = new Document();
     // Field id = new Field("id","0", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);
     Field f = new Field("f","0", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);
@@ -181,8 +181,8 @@ public class TestSort extends AbstractSo
         }
       }
       searcher.close();
-      dir.close();
     }
+    dir.close();
 
   }