-
Notifications
You must be signed in to change notification settings - Fork 30
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
Support flexible StaminaTestKit #56
Comments
Hello Yanyang, thanks for your question! When you say you "only keep the latest version of persisted events", I understand you mean you only have a case class for the latest version, but 'old' persisted events are still in storage? If so that's indeed exactly how stamina is designed to be used. When introducing You will have to add a 'sample id' to distinguish different tests for the same event type. It might look something like this: persisters.generateTestsFor(
sample(ClassV2("foo", None)),
sample("with-field2", ClassV2("bar", Some("baz")))) We should definitely add an example of this to the README, let's not close this issue before we fix that. I suspect this should fix your use case, though I don't completely understand your last paragraph. Can you confirm this helps? Or otherwise perhaps rephrase, or share some example code of what you want to achieve? |
Hi, I am trying to use your solution while I got this
The main problem is that we no longer keeping the old version persisters which causes the issue. In other word, for the case class to be persisted, only 1 persister will exist in the code anytime which is always the one with highest version. This should make my question more clear.
|
I have similar problem as @wuliaososhunhun. I have I think that |
Yes, it indeed looks like this is missing from the current testkit. Making the I wonder if we could/should make a check that ensures at least one sample goes all the way back to version 1? |
[#56] define "fromVersionNumber" for samples in TestKit
Hi,
we are using the
StaminaTestKit
for our persist test. Our use case is only keep the latest version of persisted events. When we upgrade domain to new version with additional fields, the automatic generating test cannot pass easily.e.g.
ClassV1(field1)
->ClassV2(field1, field2)
while field 1 and 2 are completely independent. the migration rule should be addfield2
with default values which should beempty
normally. That makes our test harder. if we useClassV2
with emptyfield2
as sample to test, it should pass all the test but it will not test thefield2
with data inside. if we useClassV2
with random data infield2
as sample, it will break the test fromV1
->V2
whileV2
test should be fine.Currently, we just make a hacky approach by re-writing (mostly copy paste as most method inside is private which cannot be re-used easily) the
StaminaTestKit
. I mainly make generateRoundtripTestFor andgenerateStoredVersionsDeserializationTestsFo
r public so we can use them separately. Meanwhile, we changegenerateStoredVersionsDeserializationTestsFor
to have additional field toVersion so we can decide the version range not always from version 1 to latest. By doing this, we can haveClassV2
with emptyfield2
sample for migration fromV1
toV2
while anotherClassV2
with data to checkV2
only. If there are more fields in the future, we can test starting fromV2
without changing anything beforeV2
.I believe this would make the test more flexible. Could you let me know what is your thought?
Thanks,
Yanyang
The text was updated successfully, but these errors were encountered: