mirror of
https://github.com/google/nomulus.git
synced 2025-05-02 13:07:50 +02:00
Many registry tools tests modify system properties but do not restore them to original state. These tests must be isolated from each other and cannot share the same test execution process. This has a huge impact on test performance under Gradle, which seems to have higher process startup overhead. Current Gradle test config has to set 'forEvery' to 1, i.e., every test class must be run in a freshly started process. This change significantly reduces the number of tests that need isolation, making it easier to optimize test config for the remaining tests. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=221350284
47 lines
1.7 KiB
Java
47 lines
1.7 KiB
Java
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.config;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
/**
|
|
* Wrapper interface around {@link System#setProperty(String, String)} and {@link
|
|
* System#clearProperty(String)}. Tests that modify system properties may provide custom
|
|
* implementations that keeps track of changes and restores original property values on test
|
|
* completion.
|
|
*/
|
|
public interface SystemPropertySetter {
|
|
|
|
/**
|
|
* Updates the system property specified by {@code key}. If {@code value} is not null, {@link
|
|
* System#setProperty(String, String)} is invoked; otherwise {@link System#clearProperty(String)}
|
|
* is invoked.
|
|
*/
|
|
SystemPropertySetter setProperty(String key, @Nullable String value);
|
|
|
|
/** Production implementation of {@link SystemPropertySetter}. */
|
|
SystemPropertySetter PRODUCTION_IMPL =
|
|
new SystemPropertySetter() {
|
|
@Override
|
|
public SystemPropertySetter setProperty(String key, @Nullable String value) {
|
|
if (value == null) {
|
|
System.clearProperty(key);
|
|
} else {
|
|
System.setProperty(key, value);
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
}
|