Skip to content

Commit

Permalink
Fix data generation if inventory size is bigger than products length
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkopp committed Apr 16, 2024
1 parent 8643bd2 commit 13341b4
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ public DataGenerator(@Autowired InventoryRepository repository, @Value("${t2.inv
*/
@PostConstruct
public void generateProducts() {
if (inventorySize > PRODUCT_NAMES.length) {
LOG.info("Inventory size is configured to be {}, but only {} products are available.", inventorySize, PRODUCT_NAMES.length);
inventorySize = PRODUCT_NAMES.length;
}

if (repository.count() >= inventorySize) {
LOG.info("Repository already contains {} entries. Not adding new entries.", repository.count());
return;
}

if (inventorySize > PRODUCT_NAMES.length) {
inventorySize = PRODUCT_NAMES.length;
}

LOG.info("Repository too small. Generate {} new entries.", inventorySize);

for (int i = (int) repository.count(); i < inventorySize; i++) {
Expand Down

0 comments on commit 13341b4

Please sign in to comment.