You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@texera.apache.org by gi...@apache.org on 2026/07/03 04:35:05 UTC
(texera) branch main updated: test(workflow-operator): cover User-Agent header in URLFetchUtilSpec (#5710)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/main by this push:
new a53d95a9a3 test(workflow-operator): cover User-Agent header in URLFetchUtilSpec (#5710)
a53d95a9a3 is described below
commit a53d95a9a32dd38815dcfc3e75f4157a45a2997b
Author: Justin Siek <13...@users.noreply.github.com>
AuthorDate: Fri Jul 3 12:25:36 2026 +0800
test(workflow-operator): cover User-Agent header in URLFetchUtilSpec (#5710)
### What changes were proposed in this PR?
Adds `URLFetchUtilSpec`, a unit test for
`URLFetchUtil.getInputStreamFromURL`. A stub `URLStreamHandler` scripts
per attempt success/failure, so nothing hits the network. No production
code changed.
### Any related issues, documentation, discussions?
Closes #5661
### How was this PR tested?
No production code changed, just new unit tests for existing code.
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)
Co-authored-by: Justin Siek <ju...@Justins-MacBook-Air.local>
Co-authored-by: Meng Wang <me...@uci.edu>
---
.../operator/source/fetcher/URLFetchUtilSpec.scala | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/fetcher/URLFetchUtilSpec.scala b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/fetcher/URLFetchUtilSpec.scala
index a64d21cc3f..ec16567970 100644
--- a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/fetcher/URLFetchUtilSpec.scala
+++ b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/fetcher/URLFetchUtilSpec.scala
@@ -55,11 +55,15 @@ class URLFetchUtilSpec extends AnyFlatSpec {
private class CountingStreamHandler(succeedWithBytes: Option[Array[Byte]])
extends URLStreamHandler {
val openConnectionCount = new AtomicInteger(0)
+ // Captures the most recent User-Agent request property set on a connection.
+ var userAgent: Option[String] = None
override def openConnection(u: URL): URLConnection = {
openConnectionCount.incrementAndGet()
new URLConnection(u) {
override def connect(): Unit = ()
+ override def setRequestProperty(key: String, value: String): Unit =
+ if (key == "User-Agent") userAgent = Some(value)
override def getInputStream: InputStream =
succeedWithBytes match {
case Some(bytes) => new ByteArrayInputStream(bytes)
@@ -135,4 +139,17 @@ class URLFetchUtilSpec extends AnyFlatSpec {
assert(result.isEmpty)
assert(handler.openConnectionCount.get() == 2)
}
+
+ // ---------------------------------------------------------------------------
+ // Request headers
+ // ---------------------------------------------------------------------------
+
+ it should "set a User-Agent request property before reading the stream" in {
+ val handler =
+ new CountingStreamHandler(Some("ok".getBytes(StandardCharsets.UTF_8)))
+ val result = URLFetchUtil.getInputStreamFromURL(countingUrl(handler))
+ result.foreach(_.close())
+ // Pin only that the header is set, not its specific (randomized) value.
+ assert(handler.userAgent.isDefined)
+ }
}