Skip to content

Commit e8ad6be

Browse files
Fix lingering test failures
- Add missing LockFeatureFlag annotations. - Cannot use annotation in tests which expect exception thrown. - SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY has no setting? Adding. - Flight server tests need flag enabled on setup. Signed-off-by: Finn Carroll <[email protected]>
1 parent 94fd7af commit e8ad6be

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

plugins/arrow-flight-rpc/src/test/java/org/opensearch/arrow/flight/bootstrap/FlightClientManagerTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.opensearch.cluster.node.DiscoveryNodes;
2525
import org.opensearch.cluster.service.ClusterService;
2626
import org.opensearch.common.settings.Settings;
27+
import org.opensearch.common.util.FeatureFlags;
2728
import org.opensearch.core.action.ActionListener;
2829
import org.opensearch.core.common.transport.BoundTransportAddress;
2930
import org.opensearch.core.common.transport.TransportAddress;
@@ -63,6 +64,7 @@
6364

6465
@SuppressWarnings("unchecked")
6566
public class FlightClientManagerTests extends OpenSearchTestCase {
67+
private static FeatureFlags.TestUtils.FlagLock ffLock = null;
6668

6769
private static BufferAllocator allocator;
6870
private static EventLoopGroup elg;
@@ -77,13 +79,13 @@ public class FlightClientManagerTests extends OpenSearchTestCase {
7779

7880
@BeforeClass
7981
public static void setupClass() throws Exception {
82+
ffLock = new FeatureFlags.TestUtils.FlagLock(ARROW_STREAMS);
8083
ServerConfig.init(Settings.EMPTY);
8184
allocator = new RootAllocator();
8285
elg = ServerConfig.createELG("test-grpc-worker-elg", NettyRuntime.availableProcessors() * 2);
8386
executorService = ServerConfig.createELG("test-grpc-worker", NettyRuntime.availableProcessors() * 2);
8487
}
8588

86-
@LockFeatureFlag(ARROW_STREAMS)
8789
@Override
8890
public void setUp() throws Exception {
8991
super.setUp();
@@ -175,6 +177,7 @@ private DiscoveryNode createNode(String nodeId, String host, int port) throws Ex
175177
@AfterClass
176178
public static void tearClass() {
177179
allocator.close();
180+
ffLock.close();
178181
}
179182

180183
public void testGetFlightClientForExistingNode() {

server/src/main/java/org/opensearch/common/util/FeatureFlags.java

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public class FeatureFlags {
4242
*/
4343
public static final String SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY = FEATURE_FLAG_PREFIX
4444
+ "searchable_snapshot.extended_compatibility.enabled";
45+
public static final Setting<Boolean> SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_SETTING = Setting.boolSetting(
46+
SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY,
47+
false,
48+
Property.NodeScope
49+
);
4550

4651
/**
4752
* Gates the functionality of extensions.
@@ -162,6 +167,10 @@ static class FeatureFlagsImpl {
162167
put(READER_WRITER_SPLIT_EXPERIMENTAL_SETTING, READER_WRITER_SPLIT_EXPERIMENTAL_SETTING.getDefault(Settings.EMPTY));
163168
put(TERM_VERSION_PRECOMMIT_ENABLE_SETTING, TERM_VERSION_PRECOMMIT_ENABLE_SETTING.getDefault(Settings.EMPTY));
164169
put(ARROW_STREAMS_SETTING, ARROW_STREAMS_SETTING.getDefault(Settings.EMPTY));
170+
put(
171+
SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_SETTING,
172+
SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_SETTING.getDefault(Settings.EMPTY)
173+
);
165174
}
166175
};
167176

server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

+4
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,12 @@ public void onFailure(Exception e) {
972972
);
973973
}
974974

975+
@LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)
975976
public void testPutGlobalV2TemplateWhichProvidesContextWithSpecificVersion() throws Exception {
976977
verifyTemplateCreationUsingContext("1");
977978
}
978979

980+
@LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)
979981
public void testPutGlobalV2TemplateWhichProvidesContextWithLatestVersion() throws Exception {
980982
verifyTemplateCreationUsingContext("_latest");
981983
}
@@ -1014,6 +1016,7 @@ public void testModifySystemTemplateViaUnknownSource() throws Exception {
10141016
);
10151017
}
10161018

1019+
@LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)
10171020
public void testResolveSettingsWithContextVersion() throws Exception {
10181021
ClusterService clusterService = node().injector().getInstance(ClusterService.class);
10191022
final String indexTemplateName = verifyTemplateCreationUsingContext("1");
@@ -1022,6 +1025,7 @@ public void testResolveSettingsWithContextVersion() throws Exception {
10221025
assertThat(settings.get("index.codec"), equalTo(CodecService.BEST_COMPRESSION_CODEC));
10231026
}
10241027

1028+
@LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)
10251029
public void testResolveSettingsWithContextLatest() throws Exception {
10261030
ClusterService clusterService = node().injector().getInstance(ClusterService.class);
10271031
final String indexTemplateName = verifyTemplateCreationUsingContext(Context.LATEST_VERSION);

server/src/test/java/org/opensearch/cluster/routing/OperationRoutingTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
7373
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
7474
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED;
75+
import static org.opensearch.common.util.FeatureFlags.WRITABLE_WARM_INDEX_EXPERIMENTAL_FLAG;
7576
import static org.hamcrest.CoreMatchers.containsString;
7677
import static org.hamcrest.Matchers.containsInAnyOrder;
7778
import static org.hamcrest.Matchers.equalTo;
@@ -1058,9 +1059,9 @@ public void testSearchableSnapshotPrimaryDefault() throws Exception {
10581059
}
10591060
}
10601061

1062+
@LockFeatureFlag(WRITABLE_WARM_INDEX_EXPERIMENTAL_FLAG)
10611063
@SuppressForbidden(reason = "feature flag overrides")
10621064
public void testPartialIndexPrimaryDefault() throws Exception {
1063-
System.setProperty(FeatureFlags.WRITABLE_WARM_INDEX_EXPERIMENTAL_FLAG, "true");
10641065
final int numIndices = 1;
10651066
final int numShards = 2;
10661067
final int numReplicas = 2;
@@ -1116,7 +1117,6 @@ public void testPartialIndexPrimaryDefault() throws Exception {
11161117
} finally {
11171118
IOUtils.close(clusterService);
11181119
terminate(threadPool);
1119-
System.setProperty(FeatureFlags.WRITABLE_WARM_INDEX_EXPERIMENTAL_FLAG, "false");
11201120
}
11211121
}
11221122

server/src/test/java/org/opensearch/index/mapper/ObjectMapperTests.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.opensearch.cluster.metadata.IndexMetadata;
3636
import org.opensearch.common.compress.CompressedXContent;
3737
import org.opensearch.common.settings.Settings;
38+
import org.opensearch.common.util.FeatureFlags;
3839
import org.opensearch.common.xcontent.XContentFactory;
3940
import org.opensearch.core.common.bytes.BytesArray;
4041
import org.opensearch.core.common.unit.ByteSizeUnit;
@@ -498,7 +499,6 @@ public void testDerivedFields() throws Exception {
498499
assertEquals("date", mapper.typeName());
499500
}
500501

501-
@LockFeatureFlag(STAR_TREE_INDEX)
502502
public void testCompositeFields() throws Exception {
503503
String mapping = XContentFactory.jsonBuilder()
504504
.startObject()
@@ -556,18 +556,20 @@ public void testCompositeFields() throws Exception {
556556
ex.getMessage()
557557
);
558558

559-
DocumentMapper documentMapper = createIndex("test", settings).mapperService()
560-
.documentMapperParser()
561-
.parse("tweet", new CompressedXContent(mapping));
562-
563-
Mapper mapper = documentMapper.root().getMapper("startree");
564-
assertTrue(mapper instanceof StarTreeMapper);
565-
StarTreeMapper starTreeMapper = (StarTreeMapper) mapper;
566-
assertEquals("star_tree", starTreeMapper.fieldType().typeName());
567-
// Check that field in properties was parsed correctly as well
568-
mapper = documentMapper.root().getMapper("@timestamp");
569-
assertNotNull(mapper);
570-
assertEquals("date", mapper.typeName());
559+
FeatureFlags.TestUtils.with(STAR_TREE_INDEX, () -> {
560+
DocumentMapper documentMapper = createIndex("test", settings).mapperService()
561+
.documentMapperParser()
562+
.parse("tweet", new CompressedXContent(mapping));
563+
564+
Mapper mapper = documentMapper.root().getMapper("startree");
565+
assertTrue(mapper instanceof StarTreeMapper);
566+
StarTreeMapper starTreeMapper = (StarTreeMapper) mapper;
567+
assertEquals("star_tree", starTreeMapper.fieldType().typeName());
568+
// Check that field in properties was parsed correctly as well
569+
mapper = documentMapper.root().getMapper("@timestamp");
570+
assertNotNull(mapper);
571+
assertEquals("date", mapper.typeName());
572+
});
571573
}
572574

573575
public void testNestedIsParent() throws Exception {

test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,7 @@ public abstract class OpenSearchTestCase extends LuceneTestCase {
247247
* Enables and locks a feature flag for the duration of the test case.
248248
* This annotation guarantees the feature flag will be enabled for the duration of
249249
* the test case. Feature flag is returned to previous value on test exit.
250-
* Usage:
251-
* @LockFeatureFlag("example.featureflag.setting.key.enabled")
252-
* public void testFeatureFlagExample() {
253-
* // Test flag dependant feature
254-
* }
250+
* Usage: LockFeatureFlag("example.featureflag.setting.key.enabled")
255251
*/
256252
@Retention(RetentionPolicy.RUNTIME)
257253
@Target({ ElementType.METHOD })

0 commit comments

Comments
 (0)