diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java index c644bff2ea1e..1d697fcf9042 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java @@ -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 { protected DiscoveredTestsIndex(@NotNull File file) throws IOException { - super(INDEX_EXTENSION, new MyIndexStorage(file), new MyForwardIndex() { - @NotNull - @Override - public PersistentHashMap> 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 { @@ -81,15 +79,4 @@ public class DiscoveredTestsIndex extends MapReduceIndex { - protected MyForwardIndex() throws IOException { - super(INDEX_EXTENSION); - } - - public boolean containsDataFrom(int testId) throws IOException { - return getInput(testId) != null; - } - } } diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java index fc9cb3888292..ad96c0b44db2 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java @@ -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 { protected TestFilesIndex(@NotNull File file) throws IOException { - super(INDEX_EXTENSION, new MyIndexStorage(file), new MyForwardIndex() { - @NotNull - @Override - public PersistentHashMap> 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 { @Nullable Collection getTestDataFor(int testId) throws IOException { - return ((MyForwardIndex)myForwardIndex).containsDataFrom(testId); + ForwardIndex forwardIndex = getForwardIndexMap(); + KeyCollectionForwardIndexAccessor forwardIndexAccessor = (KeyCollectionForwardIndexAccessor)getForwardIndexAccessor(); + return forwardIndexAccessor.deserializeData(forwardIndex.get(testId)); } private static class MyIndexStorage extends MapIndexStorage { @@ -80,16 +81,4 @@ public class TestFilesIndex extends MapReduceIndex { return DiscoveredTestDataHolder.VERSION; } }; - - - private abstract static class MyForwardIndex extends KeyCollectionBasedForwardIndex { - protected MyForwardIndex() throws IOException { - super(INDEX_EXTENSION); - } - - @Nullable - public Collection containsDataFrom(int testId) throws IOException { - return getInput(testId); - } - } } diff --git a/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java b/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java index 88d4c0d25dea..0fc9fd59056f 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java +++ b/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java @@ -79,7 +79,7 @@ public abstract class MapReduceIndex implements InvertedIndex< @NotNull IndexStorage storage, @Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex, @Nullable ForwardIndexAccessor 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 extension, @@ -93,6 +93,16 @@ public abstract class MapReduceIndex 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 getForwardIndexAccessor() { + //TODO simplify when will be rewritting + return myForwardIndex instanceof MyNewForwardIndexWrapper ? ((MyNewForwardIndexWrapper)myForwardIndex).myForwardIndexAccessor : null; + } + @NotNull public IndexStorage getStorage() { return myStorage; @@ -364,38 +374,41 @@ public abstract class MapReduceIndex implements InvertedIndex< } } - @NotNull - private static ForwardIndex wrapWithOldForwardIndex(com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex, - ForwardIndexAccessor forwardIndexAccessor) { - LOG.assertTrue(forwardIndex != null); - LOG.assertTrue(forwardIndexAccessor != null); - return new ForwardIndex() { - @NotNull - @Override - public InputDataDiffBuilder getDiffBuilder(int inputId) throws IOException { - return forwardIndexAccessor.getDiffBuilder(inputId, forwardIndex.get(inputId)); - } + private static class MyNewForwardIndexWrapper implements ForwardIndex { + private final ForwardIndexAccessor myForwardIndexAccessor; + private final com.intellij.util.indexing.impl.forward.ForwardIndex myForwardIndex; - @Override - public void putInputData(int inputId, @NotNull Map data) throws IOException { - forwardIndex.put(inputId, forwardIndexAccessor.serializeIndexedData(data, null)); - } + MyNewForwardIndexWrapper(@NotNull ForwardIndexAccessor forwardIndexAccessor, + @NotNull com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex) { + myForwardIndexAccessor = forwardIndexAccessor; + myForwardIndex = forwardIndex; + } - @Override - public void flush() { - forwardIndex.force(); - } + @NotNull + @Override + public InputDataDiffBuilder 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 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(); + } } } diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java index 9a59d1b8224a..cc6f193725d9 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java @@ -30,10 +30,16 @@ public abstract class AbstractForwardIndexAccessor protected abstract DataType convertToDataType(@Nullable Map 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 getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException { - return createDiffBuilder(inputId, sequence == null ? null : deserializeFromByteSeq(sequence, myDataTypeExternalizer)); + return createDiffBuilder(inputId, deserializeData(sequence)); } @Nullable diff --git a/plugins/junit5_rt_tests/test/com/intellij/testDiscovery/TestDiscoveryJUnitIntegrationTest.java b/plugins/junit5_rt_tests/test/com/intellij/testDiscovery/TestDiscoveryJUnitIntegrationTest.java index b21733197587..e0991951f19c 100644 --- a/plugins/junit5_rt_tests/test/com/intellij/testDiscovery/TestDiscoveryJUnitIntegrationTest.java +++ b/plugins/junit5_rt_tests/test/com/intellij/testDiscovery/TestDiscoveryJUnitIntegrationTest.java @@ -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 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 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); }