Skip to content

Commit 4587c4a

Browse files
committed
OAK-11719: compatibility mode test
1 parent 10b03cd commit 4587c4a

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/fulltext/VectorQuery.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class VectorQuery {
3131
public static final String INFERENCE_QUERY_CONFIG_PREFIX = System.getProperty(
3232
INFERENCE_QUERY_CONFIG_PREFIX_KEY, DEFAULT_INFERENCE_QUERY_CONFIG_PREFIX);
3333
public static final String EXPERIMENTAL_COMPATIBILITY_MODE_KEY = "oak.inference.experimental.compatibility";
34-
public static final Boolean IS_EXPERIMENTAL_COMPATIBILITY_MODE_ENABLE = Boolean.getBoolean(EXPERIMENTAL_COMPATIBILITY_MODE_KEY);
3534

3635
private final String queryInferenceConfig;
3736
private final String queryText;
@@ -76,7 +75,7 @@ private String[] parseText(String inputText) {
7675
}
7776
queryTextPart = text;
7877
} else {
79-
if (IS_EXPERIMENTAL_COMPATIBILITY_MODE_ENABLE) {
78+
if (isCompatibilityModeEnabled()) {
8079
// No JSON part present but starts with prefix
8180
// we return "{}" to be compatible with experimental inference queries
8281
jsonPart = "{}";
@@ -102,4 +101,8 @@ public String getQueryInferenceConfig() {
102101
public String getQueryText() {
103102
return queryText;
104103
}
104+
105+
private boolean isCompatibilityModeEnabled() {
106+
return Boolean.getBoolean(EXPERIMENTAL_COMPATIBILITY_MODE_KEY);
107+
}
105108
}

oak-query-spi/src/test/java/org/apache/jackrabbit/oak/spi/query/fulltext/VectorQueryCompatibilityModeTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public class VectorQueryCompatibilityModeTest {
2929
@Before
3030
public void setUp() {
3131
// Set up any necessary system properties or configurations
32-
System.setProperty(VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX_KEY, "true");
32+
System.setProperty(VectorQuery.EXPERIMENTAL_COMPATIBILITY_MODE_KEY, "true");
3333
}
3434

3535
@After
3636
public void tearDown() {
3737
// Clean up any system properties set during the tests
3838
System.clearProperty(VectorQuery.EXPERIMENTAL_COMPATIBILITY_MODE_KEY);
39+
System.clearProperty(VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX_KEY);
3940
}
4041

4142
@Test
4243
public void testQueryWithEmptyConfigExperimentalInferenceCompatible() {
43-
enableExperimentalInferenceCompatibility();
4444
// Input string: "??query text"
4545
String inputString = VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX + VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX + "query text";
4646
VectorQuery query = new VectorQuery(inputString);
@@ -51,16 +51,13 @@ public void testQueryWithEmptyConfigExperimentalInferenceCompatible() {
5151

5252
@Test
5353
public void testPrefixOnlyQueryExperimentalInferenceCompatible() {
54-
enableExperimentalInferenceCompatibility();
5554
// Input string: "?query text"
5655
VectorQuery query = new VectorQuery(VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX + "query text");
5756
assertEquals("{}", query.getQueryInferenceConfig());
5857
// With the implementation fix, the prefix should now be correctly stripped
5958
assertEquals("query text", query.getQueryText());
6059
}
6160

62-
private void enableExperimentalInferenceCompatibility() {
63-
System.setProperty(VectorQuery.EXPERIMENTAL_COMPATIBILITY_MODE_KEY, "true");
64-
}
65-
61+
// We don't need to explicitly enable experimental compatibility mode in each test anymore
62+
// as it's already set in setUp()
6663
}

oak-query-spi/src/test/java/org/apache/jackrabbit/oak/spi/query/fulltext/VectorQueryTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,27 @@
1818
*/
1919
package org.apache.jackrabbit.oak.spi.query.fulltext;
2020

21+
import org.junit.After;
22+
import org.junit.Before;
2123
import org.junit.Test;
2224

2325
import static org.junit.Assert.assertEquals;
2426

2527
public class VectorQueryTest {
2628

29+
@Before
30+
public void setUp() {
31+
// Ensure compatibility mode is disabled for these tests
32+
System.setProperty(VectorQuery.EXPERIMENTAL_COMPATIBILITY_MODE_KEY, "false");
33+
}
34+
35+
@After
36+
public void tearDown() {
37+
// Clean up all system properties set during the tests
38+
System.clearProperty(VectorQuery.EXPERIMENTAL_COMPATIBILITY_MODE_KEY);
39+
System.clearProperty(VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX_KEY);
40+
}
41+
2742
@Test
2843
public void testBasicQuery() {
2944
// Input string: "simple query"
@@ -115,8 +130,8 @@ public void testPrefixOnlyQueryExperimentalInferenceNonCompatible() {
115130
// Input string: "?query text"
116131
VectorQuery query = new VectorQuery(VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX + "query text");
117132
assertEquals("", query.getQueryInferenceConfig());
118-
// With the implementation fix, the prefix should now be correctly stripped
119-
assertEquals("?query text", query.getQueryText());
133+
// When compatibility mode is disabled, the prefix should remain part of the query text
134+
assertEquals(VectorQuery.INFERENCE_QUERY_CONFIG_PREFIX + "query text", query.getQueryText());
120135
}
121136

122137
}

0 commit comments

Comments
 (0)