Skip to content

Commit

Permalink
Remove older lucene test
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed Jun 7, 2023
1 parent 33335f7 commit f42e98f
Showing 1 changed file with 0 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.indices.replication;

import com.carrotsearch.randomizedtesting.RandomizedTest;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.SortedDocValuesField;
Expand Down Expand Up @@ -43,7 +42,6 @@
import org.opensearch.cluster.routing.ShardRouting;
import org.opensearch.cluster.routing.ShardRoutingState;
import org.opensearch.cluster.routing.allocation.command.CancelAllocationCommand;
import org.opensearch.common.io.PathUtils;
import org.opensearch.common.io.stream.NamedWriteableRegistry;
import org.opensearch.common.lease.Releasable;
import org.opensearch.common.lucene.index.OpenSearchDirectoryReader;
Expand Down Expand Up @@ -72,24 +70,14 @@
import org.opensearch.test.transport.MockTransportService;
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static java.util.Arrays.asList;
import static org.opensearch.action.search.PitTestsUtil.assertSegments;
Expand Down Expand Up @@ -1314,71 +1302,4 @@ public void testWithDifferentCompressionModes() throws Exception {
verifyStoreContent();
}
}

/**
* This test validates that segment replications works for older codec implementations
* @throws Exception
*/
public void testWithOlderCodecs() throws Exception {
final String nodeA = internalCluster().startNode();
final String nodeB = internalCluster().startNode();
final Settings settings = Settings.builder()
.put(indexSettings())
.put(EngineConfig.INDEX_CODEC_SETTING.getKey(), getOlderLuceneCodec())
.build();
createIndex(INDEX_NAME, settings);
final int initialDocCount = scaledRandomIntBetween(100, 200);
try (
BackgroundIndexer indexer = new BackgroundIndexer(
INDEX_NAME,
"_doc",
client(),
-1,
RandomizedTest.scaledRandomIntBetween(2, 5),
false,
random()
)
) {
indexer.start(initialDocCount);
waitForDocs(initialDocCount, indexer);
refresh(INDEX_NAME);
waitForSearchableDocs(initialDocCount, nodeA, nodeB);

final int additionalDocCount = scaledRandomIntBetween(0, 200);
final int expectedHitCount = initialDocCount + additionalDocCount;
indexer.start(additionalDocCount);
waitForDocs(expectedHitCount, indexer);

flushAndRefresh(INDEX_NAME);
waitForSearchableDocs(expectedHitCount, nodeA, nodeB);

ensureGreen(INDEX_NAME);
verifyStoreContent();
}
}

// Return oldest lucene codec name. It does this by iterating throw all directories under lucene library and filter
// ones matching lucene codec name regex
private String getOlderLuceneCodec() throws IOException, URISyntaxException {
final TreeSet<String> codecNames = new TreeSet<>();
final String separator = PathUtils.getDefaultFileSystem().getSeparator();
Pattern pattern = Pattern.compile("lucene[0-9]+");
Path luceneJarPath = PathUtils.get(Codec.class.getProtectionDomain().getCodeSource().getLocation().toURI());
try (var fileIn = Files.newInputStream(luceneJarPath)) {
ZipInputStream zip = new ZipInputStream(fileIn);
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
final String dirPath = entry.getName();
// Fetch name i.e. '../lucene94/' -> 'lucene94'
final String dirName = dirPath.substring(dirPath.lastIndexOf(separator, dirPath.length() - 2) + 1, dirPath.length() - 1);
Matcher matcher = pattern.matcher(dirName);
if (matcher.matches()) {
codecNames.add(dirName);
}
}
}
logger.debug("--> Older lucene codecs {}", codecNames);
String oldestSupportedCodec = codecNames.pollFirst();
// Get actual lucene codec class name i.e. lucene90 -> Lucene90
return oldestSupportedCodec.substring(0, 1).toUpperCase(Locale.getDefault()) + oldestSupportedCodec.substring(1);
}
}

0 comments on commit f42e98f

Please sign in to comment.