|
1 | 1 | package org.tron.core.db2; |
2 | 2 |
|
| 3 | +import static org.mockito.Mockito.doThrow; |
3 | 4 | import static org.mockito.Mockito.spy; |
4 | 5 | import static org.mockito.Mockito.when; |
5 | 6 |
|
|
13 | 14 | import lombok.extern.slf4j.Slf4j; |
14 | 15 | import org.junit.Assert; |
15 | 16 | import org.junit.Test; |
| 17 | +import org.mockito.MockedStatic; |
16 | 18 | import org.tron.common.BaseMethodTest; |
| 19 | +import org.tron.common.exit.ExitManager; |
| 20 | +import org.tron.common.exit.ExitManagerTestUtil; |
17 | 21 | import org.tron.common.utils.Sha256Hash; |
18 | 22 | import org.tron.core.capsule.BlockCapsule; |
19 | 23 | import org.tron.core.db2.RevokingDbWithCacheNewValueTest.TestRevokingTronStore; |
@@ -109,7 +113,25 @@ public void testFlushError() { |
109 | 113 | manager.setUnChecked(false); |
110 | 114 | when(manager.getCheckpointList()).thenReturn(Arrays.asList("check1", "check2")); |
111 | 115 | when(manager.shouldBeRefreshed()).thenReturn(true); |
112 | | - TronError thrown = Assert.assertThrows(TronError.class, manager::flush); |
113 | | - Assert.assertEquals(TronError.ErrCode.DB_FLUSH, thrown.getErrCode()); |
| 116 | + try (MockedStatic<ExitManager> exit = ExitManagerTestUtil.suppressExit()) { |
| 117 | + TronError thrown = Assert.assertThrows(TronError.class, manager::flush); |
| 118 | + Assert.assertEquals(TronError.ErrCode.DB_FLUSH, thrown.getErrCode()); |
| 119 | + exit.verify(() -> ExitManager.logAndExit(thrown)); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + public void testCheckpointOpenErrorRequestsExit() { |
| 125 | + SnapshotManager manager = spy(new SnapshotManager("")); |
| 126 | + manager.setUnChecked(false); |
| 127 | + when(manager.shouldBeRefreshed()).thenReturn(true); |
| 128 | + TronError openError = new TronError("open failed", TronError.ErrCode.LEVELDB_INIT); |
| 129 | + doThrow(openError).when(manager).createCheckpoint(); |
| 130 | + try (MockedStatic<ExitManager> exit = ExitManagerTestUtil.suppressExit()) { |
| 131 | + TronError thrown = Assert.assertThrows(TronError.class, manager::flush); |
| 132 | + Assert.assertEquals(TronError.ErrCode.DB_FLUSH, thrown.getErrCode()); |
| 133 | + Assert.assertSame(openError, thrown.getCause()); |
| 134 | + exit.verify(() -> ExitManager.logAndExit(thrown)); |
| 135 | + } |
114 | 136 | } |
115 | 137 | } |
0 commit comments