Skip to content

Commit

Permalink
Refactor: Simplify error message for invalid write preference validation
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanks committed Dec 12, 2024
1 parent a110759 commit 1a239a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,8 @@ void validateWritePreference(FailureCollector failureCollector, String writePref
);
if (!validPreferences.contains(writePreference)) {
failureCollector.addFailure(
String.format("Invalid write preference '%s'. Allowed values are '%s', '%s', or '%s'.",
writePreference,
JobInfo.WriteDisposition.WRITE_EMPTY.name(),
JobInfo.WriteDisposition.WRITE_APPEND.name(),
JobInfo.WriteDisposition.WRITE_TRUNCATE.name()
String.format("Invalid write preference '%s'. Allowed values are '%s'.",
writePreference, validPreferences.toString()
),
"Please provide a valid write preference."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.cloud.bigquery.JobStatus;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.TableResult;
import com.google.common.collect.ImmutableSet;
import io.cdap.cdap.api.metrics.Metrics;
import io.cdap.cdap.etl.api.StageMetrics;
import io.cdap.cdap.etl.api.action.ActionContext;
Expand All @@ -37,6 +38,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.util.Set;

public class BigQueryExecuteTest {
@Mock
Expand Down Expand Up @@ -228,15 +230,18 @@ public void testValidateRetryConfigurationWithInvalidReadTimeout() {

@Test
public void testValidateWritePreferenceWithInvalidValue() {
Set<String> validPreferences = ImmutableSet.of(
JobInfo.WriteDisposition.WRITE_EMPTY.name(),
JobInfo.WriteDisposition.WRITE_APPEND.name(),
JobInfo.WriteDisposition.WRITE_TRUNCATE.name()
);
config.validateWritePreference(failureCollector, "INVALID_PREFERENCE");

// Assert validation failure
Assert.assertEquals(1, failureCollector.getValidationFailures().size());
Assert.assertEquals(
String.format("Invalid write preference 'INVALID_PREFERENCE'. Allowed values are '%s', '%s', or '%s'.",
JobInfo.WriteDisposition.WRITE_EMPTY.name(),
JobInfo.WriteDisposition.WRITE_APPEND.name(),
JobInfo.WriteDisposition.WRITE_TRUNCATE.name()
String.format("Invalid write preference 'INVALID_PREFERENCE'. Allowed values are '%s'.",
validPreferences.toString()
),
failureCollector.getValidationFailures().get(0).getMessage()
);
Expand Down

0 comments on commit 1a239a4

Please sign in to comment.