Example usage for org.apache.lucene.store MockDirectoryWrapper setCheckIndexOnClose

List of usage examples for org.apache.lucene.store MockDirectoryWrapper setCheckIndexOnClose

Introduction

In this page you can find the example usage for org.apache.lucene.store MockDirectoryWrapper setCheckIndexOnClose.

Prototype

public void setCheckIndexOnClose(boolean value) 

Source Link

Document

Set whether or not checkindex should be run on close

Usage

From source file:org.apache.solr.core.MockDirectoryFactory.java

License:Apache License

@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
    Directory dir = LuceneTestCase.newDirectory();

    Directory cdir = reduce(dir);//w w  w .  j a va  2s  . c  o m
    cdir = reduce(cdir);
    cdir = reduce(cdir);

    if (cdir instanceof MockDirectoryWrapper) {
        MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) cdir;

        // 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
        mockDirWrapper.setAssertNoUnrefencedFilesOnClose(false);

        // ram dirs in cores that are restarted end up empty
        // and check index fails
        mockDirWrapper.setCheckIndexOnClose(false);

        // if we enable this, TestReplicationHandler fails when it
        // tries to write to index.properties after the file has
        // already been created.
        mockDirWrapper.setPreventDoubleWrite(false);
    }

    return dir;
}

From source file:org.elasticsearch.index.store.DistributorDirectoryTest.java

License:Apache License

public void testRenameFiles() throws IOException {
    final int iters = 1 + random().nextInt(10);
    for (int i = 0; i < iters; i++) {
        Directory[] dirs = new Directory[1 + random().nextInt(5)];
        for (int j = 0; j < dirs.length; j++) {
            MockDirectoryWrapper directory = newMockDirectory();
            directory.setEnableVirusScanner(false);
            directory.setCheckIndexOnClose(false);
            dirs[j] = directory;//from w ww .  ja va  2  s.com
        }

        DistributorDirectory dd = new DistributorDirectory(dirs);
        String file = RandomPicks.randomFrom(random(),
                Arrays.asList(Store.CHECKSUMS_PREFIX, IndexFileNames.SEGMENTS_GEN));
        String tmpFileName = RandomPicks.randomFrom(random(), Arrays.asList("recovery.", "foobar.", "test."))
                + Math.max(0, Math.abs(random().nextLong())) + "." + file;
        try (IndexOutput out = dd.createOutput(tmpFileName, IOContext.DEFAULT)) {
            out.writeInt(1);
        }
        Directory theDir = null;
        for (Directory d : dirs) {
            try {
                if (d.fileLength(tmpFileName) > 0) {
                    theDir = d;
                    break;
                }
            } catch (IOException ex) {
                // nevermind
            }
        }
        assertNotNull("file must be in at least one dir", theDir);
        DirectoryService service = new DirectoryService(new ShardId("foo", 1), ImmutableSettings.EMPTY) {
            @Override
            public Directory[] build() throws IOException {
                return new Directory[0];
            }

            @Override
            public long throttleTimeInNanos() {
                return 0;
            }

            @Override
            public void renameFile(Directory dir, String from, String to) throws IOException {
                dir.copy(dir, from, to, IOContext.DEFAULT);
                dir.deleteFile(from);
            }

        };
        dd.renameFile(service, tmpFileName, file);
        try {
            dd.fileLength(tmpFileName);
            fail("file [" + tmpFileName + "] was renamed but still exists");
        } catch (FileNotFoundException | NoSuchFileException ex) {
            // all is well
        }
        try {
            theDir.fileLength(tmpFileName);
            fail("file [" + tmpFileName + "] was renamed but still exists");
        } catch (FileNotFoundException | NoSuchFileException ex) {
            // all is well
        }

        assertEquals(theDir.fileLength(file), 4);

        try (IndexOutput out = dd.createOutput("foo.bar", IOContext.DEFAULT)) {
            out.writeInt(1);
        }
        assertNotNull(dd);
        if (dd.getDirectory("foo.bar") != dd.getDirectory(file)) {
            try {
                dd.renameFile(service, "foo.bar", file);
                fail("target file already exists in a different directory");
            } catch (IOException ex) {
                // target file already exists
            }
        }
        IOUtils.close(dd);
    }
}

From source file:org.elasticsearch.index.store.mock.MockDirectoryHelper.java

License:Apache License

public Directory wrap(Directory dir) {
    final MockDirectoryWrapper w = new MockDirectoryWrapper(random, dir);
    w.setRandomIOExceptionRate(randomIOExceptionRate);
    w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen);
    w.setThrottling(throttle);/*from  w  w  w  .  j  a va2 s.c o m*/
    w.setCheckIndexOnClose(checkIndexOnClose);
    wrappers.add(w);
    return new FilterDirectory(w) {
        @Override
        public Directory getDelegate() {
            // TODO we should port this FilterDirectory to Lucene
            return w.getDelegate();
        }
    };
}

From source file:org.elasticsearch.test.store.mock.MockDirectoryHelper.java

License:Apache License

public Directory wrap(Directory dir) {
    final MockDirectoryWrapper w = new MockDirectoryWrapper(random, dir);
    w.setRandomIOExceptionRate(randomIOExceptionRate);
    w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen);
    w.setThrottling(throttle);//from w w  w. j  av  a  2s .c  om
    w.setCheckIndexOnClose(checkIndexOnClose);
    w.setPreventDoubleWrite(preventDoubleWrite);
    w.setNoDeleteOpenFile(noDeleteOpenFile);
    wrappers.add(w);
    return new FilterDirectory(w) {
        @Override
        public Directory getDelegate() {
            // TODO we should port this FilterDirectory to Lucene
            return w.getDelegate();
        }
    };
}