Skip to content

Commit

Permalink
Private 2 Protected
Browse files Browse the repository at this point in the history
  • Loading branch information
psainics committed Nov 6, 2023
1 parent ceeda27 commit 17c2e89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ public void run(ActionContext context) throws Exception {
bigQuery, queryConfig, context);
}

private void executeQueryWithExponentialBackoff(Duration initialRetryDuration, Duration maxRetryDuration,
protected void executeQueryWithExponentialBackoff(Duration initialRetryDuration, Duration maxRetryDuration,
int multiplier, int maxRetryCount, BigQuery bigQuery,
QueryJobConfiguration queryConfig, ActionContext context)
throws ConnectException {
QueryJobConfiguration queryConfig, ActionContext context) {
RetryPolicy<Object> retryPolicy = RetryPolicy.builder()
.handle(ConnectException.class)
.withBackoff(initialRetryDuration, maxRetryDuration, multiplier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.ConnectException;
import java.time.Duration;

public class BigQueryExecuteTest {
Expand All @@ -43,8 +42,6 @@ public class BigQueryExecuteTest {
StageMetrics stageMetrics;
@Mock
Metrics metrics;
Method executeQueryWithExponentialBackoffMethod;

QueryJobConfiguration queryJobConfiguration;
BigQueryExecute.Config config;
JobInfo jobInfo;
Expand All @@ -66,10 +63,6 @@ public void setUp() throws InterruptedException, NoSuchMethodException {
jobId = JobId.newBuilder().setRandomJob().setLocation(config.getLocation()).build();
jobInfo = JobInfo.newBuilder(queryJobConfiguration).setJobId(jobId).build();
bq = new BigQueryExecute(config);
executeQueryWithExponentialBackoffMethod = bq.getClass()
.getDeclaredMethod("executeQueryWithExponentialBackoff", Duration.class, Duration.class, int.class,
int.class, BigQuery.class, QueryJobConfiguration.class, ActionContext.class);
executeQueryWithExponentialBackoffMethod.setAccessible(true);

// Mock Job Creation
Mockito.when(bigQuery.create((JobInfo) Mockito.any())).thenReturn(queryJob);
Expand All @@ -91,28 +84,25 @@ public void setUp() throws InterruptedException, NoSuchMethodException {

}

@Test(expected = java.lang.reflect.InvocationTargetException.class)
public void testExecuteQueryWithExponentialBackoffFailsWithNonRetryError() throws InvocationTargetException,
IllegalAccessException {
@Test(expected = java.lang.RuntimeException.class)
public void testExecuteQueryWithExponentialBackoffFailsWithNonRetryError() throws ConnectException {
Mockito.when(bigQueryError.getReason()).thenReturn("accessDenied");
executeQueryWithExponentialBackoffMethod.invoke(bq, initialRetryDuration, maxRetryDuration, multiplier,
maxRetryCount, bigQuery, queryJobConfiguration, context);
bq.executeQueryWithExponentialBackoff(initialRetryDuration, maxRetryDuration, multiplier, maxRetryCount,
bigQuery, queryJobConfiguration, context);
}

@Test(expected = java.lang.reflect.InvocationTargetException.class)
public void testExecuteQueryWithExponentialBackoffFailsRetryError() throws InvocationTargetException,
IllegalAccessException {
@Test(expected = java.lang.RuntimeException.class)
public void testExecuteQueryWithExponentialBackoffFailsRetryError() throws ConnectException {
Mockito.when(bigQueryError.getReason()).thenReturn("jobBackendError");
executeQueryWithExponentialBackoffMethod.invoke(bq, initialRetryDuration, maxRetryDuration, multiplier,
maxRetryCount, bigQuery, queryJobConfiguration, context);
bq.executeQueryWithExponentialBackoff(initialRetryDuration, maxRetryDuration, multiplier, maxRetryCount,
bigQuery, queryJobConfiguration, context);
}

@Test
public void testExecuteQueryWithExponentialBackoffSuccess() throws InterruptedException,
InvocationTargetException, IllegalAccessException {
public void testExecuteQueryWithExponentialBackoffSuccess() throws InterruptedException, ConnectException {
Mockito.when(jobStatus.getError()).thenReturn(null);
Mockito.when(queryJob.getQueryResults()).thenReturn(queryResults);
executeQueryWithExponentialBackoffMethod.invoke(bq, initialRetryDuration, maxRetryDuration, multiplier,
maxRetryCount, bigQuery, queryJobConfiguration, context);
bq.executeQueryWithExponentialBackoff(initialRetryDuration, maxRetryDuration, multiplier, maxRetryCount,
bigQuery, queryJobConfiguration, context);
}
}

0 comments on commit 17c2e89

Please sign in to comment.