Skip to content

Commit

Permalink
fix:fixed unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Jul 29, 2024
1 parent bf9c3da commit 0fed3db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 9 additions & 3 deletions server/src/main/java/com/hedera/block/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public static void main(final String[] args) {
Config.global(config);

try {
final ServiceStatus serviceStatus = new ServiceStatusImpl();
final StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>> streamMediator =
buildStreamMediator(config);
buildStreamMediator(config, serviceStatus);
final BlockStreamService blockStreamService =
buildBlockStreamService(config, streamMediator);
final GrpcRouting.Builder grpcRouting = buildGrpcRouting(blockStreamService);
Expand All @@ -74,6 +75,10 @@ public static void main(final String[] args) {

blockStreamService.register(webServer);

serviceStatus.setWebServer(webServer);
streamMediator.register(serviceStatus);


// Start the web server
webServer.start();
} catch (IOException e) {
Expand All @@ -82,12 +87,13 @@ public static void main(final String[] args) {
}

private static StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>>
buildStreamMediator(final Config config) throws IOException {
buildStreamMediator(final Config config, final ServiceStatus serviceStatus) throws IOException {
return new LiveStreamMediatorImpl(
new ConcurrentHashMap<>(32),
new FileSystemPersistenceHandler(
new BlockAsDirReader(BLOCKNODE_STORAGE_ROOT_PATH_KEY, config),
new BlockAsDirWriter(BLOCKNODE_STORAGE_ROOT_PATH_KEY, config)));
new BlockAsDirWriter(BLOCKNODE_STORAGE_ROOT_PATH_KEY, config)),
serviceStatus);
}

private static GrpcRouting.Builder buildGrpcRouting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hedera.block.server.mediator;

import com.hedera.block.server.ServiceStatus;
import com.hedera.block.server.ServiceStatusImpl;
import com.hedera.block.server.consumer.BlockItemEventHandler;
import com.hedera.block.server.data.ObjectEvent;
import com.hedera.block.server.persistence.BlockPersistenceHandler;
Expand Down Expand Up @@ -67,7 +68,8 @@ public LiveStreamMediatorImpl(
BlockItemEventHandler<ObjectEvent<SubscribeStreamResponse>>,
BatchEventProcessor<ObjectEvent<SubscribeStreamResponse>>>
subscribers,
final BlockPersistenceHandler<BlockItem, Block> blockPersistenceHandler) {
final BlockPersistenceHandler<BlockItem, Block> blockPersistenceHandler,
final ServiceStatus serviceStatus) {

this.subscribers = subscribers;
this.blockPersistenceHandler = blockPersistenceHandler;
Expand All @@ -77,11 +79,12 @@ public LiveStreamMediatorImpl(
new Disruptor<>(ObjectEvent::new, 1024, DaemonThreadFactory.INSTANCE);
this.ringBuffer = disruptor.start();
this.executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE);
this.serviceStatus = serviceStatus;
}

public LiveStreamMediatorImpl(
final BlockPersistenceHandler<BlockItem, Block> blockPersistenceHandler) {
this(new ConcurrentHashMap<>(), blockPersistenceHandler);
this(new ConcurrentHashMap<>(), blockPersistenceHandler, new ServiceStatusImpl());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ public void testPublishBlockStreamRegistrationAndExecution()

@Test
public void testSubscribeBlockStream() throws InterruptedException {

final ServiceStatus serviceStatus = new ServiceStatusImpl();
serviceStatus.setWebServer(webServer);

final var streamMediator =
new LiveStreamMediatorImpl(
new HashMap<>(),
new FileSystemPersistenceHandler(blockReader, blockWriter));
new FileSystemPersistenceHandler(blockReader, blockWriter),
serviceStatus);

// Build the BlockStreamService
final BlockStreamService blockStreamService =
Expand Down Expand Up @@ -520,8 +525,12 @@ private StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>> buildStr
new BlockAsDirReader(JUNIT, testConfig, blockRemover, filePerms);
final BlockWriter<BlockItem> blockWriter =
new BlockAsDirWriter(JUNIT, testConfig, blockRemover, filePerms);

final ServiceStatus serviceStatus = new ServiceStatusImpl();
serviceStatus.setWebServer(webServer);
return new LiveStreamMediatorImpl(
subscribers, new FileSystemPersistenceHandler(blockReader, blockWriter));
subscribers, new FileSystemPersistenceHandler(blockReader, blockWriter),
serviceStatus);
}

private BlockStreamService buildBlockStreamService() throws IOException {
Expand Down

0 comments on commit 0fed3db

Please sign in to comment.