-
Notifications
You must be signed in to change notification settings - Fork 101
How to stop generation of redundant parts of object graph #1183
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
Comments
Ive just noticed that: The former does seem to stop generation of redundant parts of object graph. However i need to do more testing to confirm |
Did some more testing and found scenario causing stackoverflow with fixtureMonkeyBuilder.register:
Scenario 1: "set parent.children to just null with ArbitraryBuilder works as expected"
no problems, no redundant child classes are instantiated Scenario 2: "set parent.children to just null with FixtureMonkeyBuilder.register results in stackoverflow"
stackoverflow Scenario 3: "set parent.children to null with FixtureMonkeyBuilder works but not as expected"
**no stackoverflow, but redundant child classes are instantiated ** |
@adambridger
Yes,
I have looked at your cases, but I don't fully understand the problem.
Thank you. |
Hi mate. Thanks for your time on a very helpful utlity. Here is how I reproduced stackoverflow.
Its related the map() in register. My use case is that I want to randomly generate an ORM model that is very deep. Im using Value.just(null) to cutoff circular references and parts of model that I dont want to generate. Some generated objects i want to persist in a database during generation. I solved this with a custom ArbitraryGenerator, however i did consider using the map but I find that map works strange. I seems like a simple way to modify an already generated object, however after map runs, the object is regenerated again. |
@adambridger In your case, I recommend using the
All ArbitraryBuilders are generated lazily. That's why it regenerated again. In your case, you also need to use 'fixed'. |
Uh oh!
There was an error while loading. Please reload this page.
Version 1.1.11
I have a massive model with many circular dependencies (bi-direction mappings). Im using setNull to break the circular dependencies, and im using map(...) to persist some dependent children into the database as the sample is generated.
However even though the circular dependency has been broken, an object for that property (which eventually results in null) is still created along withs its children. Due to how im using map, some of these redundant objects are getting persisted.
After much exploring of the API, I couldnt find a customization that prevents generation of redundant parts of the object graph.
Below is a small example to illustrate the problem described above.
Let me know if there is customization to stop creation of redundant parts of the graph or if i should use a different strategy all together.
Many thanks.
//returns a Foo with a Bar with a different Foo and null Bar
//returns a Foo with a Bar with the parent Foo (populated by bar.setFoo). However a distinct Bar and a distinct Foo is also constructed, the foo is persisted, but then they are discarded.
The text was updated successfully, but these errors were encountered: