Skip to content

Commit

Permalink
Adding missing javadocs and little cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 30, 2024
1 parent 8d9ce80 commit 50d5e3c
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,32 @@
import java.lang.System.Logger;
import javax.inject.Inject;

/** The BlockStreamSimulator class defines the simulator for the block stream. */
public class BlockStreamSimulator {
private static final Logger LOGGER = System.getLogger(BlockStreamSimulator.class.getName());

Configuration configuration;
BlockStreamManager blockStreamManager;
boolean isRunning = false;

/**
* Creates a new BlockStreamSimulator instance.
*
* @param configuration the configuration to be used by the block stream simulator
* @param blockStreamManager the block stream manager to be used by the block stream simulator
*/
@Inject
public BlockStreamSimulator(
@NonNull Configuration configuration, @NonNull BlockStreamManager blockStreamManager) {
this.configuration = configuration;
this.blockStreamManager = blockStreamManager;
}

/**
* The main entry point for the block stream simulator.
*
* @param args the arguments to be passed to the block stream simulator
*/
public static void main(String[] args) {

LOGGER.log(Logger.Level.INFO, "Starting Block Stream Simulator");

Check warning on line 55 in simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java#L55

Added line #L55 was not covered by tests
Expand All @@ -51,6 +63,7 @@ public static void main(String[] args) {
blockStreamSimulator.start();
}

Check warning on line 64 in simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java#L62-L64

Added lines #L62 - L64 were not covered by tests

/** Starts the block stream simulator. */
public void start() {

// use blockStreamManager to get block stream
Expand All @@ -60,9 +73,18 @@ public void start() {
LOGGER.log(Logger.Level.INFO, "Block Stream Simulator has started");
}

/**
* Returns whether the block stream simulator is running.
*
* @return true if the block stream simulator is running, false otherwise
*/
public boolean isRunning() {
return isRunning;
}

public void stop() {}
/** Stops the block stream simulator. */
public void stop() {
isRunning = false;
LOGGER.log(Logger.Level.INFO, "Block Stream Simulator has stopped");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dagger.Component;
import javax.inject.Singleton;

/** The component used to inject the block stream simulator into the application. */
@Singleton
@Component(
modules = {
Expand All @@ -31,10 +32,22 @@
})
public interface BlockStreamSimulatorInjectionComponent {

/**
* Gets the block stream simulator.
*
* @return the block stream simulator
*/
BlockStreamSimulator getBlockStreamSimulator();

/** The factory used to create the block stream simulator injection component. */
@Component.Factory
interface Factory {
/**
* Creates the block stream simulator injection component.
*
* @param configuration the configuration to be used by the block stream simulator
* @return the block stream simulator injection component
*/
BlockStreamSimulatorInjectionComponent create(@BindsInstance Configuration configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,28 @@
import dagger.Provides;
import javax.inject.Singleton;

/** The module used to inject the configuration data into the application. */
@Module
public interface ConfigInjectionModule {

/**
* Provides the block stream configuration.
*
* @param configuration the configuration to be used by the block stream
* @return the block stream configuration
*/
@Singleton
@Provides
static BlockStreamConfig provideBlockStreamConfig(Configuration configuration) {
return configuration.getConfigData(BlockStreamConfig.class);

Check warning on line 39 in simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java#L39

Added line #L39 was not covered by tests
}

/**
* Provides the gRPC configuration.
*
* @param configuration the configuration to be used by the gRPC
* @return the gRPC configuration
*/
@Singleton
@Provides
static GrpcConfig provideGrpcConfig(Configuration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
import com.swirlds.config.api.Configuration;
import edu.umd.cs.findbugs.annotations.NonNull;

/** The provider used to get the configuration for the simulator. */
public interface ConfigProvider {

/**
* Gets the configuration for the simulator, specifies the mode of generation, the mode of
* simulator and every configurable detail.
*
* @return the configuration
*/
@NonNull
Configuration getConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@
import java.io.IOException;
import java.nio.file.Path;

/** The ConfigProviderImpl class provides the implementation for the configuration provider. */
public class ConfigProviderImpl implements ConfigProvider {
private static final System.Logger LOGGER =
System.getLogger(ConfigProviderImpl.class.getName());

Check warning on line 31 in simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java#L30-L31

Added lines #L30 - L31 were not covered by tests
private final Configuration configuration;

/** Creates a new ConfigProviderImpl instance. */
public ConfigProviderImpl() {
final var builder = createConfigurationBuilder();
// addFileSources(builder, useGenesisSource);
// if (overrideValues != null) {
// overrideValues.forEach(builder::withValue);
// }
configuration = builder.build();
}

Check warning on line 38 in simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java#L35-L38

Added lines #L35 - L38 were not covered by tests

/**
* Returns the configuration.
*
* @return the configuration
*/
@NonNull
@Override
public Configuration getConfiguration() {
Expand All @@ -54,6 +57,7 @@ private ConfigurationBuilder createConfigurationBuilder() {
.autoDiscoverExtensions();

Check warning on line 57 in simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java#L53-L57

Added lines #L53 - L57 were not covered by tests

} catch (IOException e) {
LOGGER.log(System.Logger.Level.ERROR, "Failed to create configuration builder", e);
throw new RuntimeException(e);

Check warning on line 61 in simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java#L59-L61

Added lines #L59 - L61 were not covered by tests
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import com.swirlds.config.api.ConfigData;
import com.swirlds.config.api.ConfigProperty;

// TODO add block dir option to generate from directory
/**
* The BlockStreamConfig class defines the configuration data for the block stream.
*
* @param generationMode the mode of generation for the block stream
*/
@ConfigData("blockStream")
public record BlockStreamConfig(

Check warning on line 29 in simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java#L29

Added line #L29 was not covered by tests
@ConfigProperty(defaultValue = "SELF") GenerationMode generationMode) {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
import com.swirlds.config.api.validation.annotation.Max;
import com.swirlds.config.api.validation.annotation.Min;

/**
* The GrpcConfig class defines the configuration data for the gRPC client.
*
* @param serverAddress the address of the gRPC server
* @param port the port of the gRPC server
*/
@ConfigData("grpc")
public record GrpcConfig(

Check warning on line 31 in simulator/src/main/java/com/hedera/block/simulator/config/data/GrpcConfig.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/data/GrpcConfig.java#L31

Added line #L31 was not covered by tests
@ConfigProperty(defaultValue = "localhost") @Min(0) @Max(65535) String serverAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.hedera.block.simulator.config.types;

/** The GenerationMode enum defines the modes of generation for the block stream. */
public enum GenerationMode {

Check warning on line 20 in simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java#L20

Added line #L20 was not covered by tests
/** Reads Blocks from a Folder. */
FOLDER,

Check warning on line 22 in simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java#L22

Added line #L22 was not covered by tests
/** Generates Blocks from rules */
SELF

Check warning on line 24 in simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java#L24

Added line #L24 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

import com.hedera.hapi.block.stream.Block;

/** this interface defines the contract for managing the block stream. */
public interface BlockStreamManager {

/**
* Gets the next block in the block stream.
*
* @return the next block in the block stream
*/
Block getNextBlock();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
import dagger.Module;
import javax.inject.Singleton;

/** The module used to inject the block stream manager. */
@Module
public interface GeneratorInjectionModule {

/**
* Provides the block stream manager.
*
* @param blockStreamManager the block stream manager to be used
* @return the block stream manager
*/
@Singleton
@Binds
BlockStreamManager bindBlockStreamManager(MockBlockStreamManagerImpl blockStreamManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@
import com.hedera.hapi.block.stream.Block;
import javax.inject.Inject;

/** A mock implementation of the BlockStreamManager interface. */
public class MockBlockStreamManagerImpl implements BlockStreamManager {

/** Constructs a new MockBlockStreamManagerImpl. */
@Inject
public MockBlockStreamManagerImpl() {}

Check warning on line 27 in simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java#L27

Added line #L27 was not covered by tests

/**
* Gets the next block in the block stream.
*
* @return the next block in the block stream
*/
@Override
public Block getNextBlock() {
return Block.newBuilder().build();

Check warning on line 36 in simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java#L36

Added line #L36 was not covered by tests
Expand Down
5 changes: 2 additions & 3 deletions simulator/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import com.hedera.block.simulator.config.SimulatorConfigExtension;

/** Runtime module of the simulator. */
module com.hedera.block.simulator {
exports com.hedera.block.simulator.config.data to
com.swirlds.config.impl,
com.swirlds.config.extensions;
exports com.hedera.block.simulator.config.data;

requires static com.github.spotbugs.annotations;
requires static com.google.auto.service;
Expand Down

0 comments on commit 50d5e3c

Please sign in to comment.