Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ip2geo processor integ test for failure case #303

Merged
merged 1 commit into from
May 11, 2023
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,6 +43,14 @@
public final class Ip2GeoProcessor extends AbstractProcessor {
private static final Map<String, Object> DATA_EXPIRED = Map.of("error", "ip2geo_data_expired");
private static final String PROPERTY_IP = "ip";

public static final String CONFIG_FIELD = "field";
public static final String CONFIG_TARGET_FIELD = "target_field";
public static final String CONFIG_DATASOURCE = "datasource";
public static final String CONFIG_PROPERTIES = "target_field";
public static final String CONFIG_IGNORE_MISSING = "ignore_missing";
public static final String CONFIG_FIRST_ONLY = "first_only";

private final String field;
private final String targetField;
/**
Expand Down Expand Up @@ -352,12 +360,12 @@ public Ip2GeoProcessor create(
final String description,
final Map<String, Object> config
) throws IOException {
String ipField = readStringProperty(TYPE, processorTag, config, "field");
String targetField = readStringProperty(TYPE, processorTag, config, "target_field", "ip2geo");
String datasourceName = readStringProperty(TYPE, processorTag, config, "datasource");
List<String> propertyNames = readOptionalList(TYPE, processorTag, config, "properties");
boolean ignoreMissing = readBooleanProperty(TYPE, processorTag, config, "ignore_missing", false);
boolean firstOnly = readBooleanProperty(TYPE, processorTag, config, "first_only", true);
String ipField = readStringProperty(TYPE, processorTag, config, CONFIG_FIELD);
String targetField = readStringProperty(TYPE, processorTag, config, CONFIG_TARGET_FIELD, "ip2geo");
String datasourceName = readStringProperty(TYPE, processorTag, config, CONFIG_DATASOURCE);
List<String> propertyNames = readOptionalList(TYPE, processorTag, config, CONFIG_PROPERTIES);
boolean ignoreMissing = readBooleanProperty(TYPE, processorTag, config, CONFIG_IGNORE_MISSING, false);
boolean firstOnly = readBooleanProperty(TYPE, processorTag, config, CONFIG_FIRST_ONLY, true);

// Skip validation for the call by cluster applier service
if (Thread.currentThread().getName().contains(CLUSTER_UPDATE_THREAD_NAME) == false) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.geospatial.ip2geo.processor;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import lombok.SneakyThrows;

import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.geospatial.GeospatialRestTestCase;
import org.opensearch.geospatial.GeospatialTestHelper;

public class Ip2GeoProcessorIT extends GeospatialRestTestCase {

@SneakyThrows
public void testCreateIp2GeoProcessor_whenNoSuchDatasourceExist_thenFails() {
String pipelineName = GeospatialTestHelper.randomLowerCaseString();

// Run
ResponseException exception = expectThrows(
ResponseException.class,
() -> createIp2GeoProcessorPipeline(pipelineName, Collections.emptyMap())
);

// Verify
assertTrue(exception.getMessage().contains("doesn't exist"));
}

private Response createIp2GeoProcessorPipeline(final String pipelineName, final Map<String, String> properties) throws IOException {
String field = GeospatialTestHelper.randomLowerCaseString();
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
Map<String, String> defaultProperties = Map.of(
Ip2GeoProcessor.CONFIG_FIELD,
field,
Ip2GeoProcessor.CONFIG_DATASOURCE,
datasourceName
);
Map<String, String> baseProperties = new HashMap<>();
baseProperties.putAll(defaultProperties);
baseProperties.putAll(properties);
Map<String, Object> processorConfig = buildProcessorConfig(Ip2GeoProcessor.TYPE, baseProperties);

return createPipeline(pipelineName, Optional.empty(), Arrays.asList(processorConfig));
}
}