Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.TestEnvironment;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.logging.LogManager;
import org.elasticsearch.logging.Logger;
Expand Down Expand Up @@ -148,6 +147,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
Expand Down Expand Up @@ -967,13 +967,6 @@ void executeSubPlan(
ExchangeSourceHandler exchangeSource = new ExchangeSourceHandler(between(1, 64), executor);
ExchangeSinkHandler exchangeSink = new ExchangeSinkHandler(blockFactory, between(1, 64), threadPool::relativeTimeInMillis);

UserAgentParserRegistry userAgentRegistry;
try {
userAgentRegistry = createUserAgentRegistry();
} catch (IOException e) {
throw new IllegalStateException("Failed to create UserAgentParserRegistry", e);
}

LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(
getTestName(),
"",
Expand All @@ -987,7 +980,7 @@ void executeSubPlan(
mock(EnrichLookupService.class),
mock(LookupFromIndexService.class),
mock(InferenceService.class),
userAgentRegistry,
createUserAgentRegistry(),
physicalOperationProviders,
operatorFactoryRegistry
);
Expand Down Expand Up @@ -1105,17 +1098,19 @@ private static List<ExternalSplit> coordinatorSplits(OperatorFactoryRegistry ope
* Creates a {@link UserAgentParserRegistry} with a config directory
* containing the custom-regexes.yml test resource, so csv-spec tests can exercise the {@code regex_file} option.
*/
private static UserAgentParserRegistry createUserAgentRegistry() throws IOException {
Path homeDir = createTempDir();
Path userAgentConfigDir = homeDir.resolve("config").resolve("user-agent");
Files.createDirectories(userAgentConfigDir);
try (InputStream is = CsvTests.class.getResourceAsStream("/custom-regexes.yml")) {
assert is != null : "custom-regexes.yml not found on classpath";
Files.copy(is, userAgentConfigDir.resolve("custom-regexes.yml"));
private static UserAgentParserRegistry createUserAgentRegistry() {
Environment env = TestPhysicalOperationProviders.TEST_ENV.getOrCompute();
Path userAgentConfigDir = env.configDir().resolve("user-agent");
Path customRegexes = userAgentConfigDir.resolve("custom-regexes.yml");
if (Files.exists(customRegexes) == false) {
try (InputStream is = CsvTests.class.getResourceAsStream("/custom-regexes.yml")) {
assert is != null : "custom-regexes.yml not found on classpath";
Files.createDirectories(userAgentConfigDir);
Files.copy(is, customRegexes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return UserAgentPlugin.createRegistry(
TestEnvironment.newEnvironment(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), homeDir).build()),
Settings.EMPTY
);
return UserAgentPlugin.createRegistry(env, Settings.EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.LazyInitializable;
import org.elasticsearch.compute.aggregation.AggregatorMode;
import org.elasticsearch.compute.aggregation.GroupingAggregator;
import org.elasticsearch.compute.aggregation.blockhash.BlockHash;
Expand Down Expand Up @@ -81,6 +82,13 @@
import static org.elasticsearch.index.mapper.MappedFieldType.FieldExtractPreference.EXTRACT_SPATIAL_CENTROID;

public class TestPhysicalOperationProviders extends AbstractPhysicalOperationProviders {

public static final LazyInitializable<Environment, RuntimeException> TEST_ENV = new LazyInitializable<>(
() -> TestEnvironment.newEnvironment(
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build()
)
);

private final List<IndexPage> indexPages;
private final UnmappedResolution unmappedResolution;

Expand Down Expand Up @@ -112,9 +120,7 @@ Optional<Integer> columnIndex(String columnName) {

private static AnalysisRegistry createAnalysisRegistry() throws IOException {
return new AnalysisModule(
TestEnvironment.newEnvironment(
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build()
),
TEST_ENV.getOrCompute(),
List.of(new MachineLearning(Settings.EMPTY), new CommonAnalysisPlugin()),
new StablePluginsRegistry()
).getAnalysisRegistry();
Expand Down
Loading