-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embedded backfila support changing parameters in validate (#236)
Added ages ago and never added to embedded
- Loading branch information
Showing
9 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
client-base/src/test/kotlin/app/cash/backfila/client/PrepareWithParametersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package app.cash.backfila.client | ||
|
||
import app.cash.backfila.client.fixedset.FixedSetBackfill | ||
import app.cash.backfila.client.fixedset.FixedSetDatastore | ||
import app.cash.backfila.client.fixedset.FixedSetRow | ||
import app.cash.backfila.embedded.Backfila | ||
import app.cash.backfila.embedded.createWetRun | ||
import com.google.inject.Module | ||
import javax.inject.Inject | ||
import misk.testing.MiskTest | ||
import misk.testing.MiskTestModule | ||
import okio.ByteString.Companion.encodeUtf8 | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
/** | ||
* Tests modifying parameters by returning them in the PrepareBackfillResponse. | ||
*/ | ||
@MiskTest(startService = true) | ||
class PrepareWithParametersTest { | ||
@Suppress("unused") | ||
@MiskTestModule | ||
val module: Module = TestingModule() | ||
|
||
@Inject lateinit var backfila: Backfila | ||
@Inject lateinit var datastore: FixedSetDatastore | ||
|
||
data class PrepareParameters( | ||
val favoriteNumber: Int? = null | ||
) | ||
|
||
class PrepareWithParametersBackfill @Inject constructor() : FixedSetBackfill<PrepareParameters>() { | ||
override fun checkBackfillConfig( | ||
backfillConfig: BackfillConfig<PrepareParameters> | ||
): ValidateResult<PrepareParameters> { | ||
if (backfillConfig.parameters.favoriteNumber != null) { | ||
return ValidateResult(backfillConfig.parameters) | ||
} | ||
return ValidateResult( | ||
PrepareParameters(favoriteNumber = 42) | ||
) | ||
} | ||
|
||
override fun runOne(row: FixedSetRow) { | ||
} | ||
} | ||
|
||
@Test fun `add parameters from prepare response`() { | ||
datastore.put("instance", "a", "b", "c") | ||
|
||
val backfillRun = backfila.createWetRun<PrepareWithParametersBackfill>() | ||
backfillRun.execute() | ||
assertThat(backfillRun.parameters["favoriteNumber"]).isEqualTo("42".encodeUtf8()) | ||
} | ||
|
||
@Test fun `keep original parameters`() { | ||
datastore.put("instance", "a", "b", "c") | ||
|
||
val backfillRun = backfila.createWetRun<PrepareWithParametersBackfill>( | ||
parameters = PrepareParameters( | ||
favoriteNumber = 12 | ||
) | ||
) | ||
backfillRun.execute() | ||
assertThat(backfillRun.parameters["favoriteNumber"]).isEqualTo("12".encodeUtf8()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
client/src/main/kotlin/app/cash/backfila/client/ValidateResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.cash.backfila.client | ||
|
||
data class ValidateResult<Param : Any>( | ||
/** | ||
* Set to override parameters used for the backfill from the original parameters provided by the user. | ||
* | ||
* Example usage: pick a random token to use for the rest of the backfill. | ||
*/ | ||
val parameters: Param, | ||
) |