Skip to content

Commit a099357

Browse files
committed
test(db): cover dbSource exception path in doClose()
1 parent 39cddb5 commit a099357

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

framework/src/test/java/org/tron/core/db/CheckPointV2StoreTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ public void testCloseReleasesAllResources() throws Exception {
6868
}
6969
}
7070

71+
@Test
72+
public void testCloseWhenDbSourceThrows() throws Exception {
73+
CheckPointV2Store store = new CheckPointV2Store("test-close-dbsource-throws");
74+
75+
Field dbSourceField = TronDatabase.class.getDeclaredField("dbSource");
76+
dbSourceField.setAccessible(true);
77+
DbSourceInter<byte[]> originalDbSource = (DbSourceInter<byte[]>) dbSourceField.get(store);
78+
DbSourceInter<byte[]> mockDbSource = mock(DbSourceInter.class);
79+
doThrow(new RuntimeException("simulated dbSource failure")).when(mockDbSource).closeDB();
80+
dbSourceField.set(store, mockDbSource);
81+
82+
try {
83+
store.close();
84+
} finally {
85+
originalDbSource.closeDB();
86+
}
87+
}
88+
7189
@Test
7290
public void testCloseDbSourceWhenWriteOptionsThrows() throws Exception {
7391
CheckPointV2Store store = new CheckPointV2Store("test-close-exception");

0 commit comments

Comments
 (0)