-
Notifications
You must be signed in to change notification settings - Fork 1
allow dropping stale messages #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
facda31
add kumulus topology changes
yoavschw 2765273
compy component changes
yoavschw 087fc98
add test
yoavschw 680af3e
update pom.xml version
yoavschw e2f6374
move monitoring to hook
yoavschw c43b7a9
Revert "move monitoring to hook"
yoavschw a646aa4
Revert "Revert "move monitoring to hook""
yoavschw 45bf806
update test
yoavschw e6051f7
clean
yoavschw 90fabbe
whitespace
yoavschw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
124 changes: 124 additions & 0 deletions
124
src/test/kotlin/org/xyro/kumulus/TestDroppingStaleMessages.kt
This file contains hidden or 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,124 @@ | ||
| package org.xyro.kumulus | ||
|
|
||
| import mu.KotlinLogging | ||
| import org.apache.storm.Config | ||
| import org.apache.storm.spout.SpoutOutputCollector | ||
| import org.apache.storm.task.OutputCollector | ||
| import org.apache.storm.task.TopologyContext | ||
| import org.apache.storm.topology.BasicOutputCollector | ||
| import org.apache.storm.topology.IRichBolt | ||
| import org.apache.storm.topology.OutputFieldsDeclarer | ||
| import org.apache.storm.tuple.Fields | ||
| import org.apache.storm.tuple.Tuple | ||
| import org.junit.Test | ||
| import java.util.concurrent.TimeUnit | ||
| import java.util.concurrent.atomic.AtomicLong | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class TestDroppingStaleMessages { | ||
| @Test | ||
| fun testLateBolt() { | ||
| val builder = org.apache.storm.topology.TopologyBuilder() | ||
| val config: MutableMap<String, Any> = mutableMapOf() | ||
| config[Config.TOPOLOGY_MAX_SPOUT_PENDING] = 1L | ||
| config[KumulusTopology.CONF_THREAD_POOL_CORE_SIZE] = 5L | ||
| config[KumulusTopology.CONF_LATE_MESSAGES_DROPPING_SHOULD_DROP] = true; | ||
| config[KumulusTopology.CONF_LATE_MESSAGES_DROPPING_STREAMS_NAME] = setOf("default"); | ||
| config[KumulusTopology.CONF_LATE_MESSAGES_DROPPING_MAX_WAIT_SECONDS] = 1; | ||
|
|
||
| builder.setSpout("spout", LatencyDeltaSpout()) | ||
|
|
||
| builder.setBolt("unanchoring-bolt", UnanchoringBolt()) | ||
| .noneGrouping("spout") | ||
|
|
||
| builder.setBolt("delay-unanchored-bolt", StuckBolt()) | ||
| .noneGrouping("unanchoring-bolt") | ||
|
|
||
|
|
||
| val stormTopology = builder.createTopology()!! | ||
| val kumulusTopology = | ||
| KumulusStormTransformer.initializeTopology(stormTopology, config, "test") | ||
|
|
||
| var lateHookCalled = false | ||
|
|
||
| kumulusTopology.onLateMessageHook = { _, _, _, _ -> | ||
| lateHookCalled = true | ||
| } | ||
|
|
||
| kumulusTopology.prepare(10, TimeUnit.SECONDS) | ||
| kumulusTopology.start(block = false) | ||
| Thread.sleep(5000) | ||
| kumulusTopology.stop() | ||
|
|
||
| logger.info { "Dropped ${lateHookCalled} messages" } | ||
| assertTrue { lateHookCalled} | ||
| } | ||
|
|
||
| class LatencyDeltaSpout : DummySpout({ | ||
| it.declare(Fields("id")) | ||
| }) { | ||
| private var index: Int = 0 | ||
| private var lastCall: Long? = 0 | ||
|
|
||
| override fun open(conf: MutableMap<Any?, Any?>?, context: TopologyContext?, collector: SpoutOutputCollector?) { | ||
| super.open(conf, context, collector) | ||
| this.index = 0 | ||
| this.lastCall = null | ||
| } | ||
|
|
||
| override fun nextTuple() { | ||
| val now = System.nanoTime() | ||
| if (this.lastCall != null) { | ||
| val tookMillis = TimeUnit.NANOSECONDS.toMillis(now - this.lastCall!!) | ||
| sumWait.addAndGet(tookMillis) | ||
| if (tookMillis > 100) { | ||
| logger.error { "Took $tookMillis to nextTuple" } | ||
| } | ||
| calledCount.incrementAndGet() | ||
| } | ||
| this.lastCall = now | ||
| val messageId = ++index | ||
| collector.emit(listOf(messageId), messageId) | ||
| } | ||
| } | ||
|
|
||
| class UnanchoringBolt : IRichBolt { | ||
| private lateinit var collector: OutputCollector | ||
|
|
||
| override fun execute(input: Tuple) { | ||
| collector.emit(input.values) | ||
| collector.ack(input) | ||
| } | ||
|
|
||
| override fun prepare(p0: MutableMap<Any?, Any?>?, p1: TopologyContext?, p2: OutputCollector?) { | ||
| this.collector = p2!! | ||
| } | ||
|
|
||
| override fun cleanup() = Unit | ||
|
|
||
| override fun getComponentConfiguration(): MutableMap<String, Any> { | ||
| return mutableMapOf() | ||
| } | ||
|
|
||
| override fun declareOutputFields(p0: OutputFieldsDeclarer) { | ||
| p0.declare(Fields("id")) | ||
| } | ||
| } | ||
|
|
||
| class StuckBolt : DummyBolt({ | ||
| it.declare(Fields("id")) | ||
| }) { | ||
| override fun execute(input: Tuple, collector: BasicOutputCollector) { | ||
| logger.info { "StuckBolt: started" } | ||
| while (true){ | ||
| Thread.sleep(50) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private val logger = KotlinLogging.logger {} | ||
| private val sumWait = AtomicLong(0) | ||
| private val calledCount = AtomicLong(0) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.