Skip to content

Commit f3b47b3

Browse files
committed
Fix broken Dataflow unit test that depends on GOOGLE_APPLICATION_CREDENTIALS
1 parent 6015ec7 commit f3b47b3

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

core/src/main/java/feast/core/job/dataflow/DataflowJobManager.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static feast.core.util.PipelineUtil.detectClassPathResourcesToStage;
2020

21+
import com.google.api.client.auth.oauth2.Credential;
2122
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
2223
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
2324
import com.google.api.client.json.jackson2.JacksonFactory;
@@ -66,16 +67,15 @@ public class DataflowJobManager implements JobManager {
6667

6768
public DataflowJobManager(
6869
Map<String, String> runnerConfigOptions, MetricsProperties metricsProperties) {
70+
this(runnerConfigOptions, metricsProperties, getGoogleCredential());
71+
}
6972

70-
DataflowRunnerConfig config = new DataflowRunnerConfig(runnerConfigOptions);
73+
public DataflowJobManager(
74+
Map<String, String> runnerConfigOptions,
75+
MetricsProperties metricsProperties,
76+
Credential credential) {
7177

72-
GoogleCredential credential = null;
73-
try {
74-
credential = GoogleCredential.getApplicationDefault().createScoped(DataflowScopes.all());
75-
} catch (IOException e) {
76-
throw new IllegalStateException(
77-
"Unable to find credential required for Dataflow monitoring API", e);
78-
}
78+
DataflowRunnerConfig config = new DataflowRunnerConfig(runnerConfigOptions);
7979

8080
Dataflow dataflow = null;
8181
try {
@@ -97,6 +97,17 @@ public DataflowJobManager(
9797
this.location = config.getRegion();
9898
}
9999

100+
private static Credential getGoogleCredential() {
101+
GoogleCredential credential = null;
102+
try {
103+
credential = GoogleCredential.getApplicationDefault().createScoped(DataflowScopes.all());
104+
} catch (IOException e) {
105+
throw new IllegalStateException(
106+
"Unable to find credential required for Dataflow monitoring API", e);
107+
}
108+
return credential;
109+
}
110+
100111
@Override
101112
public Runner getRunnerType() {
102113
return RUNNER_TYPE;

core/src/test/java/feast/core/job/dataflow/DataflowJobManagerTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static org.mockito.Mockito.*;
2323
import static org.mockito.MockitoAnnotations.initMocks;
2424

25+
import com.google.api.client.auth.oauth2.Credential;
26+
import com.google.api.client.googleapis.testing.auth.oauth2.MockGoogleCredential;
2527
import com.google.api.services.dataflow.Dataflow;
2628
import com.google.common.collect.Lists;
2729
import com.google.protobuf.Duration;
@@ -83,7 +85,14 @@ public void setUp() {
8385
defaults.put("subnetwork", "subnetwork");
8486
MetricsProperties metricsProperties = new MetricsProperties();
8587
metricsProperties.setEnabled(false);
86-
dfJobManager = new DataflowJobManager(defaults, metricsProperties);
88+
Credential credential = null;
89+
try {
90+
credential = MockGoogleCredential.getApplicationDefault();
91+
} catch (IOException e) {
92+
e.printStackTrace();
93+
}
94+
95+
dfJobManager = new DataflowJobManager(defaults, metricsProperties, credential);
8796
dfJobManager = spy(dfJobManager);
8897
}
8998

0 commit comments

Comments
 (0)