Skip to content

Commit

Permalink
Minor fixes to RemoteBigQueryHelper
Browse files Browse the repository at this point in the history
- Remove RemoteBigQueryHelper.create(String, String)
- Add javadoc to RemoteBigQueryHelper to document retry options
- Add global timeout of 5minutes to each of the BigQuery ITs
- Remove print from BigQueryImplTest and other nits
  • Loading branch information
mziccard committed Dec 21, 2015
1 parent ba8acf1 commit 7eee528
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@
import com.google.gcloud.bigquery.BigQueryException;
import com.google.gcloud.bigquery.BigQueryOptions;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Utility to create a remote BigQuery configuration for testing.
* Utility to create a remote BigQuery configuration for testing. BigQuery options can be obtained
* via the {@link #options()} method. Returned options have custom
* {@link BigQueryOptions#retryParams()}: {@link RetryParams#retryMaxAttempts()} is {@code 10},
* {@link RetryParams#retryMinAttempts()} is {@code 6}, {@link RetryParams#maxRetryDelayMillis()} is
* {@code 30000}, {@link RetryParams#totalRetryPeriodMillis()} is {@code 120000} and
* {@link RetryParams#initialRetryDelayMillis()} is {@code 250}.
* {@link BigQueryOptions#connectTimeout()} and {@link BigQueryOptions#readTimeout()} are both set
* to {@code 60000}.
*/
public class RemoteBigQueryHelper {

Expand Down Expand Up @@ -97,27 +102,6 @@ public static RemoteBigQueryHelper create(String projectId, InputStream keyStrea
}
}

/**
* Creates a {@code RemoteBigQueryHelper} object for the given project id and JSON key path.
*
* @param projectId id of the project to be used for running the tests
* @param keyPath path to the JSON key to be used for running the tests
* @return A {@code RemoteBigQueryHelper} object for the provided options.
* @throws BigQueryHelperException if the file pointed by {@code keyPath} does not exist
*/
public static RemoteBigQueryHelper create(String projectId, String keyPath)
throws BigQueryHelperException {
try {
InputStream keyFileStream = new FileInputStream(keyPath);
return create(projectId, keyFileStream);
} catch (FileNotFoundException ex) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING, ex.getMessage());
}
throw BigQueryHelperException.translate(ex);
}
}

/**
* Creates a {@code RemoteBigQueryHelper} object using default project id and authentication
* credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,6 @@ public Job apply(JobInfo jobInfo) {
assertEquals(cursor, page.nextPageCursor());
assertArrayEquals(jobList.toArray(), Iterables.toArray(page.values(), JobInfo.class));
String selector = (String) capturedOptions.getValue().get(JOB_OPTION_FIELDS.rpcOption());
System.out.println(selector);
assertTrue(selector.contains("etag,jobs("));
assertTrue(selector.contains("configuration"));
assertTrue(selector.contains("jobReference"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -128,6 +130,9 @@ public class ITBigQueryTest {
private static BigQuery bigquery;
private static Storage storage;

@Rule
public Timeout globalTimeout = Timeout.seconds(300);

@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
Expand Down Expand Up @@ -732,7 +737,6 @@ public void testQueryJob() throws InterruptedException {
assertTrue(bigquery.delete(DATASET, tableName));
}


@Test
public void testExtract() throws InterruptedException {
String tableName = "test_export_job_table";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@
import com.google.gcloud.bigquery.testing.RemoteBigQueryHelper;

import org.easymock.EasyMock;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

public class RemoteBigQueryHelperTest {
Expand Down Expand Up @@ -66,18 +62,9 @@ public class RemoteBigQueryHelperTest {
+ " \"type\": \"service_account\"\n"
+ "}";
private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes());
private static String keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";

@Rule
public ExpectedException thrown = ExpectedException.none();

@BeforeClass
public static void beforeClass() {
while (Files.exists(Paths.get(JSON_KEY))) {
keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
}
}

@Test
public void testForceDelete() throws InterruptedException, ExecutionException {
BigQuery bigqueryMock = EasyMock.createMock(BigQuery.class);
Expand All @@ -101,11 +88,4 @@ public void testCreateFromStream() {
assertEquals(120000, options.retryParams().totalRetryPeriodMillis());
assertEquals(250, options.retryParams().initialRetryDelayMillis());
}

@Test
public void testCreateNoKey() {
thrown.expect(RemoteBigQueryHelper.BigQueryHelperException.class);
thrown.expectMessage(keyPath + " (No such file or directory)");
RemoteBigQueryHelper.create(PROJECT_ID, keyPath);
}
}

0 comments on commit 7eee528

Please sign in to comment.