-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
9 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
57 changes: 57 additions & 0 deletions
57
src/test/scala/org/apache/spark/sql/pulsar/PulsarAdmissionControlSuite.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,57 @@ | ||
package org.apache.spark.sql.pulsar | ||
|
||
import org.apache.pulsar.client.admin.PulsarAdmin | ||
import org.apache.spark.sql.streaming.Trigger.{Once, ProcessingTime} | ||
import org.apache.spark.util.Utils | ||
|
||
class PulsarAdmissionControlSuite extends PulsarSourceTest { | ||
|
||
import PulsarOptions._ | ||
import testImplicits._ | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
} | ||
|
||
/** | ||
* Write unit test to create limits, can construct fake ledger statistics | ||
* Can call latestOffset() directly from the unit test | ||
* | ||
* Just need to verify that each microbatch is <= maxBytesPerTrigger (within some threshold) | ||
* Can send message of specific size in AddPulsarData here | ||
*/ | ||
|
||
test("Admission Control") { | ||
val topic = newTopic() | ||
sendMessages(topic, Array("-1")) | ||
require(getLatestOffsets(Set(topic)).size === 1) | ||
sparkContext.setLogLevel("INFO") | ||
val pulsar = spark.readStream | ||
.format("pulsar") | ||
.option(TopicSingle, topic) | ||
.option(ServiceUrlOptionKey, serviceUrl) | ||
.option(AdminUrlOptionKey, adminUrl) | ||
.option(MaxBytesPerTrigger, 120) | ||
.load() | ||
.selectExpr("CAST(__key AS STRING)", "CAST(value AS STRING)") | ||
.as[(String, String)] | ||
|
||
val mapped = pulsar.map(kv => kv._2.toInt + 1) | ||
|
||
// Each Int adds 38 bytes to message size, so we expect 3 Ints in each message | ||
testStream(mapped)( | ||
StartStream(trigger = ProcessingTime(100)), | ||
makeSureGetOffsetCalled, | ||
AddPulsarData(Set(topic), 1, 2, 3), | ||
CheckLastBatch(2, 3, 4), | ||
AddPulsarData(Set(topic), 4, 5, 6, 7, 8, 9), | ||
CheckLastBatch(8, 9, 10), | ||
AssertOnQuery { query => | ||
val recordsRead = query.recentProgress.map(_.numInputRows).sum | ||
recordsRead == 9 | ||
} | ||
) | ||
|
||
} | ||
|
||
} |