-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FeatureFlagSetter helper class
Also refactored unit test classes to use the helper class. Signed-off-by: Kartik Ganesh <gkart@amazon.com>
- Loading branch information
Showing
6 changed files
with
98 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/framework/src/main/java/org/opensearch/test/FeatureFlagSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.test; | ||
|
||
import org.opensearch.common.SuppressForbidden; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* Helper class that wraps the lifecycle of setting and finally clearing of | ||
* a {@link org.opensearch.common.util.FeatureFlags} string in an {@link AutoCloseable}. | ||
*/ | ||
public class FeatureFlagSetter implements AutoCloseable { | ||
|
||
private final String flag; | ||
|
||
private FeatureFlagSetter(String flag) { | ||
this.flag = flag; | ||
} | ||
|
||
@SuppressForbidden(reason = "Enables setting of feature flags") | ||
public static final FeatureFlagSetter set(String flag) { | ||
AccessController.doPrivileged((PrivilegedAction<String>) () -> System.setProperty(flag, "true")); | ||
return new FeatureFlagSetter(flag); | ||
} | ||
|
||
@SuppressForbidden(reason = "Clears the set feature flag on close") | ||
@Override | ||
public void close() throws Exception { | ||
AccessController.doPrivileged((PrivilegedAction<String>) () -> System.clearProperty(this.flag)); | ||
} | ||
} |