Repository navigation
Share the GML reader proxy, not the whole reader factory - #404
Merged
Merged
Conversation
BertScholten
left a comment
Member
There was a problem hiding this comment.
Would it now be OK to get rid of the public constructor (and get rid of the whole cache thing in AssertGML), and perhaps make the remaining constructor private to avoid someone using it that way?
Member
Author
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactors the part where the cheap factory, instead of the expensive reader proxy, is turned into a singleton.
When running calculator's integration tests one after another in the same JVM (i.e. reuseForks=true), the factory would be created once, and for different helpers would return the same factory, using the first helper. This caused tests to fail because those helpers (a class which provides emission categories/factors etc.) would be different in the tests (they are not different in production, hence it leads to no issues there).
This changes this factory to turn the GMLReaderProxy into a singleton, rather than itself, which makes all calls work with the helper they pass, even when they pass helpers which are actually different.
This change enables running integration tests on the same JVM, creating a ~4 minute speedup (which brings it in the ballpark of where running them for each PR is somewhat feasible)
LLM-generated technical summary
Before this change,
GMLReaderFactory.getFactory(gmlHelper)stored the whole factory in a static field on the first call, including that firstGMLHelper, and returned the same instance on every later call.createReaderbuilds eachGMLReaderwith the factory's helper, and the reader uses it for feature conversion (GMLConversionData: sector ids, default characteristics, inland shipping) and forenforceEmissions;createValidationHelper()also comes from it.ImaerImporter(GMLHelper)callsgetFactory, so every importer in a JVM converted, computed emissions and validated with the helper of the first importer, whatever helper it was given.The static field now holds only the
GMLReaderProxy: the 12 version reader factories, each of which compiles its XSD schema and builds a legacy code converter from the helper's legacy code methods. That is the costly part, and it is still built once per JVM.getFactoryreturns a newGMLReaderFactory(gmlHelper, sharedReaderProxy)per call, which only sets two fields. The legacy code conversions still come from the first helper; the Javadoc says so. In AERIUS Calculator they come from the same database tables for every helper. No public signatures change.getFactorynow returns a new instance per call; its callers (ImaerImporterand two tests) do not rely on getting the same instance.No effect is expected in production. Calculator creates a helper per import, with NL or EN categories depending on the locale. Those two sets differ only in description text, and the reader only uses ids, codes and emission factors.
Found with Maven Failsafe reusing one JVM per module in calculator:
SRMSourceConversionVerificationIT, which uses categories built in code with different emission factors, failed wheneverImporterFacadeIT,RemovedVehicleCodeITorImportSummaryGeneratorJsonIThad run earlier in the same JVM. With this change installed locally, it passes after each of those three, and all 10 integration test classes ofaerius-commons-imaerpass in three random orders. The imaer-java test suite passes (1,213 tests).Calculator uses
6.0.2-2-SNAPSHOT, which is what main builds, so it picks this up without a version bump once the snapshot is published.Written at 8864259.