justinmclean opened a new issue, #8165:
URL: https://github.com/apache/gravitino/issues/8165

   ### What would you like to be improved?
   
   In 
core/src/main/java/org/apache/gravitino/storage/relational/session/SqlSessions.java,
 ensure commitAndCloseSqlSession closes the session even if commit() throws, 
preventing resource leaks.
   
   The same needs to be done to rollbackAndCloseSqlSession.
   
   Here's some unit tests to help:
   ```
     @Test
     public void testCommitAndCloseSqlSessionWhenCommitFails() {
       SqlSession mockSession = Mockito.mock(SqlSession.class);
       Mockito.doThrow(new RuntimeException("commit 
fail")).when(mockSession).commit();
       SqlSessions.getSessions().set(mockSession);
       assertThrows(RuntimeException.class, 
SqlSessions::commitAndCloseSqlSession);
       Mockito.verify(mockSession).close();
       assertNull(SqlSessions.getSessions().get());
     }
   
     @Test
     public void testRollbackAndCloseSqlSessionWhenRollbackFails() {
       SqlSession mockSession = Mockito.mock(SqlSession.class);
       Mockito.doThrow(new RuntimeException("rollback 
fail")).when(mockSession).rollback();
       SqlSessions.getSessions().set(mockSession);
       assertThrows(RuntimeException.class, 
SqlSessions::rollbackAndCloseSqlSession);
       Mockito.verify(mockSession).close();
       assertNull(SqlSessions.getSessions().get());
     }
   ```
   
   ### How should we improve?
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to