jerrypeng commented on code in PR #56196:
URL: https://github.com/apache/spark/pull/56196#discussion_r3360703727


##########
core/src/test/scala/org/apache/spark/shuffle/streaming/StreamingShuffleManagerSuite.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.spark.shuffle.streaming
+
+import io.netty.buffer.Unpooled
+import org.mockito.Mockito.when
+import org.scalatest.matchers.should.Matchers
+import org.scalatestplus.mockito.MockitoSugar
+
+import org.apache.spark._
+import org.apache.spark.LocalSparkContext.withSpark
+import org.apache.spark.internal.config.SHUFFLE_MANAGER
+import org.apache.spark.network.shuffle.streaming.{DataMessage, 
TerminationAckMessage, TerminationControlMessage}
+import org.apache.spark.shuffle.sort.SortShuffleManager
+import org.apache.spark.shuffle.streaming.StreamingShuffleManager.{getQueryId, 
getWriterId, QUERY_ID_PROPERTY_KEY}
+
+class StreamingShuffleManagerSuite
+  extends SparkFunSuite
+  with LocalSparkContext
+  with Matchers
+  with MockitoSugar {
+
+  private val SQL_EXECUTION_ID_KEY = "spark.sql.execution.id"
+
+  // ---- getWriterId ----
+
+  test("getWriterId returns the writer id for a data message") {
+    val msg = new DataMessage(7, 3, 0, Unpooled.EMPTY_BUFFER, 0L)
+    getWriterId(msg) should be(7)
+  }
+
+  test("getWriterId returns the writer id for a termination control message") {
+    getWriterId(new TerminationControlMessage(5, 2)) should be(5)
+  }
+
+  test("getWriterId throws on an unexpected message type") {
+    val e = intercept[SparkRuntimeException] {
+      getWriterId(new TerminationAckMessage(1, 1))
+    }
+    checkError(
+      e,
+      condition = "STREAMING_SHUFFLE_UNEXPECTED_MESSAGE_TYPE",
+      parameters = Map("messageType" -> "TERMINATION_ACK_MESSAGE"))
+  }
+
+  // ---- getQueryId ----
+
+  test("getQueryId returns the streaming query id when set") {
+    val context = mock[TaskContext]
+    
when(context.getLocalProperty(QUERY_ID_PROPERTY_KEY)).thenReturn("query-123")
+    getQueryId(context) should be("query-123")
+  }
+
+  test("getQueryId falls back to the SQL execution id for batch queries") {
+    val context = mock[TaskContext]
+    when(context.getLocalProperty(SQL_EXECUTION_ID_KEY)).thenReturn("42")
+    getQueryId(context) should be("42")
+  }
+
+  test("getQueryId throws when no query id property is set") {
+    val context = mock[TaskContext]
+    intercept[SparkException] {

Review Comment:
   Done — now asserting the exact error with checkError (INTERNAL_ERROR + the 
message).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to