private void prepareEnvironment(final boolean useDefConstructor) throws IOException { cache0 = cache(0, CACHE_NAME); cache1 = cache(1, CACHE_NAME); if (useDefConstructor) { dirA = createDirectory(cache0); dirB = createDirectory(cache1); } else { dirA = createAdditionalDirectory(cache0); dirB = createAdditionalDirectory(cache1); } CacheTestSupport.initializeDirectory(dirA); }
@Test public void testAdditionalIndexWritingAndFinding() throws IOException, InterruptedException { prepareEnvironment(true); testIndexWritingAndFinding(); }
@Test @Override public void testIndexWritingAndFinding() throws IOException, InterruptedException { prepareEnvironment(false); verifyBoth(cache0,cache1); IndexOutput indexOutput = dirA.createOutput(filename, IOContext.DEFAULT); indexOutput.writeString("no need to write, nobody ever will read this"); indexOutput.close(); assertFileExistsHavingRLCount(filename, 1, true); IndexInput firstOpenOnB = dirB.openInput(filename, IOContext.DEFAULT); assertFileExistsHavingRLCount(filename, 2, true); dirA.deleteFile(filename); assertFileExistsHavingRLCount(filename, 1, false); assertFileExistsHavingRLCount(filename, 1, false); cloneOfFirstOpenOnB.close(); assertFileExistsHavingRLCount(filename, 1, false); IndexInput firstOpenOnA = dirA.openInput(filename, IOContext.DEFAULT); assertFileExistsHavingRLCount(filename, 2, false); IndexInput secondOpenOnA = dirA.openInput(filename, IOContext.DEFAULT); assertFileExistsHavingRLCount(filename, 2, false); firstOpenOnA.close(); assertFileExistsHavingRLCount(filename, 2, false); secondOpenOnA.close(); assertFileExistsHavingRLCount(filename, 1, false); firstOpenOnB.close(); assertFileNotExists(filename); dirA.close(); dirB.close(); verifyBoth(cache0, cache1);