Consolidate BigQuery handling into one place

I'm writing a follow-up CL that will send integrity checking data to
BigQuery, and that is made a lot easier by centralizing the BigQuery
connection logic.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=119375766
This commit is contained in:
mcilwain 2016-04-08 08:44:04 -07:00 committed by Justine Tunney
parent c880a042a7
commit 755fce9e52
12 changed files with 329 additions and 347 deletions

View file

@ -25,9 +25,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.model.Dataset;
import com.google.api.services.bigquery.model.Table;
@ -107,17 +104,11 @@ public class UpdateSnapshotViewServletTest {
@Before
public void before() throws Exception {
inject.setStaticField(UpdateSnapshotViewServlet.class, "bigqueryFactory", bigqueryFactory);
when(bigqueryFactory.create(anyString(), anyString())).thenReturn(bigquery);
when(req.getMethod()).thenReturn("POST");
when(rsp.getWriter()).thenReturn(new PrintWriter(httpOutput));
when(bigqueryFactory.create(
anyString(),
any(HttpTransport.class),
any(JsonFactory.class),
any(HttpRequestInitializer.class)))
.thenReturn(bigquery);
when(bigquery.datasets()).thenReturn(bigqueryDatasets);
when(bigqueryDatasets.insert(eq("Project-Id"), any(Dataset.class)))
.thenReturn(bigqueryDatasetsInsert);
@ -154,15 +145,6 @@ public class UpdateSnapshotViewServletTest {
servlet.service(req, rsp);
// Check that we attempted to create the latest_snapshot dataset.
ArgumentCaptor<Dataset> datasetArgument = ArgumentCaptor.forClass(Dataset.class);
verify(bigqueryDatasets).insert(eq("Project-Id"), datasetArgument.capture());
assertThat(datasetArgument.getValue().getDatasetReference().getProjectId())
.isEqualTo("Project-Id");
assertThat(datasetArgument.getValue().getDatasetReference().getDatasetId())
.isEqualTo("testdataset");
verify(bigqueryDatasetsInsert).execute();
// Check that we updated the view.
ArgumentCaptor<Table> tableArg = ArgumentCaptor.forClass(Table.class);
verify(bigqueryTables).update(