Skip to content

Commit

Permalink
Refactored GrpcProvider dagger bean to use the interface instead of t…
Browse files Browse the repository at this point in the history
…he implementation, to be able to use Bind instead of Provide, deleted unneeded UT.

Removed @nonnull annotation from injection module, since is redundant.

Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 26, 2024
1 parent 86ac482 commit 15076c5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.helidon.webserver.WebServer;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.grpc.GrpcRouting;
import io.helidon.webserver.grpc.GrpcService;
import io.helidon.webserver.http.HttpRouting;
import java.io.IOException;
import javax.inject.Inject;
Expand All @@ -40,7 +41,7 @@ public class BlockNodeApp {

private final ServiceStatus serviceStatus;
private final HealthService healthService;
private final BlockStreamService blockStreamService;
private final GrpcService blockStreamService;
private final WebServerConfig.Builder webServerBuilder;

/**
Expand All @@ -55,7 +56,7 @@ public class BlockNodeApp {
public BlockNodeApp(
@NonNull ServiceStatus serviceStatus,
@NonNull HealthService healthService,
@NonNull BlockStreamService blockStreamService,
@NonNull GrpcService blockStreamService,
@NonNull WebServerConfig.Builder webServerBuilder) {
this.serviceStatus = serviceStatus;
this.healthService = healthService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@
package com.hedera.block.server;

import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.data.ObjectEvent;
import com.hedera.block.server.mediator.StreamMediator;
import com.hedera.block.server.metrics.MetricsService;
import com.hedera.block.server.persistence.storage.read.BlockReader;
import com.hedera.hapi.block.SubscribeStreamResponse;
import com.hedera.hapi.block.stream.Block;
import com.hedera.hapi.block.stream.BlockItem;
import com.swirlds.config.api.Configuration;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import edu.umd.cs.findbugs.annotations.NonNull;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.grpc.GrpcService;
import javax.inject.Singleton;

/**
Expand Down Expand Up @@ -66,23 +60,12 @@ static BlockNodeContext provideBlockNodeContext(
/**
* Provides a block stream service singleton using DI.
*
* @param streamMediator should come from DI
* @param blockReader should come from DI
* @param serviceStatus should come from DI
* @param blockNodeContext should come from DI
* @param blockStreamService should come from DI
* @return a block stream service singleton
*/
@Singleton
@Provides
static BlockStreamService provideBlockStreamService(
@NonNull
final StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>>
streamMediator,
@NonNull final BlockReader<Block> blockReader,
@NonNull final ServiceStatus serviceStatus,
@NonNull final BlockNodeContext blockNodeContext) {
return new BlockStreamService(streamMediator, blockReader, serviceStatus, blockNodeContext);
}
@Binds
GrpcService bindBlockStreamService(BlockStreamService blockStreamService);

/**
* Provides a web server config builder singleton using DI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.swirlds.config.api.Configuration;
import dagger.Module;
import dagger.Provides;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Singleton;

/**
Expand All @@ -41,8 +40,7 @@ public interface ConfigInjectionModule {
*/
@Singleton
@Provides
static PersistenceStorageConfig providePersistenceStorageConfig(
@NonNull Configuration configuration) {
static PersistenceStorageConfig providePersistenceStorageConfig(Configuration configuration) {
return configuration.getConfigData(PersistenceStorageConfig.class);
}

Expand All @@ -54,7 +52,7 @@ static PersistenceStorageConfig providePersistenceStorageConfig(
*/
@Singleton
@Provides
static MetricsConfig provideMetricsConfig(@NonNull Configuration configuration) {
static MetricsConfig provideMetricsConfig(Configuration configuration) {
return configuration.getConfigData(MetricsConfig.class);
}

Expand All @@ -66,7 +64,7 @@ static MetricsConfig provideMetricsConfig(@NonNull Configuration configuration)
*/
@Singleton
@Provides
static PrometheusConfig providePrometheusConfig(@NonNull Configuration configuration) {
static PrometheusConfig providePrometheusConfig(Configuration configuration) {
return configuration.getConfigData(PrometheusConfig.class);
}

Expand All @@ -78,7 +76,7 @@ static PrometheusConfig providePrometheusConfig(@NonNull Configuration configura
*/
@Singleton
@Provides
static ConsumerConfig provideConsumerConfig(@NonNull Configuration configuration) {
static ConsumerConfig provideConsumerConfig(Configuration configuration) {
return configuration.getConfigData(ConsumerConfig.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import dagger.Binds;
import dagger.Module;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Singleton;

/**
Expand All @@ -36,5 +35,5 @@ public interface HealthInjectionModule {
*/
@Singleton
@Binds
HealthService bindHealthService(@NonNull HealthServiceImpl healthService);
HealthService bindHealthService(HealthServiceImpl healthService);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.hedera.hapi.block.stream.BlockItem;
import dagger.Module;
import dagger.Provides;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import javax.inject.Singleton;

Expand All @@ -42,7 +41,7 @@ public interface PersistenceInjectionModule {
*/
@Provides
@Singleton
static BlockWriter<BlockItem> providesBlockWriter(@NonNull BlockNodeContext blockNodeContext) {
static BlockWriter<BlockItem> providesBlockWriter(BlockNodeContext blockNodeContext) {
try {
return BlockAsDirWriterBuilder.newBuilder(blockNodeContext).build();
} catch (IOException e) {
Expand All @@ -58,7 +57,7 @@ static BlockWriter<BlockItem> providesBlockWriter(@NonNull BlockNodeContext bloc
*/
@Provides
@Singleton
static BlockReader<Block> providesBlockReader(@NonNull PersistenceStorageConfig config) {
static BlockReader<Block> providesBlockReader(PersistenceStorageConfig config) {
return BlockAsDirReaderBuilder.newBuilder(config).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ void testProvideBlockNodeContext() {
blockNodeContext.metricsService(), providedBlockNodeContext.metricsService());
}

@Test
void testProvideBlockStreamService() {
BlockStreamService blockStreamService =
BlockNodeAppInjectionModule.provideBlockStreamService(
streamMediator, blockReader, serviceStatus, blockNodeContext);

Assertions.assertNotNull(blockStreamService);
}

@Test
void testProvideWebServerConfigBuilder() {
WebServerConfig.Builder webServerConfigBuilder =
Expand Down

0 comments on commit 15076c5

Please sign in to comment.