Skip to content

Commit

Permalink
test temp path resolution improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Atanasov <[email protected]>
  • Loading branch information
ata-nas committed Feb 27, 2025
1 parent 60e6cfe commit d6231a3
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,21 @@ class BlockAccessServiceTest {
private ServiceStatus serviceStatus;

@TempDir
private Path testLiveRootPath;
private Path testTempDir;

private BlockNodeContext blockNodeContext;
private PersistenceStorageConfig testConfig;
private PbjBlockAccessService blockAccessService;

@BeforeEach
void setUp() throws IOException {
final Path testLiveRootPath = testTempDir.resolve("live");
blockNodeContext = TestConfigUtil.getTestBlockNodeContext(
Map.of(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath.toString()));
testConfig = blockNodeContext.configuration().getConfigData(PersistenceStorageConfig.class);

blockAccessService = new PbjBlockAccessServiceProxy(serviceStatus, blockReader, blockNodeContext);

final Path testConfigLiveRootPath = testConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
blockAccessService = new PbjBlockAccessServiceProxy(serviceStatus, blockReader, blockNodeContext);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY;
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY;
import static com.hedera.block.server.util.PersistTestUtils.generateBlockItemsUnparsed;
import static com.hedera.block.server.util.TestConfigUtil.CONSUMER_TIMEOUT_THRESHOLD_KEY;
import static com.hedera.block.server.util.TestConfigUtil.MEDIATOR_RING_BUFFER_SIZE_KEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -112,13 +111,20 @@ class LiveStreamMediatorImplTest {
@BeforeEach
void setup() throws IOException {
final Map<String, String> properties = new HashMap<>();
properties.put(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testTempDir.toString());
properties.put(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testTempDir.toString());
properties.put(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testTempDir.toString());
properties.put(CONSUMER_TIMEOUT_THRESHOLD_KEY, String.valueOf(TIMEOUT_THRESHOLD_MILLIS));
properties.put(MEDIATOR_RING_BUFFER_SIZE_KEY, String.valueOf(1024));
final Path testLiveRootPath = testTempDir.resolve("live");
final Path testArchiveRootPath = testTempDir.resolve("archive");
final Path testUnverifiedRootPath = testTempDir.resolve("unverified");
properties.put(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testArchiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testUnverifiedRootPath.toString());
this.testContext = TestConfigUtil.getTestBlockNodeContext(properties);
this.persistenceStorageConfig = testContext.configuration().getConfigData(PersistenceStorageConfig.class);
final Path testConfigLiveRootPath = persistenceStorageConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
final Path testConfigArchiveRootPath = persistenceStorageConfig.archiveRootPath();
assertThat(testConfigArchiveRootPath).isEqualTo(testArchiveRootPath);
final Path testConfigUnverifiedRootPath = persistenceStorageConfig.unverifiedRootPath();
assertThat(testConfigUnverifiedRootPath).isEqualTo(testUnverifiedRootPath);
this.completionService = new ExecutorCompletionService<>(Executors.newSingleThreadExecutor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY;
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY;
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.timeout;
Expand Down Expand Up @@ -129,13 +130,21 @@ class NotifierImplTest {

@BeforeEach
void setUp() throws IOException {

final Map<String, String> properties = new HashMap<>();
properties.put(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testTempDir.toString());
properties.put(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testTempDir.toString());
properties.put(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testTempDir.toString());
final Path testLiveRootPath = testTempDir.resolve("live");
final Path testArchiveRootPath = testTempDir.resolve("archive");
final Path testUnverifiedRootPath = testTempDir.resolve("unverified");
properties.put(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testArchiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testUnverifiedRootPath.toString());
blockNodeContext = TestConfigUtil.getTestBlockNodeContext(properties);
persistenceStorageConfig = blockNodeContext.configuration().getConfigData(PersistenceStorageConfig.class);
final Path testConfigLiveRootPath = persistenceStorageConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
final Path testConfigArchiveRootPath = persistenceStorageConfig.archiveRootPath();
assertThat(testConfigArchiveRootPath).isEqualTo(testArchiveRootPath);
final Path testConfigUnverifiedRootPath = persistenceStorageConfig.unverifiedRootPath();
assertThat(testConfigUnverifiedRootPath).isEqualTo(testUnverifiedRootPath);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,28 @@ class PbjBlockStreamServiceIntegrationTest {
private BlockPathResolver pathResolverMock;

@TempDir
private Path testLiveRootPath;
private Path testTempDir;

private BlockNodeContext blockNodeContext;
private PersistenceStorageConfig persistenceStorageConfig;

@BeforeEach
void setUp() throws IOException {
final Map<String, String> properties = new HashMap<>();
final Path testLiveRootPath = testTempDir.resolve("live");
final Path testArchiveRootPath = testTempDir.resolve("archive");
final Path testUnverifiedRootPath = testTempDir.resolve("unverified");
properties.put(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testLiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testLiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testArchiveRootPath.toString());
properties.put(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testUnverifiedRootPath.toString());
blockNodeContext = TestConfigUtil.getTestBlockNodeContext(properties);
persistenceStorageConfig = blockNodeContext.configuration().getConfigData(PersistenceStorageConfig.class);

final Path testConfigLiveRootPath = persistenceStorageConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
final Path testConfigArchiveRootPath = persistenceStorageConfig.archiveRootPath();
assertThat(testConfigArchiveRootPath).isEqualTo(testArchiveRootPath);
final Path testConfigUnverifiedRootPath = persistenceStorageConfig.unverifiedRootPath();
assertThat(testConfigUnverifiedRootPath).isEqualTo(testUnverifiedRootPath);
}

@Disabled("@todo(642) make test deterministic via correct executor injection")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static com.hedera.block.server.util.PersistTestUtils.*;
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY;
import static com.hedera.block.server.util.PersistTestUtils.generateBlockItemsUnparsed;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -75,11 +76,20 @@ class StreamPersistenceHandlerImplTest {
@BeforeEach
void setUp() {
final TestConfigBuilder configBuilder = new TestConfigBuilder(PersistenceStorageConfig.class);
configBuilder.withValue(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testTempDir.toString());
configBuilder.withValue(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testTempDir.toString());
configBuilder.withValue(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testTempDir.toString());
final Path testLiveRootPath = testTempDir.resolve("live");
final Path testArchiveRootPath = testTempDir.resolve("archive");
final Path testUnverifiedRootPath = testTempDir.resolve("unverified");
configBuilder.withValue(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath.toString());
configBuilder.withValue(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testArchiveRootPath.toString());
configBuilder.withValue(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testUnverifiedRootPath.toString());
final Configuration config = configBuilder.getOrCreateConfig();
persistenceStorageConfig = config.getConfigData(PersistenceStorageConfig.class);
final Path testConfigLiveRootPath = persistenceStorageConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
final Path testConfigArchiveRootPath = persistenceStorageConfig.archiveRootPath();
assertThat(testConfigArchiveRootPath).isEqualTo(testArchiveRootPath);
final Path testConfigUnverifiedRootPath = persistenceStorageConfig.unverifiedRootPath();
assertThat(testConfigUnverifiedRootPath).isEqualTo(testUnverifiedRootPath);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ class LocalGroupZipArchiveTaskTest {

@BeforeEach
void setUp() throws IOException {
final Path testLiveRootPath = testTempDir.resolve("live");
final Path testArchiveRootPath = testTempDir.resolve("archive");
final Configuration config = new TestConfigBuilder(PersistenceStorageConfig.class)
.withValue(PERSISTENCE_STORAGE_COMPRESSION_TYPE, "NONE")
.withValue(PERSISTENCE_STORAGE_ARCHIVE_GROUP_SIZE, String.valueOf(ARCHIVE_GROUP_SIZE))
.withValue(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testTempDir.resolve("live"))
.withValue(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testTempDir.resolve("archive"))
.withValue(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath)
.withValue(PERSISTENCE_STORAGE_ARCHIVE_ROOT_PATH_KEY, testArchiveRootPath)
.getOrCreateConfig();
persistenceStorageConfig = config.getConfigData(PersistenceStorageConfig.class);
final Path testConfigLiveRootPath = persistenceStorageConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
final Path testConfigArchiveRootPath = persistenceStorageConfig.archiveRootPath();
assertThat(testConfigArchiveRootPath).isEqualTo(testArchiveRootPath);
// using spy for path resolver because we should test with actual logic for path resolution
// also asserts would be based on the findLive/findArchive methods, which are unit tested themselves
// in the respective test class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ void setUp() throws IOException {
configBuilder.withValue(PERSISTENCE_STORAGE_UNVERIFIED_ROOT_PATH_KEY, testUnverifiedRootPath.toString());
configBuilder.withValue(PERSISTENCE_STORAGE_ARCHIVE_GROUP_SIZE, "10");
testConfig = configBuilder.getOrCreateConfig().getConfigData(PersistenceStorageConfig.class);
final Path testConfigLiveRootPath = testConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
final Path testConfigArchiveRootPath = testConfig.archiveRootPath();
assertThat(testConfigArchiveRootPath).isEqualTo(testArchiveRootPath);
final Path testConfigUnverifiedRootPath = testConfig.unverifiedRootPath();
assertThat(testConfigUnverifiedRootPath).isEqualTo(testUnverifiedRootPath);
// final Path testConfigLiveRootPath = testConfig.liveRootPath();
// assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);
// final Path testConfigUnverifiedRootPath = testConfig.unverifiedRootPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.block.server.persistence.storage.read;

import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_COMPRESSION_TYPE;
import static com.hedera.block.server.util.PersistTestUtils.PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.from;
import static org.mockito.Mockito.spy;

import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.config.TestConfigBuilder;
import com.hedera.block.server.persistence.storage.PersistenceStorageConfig;
import com.hedera.block.server.persistence.storage.compression.Compression;
import com.hedera.block.server.persistence.storage.compression.NoOpCompression;
import com.hedera.block.server.persistence.storage.path.BlockAsLocalFilePathResolver;
import com.hedera.block.server.persistence.storage.path.BlockPathResolver;
import com.hedera.block.server.util.PersistTestUtils;
import com.hedera.block.server.util.TestConfigUtil;
import com.hedera.hapi.block.BlockItemUnparsed;
import com.hedera.hapi.block.BlockUnparsed;
import com.hedera.hapi.block.stream.output.BlockHeader;
import com.hedera.pbj.runtime.ParseException;
import com.swirlds.config.api.Configuration;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
Expand All @@ -44,20 +44,20 @@ class BlockAsLocalFileReaderTest {
private BlockAsLocalFileReader toTest;

@TempDir
private Path testLiveRootPath;
private Path testTempDir;

@BeforeEach
void setUp() throws IOException {
final BlockNodeContext blockNodeContext = TestConfigUtil.getTestBlockNodeContext(
Map.of(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath.toString()));
final PersistenceStorageConfig testConfig =
blockNodeContext.configuration().getConfigData(PersistenceStorageConfig.class);

final Path testConfigLiveRootPath = testConfig.liveRootPath();
final Path testLiveRootPath = testTempDir.resolve("live");
final Configuration config = new TestConfigBuilder(PersistenceStorageConfig.class)
.withValue(PERSISTENCE_STORAGE_COMPRESSION_TYPE, "NONE")
.withValue(PERSISTENCE_STORAGE_LIVE_ROOT_PATH_KEY, testLiveRootPath)
.getOrCreateConfig();
final PersistenceStorageConfig persistenceStorageConfig = config.getConfigData(PersistenceStorageConfig.class);
final Path testConfigLiveRootPath = persistenceStorageConfig.liveRootPath();
assertThat(testConfigLiveRootPath).isEqualTo(testLiveRootPath);

compressionMock = spy(NoOpCompression.newInstance());
blockPathResolverMock = spy(new BlockAsLocalFilePathResolver(testConfig));
blockPathResolverMock = spy(new BlockAsLocalFilePathResolver(persistenceStorageConfig));
toTest = BlockAsLocalFileReader.of(compressionMock, blockPathResolverMock);
}

Expand Down

0 comments on commit d6231a3

Please sign in to comment.