|
1 | 1 | // SPDX-License-Identifier: Apache-2.0
|
2 | 2 | package com.swirlds.state.merkle.disk;
|
3 | 3 |
|
| 4 | +import static com.swirlds.common.test.fixtures.AssertionUtils.assertEventuallyEquals; |
4 | 5 | import static org.assertj.core.api.Assertions.assertThat;
|
5 | 6 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
6 | 7 | import static org.mockito.Mockito.verify;
|
7 | 8 |
|
| 9 | +import com.swirlds.merkledb.MerkleDbDataSource; |
8 | 10 | import com.swirlds.state.test.fixtures.merkle.MerkleTestBase;
|
9 | 11 | import com.swirlds.virtualmap.VirtualMap;
|
| 12 | +import java.time.Duration; |
| 13 | +import java.time.temporal.ChronoUnit; |
| 14 | +import org.junit.jupiter.api.AfterEach; |
10 | 15 | import org.junit.jupiter.api.BeforeEach;
|
11 | 16 | import org.junit.jupiter.api.DisplayName;
|
12 | 17 | import org.junit.jupiter.api.Nested;
|
@@ -86,4 +91,22 @@ void warm(@Mock VirtualMap virtualMapMock) {
|
86 | 91 | state.warm(A_KEY);
|
87 | 92 | verify(virtualMapMock).warm(STRING_CODEC.toBytes(A_KEY));
|
88 | 93 | }
|
| 94 | + |
| 95 | + @AfterEach |
| 96 | + void tearDown() { |
| 97 | + if (fruitVirtualMap != null && fruitVirtualMap.getReservationCount() > -1) { |
| 98 | + fruitVirtualMap.release(); |
| 99 | + } |
| 100 | + assertEventuallyEquals( |
| 101 | + 0L, |
| 102 | + MerkleDbDataSource::getCountOfOpenDatabases, |
| 103 | + Duration.of(5, ChronoUnit.SECONDS), |
| 104 | + "All databases should be closed"); |
| 105 | + try { |
| 106 | + // FUTURE WORK: need a better way to make sure that DB files are deleted |
| 107 | + Thread.sleep(100); |
| 108 | + } catch (InterruptedException e) { |
| 109 | + throw new RuntimeException(e); |
| 110 | + } |
| 111 | + } |
89 | 112 | }
|
0 commit comments