Skip to content

Commit

Permalink
Update tests for backwards codecs (#710)
Browse files Browse the repository at this point in the history
Updates tests for backwards codecs to prevent backwards codecs from
writing with a read only codec.

Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 authored Jan 5, 2023
1 parent 6bbf086 commit 8b16831
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
package org.opensearch.knn.index.codec.KNN940Codec;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.knn.index.codec.KNNCodecTestCase;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;

import static org.opensearch.knn.index.codec.KNNCodecVersion.V_9_4_0;

Expand All @@ -26,15 +22,9 @@ public void testBuildFromModelTemplate() throws InterruptedException, ExecutionE
testBuildFromModelTemplate((KNN940Codec.builder().delegate(V_9_4_0.getDefaultCodecDelegate()).build()));
}

public void testKnnVectorIndex() throws Exception {
Function<MapperService, PerFieldKnnVectorsFormat> perFieldKnnVectorsFormatProvider = (
mapperService) -> new KNN940PerFieldKnnVectorsFormat(Optional.of(mapperService));

Function<PerFieldKnnVectorsFormat, Codec> knnCodecProvider = (knnVectorFormat) -> KNN940Codec.builder()
.delegate(V_9_4_0.getDefaultCodecDelegate())
.knnVectorsFormat(knnVectorFormat)
.build();

testKnnVectorIndex(knnCodecProvider, perFieldKnnVectorsFormatProvider);
// Ensure that the codec is able to return the correct per field knn vectors format for codec
public void testCodecSetsCustomPerFieldKnnVectorsFormat() {
final Codec codec = new KNN940Codec();
assertTrue(codec.knnVectorsFormat() instanceof KNN940PerFieldKnnVectorsFormat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public void testBuildFromModelTemplate() {
testBuildFromModelTemplate((KNN950Codec.builder().delegate(V_9_5_0.getDefaultCodecDelegate()).build()));
}

// Ensure that the codec is able to return the correct per field knn vectors format for codec
public void testCodecSetsCustomPerFieldKnnVectorsFormat() {
final Codec codec = new KNN950Codec();
assertTrue(codec.knnVectorsFormat() instanceof KNN950PerFieldKnnVectorsFormat);
}

// IMPORTANT: When this Codec is moved to a backwards Codec, this test needs to be removed, because it attempts to
// write with a read only codec, which will fail
@SneakyThrows
public void testKnnVectorIndex() {
Function<MapperService, PerFieldKnnVectorsFormat> perFieldKnnVectorsFormatProvider = (
Expand Down

0 comments on commit 8b16831

Please sign in to comment.