Skip to content

Fix unit test failures from env configs #10998

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

Merged
merged 5 commits into from
Mar 9, 2022
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 @@ -71,4 +71,12 @@ public interface Procedure {

}

public static <T> T swallowWithDefault(final Callable<T> procedure, final T defaultValue) {
try {
return procedure.call();
} catch (Exception e) {
return defaultValue;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import io.airbyte.commons.lang.Exceptions;
import io.airbyte.commons.map.MoreMaps;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.helpers.LogClientSingleton;
Expand Down Expand Up @@ -651,9 +652,12 @@ public Map<String, String> getJobDefaultEnvMap() {
final Map<String, String> jobPrefixedEnvMap = getAllEnvKeys.get().stream()
.filter(key -> key.startsWith(JOB_DEFAULT_ENV_PREFIX))
.collect(Collectors.toMap(key -> key.replace(JOB_DEFAULT_ENV_PREFIX, ""), getEnv));
// This method assumes that these shared env variables are not critical to the execution
// of the jobs, and only serve as metadata. So any exception is swallowed and default to
// an empty string. Change this logic if this assumption no longer holds.
final Map<String, String> jobSharedEnvMap = JOB_SHARED_ENVS.entrySet().stream().collect(Collectors.toMap(
Entry::getKey,
entry -> Objects.requireNonNullElse(entry.getValue().apply(this), "")));
entry -> Exceptions.swallowWithDefault(() -> Objects.requireNonNullElse(entry.getValue().apply(this), ""), "")));
return MoreMaps.merge(jobPrefixedEnvMap, jobSharedEnvMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import io.airbyte.config.EnvConfigs;
import io.airbyte.config.WorkerEnvConstants;
import io.airbyte.workers.WorkerConfigs;
import io.airbyte.workers.WorkerException;
import java.nio.file.Path;
Expand All @@ -31,6 +32,10 @@ class AirbyteIntegrationLauncherTest {
"config", "{}",
"catalog", "{}",
"state", "{}");
private static final Map<String, String> JOB_METADATA = Map.of(
WorkerEnvConstants.WORKER_CONNECTOR_IMAGE, FAKE_IMAGE,
WorkerEnvConstants.WORKER_JOB_ID, JOB_ID,
WorkerEnvConstants.WORKER_JOB_ATTEMPT, String.valueOf(JOB_ATTEMPT));

private WorkerConfigs workerConfigs;
private ProcessFactory processFactory;
Expand All @@ -48,7 +53,7 @@ void spec() throws WorkerException {
launcher.spec(JOB_ROOT);

Mockito.verify(processFactory).create(JOB_ID, JOB_ATTEMPT, JOB_ROOT, FAKE_IMAGE, false, Collections.emptyMap(), null,
workerConfigs.getResourceRequirements(), Map.of(KubeProcessFactory.JOB_TYPE, KubeProcessFactory.SPEC_JOB), Map.of(), Map.of(),
workerConfigs.getResourceRequirements(), Map.of(KubeProcessFactory.JOB_TYPE, KubeProcessFactory.SPEC_JOB), JOB_METADATA, Map.of(),
"spec");
}

Expand All @@ -59,7 +64,7 @@ void check() throws WorkerException {
Mockito.verify(processFactory).create(JOB_ID, JOB_ATTEMPT, JOB_ROOT, FAKE_IMAGE, false, CONFIG_FILES, null,
workerConfigs.getResourceRequirements(),
Map.of(KubeProcessFactory.JOB_TYPE, KubeProcessFactory.CHECK_JOB),
Map.of(),
JOB_METADATA,
Map.of(),
"check",
"--config", "config");
Expand All @@ -72,7 +77,7 @@ void discover() throws WorkerException {
Mockito.verify(processFactory).create(JOB_ID, JOB_ATTEMPT, JOB_ROOT, FAKE_IMAGE, false, CONFIG_FILES, null,
workerConfigs.getResourceRequirements(),
Map.of(KubeProcessFactory.JOB_TYPE, KubeProcessFactory.DISCOVER_JOB),
Map.of(),
JOB_METADATA,
Map.of(),
"discover",
"--config", "config");
Expand All @@ -85,7 +90,7 @@ void read() throws WorkerException {
Mockito.verify(processFactory).create(JOB_ID, JOB_ATTEMPT, JOB_ROOT, FAKE_IMAGE, false, CONFIG_CATALOG_STATE_FILES, null,
workerConfigs.getResourceRequirements(),
Map.of(KubeProcessFactory.JOB_TYPE, KubeProcessFactory.SYNC_JOB, KubeProcessFactory.SYNC_STEP, KubeProcessFactory.READ_STEP),
Map.of(),
JOB_METADATA,
Map.of(),
Lists.newArrayList(
"read",
Expand All @@ -101,7 +106,7 @@ void write() throws WorkerException {
Mockito.verify(processFactory).create(JOB_ID, JOB_ATTEMPT, JOB_ROOT, FAKE_IMAGE, true, CONFIG_CATALOG_FILES, null,
workerConfigs.getResourceRequirements(),
Map.of(KubeProcessFactory.JOB_TYPE, KubeProcessFactory.SYNC_JOB, KubeProcessFactory.SYNC_STEP, KubeProcessFactory.WRITE_STEP),
Map.of(),
JOB_METADATA,
Map.of(),
"write",
"--config", "config",
Expand Down