Restore custom suppliers in TestDataGenerator#1976
Restore custom suppliers in TestDataGenerator#1976labkey-chrisj merged 3 commits intorelease24.7-SNAPSHOTfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
| if (!_dataSuppliers.containsKey(columnName)) | ||
| { | ||
| _dataSuppliers.put(columnName, getDefaultDataSupplier(_columns.get(columnName).getRangeURI())); | ||
| } |
There was a problem hiding this comment.
Sick Map trick 🛹
| if (!_dataSuppliers.containsKey(columnName)) | |
| { | |
| _dataSuppliers.put(columnName, getDefaultDataSupplier(_columns.get(columnName).getRangeURI())); | |
| } | |
| _dataSuppliers.computeIfAbsent(columnName, k -> getDefaultDataSupplier(_columns.get(columnName).getRangeURI())); |
There was a problem hiding this comment.
I was excited to try this sick map trick, but unfortunately it didn't update the suppliers map; this meant that below the call to
_dataSuppliers.get(columnName).get();
...would fail because _dataSuppliers.get(columnName) would be null
| // Generate values | ||
| Object columnValue = _dataSuppliers.get(columnName).apply(_rows); |
There was a problem hiding this comment.
Consider making _dataSuppliers actually be Suppliers. We don't actually use the row collection in any existing data suppliers and I don't know that it adds much utility to provide it.
Map<String, Supplier<Object>> _dataSuppliers = new CaseInsensitiveHashMap<>()
Then this simplifies to:
| // Generate values | |
| Object columnValue = _dataSuppliers.get(columnName).apply(_rows); | |
| // Generate values | |
| Object columnValue = _dataSuppliers.get(columnName).get(); |
And we could remove the unused method addDataSupplier(String columnName, Function<List<Map<String, Object>>, Object> supplier)
There was a problem hiding this comment.
Thanks, I like this suggestion a lot. (applying it to _rows without really understanding why has bothered me, this gets me out of that)
Also, this makes everything else that interacts with _dataSuppliers a lot more readable
Co-authored-by: Trey Chadick <tchad@labkey.com>
Rationale
Recently on 24.7, BiologicsReportTest.testBarChartWithAggregateMethod began failing because the chart-builder expects there to be values in the field it is using for its y-axis column. The reason that column was empty, it happens, is that this domain was being generated using a custom dataSupplier (its job was to put the value '1' in generated rows.)
My recent changes to TestDataGenerator seem to have inadvertently regressed its ability to use custom dataSuppliers when generating row data. This change initializes the default field data-generating suppliers to the list of suppliers if no supplier is in the list, and uses suppliers from the list (vs. calling getDefaultDataSupplier every row to get a supplier) to generate data.
Related Pull Requests
#1971
Changes