ctudose / java-persistence-spring-data-hibernate

58 stars 51 forks source link

noRollback test code in Chapter 11 #5

Open mklinkj opened 6 months ago

mklinkj commented 6 months ago

hello.

Java Persistence with Spring Data and Hibernate has been published in Korea, so I am reading it well.

Among the example tests in Chapter 11, there is a noRollback test method as follows, but I am inquiring because it does not seem to be a test of the operation of noRollback.

https://github.com/ctudose/java-persistence-spring-data-hibernate/blob/586c2126775b8d7caabb635a14ce322cc48d6d2a/Ch11/transactions5-springdata/src/test/java/com/manning/javapersistence/ch11/concurrency/TransactionPropagationTest.java#L123-L136

Since noRollback is set in ItemRepository#addItemNoRollback() -> LogRepository#log(), it seems that there must be a scenario where duplication occurs when calling addItemNoRollback().

In the case of ItemRepository#addItem() in the middle, it seems to have no relation to setting noRollback because it is set to REQUIRED_NEW.

So I thought about the following test code:

 @Test 
 public void noRollback() { 
     itemRepository.addItemNoRollback("Item1", LocalDate.of(2022, 5, 1)); 
     itemRepository.addItemNoRollback("Item2", LocalDate.of(2022, 3, 1)); 

     DuplicateItemNameException ex = assertThrows(DuplicateItemNameException.class, () -> itemRepository.addItemNoRollback("Item2", LocalDate.of(2022, 1, 1))); 
     assertAll( 
             () -> assertEquals("Item with name Item2 already exists", ex.getMessage()), 
             () -> assertEquals(3, logRepository.findAll().size()), 
             () -> assertEquals(2, itemRepository.findAll().size()) 
     ); 
     // ...

Then, I will finish reading the book. I've read up to chapter 11 now..😅

thank you have a good day. 👍

mklinkj commented 6 months ago

https://github.com/ctudose/java-persistence-spring-data-hibernate/blob/586c2126775b8d7caabb635a14ce322cc48d6d2a/Ch11/transactions5-springdata/src/test/java/com/manning/javapersistence/ch11/concurrency/TransactionPropagationTest.java#L131

It seems like there’s no need for various modifications… Just changing addItem() to addItemNoRollback() in the line above should do the trick. 😂

ctudose commented 6 months ago

Hello!

Thank you for your interest in my book. I am glad things are clear now, good luck further!

On Monday, May 6, 2024, mklinkj @.***> wrote:

https://github.com/ctudose/java-persistence-spring-data-hibernate/blob/ 586c2126775b8d7caabb635a14ce322cc48d6d2a/Ch11/transactions5- springdata/src/test/java/com/manning/javapersistence/ch11/concurrency/ TransactionPropagationTest.java#L131

It seems like there’s no need for various modifications… Just changing addItem() to addItemNoRollback() in the line above should do the trick. 😂

— Reply to this email directly, view it on GitHub https://github.com/ctudose/java-persistence-spring-data-hibernate/issues/5#issuecomment-2094978817, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKRPZWHN4GWS5DYX4LCOOVLZA2Y43AVCNFSM6AAAAABHICNYBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJUHE3TQOBRG4 . You are receiving this because you are subscribed to this thread.Message ID: <ctudose/java-persistence-spring-data-hibernate/issues/5/2094978817@ github.com>