Skip to content

Commit 59d8583

Browse files
fix: spotlesscheck
1 parent e447ade commit 59d8583

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

src/integration-test/java/com/commercetools/sync/integration/services/impl/ProductTypeServiceImplIT.java

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,16 @@ void updateProductType_WithValidChanges_ShouldUpdateProductTypeCorrectly() {
450450
}
451451

452452
/*
453-
* This test verifies the cache stampede fix by making concurrent calls
454-
and ensuring the cache is populated correctly without race conditions.
455-
456-
What this test verifies:
457-
1. All concurrent calls complete successfully (no race conditions)
458-
2. All calls return the same cached data (cache consistency)
459-
3. No exceptions occur during concurrent access
460-
461-
NOTE: The tests were execute with logs and it can be seen that only one query is executed.
462-
*/
453+
* This test verifies the cache stampede fix by making concurrent calls
454+
and ensuring the cache is populated correctly without race conditions.
455+
456+
What this test verifies:
457+
1. All concurrent calls complete successfully (no race conditions)
458+
2. All calls return the same cached data (cache consistency)
459+
3. No exceptions occur during concurrent access
460+
461+
NOTE: The tests were execute with logs and it can be seen that only one query is executed.
462+
*/
463463
@Test
464464
void
465465
fetchCachedProductAttributeMetaDataMap_WithConcurrentCalls_ShouldHandleCacheStampedeCorrectly()
@@ -479,7 +479,8 @@ void updateProductType_WithValidChanges_ShouldUpdateProductTypeCorrectly() {
479479

480480
final ProductTypeSyncOptions productTypeSyncOptions =
481481
ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
482-
final ProductTypeService productTypeService = new ProductTypeServiceImpl(productTypeSyncOptions);
482+
final ProductTypeService productTypeService =
483+
new ProductTypeServiceImpl(productTypeSyncOptions);
483484

484485
// test - make 10 concurrent calls to fetchCachedProductAttributeMetaDataMap
485486
// Used a CountDownLatch to ensure all threads start at approximately the same time
@@ -490,26 +491,28 @@ void updateProductType_WithValidChanges_ShouldUpdateProductTypeCorrectly() {
490491
new java.util.concurrent.CountDownLatch(numberOfConcurrentCalls);
491492
final java.util.concurrent.ExecutorService executorService =
492493
java.util.concurrent.Executors.newFixedThreadPool(numberOfConcurrentCalls);
493-
final java.util.List<java.util.concurrent.CompletableFuture<Optional<Map<String, AttributeMetaData>>>>
494+
final java.util.List<
495+
java.util.concurrent.CompletableFuture<Optional<Map<String, AttributeMetaData>>>>
494496
futures = new java.util.ArrayList<>();
495497

496498
for (int i = 0; i < numberOfConcurrentCalls; i++) {
497-
final java.util.concurrent.CompletableFuture<Optional<Map<String, AttributeMetaData>>> future =
498-
java.util.concurrent.CompletableFuture.supplyAsync(
499-
() -> {
500-
try {
501-
readyLatch.countDown();
502-
startLatch.await(); // Wait for all threads to be ready
503-
return productTypeService
504-
.fetchCachedProductAttributeMetaDataMap(createdProductType.getId())
505-
.toCompletableFuture()
506-
.join();
507-
} catch (InterruptedException e) {
508-
Thread.currentThread().interrupt();
509-
throw new RuntimeException(e);
510-
}
511-
},
512-
executorService);
499+
final java.util.concurrent.CompletableFuture<Optional<Map<String, AttributeMetaData>>>
500+
future =
501+
java.util.concurrent.CompletableFuture.supplyAsync(
502+
() -> {
503+
try {
504+
readyLatch.countDown();
505+
startLatch.await(); // Wait for all threads to be ready
506+
return productTypeService
507+
.fetchCachedProductAttributeMetaDataMap(createdProductType.getId())
508+
.toCompletableFuture()
509+
.join();
510+
} catch (InterruptedException e) {
511+
Thread.currentThread().interrupt();
512+
throw new RuntimeException(e);
513+
}
514+
},
515+
executorService);
513516
futures.add(future);
514517
}
515518

@@ -519,7 +522,8 @@ void updateProductType_WithValidChanges_ShouldUpdateProductTypeCorrectly() {
519522
startLatch.countDown();
520523

521524
// Wait for all futures to complete
522-
java.util.concurrent.CompletableFuture.allOf(futures.toArray(new java.util.concurrent.CompletableFuture[0]))
525+
java.util.concurrent.CompletableFuture.allOf(
526+
futures.toArray(new java.util.concurrent.CompletableFuture[0]))
523527
.join();
524528

525529
executorService.shutdown();
@@ -567,7 +571,8 @@ void fetchCachedProductAttributeMetaDataMap_WithPopulatedCache_ShouldReturnCache
567571

568572
final ProductTypeSyncOptions productTypeSyncOptions =
569573
ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
570-
final ProductTypeService productTypeService = new ProductTypeServiceImpl(productTypeSyncOptions);
574+
final ProductTypeService productTypeService =
575+
new ProductTypeServiceImpl(productTypeSyncOptions);
571576

572577
// test - first call to populate cache
573578
final Optional<Map<String, AttributeMetaData>> firstResult =
@@ -588,8 +593,9 @@ void fetchCachedProductAttributeMetaDataMap_WithPopulatedCache_ShouldReturnCache
588593
assertThat(secondResult).isPresent();
589594
assertThat(firstResult.get()).isEqualTo(secondResult.get());
590595
assertThat(firstResult.get()).hasSize(2);
591-
assertThat(firstResult.get()).containsKeys(
592-
ATTRIBUTE_DEFINITION_DRAFT_1.getName(), ATTRIBUTE_DEFINITION_DRAFT_2.getName());
596+
assertThat(firstResult.get())
597+
.containsKeys(
598+
ATTRIBUTE_DEFINITION_DRAFT_1.getName(), ATTRIBUTE_DEFINITION_DRAFT_2.getName());
593599

594600
// cleanup
595601
CTP_TARGET_CLIENT
@@ -607,7 +613,8 @@ void fetchCachedProductAttributeMetaDataMap_WithPopulatedCache_ShouldReturnCache
607613
// preparation
608614
final ProductTypeSyncOptions productTypeSyncOptions =
609615
ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
610-
final ProductTypeService productTypeService = new ProductTypeServiceImpl(productTypeSyncOptions);
616+
final ProductTypeService productTypeService =
617+
new ProductTypeServiceImpl(productTypeSyncOptions);
611618

612619
// test - query for non-existent product type ID
613620
final Optional<Map<String, AttributeMetaData>> result =

0 commit comments

Comments
 (0)