Search in sources :

Example 1 with AnalyzerScope

use of org.opensearch.index.analysis.AnalyzerScope in project OpenSearch by opensearch-project.

the class IndexModuleTests method testIndexAnalyzersCleanedUpIfIndexServiceCreationFails.

public void testIndexAnalyzersCleanedUpIfIndexServiceCreationFails() {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
    final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    final HashSet<Analyzer> openAnalyzers = new HashSet<>();
    final AnalysisModule.AnalysisProvider<AnalyzerProvider<?>> analysisProvider = (i, e, n, s) -> new AnalyzerProvider<Analyzer>() {

        @Override
        public String name() {
            return "test";
        }

        @Override
        public AnalyzerScope scope() {
            return AnalyzerScope.INDEX;
        }

        @Override
        public Analyzer get() {
            final Analyzer analyzer = new Analyzer() {

                @Override
                protected TokenStreamComponents createComponents(String fieldName) {
                    return new TokenStreamComponents(new StandardTokenizer());
                }

                @Override
                public void close() {
                    super.close();
                    openAnalyzers.remove(this);
                }
            };
            openAnalyzers.add(analyzer);
            return analyzer;
        }
    };
    final AnalysisRegistry analysisRegistry = new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), singletonMap("test", analysisProvider), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap());
    IndexModule module = createIndexModule(indexSettings, analysisRegistry);
    // causes index service creation to fail
    threadPool.shutdown();
    expectThrows(OpenSearchRejectedExecutionException.class, () -> newIndexService(module));
    assertThat(openAnalyzers, empty());
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) IndexRemovalReason(org.opensearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) CREATE_INDEX(org.opensearch.index.IndexService.IndexCreationContext.CREATE_INDEX) IndicesModule(org.opensearch.indices.IndicesModule) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CheckedFunction(org.opensearch.common.CheckedFunction) Term(org.apache.lucene.index.Term) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) AnalyzerScope(org.opensearch.index.analysis.AnalyzerScope) CircuitBreaker(org.opensearch.common.breaker.CircuitBreaker) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) AssertingDirectoryReader(org.apache.lucene.index.AssertingDirectoryReader) IndexStorePlugin(org.opensearch.plugins.IndexStorePlugin) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AnalysisRegistry(org.opensearch.index.analysis.AnalysisRegistry) IndexFieldDataCache(org.opensearch.index.fielddata.IndexFieldDataCache) RecoveryState(org.opensearch.indices.recovery.RecoveryState) Directory(org.apache.lucene.store.Directory) Property(org.opensearch.common.settings.Setting.Property) Map(java.util.Map) MockEngineFactory(org.opensearch.test.engine.MockEngineFactory) QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) AlreadySetException(org.apache.lucene.util.SetOnce.AlreadySetException) NodeEnvironment(org.opensearch.env.NodeEnvironment) ScriptService(org.opensearch.script.ScriptService) IndexEventListener(org.opensearch.index.shard.IndexEventListener) DirectoryReader(org.apache.lucene.index.DirectoryReader) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) Engine(org.opensearch.index.engine.Engine) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) FieldInvertState(org.apache.lucene.index.FieldInvertState) EngineConfigFactory(org.opensearch.index.engine.EngineConfigFactory) FsDirectoryFactory(org.opensearch.index.store.FsDirectoryFactory) AnalyzerProvider(org.opensearch.index.analysis.AnalyzerProvider) Matchers.is(org.hamcrest.Matchers.is) BigArrays(org.opensearch.common.util.BigArrays) ShardLock(org.opensearch.env.ShardLock) ClusterServiceUtils(org.opensearch.test.ClusterServiceUtils) Matchers.containsString(org.hamcrest.Matchers.containsString) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Uid(org.opensearch.index.mapper.Uid) IndexSettingsModule(org.opensearch.test.IndexSettingsModule) Mockito.mock(org.mockito.Mockito.mock) TestEnvironment(org.opensearch.env.TestEnvironment) StandardTokenizer(org.apache.lucene.analysis.standard.StandardTokenizer) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) SimilarityService(org.opensearch.index.similarity.SimilarityService) QueryCache(org.opensearch.index.cache.query.QueryCache) ThreadPool(org.opensearch.threadpool.ThreadPool) Weight(org.apache.lucene.search.Weight) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndicesFieldDataCache(org.opensearch.indices.fielddata.cache.IndicesFieldDataCache) RecoverySource(org.opensearch.cluster.routing.RecoverySource) InternalEngineTests(org.opensearch.index.engine.InternalEngineTests) HashSet(java.util.HashSet) ReaderContext(org.opensearch.search.internal.ReaderContext) IndexingOperationListener(org.opensearch.index.shard.IndexingOperationListener) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) Similarity(org.apache.lucene.search.similarities.Similarity) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) Collections.singletonMap(java.util.Collections.singletonMap) ShardPath(org.opensearch.index.shard.ShardPath) IndicesQueryCache(org.opensearch.indices.IndicesQueryCache) TermStatistics(org.apache.lucene.search.TermStatistics) IndexQueryCache(org.opensearch.index.cache.query.IndexQueryCache) Environment(org.opensearch.env.Environment) InternalEngineFactory(org.opensearch.index.engine.InternalEngineFactory) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) Setting(org.opensearch.common.settings.Setting) Analyzer(org.apache.lucene.analysis.Analyzer) DisabledQueryCache(org.opensearch.index.cache.query.DisabledQueryCache) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) SearchOperationListener(org.opensearch.index.shard.SearchOperationListener) ShardRouting(org.opensearch.cluster.routing.ShardRouting) IOUtils(org.opensearch.core.internal.io.IOUtils) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) CollectionStatistics(org.apache.lucene.search.CollectionStatistics) AnalysisModule(org.opensearch.indices.analysis.AnalysisModule) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) ClusterService(org.opensearch.cluster.service.ClusterService) Collections(java.util.Collections) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) NonNegativeScoresSimilarity(org.opensearch.index.similarity.NonNegativeScoresSimilarity) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Analyzer(org.apache.lucene.analysis.Analyzer) AnalyzerProvider(org.opensearch.index.analysis.AnalyzerProvider) AnalysisRegistry(org.opensearch.index.analysis.AnalysisRegistry) StandardTokenizer(org.apache.lucene.analysis.standard.StandardTokenizer) AnalysisModule(org.opensearch.indices.analysis.AnalysisModule) Settings(org.opensearch.common.settings.Settings) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 StandardTokenizer (org.apache.lucene.analysis.standard.StandardTokenizer)1 AssertingDirectoryReader (org.apache.lucene.index.AssertingDirectoryReader)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 FieldInvertState (org.apache.lucene.index.FieldInvertState)1 Term (org.apache.lucene.index.Term)1 CollectionStatistics (org.apache.lucene.search.CollectionStatistics)1 QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)1 TermStatistics (org.apache.lucene.search.TermStatistics)1 Weight (org.apache.lucene.search.Weight)1 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)1