عرض عملي: سباق بين طلبين على قيد Unique
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
prove the application check fails under concurrency and the constraint saves you; prepares JNR-034-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Implement
createProductasif (!repo.existsBySku(sku)) repo.save(...)with no constraint. - Fire two concurrent requests with the same SKU (two threads released by a
CountDownLatch). - Planned mistake: run it and show two rows with the same SKU.
- Add
V3__unique_sku.sql(clean the duplicate first), then re-run. - Map the violation to 409 in the exception handler.
- Result: one 201 and one 409, every time.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.