-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed ConfigProvider, since we will be injecting the config we don'…
…t need a provider. And refactored code around that, also divided the main entry point from the ActualApp so we can only ignore the entry point in the unit test coverage. Added Missing unit tests Signed-off-by: Alfredo Gutierrez <[email protected]>
- Loading branch information
1 parent
5384ffe
commit ef7f0a9
Showing
9 changed files
with
205 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator; | ||
|
||
import com.hedera.block.simulator.generator.BlockStreamManager; | ||
import com.swirlds.config.api.Configuration; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import javax.inject.Inject; | ||
|
||
/** BlockStream Simulator App */ | ||
public class BlockStreamSimulatorApp { | ||
|
||
private static final System.Logger LOGGER = | ||
System.getLogger(BlockStreamSimulatorApp.class.getName()); | ||
|
||
Configuration configuration; | ||
BlockStreamManager blockStreamManager; | ||
boolean isRunning = false; | ||
|
||
/** | ||
* Creates a new BlockStreamSimulatorApp 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 BlockStreamSimulatorApp( | ||
@NonNull Configuration configuration, @NonNull BlockStreamManager blockStreamManager) { | ||
this.configuration = configuration; | ||
this.blockStreamManager = blockStreamManager; | ||
} | ||
|
||
/** Starts the block stream simulator. */ | ||
public void start() { | ||
|
||
// use blockStreamManager to get block stream | ||
|
||
// use PublishStreamGrpcClient to stream it to the block-node. | ||
isRunning = true; | ||
LOGGER.log(System.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; | ||
} | ||
|
||
/** Stops the block stream simulator. */ | ||
public void stop() { | ||
isRunning = false; | ||
LOGGER.log(System.Logger.Level.INFO, "Block Stream Simulator has stopped"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
simulator/src/test/java/com/hedera/block/simulator/config/ConfigInjectionModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator.config; | ||
|
||
import com.hedera.block.simulator.config.data.BlockStreamConfig; | ||
import com.hedera.block.simulator.config.data.GrpcConfig; | ||
import com.hedera.block.simulator.config.types.GenerationMode; | ||
import com.swirlds.config.api.Configuration; | ||
import com.swirlds.config.api.ConfigurationBuilder; | ||
import com.swirlds.config.extensions.sources.ClasspathFileConfigSource; | ||
import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource; | ||
import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ConfigInjectionModuleTest { | ||
|
||
static Configuration configuration; | ||
|
||
@BeforeAll | ||
static void setUpAll() throws IOException { | ||
configuration = | ||
ConfigurationBuilder.create() | ||
.withSource(SystemEnvironmentConfigSource.getInstance()) | ||
.withSource(SystemPropertiesConfigSource.getInstance()) | ||
.withSource(new ClasspathFileConfigSource(Path.of("app.properties"))) | ||
.autoDiscoverExtensions() | ||
.build(); | ||
} | ||
|
||
@Test | ||
void provideBlockStreamConfig() { | ||
|
||
BlockStreamConfig blockStreamConfig = | ||
ConfigInjectionModule.provideBlockStreamConfig(configuration); | ||
|
||
Assertions.assertNotNull(blockStreamConfig); | ||
Assertions.assertEquals(GenerationMode.SELF, blockStreamConfig.generationMode()); | ||
} | ||
|
||
@Test | ||
void provideGrpcConfig() { | ||
GrpcConfig grpcConfig = ConfigInjectionModule.provideGrpcConfig(configuration); | ||
|
||
Assertions.assertNotNull(grpcConfig); | ||
Assertions.assertEquals("localhost", grpcConfig.serverAddress()); | ||
Assertions.assertEquals(8080, grpcConfig.port()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
simulator/src/test/java/com/hedera/block/simulator/generator/BlockStreamManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator.generator; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class BlockStreamManagerTest { | ||
|
||
@Test | ||
void getNextBlock() { | ||
BlockStreamManager blockStreamManager = new MockBlockStreamManagerImpl(); | ||
assertNotNull(blockStreamManager.getNextBlock()); | ||
} | ||
} |