|
|
|
@ -13,6 +13,7 @@ import com.mydreamjob.onboarding.dto.CompanyKnowledgeView; |
|
|
|
import com.mydreamjob.onboarding.dto.ProgressUpdateRequest; |
|
|
|
import com.mydreamjob.onboarding.dto.ProgressUpdateResponse; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Nested; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
@ -97,23 +98,6 @@ class OnboardingConcurrencyIntegrationTest { |
|
|
|
.hasSize(1); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void concurrentCreatesAtLimitBoundaryNeverWriteFiftyFirstItem() throws Exception { |
|
|
|
CompanyOwner owner = createCompanyOwner("上限企业"); |
|
|
|
seedCompanyItems(owner.companyId(), 49); |
|
|
|
|
|
|
|
List<Attempt<CompanyChecklistItemView>> attempts = runConcurrently( |
|
|
|
() -> checklistService.createCompanyChecklistItem( |
|
|
|
owner.userId(), createRequest("边界A", "limit-a")), |
|
|
|
() -> checklistService.createCompanyChecklistItem( |
|
|
|
owner.userId(), createRequest("边界B", "limit-b"))); |
|
|
|
|
|
|
|
assertThat(attempts).filteredOn(attempt -> attempt.error() == null).hasSize(1); |
|
|
|
assertThat(attempts).filteredOn(Attempt::failedWithItemLimit).hasSize(1); |
|
|
|
assertThat(companyRows(owner.companyId())) |
|
|
|
.filteredOn(item -> Boolean.TRUE.equals(item.getActive())) |
|
|
|
.hasSize(50); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void inactiveItemsDoNotConsumeLimitAndExistingKeyStillReplays() throws Exception { |
|
|
|
@ -241,6 +225,31 @@ class OnboardingConcurrencyIntegrationTest { |
|
|
|
.isEqualTo(1L); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Nested |
|
|
|
@TestPropertySource(properties = |
|
|
|
"spring.datasource.hikari.transaction-isolation=TRANSACTION_REPEATABLE_READ") |
|
|
|
class RepeatableReadLimitBoundary { |
|
|
|
|
|
|
|
@Test |
|
|
|
void concurrentCreatesAtLimitBoundaryNeverWriteFiftyFirstItem() throws Exception { |
|
|
|
CompanyOwner owner = createCompanyOwner("上限企业"); |
|
|
|
seedCompanyItems(owner.companyId(), 49); |
|
|
|
|
|
|
|
List<Attempt<CompanyChecklistItemView>> attempts = runConcurrently( |
|
|
|
() -> checklistService.createCompanyChecklistItem( |
|
|
|
owner.userId(), createRequest("边界A", "limit-a")), |
|
|
|
() -> checklistService.createCompanyChecklistItem( |
|
|
|
owner.userId(), createRequest("边界B", "limit-b"))); |
|
|
|
|
|
|
|
assertThat(attempts).filteredOn(attempt -> attempt.error() == null).hasSize(1); |
|
|
|
assertThat(attempts).filteredOn(Attempt::failedWithItemLimit).hasSize(1); |
|
|
|
assertThat(companyRows(owner.companyId())) |
|
|
|
.filteredOn(item -> Boolean.TRUE.equals(item.getActive())) |
|
|
|
.hasSize(50); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private int failedWith(ThrowingSupplier<?> supplier) { |
|
|
|
try { |
|
|
|
supplier.get(); |
|
|
|
|