package org.apache.solr.core;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;

/**
 * Opens a directory with {@link LuceneTestCase#newDirectory()}
 */
public class MockDirectoryFactory extends EphemeralDirectoryFactory {

  @Override
  protected Directory create(String path) throws IOException {
    Directory dir = LuceneTestCase.newDirectory();
    // we can't currently do this check because of how
    // Solr has to reboot a new Directory sometimes when replicating
    // or rolling back - the old directory is closed and the following
    // test assumes it can open an IndexWriter when that happens - we
    // have a new Directory for the same dir and still an open IW at 
    // this point
    if (dir instanceof MockDirectoryWrapper) {
      ((MockDirectoryWrapper)dir).setAssertNoUnrefencedFilesOnClose(false);
    }
    
    // ram dirs in cores that are restarted end up empty
    // and check index fails
    if (dir instanceof MockDirectoryWrapper) {
      ((MockDirectoryWrapper)dir).setCheckIndexOnClose(false);
    }
    return dir;
  }

}

@@ -1267,16 +1267,144 @@
 tory();%0A
+    if (dir instanceof MockDirectoryWrapper) %7B%0A      MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) dir;%0A      %0A  
     // w
@@ -1454,16 +1454,18 @@
 how%0A    
+ 
+ 
 // Solr 
@@ -1517,24 +1517,26 @@
 replicating%0A
+  
     // or ro
@@ -1594,24 +1594,26 @@
 llowing%0A    
+ 
+ 
 // test assu
@@ -1666,16 +1666,18 @@
 ns - we%0A
+  
     // h
@@ -1738,24 +1738,26 @@
  IW at %0A    
+  
 // this poin
@@ -1766,84 +1766,24 @@
     
-if (dir instanceof MockDirectoryWrapper) %7B%0A      ((MockDirectory
+  mockDir
 Wrapper
-)dir)
 .set
@@ -1829,15 +1829,13 @@
     
-%7D%0A
   
+%0A
   
-%0A
     
@@ -1891,16 +1891,18 @@
 pty%0A    
+  
 // and c
@@ -1926,104 +1926,261 @@
     
-if (dir instanceof MockDirectoryWrapper) %7B%0A      ((MockDirectoryWrapper)dir).setCheckIndexOnClos
+  mockDirWrapper.setCheckIndexOnClose(false);%0A      %0A      // if we enable this, TestReplicationHandler fails when it%0A      // tries to write to index.properties after the file has%0A      // already been created.%0A      mockDirWrapper.setPreventDoubleWrit
 e(fa
@@ -2191,16 +2191,21 @@
 ;%0A    %7D%0A
+    %0A
     retu

disable doubleWrite check in MockDirectoryFactory, or otherwise TestReplicationHandler fails