Skip to content

Commit

Permalink
addressing feedback of PR Reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Sep 10, 2024
1 parent 7b8bec7 commit 7b3dc4b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BlockStreamSimulatorApp {

Configuration configuration;
BlockStreamManager blockStreamManager;

boolean isRunning = false;

/**
Expand All @@ -52,6 +53,17 @@ public void start() {
// use PublishStreamGrpcClient to stream it to the block-node.
isRunning = true;
LOGGER.log(System.Logger.Level.INFO, "Block Stream Simulator has started");

// while

// get block item
// send block item

// verify if ack is needed
// wait for ack async...

// verify exit condition

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public record BlockStreamConfig(
Path path = Path.of(folderRootPath);

// if rootPath is empty, set it to the default data directory
// default data directory is the "src/main/resources/blocks" directory
if (folderRootPath.isEmpty()) {
path =
Paths.get(folderRootPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package com.hedera.block.simulator.generator;

import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.INFO;

import com.hedera.block.simulator.config.data.BlockStreamConfig;
import com.hedera.block.simulator.config.types.GenerationMode;
import com.hedera.hapi.block.stream.Block;
Expand All @@ -35,12 +39,11 @@
/** The block as file block stream manager. */
public class BlockAsFileBlockStreamManager implements BlockStreamManager {

private static final System.Logger LOGGER =
System.getLogger(BlockAsFileBlockStreamManager.class.getName());
private final System.Logger LOGGER = System.getLogger(getClass().getName());

final String rootFolder;

final List<Block> blockList = new ArrayList<>();
final List<Block> blocks = new ArrayList<>();

int currentBlockIndex = 0;
int currentBlockItemIndex = 0;
Expand All @@ -57,11 +60,11 @@ public BlockAsFileBlockStreamManager(@NonNull BlockStreamConfig blockStreamConfi
try {
this.loadBlocks();
} catch (IOException | ParseException | IllegalArgumentException e) {
LOGGER.log(System.Logger.Level.ERROR, "Error loading blocks", e);
LOGGER.log(ERROR, "Error loading blocks", e);
throw new RuntimeException(e);
}

LOGGER.log(System.Logger.Level.INFO, "Loaded " + blockList.size() + " blocks into memory");
LOGGER.log(INFO, "Loaded " + blocks.size() + " blocks into memory");
}

@Override
Expand All @@ -71,10 +74,9 @@ public GenerationMode getGenerationMode() {

@Override
public BlockItem getNextBlockItem() {
BlockItem nextBlockItem =
blockList.get(currentBlockIndex).items().get(currentBlockItemIndex);
BlockItem nextBlockItem = blocks.get(currentBlockIndex).items().get(currentBlockItemIndex);
currentBlockItemIndex++;
if (currentBlockItemIndex >= blockList.get(currentBlockIndex).items().size()) {
if (currentBlockItemIndex >= blocks.get(currentBlockIndex).items().size()) {
currentBlockItemIndex = 0;
currentBlockIndex++;
}
Expand All @@ -83,10 +85,10 @@ public BlockItem getNextBlockItem() {

@Override
public Block getNextBlock() {
Block nextBlock = blockList.get(currentBlockIndex);
Block nextBlock = blocks.get(currentBlockIndex);
currentBlockIndex++;
lastGivenBlockNumber++;
if (currentBlockIndex >= blockList.size()) {
if (currentBlockIndex >= blocks.size()) {
currentBlockIndex = 0;
}
return nextBlock;
Expand All @@ -113,8 +115,8 @@ private void loadBlocks() throws IOException, ParseException {
}

Block block = Block.PROTOBUF.parse(Bytes.wrap(blockBytes));
blockList.add(block);
LOGGER.log(System.Logger.Level.DEBUG, "Loaded block: " + blockPath);
blocks.add(block);
LOGGER.log(DEBUG, "Loaded block: " + blockPath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.zip.GZIPInputStream;

/** Utility class for the simulator. */
public class Utils {
public final class Utils {

private Utils() {}

Expand Down

0 comments on commit 7b3dc4b

Please sign in to comment.