-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: eventing testkit - supporting multiple subscription to the same …
…topic
- Loading branch information
Showing
5 changed files
with
147 additions
and
46 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
66 changes: 66 additions & 0 deletions
66
sdk/java-sdk-protobuf-testkit/src/main/scala/kalix/javasdk/testkit/impl/SourcesHolder.scala
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 2021 Lightbend Inc. | ||
* | ||
* 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 kalix.javasdk.testkit.impl | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
import akka.actor.Actor | ||
import akka.event.Logging | ||
import com.google.protobuf.ByteString | ||
import kalix.javasdk.testkit.KalixTestKit | ||
import kalix.javasdk.testkit.impl.EventingTestKitImpl.RunningSourceProbe | ||
import kalix.javasdk.testkit.impl.SourcesHolder.AddSource | ||
import kalix.javasdk.testkit.impl.SourcesHolder.Publish | ||
import kalix.javasdk.{ Metadata => SdkMetadata } | ||
import org.slf4j.LoggerFactory | ||
|
||
object SourcesHolder { | ||
|
||
case class AddSource(runningSourceProbe: RunningSourceProbe) | ||
case class Publish(message: ByteString, metadata: SdkMetadata) | ||
} | ||
|
||
class SourcesHolder extends Actor { | ||
|
||
private val log = LoggerFactory.getLogger(classOf[KalixTestKit]) | ||
|
||
private val sources: ArrayBuffer[RunningSourceProbe] = ArrayBuffer.empty | ||
private val publishedMessages: ArrayBuffer[PublishedMessage] = ArrayBuffer.empty | ||
|
||
private case class PublishedMessage(message: ByteString, metadata: SdkMetadata) | ||
|
||
override def receive: Receive = { | ||
case AddSource(runningSourceProbe) => | ||
if (publishedMessages.nonEmpty) { | ||
log.debug( | ||
s"Emitting ${publishedMessages.size} messages to the new source from [${runningSourceProbe.serviceName}]") | ||
publishedMessages.foreach { msg => | ||
runningSourceProbe.emit(msg.message, msg.metadata) | ||
} | ||
} | ||
sources.addOne(runningSourceProbe) | ||
log.debug(s"Source from [${runningSourceProbe.serviceName}] added") | ||
sender() ! "ok" | ||
case Publish(message, metadata) => | ||
sources.foreach { source => | ||
log.debug(s"Emitting message to the source from [${source.serviceName}]") | ||
source.emit(message, metadata) | ||
} | ||
publishedMessages.addOne(PublishedMessage(message, metadata)) | ||
sender() ! "ok" | ||
} | ||
} |
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
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