Skip to content

Commit

Permalink
fix: Adjusted the mediator dagger interface to correctly return singl…
Browse files Browse the repository at this point in the history
…etons

Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Sep 19, 2024
1 parent dd5fa4b commit ccd7717
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.hedera.block.server.notifier.Notifiable;
import com.hedera.block.server.service.ServiceStatus;
import com.hedera.hapi.block.SubscribeStreamResponse;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -44,32 +45,23 @@ static LiveStreamMediator providesLiveStreamMediator(
}

/**
* Provides the subscription handler.
* Binds the subscription handler to the live stream mediator.
*
* @param blockNodeContext the block node context
* @param serviceStatus the service status
* @param liveStreamMediator the live stream mediator
* @return the subscription handler
*/
@Provides
@Binds
@Singleton
static SubscriptionHandler<SubscribeStreamResponse> provideSubscriptionHandler(
@NonNull final BlockNodeContext blockNodeContext,
@NonNull final ServiceStatus serviceStatus) {
return LiveStreamMediatorBuilder.newBuilder(blockNodeContext, serviceStatus).build();
}
SubscriptionHandler<SubscribeStreamResponse> bindSubscriptionHandler(
@NonNull final LiveStreamMediator liveStreamMediator);

/**
* Provides the mediator as a Notifiable instance.
* Binds the mediator to the notifiable interface.
*
* @param blockNodeContext the block node context
* @param serviceStatus the service status
* @return the mediator as a Notifiable instance
* @param liveStreamMediator the live stream mediator
* @return the notifiable interface
*/
@Provides
@Binds
@Singleton
static Notifiable provideMediator(
@NonNull final BlockNodeContext blockNodeContext,
@NonNull final ServiceStatus serviceStatus) {
return LiveStreamMediatorBuilder.newBuilder(blockNodeContext, serviceStatus).build();
}
Notifiable bindMediator(@NonNull final LiveStreamMediator liveStreamMediator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.notifier.Notifiable;
import com.hedera.block.server.service.ServiceStatus;
import com.hedera.block.server.util.TestConfigUtil;
import com.hedera.hapi.block.SubscribeStreamResponse;
Expand Down Expand Up @@ -53,30 +52,4 @@ void testProvidesStreamMediator() throws IOException {
// Verify that the streamMediator is correctly instantiated
assertNotNull(streamMediator);
}

@Test
void testProvidesSubscriptionHandler() throws IOException {

BlockNodeContext blockNodeContext = TestConfigUtil.getTestBlockNodeContext();

// Call the method under test
SubscriptionHandler<SubscribeStreamResponse> subscriptionHandler =
MediatorInjectionModule.provideSubscriptionHandler(blockNodeContext, serviceStatus);

// Verify that the subscriptionHandler is correctly instantiated
assertNotNull(subscriptionHandler);
}

@Test
void testProvidesMediator() throws IOException {

BlockNodeContext blockNodeContext = TestConfigUtil.getTestBlockNodeContext();

// Call the method under test
Notifiable mediator =
MediatorInjectionModule.provideMediator(blockNodeContext, serviceStatus);

// Verify that the mediator is correctly instantiated
assertNotNull(mediator);
}
}

0 comments on commit ccd7717

Please sign in to comment.