Use HttpException for error handling in UpdateSnapshotViewAction

This is a follow-up to []
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120238590
This commit is contained in:
mcilwain 2016-04-19 09:50:28 -07:00 committed by Justine Tunney
parent 0f4a1035b2
commit 4ba8c0e552
2 changed files with 19 additions and 2 deletions

View file

@ -25,6 +25,7 @@ import com.google.appengine.api.taskqueue.TaskOptions.Method;
import com.google.domain.registry.bigquery.BigqueryFactory; import com.google.domain.registry.bigquery.BigqueryFactory;
import com.google.domain.registry.config.RegistryEnvironment; import com.google.domain.registry.config.RegistryEnvironment;
import com.google.domain.registry.request.Action; import com.google.domain.registry.request.Action;
import com.google.domain.registry.request.HttpException.InternalServerErrorException;
import com.google.domain.registry.request.Parameter; import com.google.domain.registry.request.Parameter;
import com.google.domain.registry.util.FormattingLogger; import com.google.domain.registry.util.FormattingLogger;
import com.google.domain.registry.util.SqlTemplate; import com.google.domain.registry.util.SqlTemplate;
@ -71,7 +72,8 @@ public class UpdateSnapshotViewAction implements Runnable {
try { try {
updateSnapshotView(datasetId, tableId, kindName); updateSnapshotView(datasetId, tableId, kindName);
} catch (Throwable e) { } catch (Throwable e) {
throw new RuntimeException("Error in update snapshot view action.", e); logger.severefmt(e, "Could not update snapshot view for table %s", tableId);
throw new InternalServerErrorException("Error in update snapshot view action");
} }
} }

View file

@ -31,7 +31,9 @@ import com.google.api.services.bigquery.model.Table;
import com.google.appengine.api.taskqueue.QueueFactory; import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.domain.registry.bigquery.BigqueryFactory; import com.google.domain.registry.bigquery.BigqueryFactory;
import com.google.domain.registry.config.TestRegistryConfig; import com.google.domain.registry.config.TestRegistryConfig;
import com.google.domain.registry.request.HttpException.InternalServerErrorException;
import com.google.domain.registry.testing.AppEngineRule; import com.google.domain.registry.testing.AppEngineRule;
import com.google.domain.registry.testing.ExceptionRule;
import com.google.domain.registry.testing.RegistryConfigRule; import com.google.domain.registry.testing.RegistryConfigRule;
import com.google.domain.registry.testing.TaskQueueHelper.TaskMatcher; import com.google.domain.registry.testing.TaskQueueHelper.TaskMatcher;
@ -43,6 +45,8 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import java.io.IOException;
/** Unit tests for {@link UpdateSnapshotViewAction}. */ /** Unit tests for {@link UpdateSnapshotViewAction}. */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class UpdateSnapshotViewActionTest { public class UpdateSnapshotViewActionTest {
@ -52,6 +56,9 @@ public class UpdateSnapshotViewActionTest {
.withTaskQueue() .withTaskQueue()
.build(); .build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Rule @Rule
public final RegistryConfigRule configRule = new RegistryConfigRule(new TestRegistryConfig() { public final RegistryConfigRule configRule = new RegistryConfigRule(new TestRegistryConfig() {
@Override public String getProjectId() { @Override public String getProjectId() {
@ -91,7 +98,7 @@ public class UpdateSnapshotViewActionTest {
.thenReturn(bigqueryDatasetsInsert); .thenReturn(bigqueryDatasetsInsert);
when(bigquery.tables()).thenReturn(bigqueryTables); when(bigquery.tables()).thenReturn(bigqueryTables);
when(bigqueryTables.update( when(bigqueryTables.update(
eq("Project-Id"), any(String.class), any(String.class), any(Table.class))) eq("Project-Id"), anyString(), anyString(), any(Table.class)))
.thenReturn(bigqueryTablesUpdate); .thenReturn(bigqueryTablesUpdate);
action = new UpdateSnapshotViewAction(); action = new UpdateSnapshotViewAction();
@ -125,4 +132,12 @@ public class UpdateSnapshotViewActionTest {
assertThat(tableArg.getValue().getView().getQuery()) assertThat(tableArg.getValue().getView().getQuery())
.isEqualTo("SELECT * FROM [some_dataset.12345_fookind]"); .isEqualTo("SELECT * FROM [some_dataset.12345_fookind]");
} }
@Test
public void testFailure_bigqueryConnectionThrowsError() throws Exception {
when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
.thenThrow(new IOException("I'm sorry Dave, I can't let you do that"));
thrown.expect(InternalServerErrorException.class, "Error in update snapshot view action");
action.run();
}
} }