mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use new forward index in test discovery (example of exposed forward index)
This commit is contained in:
+7
-20
@@ -8,6 +8,8 @@ import com.intellij.util.indexing.IndexId;
|
||||
import com.intellij.util.indexing.impl.KeyCollectionBasedForwardIndex;
|
||||
import com.intellij.util.indexing.impl.MapIndexStorage;
|
||||
import com.intellij.util.indexing.impl.MapReduceIndex;
|
||||
import com.intellij.util.indexing.impl.forward.KeyCollectionForwardIndexAccessor;
|
||||
import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex;
|
||||
import com.intellij.util.io.*;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -18,14 +20,10 @@ import java.util.Collection;
|
||||
|
||||
public class DiscoveredTestsIndex extends MapReduceIndex<Integer, TIntArrayList, UsedSources> {
|
||||
protected DiscoveredTestsIndex(@NotNull File file) throws IOException {
|
||||
super(INDEX_EXTENSION, new MyIndexStorage(file), new MyForwardIndex() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PersistentHashMap<Integer, Collection<Integer>> createMap() throws IOException {
|
||||
return new PersistentHashMap<>(new File(file, "forward.idx"), EnumeratorIntegerDescriptor.INSTANCE,
|
||||
new IntCollectionDataExternalizer());
|
||||
}
|
||||
});
|
||||
super(INDEX_EXTENSION,
|
||||
new MyIndexStorage(file),
|
||||
new PersistentMapBasedForwardIndex(new File(file, "forward.idx")),
|
||||
new KeyCollectionForwardIndexAccessor<>(new IntCollectionDataExternalizer()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +37,7 @@ public class DiscoveredTestsIndex extends MapReduceIndex<Integer, TIntArrayList,
|
||||
}
|
||||
|
||||
public boolean containsDataFrom(int testId) throws IOException {
|
||||
return ((MyForwardIndex)myForwardIndex).containsDataFrom(testId);
|
||||
return getForwardIndexMap().get(testId) != null;
|
||||
}
|
||||
|
||||
private static class MyIndexStorage extends MapIndexStorage<Integer, TIntArrayList> {
|
||||
@@ -81,15 +79,4 @@ public class DiscoveredTestsIndex extends MapReduceIndex<Integer, TIntArrayList,
|
||||
return DiscoveredTestDataHolder.VERSION;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private abstract static class MyForwardIndex extends KeyCollectionBasedForwardIndex<Integer, TIntArrayList> {
|
||||
protected MyForwardIndex() throws IOException {
|
||||
super(INDEX_EXTENSION);
|
||||
}
|
||||
|
||||
public boolean containsDataFrom(int testId) throws IOException {
|
||||
return getInput(testId) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-21
@@ -6,6 +6,9 @@ import com.intellij.util.indexing.DataIndexer;
|
||||
import com.intellij.util.indexing.IndexExtension;
|
||||
import com.intellij.util.indexing.IndexId;
|
||||
import com.intellij.util.indexing.impl.*;
|
||||
import com.intellij.util.indexing.impl.forward.ForwardIndex;
|
||||
import com.intellij.util.indexing.impl.forward.KeyCollectionForwardIndexAccessor;
|
||||
import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex;
|
||||
import com.intellij.util.io.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -16,14 +19,10 @@ import java.util.Collection;
|
||||
|
||||
public class TestFilesIndex extends MapReduceIndex<Integer, Void, UsedSources> {
|
||||
protected TestFilesIndex(@NotNull File file) throws IOException {
|
||||
super(INDEX_EXTENSION, new MyIndexStorage(file), new MyForwardIndex() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PersistentHashMap<Integer, Collection<Integer>> createMap() throws IOException {
|
||||
return new PersistentHashMap<>(new File(file, "forward.idx"), EnumeratorIntegerDescriptor.INSTANCE,
|
||||
new IntCollectionDataExternalizer());
|
||||
}
|
||||
});
|
||||
super(INDEX_EXTENSION,
|
||||
new MyIndexStorage(file),
|
||||
new PersistentMapBasedForwardIndex(new File(file, "forward.idx")),
|
||||
new KeyCollectionForwardIndexAccessor<>(new IntCollectionDataExternalizer()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +37,9 @@ public class TestFilesIndex extends MapReduceIndex<Integer, Void, UsedSources> {
|
||||
|
||||
@Nullable
|
||||
Collection<Integer> getTestDataFor(int testId) throws IOException {
|
||||
return ((MyForwardIndex)myForwardIndex).containsDataFrom(testId);
|
||||
ForwardIndex forwardIndex = getForwardIndexMap();
|
||||
KeyCollectionForwardIndexAccessor<Integer, Void, UsedSources> forwardIndexAccessor = (KeyCollectionForwardIndexAccessor<Integer, Void, UsedSources>)getForwardIndexAccessor();
|
||||
return forwardIndexAccessor.deserializeData(forwardIndex.get(testId));
|
||||
}
|
||||
|
||||
private static class MyIndexStorage extends MapIndexStorage<Integer, Void> {
|
||||
@@ -80,16 +81,4 @@ public class TestFilesIndex extends MapReduceIndex<Integer, Void, UsedSources> {
|
||||
return DiscoveredTestDataHolder.VERSION;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private abstract static class MyForwardIndex extends KeyCollectionBasedForwardIndex<Integer, Void> {
|
||||
protected MyForwardIndex() throws IOException {
|
||||
super(INDEX_EXTENSION);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Collection<Integer> containsDataFrom(int testId) throws IOException {
|
||||
return getInput(testId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
@NotNull IndexStorage<Key, Value> storage,
|
||||
@Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex,
|
||||
@Nullable ForwardIndexAccessor<Key, Value, Input> forwardIndexAccessor) {
|
||||
this(extension, storage, forwardIndex == null && forwardIndexAccessor == null ? null : wrapWithOldForwardIndex(forwardIndex, forwardIndexAccessor));
|
||||
this(extension, storage, forwardIndex == null || forwardIndexAccessor == null ? null : new MyNewForwardIndexWrapper<>(forwardIndexAccessor, forwardIndex));
|
||||
}
|
||||
|
||||
protected MapReduceIndex(@NotNull IndexExtension<Key, Value, Input> extension,
|
||||
@@ -93,6 +93,16 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
myForwardIndex = forwardIndex;
|
||||
}
|
||||
|
||||
public com.intellij.util.indexing.impl.forward.ForwardIndex getForwardIndexMap() {
|
||||
//TODO simplify and rename (inheritors already have getForwardIndex() method) when will be rewritting
|
||||
return myForwardIndex instanceof MyNewForwardIndexWrapper<?, ?, ?> ? ((MyNewForwardIndexWrapper)myForwardIndex).myForwardIndex : null;
|
||||
}
|
||||
|
||||
public ForwardIndexAccessor<Key, Value, Input> getForwardIndexAccessor() {
|
||||
//TODO simplify when will be rewritting
|
||||
return myForwardIndex instanceof MyNewForwardIndexWrapper<?, ?, ?> ? ((MyNewForwardIndexWrapper)myForwardIndex).myForwardIndexAccessor : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public IndexStorage<Key, Value> getStorage() {
|
||||
return myStorage;
|
||||
@@ -364,38 +374,41 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <Key, Value, Input> ForwardIndex<Key, Value> wrapWithOldForwardIndex(com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex,
|
||||
ForwardIndexAccessor<Key, Value, Input> forwardIndexAccessor) {
|
||||
LOG.assertTrue(forwardIndex != null);
|
||||
LOG.assertTrue(forwardIndexAccessor != null);
|
||||
return new ForwardIndex<Key, Value>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId) throws IOException {
|
||||
return forwardIndexAccessor.getDiffBuilder(inputId, forwardIndex.get(inputId));
|
||||
}
|
||||
private static class MyNewForwardIndexWrapper<Key, Value, Input> implements ForwardIndex<Key, Value> {
|
||||
private final ForwardIndexAccessor<Key, Value, Input> myForwardIndexAccessor;
|
||||
private final com.intellij.util.indexing.impl.forward.ForwardIndex myForwardIndex;
|
||||
|
||||
@Override
|
||||
public void putInputData(int inputId, @NotNull Map<Key, Value> data) throws IOException {
|
||||
forwardIndex.put(inputId, forwardIndexAccessor.serializeIndexedData(data, null));
|
||||
}
|
||||
MyNewForwardIndexWrapper(@NotNull ForwardIndexAccessor<Key, Value, Input> forwardIndexAccessor,
|
||||
@NotNull com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex) {
|
||||
myForwardIndexAccessor = forwardIndexAccessor;
|
||||
myForwardIndex = forwardIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
forwardIndex.force();
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId) throws IOException {
|
||||
return myForwardIndexAccessor.getDiffBuilder(inputId, myForwardIndex.get(inputId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws IOException {
|
||||
forwardIndex.clear();
|
||||
}
|
||||
@Override
|
||||
public void putInputData(int inputId, @NotNull Map<Key, Value> data) throws IOException {
|
||||
myForwardIndex.put(inputId, myForwardIndexAccessor.serializeIndexedData(data, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
forwardIndex.close();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void flush() {
|
||||
myForwardIndex.force();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws IOException {
|
||||
myForwardIndex.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
myForwardIndex.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -30,10 +30,16 @@ public abstract class AbstractForwardIndexAccessor<Key, Value, DataType, Input>
|
||||
|
||||
protected abstract DataType convertToDataType(@Nullable Map<Key, Value> map, @Nullable Input content) throws IOException;
|
||||
|
||||
@Nullable
|
||||
public DataType deserializeData(@Nullable ByteArraySequence sequence) throws IOException {
|
||||
if (sequence == null) return null;
|
||||
return deserializeFromByteSeq(sequence, myDataTypeExternalizer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException {
|
||||
return createDiffBuilder(inputId, sequence == null ? null : deserializeFromByteSeq(sequence, myDataTypeExternalizer));
|
||||
return createDiffBuilder(inputId, deserializeData(sequence));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+14
-3
@@ -2,6 +2,8 @@
|
||||
package com.intellij.testDiscovery;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.PsiLocation;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.execution.configurations.RunConfigurationBase;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
@@ -21,6 +23,7 @@ import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.EdtRule;
|
||||
import com.intellij.testFramework.MapDataContext;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
@@ -37,8 +40,10 @@ import org.junit.rules.TestName;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -146,6 +151,12 @@ public class TestDiscoveryJUnitIntegrationTest extends AbstractTestFrameworkComp
|
||||
.collect(Collectors.toSet());
|
||||
String module = assertOneElement(modules);
|
||||
assertEquals(myModule.getName(), module);
|
||||
|
||||
for (Pair<String, String> test : expectedTests) {
|
||||
assertTrue(testDiscoveryIndex.hasTestTrace(test.getFirst(), test.getSecond(), JUnitConfiguration.FRAMEWORK_ID));
|
||||
}
|
||||
assertFalse(testDiscoveryIndex.hasTestTrace("dummy test name", "123", JUnitConfiguration.FRAMEWORK_ID));
|
||||
|
||||
}
|
||||
|
||||
private static Pair<String, String> t(String testClassName, String testMethodName) {
|
||||
@@ -155,12 +166,12 @@ public class TestDiscoveryJUnitIntegrationTest extends AbstractTestFrameworkComp
|
||||
private void runTestConfiguration(@NotNull PsiElement psiElement) throws ExecutionException {
|
||||
MapDataContext context = new MapDataContext();
|
||||
context.put(LangDataKeys.MODULE, myModule);
|
||||
RunConfiguration configuration = createConfiguration(psiElement, context);
|
||||
JUnitConfiguration configuration = createConfiguration(psiElement, context);
|
||||
ProcessOutput processOutput = doStartTestsProcess(configuration);
|
||||
TestDiscoveryDataSocketListener socketListener =
|
||||
((RunConfigurationBase)configuration).getUserData(TestDiscoveryExtension.SOCKET_LISTENER_KEY);
|
||||
configuration.getUserData(TestDiscoveryExtension.SOCKET_LISTENER_KEY);
|
||||
socketListener.awaitTermination();
|
||||
((RunConfigurationBase)configuration).putUserData(TestDiscoveryExtension.SOCKET_LISTENER_KEY, null);
|
||||
configuration.putUserData(TestDiscoveryExtension.SOCKET_LISTENER_KEY, null);
|
||||
assertEmpty(processOutput.err);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user