-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor TestFormula and key logic. #379
Conversation
import com.instacart.formula.Snapshot | ||
import java.util.concurrent.atomic.AtomicLong | ||
|
||
/** | ||
* Test formula is used to provide a fake formula implementation. It allows you to [send][output] | ||
* output updates and [inspect/interact][input] with input. | ||
*/ | ||
abstract class TestFormula<Input, Output> : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both inheritance and factory approaches creates inconsistencies in the API. I've decided to make this a final class and keep the following API as the primary approach
class FakeUserFormula : UserFormula {
override val implementation = testFormula(
initialOutput = User(
name = "Fake user name",
)
)
}
JaCoCo Code Coverage 88.01% ✅
Generated by 🚫 Danger |
* override fun key(input: ItemInput) = input.itemId | ||
* ``` | ||
*/ | ||
override fun key(input: Input): Any? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed since the default implementation uses implementation.key()
which is null.
b400b66
to
c2bd013
Compare
c2bd013
to
c826fc2
Compare
private val stateMap = mutableMapOf<Any?, Value<Input, Output>>() | ||
|
||
abstract fun initialOutput(): Output | ||
private val runningInstanceManager = RunningInstanceManager<Input, Output>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the logic to keep track of individual formulas state to this class
return requireNotNull(stateMap.values.lastOrNull()) { | ||
"Formula is not running" | ||
} | ||
fun mostRecentInputs(): List<Input> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the ability to get a list of inputs instead of the most recent one.
* output updates and [inspect/interact][input] with input. | ||
* Test formula is used to replace a real formula with a fake implementation. This allows you to: | ||
* - Verify that parent passes correct inputs. Take a look at [input]. | ||
* - Verify that parent deals with output changes correctly. Take a look at [output] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also call out that we support the running count? This is a handy feature that I think a lot of devs don't know about.
There are a couple of changes around this PR
TestFormula
into a final class constructed viatestFormula
extension.TestFormula
key resolutionTestFormula
usage.RunningInstanceManager