fabriziofortino commented on code in PR #566: URL: https://github.com/apache/jackrabbit-oak/pull/566#discussion_r871441280
########## oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImpl.java: ########## @@ -46,6 +47,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.jmx.Name; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.StringUtils; Review Comment: unused import ```suggestion ``` ########## oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImplTest.java: ########## @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.plugins.index.lucene; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; Review Comment: unused ```suggestion ``` ########## oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImplTest.java: ########## @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.plugins.index.lucene; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.SimpleAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field.Store; +import org.apache.lucene.document.IntField; +import org.apache.lucene.document.LongField; +import org.apache.lucene.document.StringField; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util.Version; +import org.junit.Before; +import org.junit.Test; + +public class LuceneIndexMBeanImplTest { + + private LuceneIndexMBeanImpl luceneIndexMBean; + + private final Map<String, LuceneIndexNode> indexes = new HashMap<>(); + + @Before + public void before() throws Exception { + IndexTracker tracker = mock(IndexTracker.class); + when(tracker.acquireIndexNode(anyString())).thenAnswer((inv) -> { + String path = inv.getArgument(0, String.class); + return indexes.get(path); + }); + NodeStore nodeStore = mock(NodeStore.class); + luceneIndexMBean = new LuceneIndexMBeanImpl(tracker, nodeStore, null, + new File("target/index"), null); + } + + private IndexWriter addNodeIndex(String path) throws IOException { + Directory directory = new RAMDirectory(); + Analyzer analyzer = new SimpleAnalyzer(Version.LUCENE_47); + IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer); + IndexWriter writer = new IndexWriter(directory, config); + LuceneIndexNode indexNode = mock(LuceneIndexNode.class); + when(indexNode.getSearcher()).thenAnswer(inv -> new IndexSearcher(DirectoryReader.open(directory))); + indexes.put(path, indexNode); + return writer; + } + + private void assertTermsMatch(String expectedFile, String[] actualTermsResult) throws IOException { + String[] expectedtermsResult = IOUtils + .readLines(getClass().getResourceAsStream(expectedFile), StandardCharsets.UTF_8).toArray(new String[0]); + assertArrayEquals(expectedtermsResult, actualTermsResult); + } + + @Test + public void testGetFieldTermsInfo_withType() throws IOException { + String INDEX_PATH = "/oak:index/test-index"; + IndexWriter indexWriter = addNodeIndex(INDEX_PATH); + for (int i = 0; i < 10; i++) { + Document doc = new Document(); + doc.add(new StringField("string", "value-" + i, Store.NO)); + doc.add(new LongField("long", (long) i, Store.NO)); Review Comment: redundant cast ```suggestion doc.add(new LongField("long", i, Store.NO)); ``` ########## oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImplTest.java: ########## @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.plugins.index.lucene; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.SimpleAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field.Store; +import org.apache.lucene.document.IntField; +import org.apache.lucene.document.LongField; +import org.apache.lucene.document.StringField; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util.Version; +import org.junit.Before; +import org.junit.Test; + +public class LuceneIndexMBeanImplTest { + + private LuceneIndexMBeanImpl luceneIndexMBean; + + private final Map<String, LuceneIndexNode> indexes = new HashMap<>(); + + @Before + public void before() throws Exception { + IndexTracker tracker = mock(IndexTracker.class); + when(tracker.acquireIndexNode(anyString())).thenAnswer((inv) -> { + String path = inv.getArgument(0, String.class); + return indexes.get(path); + }); + NodeStore nodeStore = mock(NodeStore.class); + luceneIndexMBean = new LuceneIndexMBeanImpl(tracker, nodeStore, null, + new File("target/index"), null); + } + + private IndexWriter addNodeIndex(String path) throws IOException { + Directory directory = new RAMDirectory(); + Analyzer analyzer = new SimpleAnalyzer(Version.LUCENE_47); + IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer); + IndexWriter writer = new IndexWriter(directory, config); + LuceneIndexNode indexNode = mock(LuceneIndexNode.class); + when(indexNode.getSearcher()).thenAnswer(inv -> new IndexSearcher(DirectoryReader.open(directory))); + indexes.put(path, indexNode); + return writer; + } + + private void assertTermsMatch(String expectedFile, String[] actualTermsResult) throws IOException { + String[] expectedtermsResult = IOUtils + .readLines(getClass().getResourceAsStream(expectedFile), StandardCharsets.UTF_8).toArray(new String[0]); + assertArrayEquals(expectedtermsResult, actualTermsResult); Review Comment: fix camel case ```suggestion String[] expectedTermsResult = IOUtils .readLines(getClass().getResourceAsStream(expectedFile), StandardCharsets.UTF_8).toArray(new String[0]); assertArrayEquals(expectedTermsResult, actualTermsResult); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
