Skip to content

Commit 4d09bc2

Browse files
authored
KE-740: increase DatabricksJobManager test coverage (feast-dev#31)
Increase DatabricksJobManager test coverage
1 parent 36e7fa4 commit 4d09bc2

1 file changed

Lines changed: 41 additions & 5 deletions

File tree

‎core/src/test/java/feast/core/job/databricks/DatabricksJobManagerTest.java‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.google.common.collect.Lists;
2626
import feast.core.config.FeastProperties.MetricsProperties;
27+
import feast.core.exception.JobExecutionException;
2728
import feast.core.job.Runner;
2829
import feast.core.model.*;
2930
import feast.proto.core.FeatureSetProto;
@@ -33,11 +34,13 @@
3334
import java.io.IOException;
3435
import java.net.http.HttpClient;
3536
import java.net.http.HttpResponse;
37+
import org.apache.http.HttpStatus;
3638
import org.junit.Before;
3739
import org.junit.Rule;
3840
import org.junit.Test;
3941
import org.junit.rules.ExpectedException;
4042
import org.mockito.Mock;
43+
import org.mockito.Mockito;
4144

4245
public class DatabricksJobManagerTest {
4346

@@ -116,7 +119,7 @@ public void testGetCalltoDatabricksWithOnlyLifeCycle() throws IOException, Inter
116119
String responseBody =
117120
"{ \"state\": {\"life_cycle_state\" : \"INTERNAL_ERROR\", \"state_message\": \"a state message\"} } ";
118121
when(httpResponse.body()).thenReturn(responseBody);
119-
when(httpResponse.statusCode()).thenReturn(200);
122+
when(httpResponse.statusCode()).thenReturn(HttpStatus.SC_OK);
120123
when(httpClient.send(any(), any())).thenReturn(httpResponse);
121124

122125
JobStatus jobStatus = dbJobManager.getJobStatus(job);
@@ -130,15 +133,15 @@ public void testGetCalltoDatabricksWithLifeCycleAndRunState()
130133
"{ \"state\": {\"life_cycle_state\" : \"TERMINATED\", \"result_state\": \"SUCCESS\", \"state_message\": \"a state message\" } } ";
131134

132135
when(httpResponse.body()).thenReturn(responseBody);
133-
when(httpResponse.statusCode()).thenReturn(200);
136+
when(httpResponse.statusCode()).thenReturn(HttpStatus.SC_OK);
134137
when(httpClient.send(any(), any())).thenReturn(httpResponse);
135138

136139
JobStatus jobStatus = dbJobManager.getJobStatus(job);
137140
assertThat(jobStatus, equalTo(JobStatus.COMPLETED));
138141
}
139142

140143
@Test
141-
public void testStartJob() throws IOException, InterruptedException {
144+
public void testStartJob_OK() throws IOException, InterruptedException {
142145
String createResponseBody = "{ \"job_id\" : \"5\" } ";
143146
String runNowResponseBody = "{ \"run_id\" : \"10\", \"number_in_job\" : \"10\"} ";
144147
String jobStatusResponseBody =
@@ -148,13 +151,46 @@ public void testStartJob() throws IOException, InterruptedException {
148151
.thenReturn(createResponseBody)
149152
.thenReturn(runNowResponseBody)
150153
.thenReturn(jobStatusResponseBody);
151-
when(httpResponse.statusCode()).thenReturn(200);
154+
when(httpResponse.statusCode()).thenReturn(HttpStatus.SC_OK);
152155
when(httpClient.send(any(), any())).thenReturn(httpResponse);
153-
doReturn(httpResponse).when(httpClient).send(any(), any());
154156

155157
Job actual = dbJobManager.startJob(job);
156158

157159
assertThat(actual.getExtId(), equalTo("10"));
158160
assertThat(actual.getId(), equalTo(job.getId()));
159161
}
162+
163+
@Test(expected = JobExecutionException.class)
164+
public void testStartJob_BadRequest() throws IOException, InterruptedException {
165+
when(httpResponse.statusCode()).thenReturn(HttpStatus.SC_BAD_REQUEST);
166+
when(httpClient.send(any(), any())).thenReturn(httpResponse);
167+
168+
dbJobManager.startJob(job);
169+
170+
verify(httpClient, Mockito.times(1)).send(any(), any());
171+
}
172+
173+
@Test
174+
public void testAbortJob_OKRequest() throws IOException, InterruptedException {
175+
String runId = "1";
176+
177+
when(httpResponse.statusCode()).thenReturn(HttpStatus.SC_OK);
178+
when(httpClient.send(any(), any())).thenReturn(httpResponse);
179+
180+
dbJobManager.abortJob(runId);
181+
182+
verify(httpClient, Mockito.times(1)).send(any(), any());
183+
}
184+
185+
@Test(expected = JobExecutionException.class)
186+
public void testAbortJob_BadRequest() throws IOException, InterruptedException {
187+
String runId = "1";
188+
189+
when(httpResponse.statusCode()).thenReturn(HttpStatus.SC_BAD_REQUEST);
190+
when(httpClient.send(any(), any())).thenReturn(httpResponse);
191+
192+
dbJobManager.startJob(job);
193+
194+
verify(httpClient, Mockito.times(1)).send(any(), any());
195+
}
160196
}

0 commit comments

Comments
 (0)