Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/9143#discussion_r44240691
--- Diff:
streaming/src/test/scala/org/apache/spark/streaming/util/WriteAheadLogUtilsSuite.scala
---
@@ -0,0 +1,286 @@
+/*
+ * 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.streaming.util
+
+import java.io.EOFException
+import java.nio.ByteBuffer
+import java.util
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable.ArrayBuffer
+import scala.language.{implicitConversions, postfixOps}
+import scala.reflect.ClassTag
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.Path
+import org.scalatest.PrivateMethodTester
+
+import org.apache.spark.{SparkException, SparkConf, SparkFunSuite}
+import org.apache.spark.util.{ManualClock, Utils}
+
+class WriteAheadLogUtilsSuite extends SparkFunSuite {
+ import WriteAheadLogSuite._
+
+ private val logDir = Utils.createTempDir().getAbsolutePath()
+ private val hadoopConf = new Configuration()
+
+ def assertDriverLogClass[T <: WriteAheadLog: ClassTag](
+ conf: SparkConf,
+ isBatched: Boolean = false): WriteAheadLog = {
+ val log = WriteAheadLogUtils.createLogForDriver(conf, logDir,
hadoopConf)
+ if (isBatched) {
+ assert(log.isInstanceOf[BatchedWriteAheadLog])
+ val parentLog = log.asInstanceOf[BatchedWriteAheadLog].wrappedLog
+ assert(parentLog.getClass === implicitly[ClassTag[T]].runtimeClass)
+ } else {
+ assert(log.getClass === implicitly[ClassTag[T]].runtimeClass)
+ }
+ log
+ }
+
+ def assertReceiverLogClass[T <: WriteAheadLog: ClassTag](conf:
SparkConf): WriteAheadLog = {
+ val log = WriteAheadLogUtils.createLogForReceiver(conf, logDir,
hadoopConf)
+ assert(log.getClass === implicitly[ClassTag[T]].runtimeClass)
+ log
+ }
+
+ test("log selection and creation") {
+
+ val emptyConf = new SparkConf() // no log configuration
+ assertDriverLogClass[FileBasedWriteAheadLog](emptyConf)
+ assertReceiverLogClass[FileBasedWriteAheadLog](emptyConf)
+
+ // Verify setting driver WAL class
+ val driverWALConf = new
SparkConf().set("spark.streaming.driver.writeAheadLog.class",
+ classOf[MockWriteAheadLog0].getName())
+ assertDriverLogClass[MockWriteAheadLog0](driverWALConf)
+ assertReceiverLogClass[FileBasedWriteAheadLog](driverWALConf)
+
+ // Verify setting receiver WAL class
+ val receiverWALConf = new
SparkConf().set("spark.streaming.receiver.writeAheadLog.class",
+ classOf[MockWriteAheadLog0].getName())
+ assertDriverLogClass[FileBasedWriteAheadLog](receiverWALConf)
+ assertReceiverLogClass[MockWriteAheadLog0](receiverWALConf)
+
+ // Verify setting receiver WAL class with 1-arg constructor
+ val receiverWALConf2 = new
SparkConf().set("spark.streaming.receiver.writeAheadLog.class",
+ classOf[MockWriteAheadLog1].getName())
+ assertReceiverLogClass[MockWriteAheadLog1](receiverWALConf2)
+
+ // Verify failure setting receiver WAL class with 2-arg constructor
+ intercept[SparkException] {
+ val receiverWALConf3 = new
SparkConf().set("spark.streaming.receiver.writeAheadLog.class",
+ classOf[MockWriteAheadLog2].getName())
+ assertReceiverLogClass[MockWriteAheadLog1](receiverWALConf3)
+ }
+ }
+
+ test("wrap WriteAheadLog in BatchedWriteAheadLog when batching is
enabled") {
+ def getBatchedSparkConf: SparkConf =
+ new
SparkConf().set("spark.streaming.driver.writeAheadLog.allowBatching", "true")
+
+ val justBatchingConf = getBatchedSparkConf
+ assertDriverLogClass[FileBasedWriteAheadLog](justBatchingConf,
isBatched = true)
+ assertReceiverLogClass[FileBasedWriteAheadLog](justBatchingConf)
+
+ // Verify setting driver WAL class
+ val driverWALConf =
getBatchedSparkConf.set("spark.streaming.driver.writeAheadLog.class",
+ classOf[MockWriteAheadLog0].getName())
+ assertDriverLogClass[MockWriteAheadLog0](driverWALConf, isBatched =
true)
+ assertReceiverLogClass[FileBasedWriteAheadLog](driverWALConf)
+
+ // Verify receivers are not wrapped
+ val receiverWALConf =
getBatchedSparkConf.set("spark.streaming.receiver.writeAheadLog.class",
+ classOf[MockWriteAheadLog0].getName())
+ assertDriverLogClass[FileBasedWriteAheadLog](receiverWALConf,
isBatched = true)
+ assertReceiverLogClass[MockWriteAheadLog0](receiverWALConf)
+ }
+}
+
+object WriteAheadLogSuite {
--- End diff --
Why is WriteAheadLogSuite in the file WriteAheadLogUtilsSuite. Should be in
the file WriteAheadLogSuite. Only the stuff needed by the class
WriteAheadLogUtilsSuite (like the MockWAL classes) should be in the
WriteAheadLogSuite object.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]