LUCENE-5067: fix testThreadSafety to actually test the dir in question (not copy into random impl), fix performance issues, remove Nightly

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1587592 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-04-15 14:24:31 +00:00
parent a3bf11591b
commit 80f00226e7
6 changed files with 32 additions and 15 deletions

View File

@ -37,6 +37,12 @@ public class TestDirectory extends BaseDirectoryTestCase {
} }
} }
// we wrap the directory in slow stuff, so only run nightly
@Override @Nightly
public void testThreadSafety() throws Exception {
super.testThreadSafety();
}
// Test that different instances of FSDirectory can coexist on the same // Test that different instances of FSDirectory can coexist on the same
// path, can read, write, and lock files. // path, can read, write, and lock files.
public void testDirectInstantiation() throws Exception { public void testDirectInstantiation() throws Exception {

View File

@ -97,8 +97,7 @@ public class TestFileSwitchDirectory extends BaseDirectoryTestCase {
private Directory newFSSwitchDirectory(File aDir, File bDir, Set<String> primaryExtensions) throws IOException { private Directory newFSSwitchDirectory(File aDir, File bDir, Set<String> primaryExtensions) throws IOException {
Directory a = new SimpleFSDirectory(aDir); Directory a = new SimpleFSDirectory(aDir);
Directory b = new SimpleFSDirectory(bDir); Directory b = new SimpleFSDirectory(bDir);
FileSwitchDirectory switchDir = new FileSwitchDirectory(primaryExtensions, a, b, true); return new FileSwitchDirectory(primaryExtensions, a, b, true);
return new MockDirectoryWrapper(random(), switchDir);
} }
// LUCENE-3380 -- make sure we get exception if the directory really does not exist. // LUCENE-3380 -- make sure we get exception if the directory really does not exist.

View File

@ -18,6 +18,7 @@ package org.apache.lucene.store;
*/ */
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,9 +39,12 @@ import org.apache.lucene.util.TestUtil;
public class TestNRTCachingDirectory extends BaseDirectoryTestCase { public class TestNRTCachingDirectory extends BaseDirectoryTestCase {
// TODO: RAMDir used here, because its still too slow to use e.g. SimpleFS
// for the threads tests... maybe because of the synchronization in listAll?
// would be good to investigate further...
@Override @Override
protected Directory getDirectory(File path) { protected Directory getDirectory(File path) throws IOException {
return new NRTCachingDirectory(newFSDirectory(path), return new NRTCachingDirectory(new RAMDirectory(),
.1 + 2.0*random().nextDouble(), .1 + 2.0*random().nextDouble(),
.1 + 5.0*random().nextDouble()); .1 + 5.0*random().nextDouble());
} }

View File

@ -28,4 +28,10 @@ public class TestRateLimitedDirectoryWrapper extends BaseDirectoryTestCase {
dir.setRateLimiter(limiter, IOContext.Context.MERGE); dir.setRateLimiter(limiter, IOContext.Context.MERGE);
return dir; return dir;
} }
// since we are rate-limiting, this test gets pretty slow
@Override @Nightly
public void testThreadSafety() throws Exception {
super.testThreadSafety();
}
} }

View File

@ -51,13 +51,11 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
} }
} }
// test is occasionally very slow, i dont know why
// try this seed: 7D7E036AD12927F5:93333EF9E6DE44DE
@Nightly
public void testThreadSafety() throws Exception { public void testThreadSafety() throws Exception {
final Directory raw = getDirectory(createTempDir("testThreadSafety")); final Directory dir = getDirectory(createTempDir("testThreadSafety"));
final BaseDirectoryWrapper dir = newDirectory(raw); if (dir instanceof BaseDirectoryWrapper) {
dir.setCheckIndexOnClose(false); // we arent making an index ((BaseDirectoryWrapper)dir).setCheckIndexOnClose(false); // we arent making an index
}
if (dir instanceof MockDirectoryWrapper) { if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER); // makes this test really slow ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER); // makes this test really slow
} }
@ -91,6 +89,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
class TheThread2 extends Thread { class TheThread2 extends Thread {
private String name; private String name;
private volatile boolean stop;
public TheThread2(String name) { public TheThread2(String name) {
this.name = name; this.name = name;
@ -98,7 +97,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
@Override @Override
public void run() { public void run() {
for (int i = 0; i < 10000; i++) { while (stop == false) {
try { try {
String[] files = dir.listAll(); String[] files = dir.listAll();
for (String file : files) { for (String file : files) {
@ -109,7 +108,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
} catch (FileNotFoundException | NoSuchFileException e) { } catch (FileNotFoundException | NoSuchFileException e) {
// ignore // ignore
} catch (IOException e) { } catch (IOException e) {
if (e.getMessage().contains("still open for writing")) { if (e.getMessage() != null && e.getMessage().contains("still open for writing")) {
// ignore // ignore
} else { } else {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -132,10 +131,13 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
theThread2.start(); theThread2.start();
theThread.join(); theThread.join();
// after first thread is done, no sense in waiting on thread 2
// to listFiles() and loop over and over
theThread2.stop = true;
theThread2.join(); theThread2.join();
dir.close(); dir.close();
raw.close();
} }
/** LUCENE-1464: just creating a Directory should not /** LUCENE-1464: just creating a Directory should not

View File

@ -1099,11 +1099,11 @@ public abstract class LuceneTestCase extends Assert {
} }
private static BaseDirectoryWrapper wrapDirectory(Random random, Directory directory, boolean bare) { private static BaseDirectoryWrapper wrapDirectory(Random random, Directory directory, boolean bare) {
if (rarely(random)) { if (rarely(random) && !bare) {
directory = new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble()); directory = new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble());
} }
if (rarely(random)) { if (rarely(random) && !bare) {
final double maxMBPerSec = 10 + 5*(random.nextDouble()-0.5); final double maxMBPerSec = 10 + 5*(random.nextDouble()-0.5);
if (LuceneTestCase.VERBOSE) { if (LuceneTestCase.VERBOSE) {
System.out.println("LuceneTestCase: will rate limit output IndexOutput to " + maxMBPerSec + " MB/sec"); System.out.println("LuceneTestCase: will rate limit output IndexOutput to " + maxMBPerSec + " MB/sec");