Skip to content

Commit

Permalink
Adding Backfill Id to the config object.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpawliszyn committed May 25, 2023
1 parent 32973f0 commit f967529
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ class BackfilaParametersOperator<T : Any>(
fun constructBackfillConfig(request: GetNextBatchRangeRequest): BackfillConfig<T> = BackfillConfig(
constructParameters(request.parameters),
request.partition_name,
request.backfill_id,
request.dry_run,
)

fun constructBackfillConfig(request: RunBatchRequest): BackfillConfig<T> = BackfillConfig(
constructParameters(request.parameters),
request.partition_name,
request.backfill_id,
request.dry_run,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,15 @@ void twoInstanceBackfill() {
assertThat(backfillRun.getBackfill().runOrder).containsExactly("a", "b", "c", "e", "f");
assertThat(datastore.valuesToList()).containsExactly("A", "B", "C", "E", "F");
}

@Test
void backfillIdIsANumber() {
datastore.put("instance", "A", "b", "C");

var backfillRun = backfila.createWetRun(JavaChangeCaseTestBackfill.class,
Map.of("required", ByteString.encodeUtf8("isRequired")));
backfillRun.execute();
String seenBackfillId = backfillRun.getBackfill().seenBackfillId;
assertThat(Integer.parseInt(seenBackfillId)).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class JavaChangeCaseTestBackfill extends FixedSetBackfill<CaseParameters> {
public List<String> runOrder = new ArrayList();
public CaseParameters seenParameters = null;
public String seenBackfillId = null;

@Inject
public JavaChangeCaseTestBackfill(){
Expand All @@ -32,6 +33,7 @@ public ValidateResult<CaseParameters> checkParameters(@NotNull CaseParameters pa
@Override public void runOne(@NotNull FixedSetRow row,
@NotNull BackfillConfig<CaseParameters> backfillConfig) {
seenParameters = backfillConfig.getParameters();
seenBackfillId = backfillConfig.getBackfillId();
runOrder.add(row.getValue());
if (backfillConfig.getParameters().toUpper) {
row.setValue(row.getValue().toUpperCase(Locale.ROOT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class FixedSetTest {

class ToUpperCaseBackfill @Inject constructor() : FixedSetBackfill<NoParameters>() {
val runOrder = mutableListOf<String>()
var seenBackfillId: String? = null
override fun runOne(row: FixedSetRow, backfillConfig: BackfillConfig<NoParameters>) {
seenBackfillId = backfillConfig.backfillId
runOrder += row.value
row.value = row.value.toUpperCase(Locale.ROOT)
}
Expand All @@ -49,4 +51,12 @@ class FixedSetTest {
assertThat(backfillRun.backfill.runOrder).containsExactly("a", "b", "c", "e", "f")
assertThat(datastore.valuesToList()).containsExactly("A", "B", "C", "E", "F")
}

@Test fun `backfillId is a number`() {
datastore.put("instance", "a", "b", "c")

val backfillRun = backfila.createWetRun<ToUpperCaseBackfill>()
backfillRun.execute()
assertThat(backfillRun.backfill.seenBackfillId?.toInt()).isNotNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.cash.backfila.client
data class BackfillConfig<Param : Any>(
val parameters: Param,
val partitionName: String,
val backfillId: String,
val dryRun: Boolean,
) {
fun prepareConfig() = PrepareBackfillConfig(parameters, dryRun)
Expand Down

0 comments on commit f967529

Please sign in to comment.