mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-10 13:17:09 +07:00
read-only index storage
This commit is contained in:
@@ -64,6 +64,7 @@ import com.intellij.testFramework.SkipSlowTestLocally
|
||||
import com.intellij.testFramework.exceptionCases.IllegalArgumentExceptionCase
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
|
||||
import com.intellij.util.FileContentUtil
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import com.intellij.util.Processor
|
||||
import com.intellij.util.indexing.*
|
||||
import com.intellij.util.io.*
|
||||
@@ -86,7 +87,7 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
void testUpdate() throws StorageException, IOException {
|
||||
StringIndex index = createIndex(getTestName(false), new EnumeratorStringDescriptor())
|
||||
StringIndex index = createIndex(getTestName(false), new EnumeratorStringDescriptor(), false)
|
||||
|
||||
try {
|
||||
// build index
|
||||
@@ -133,7 +134,7 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
void testUpdateWithCustomEqualityPolicy() {
|
||||
def index = createIndex(getTestName(false), new CaseInsensitiveEnumeratorStringDescriptor())
|
||||
def index = createIndex(getTestName(false), new CaseInsensitiveEnumeratorStringDescriptor(), false)
|
||||
try {
|
||||
index.update("a.java", "x", null)
|
||||
assertDataEquals(index.getFilesByWord("x"), "a.java")
|
||||
@@ -151,12 +152,12 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static StringIndex createIndex(String testName, EnumeratorStringDescriptor keyDescriptor) {
|
||||
private static StringIndex createIndex(String testName, EnumeratorStringDescriptor keyDescriptor, boolean readOnly) {
|
||||
final File storageFile = FileUtil.createTempFile("index_test", "storage")
|
||||
final File metaIndexFile = FileUtil.createTempFile("index_test_inputs", "storage")
|
||||
PersistentHashMap<Integer, Collection<String>> index = createMetaIndex(metaIndexFile)
|
||||
final VfsAwareMapIndexStorage indexStorage = new VfsAwareMapIndexStorage(storageFile, keyDescriptor, new EnumeratorStringDescriptor(), 16 * 1024)
|
||||
return new StringIndex(testName, indexStorage, index)
|
||||
final VfsAwareMapIndexStorage indexStorage = new VfsAwareMapIndexStorage(storageFile, keyDescriptor, new EnumeratorStringDescriptor(), 16 * 1024, readOnly)
|
||||
return new StringIndex(testName, indexStorage, index, !readOnly)
|
||||
}
|
||||
|
||||
private static PersistentHashMap<Integer, Collection<String>> createMetaIndex(File metaIndexFile) throws IOException {
|
||||
@@ -665,6 +666,15 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
assert JavaFileElementType.isInSourceContent(myFixture.tempDirFixture.getFile('another/doo/A.java'))
|
||||
}
|
||||
|
||||
void "test read-only index access"() {
|
||||
StringIndex index = createIndex(getTestName(false), new EnumeratorStringDescriptor(), true)
|
||||
assertFalse(index.update("qwe/asd", "some_string", null))
|
||||
def rebuildException = index.getRebuildException()
|
||||
assertInstanceOf(rebuildException, StorageException.class)
|
||||
def rebuildCause = rebuildException.getCause()
|
||||
assertInstanceOf(rebuildCause, IncorrectOperationException.class)
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
void "test Vfs Events Processing Performance"() {
|
||||
def filename = 'A.java'
|
||||
|
||||
@@ -40,8 +40,11 @@ import java.util.Map;
|
||||
*/
|
||||
public class StringIndex {
|
||||
private final MapReduceIndex<String, String, PathContentPair> myIndex;
|
||||
|
||||
public StringIndex(String testName, final IndexStorage<String, String> storage, final PersistentHashMap<Integer, Collection<String>> inputIndex)
|
||||
private volatile Exception myRebuildException;
|
||||
public StringIndex(String testName,
|
||||
final IndexStorage<String, String> storage,
|
||||
final PersistentHashMap<Integer, Collection<String>> inputIndex,
|
||||
boolean failOnRebuildRequest)
|
||||
throws IOException {
|
||||
ID<String, String> id = ID.create(testName + "string_index");
|
||||
IndexExtension<String, String, PathContentPair> extension = new IndexExtension<String, String, PathContentPair>() {
|
||||
@@ -83,7 +86,11 @@ public class StringIndex {
|
||||
}) {
|
||||
@Override
|
||||
public void requestRebuild(@NotNull Exception ex) {
|
||||
Assert.fail();
|
||||
if (failOnRebuildRequest) {
|
||||
Assert.fail();
|
||||
} else {
|
||||
myRebuildException = ex;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -93,8 +100,8 @@ public class StringIndex {
|
||||
return ContainerUtil.collect(myIndex.getData(word).getValueIterator());
|
||||
}
|
||||
|
||||
public void update(final String path, @Nullable String content, @Nullable String oldContent) throws StorageException {
|
||||
myIndex.update(Math.abs(path.hashCode()), toInput(path, content)).compute();
|
||||
public boolean update(final String path, @Nullable String content, @Nullable String oldContent) throws StorageException {
|
||||
return myIndex.update(Math.abs(path.hashCode()), toInput(path, content)).compute();
|
||||
}
|
||||
|
||||
public void flush() throws StorageException {
|
||||
@@ -110,6 +117,10 @@ public class StringIndex {
|
||||
return content != null ? new PathContentPair(path, content) : null;
|
||||
}
|
||||
|
||||
public Exception getRebuildException() {
|
||||
return myRebuildException;
|
||||
}
|
||||
|
||||
private static class Indexer implements DataIndexer<String, String, PathContentPair> {
|
||||
@Override
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user