Skip to content

Commit

Permalink
chore: Proto ByteString in EventingTestKit.IncomingMessages.publish (#97
Browse files Browse the repository at this point in the history
)
  • Loading branch information
patriknw authored Dec 16, 2024
1 parent 4365544 commit 486b22e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,39 @@ interface IncomingMessages {
/**
* Simulate the publishing of a raw message.
*
* @param message raw bytestring to be published
* @param message raw protobuf bytestring to be published
*
* @deprecated Use publish with byte array parameter
*/
@Deprecated
void publish(ByteString message);

/**
* Simulate the publishing of a raw message.
*
* @param message raw bytestring to be published
* @param message raw protobuf bytestring to be published
* @param metadata associated with the message
*
* @deprecated Use publish with byte array parameter
*/
@Deprecated
void publish(ByteString message, Metadata metadata);

/**
* Simulate the publishing of a raw message.
*
* @param message raw byte array to be published
*/
void publish(byte[] message);

/**
* Simulate the publishing of a raw message.
*
* @param message raw byte array to be published
* @param metadata associated with the message
*/
void publish(byte[] message, Metadata metadata);

/**
* Simulate the publishing of a message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ private[testkit] class IncomingMessagesImpl(val sourcesHolder: ActorRef, val ser
Await.result(addSource, 5.seconds)
}

override def publish(message: Array[Byte]): Unit =
publish(message, SdkMetadata.EMPTY)

override def publish(message: Array[Byte], metadata: SdkMetadata): Unit = {
val addSource = sourcesHolder.ask(SourcesHolder.Publish(ByteString.copyFrom(message), metadata))(5.seconds)
Await.result(addSource, 5.seconds)
}

override def publish(message: TestKitMessage[_]): Unit = message.getPayload match {
case javaPb: GeneratedMessageV3 => publish(javaPb.toByteString, message.getMetadata)
case scalaPb: GeneratedMessage => publish(scalaPb.toByteString, message.getMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import scala.collection.mutable.ArrayBuffer

object SourcesHolder {

case class AddSource(runningSourceProbe: RunningSourceProbe)
case class Publish(message: ByteString, metadata: SdkMetadata)
final case class AddSource(runningSourceProbe: RunningSourceProbe)
final case class Publish(message: ByteString, metadata: SdkMetadata)
}

class SourcesHolder extends Actor {
Expand Down

0 comments on commit 486b22e

Please sign in to comment.