Github user tdas commented on a diff in the pull request: https://github.com/apache/spark/pull/11645#discussion_r56387171 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/state/StateStoreRDDSuite.scala --- @@ -0,0 +1,147 @@ +/* + * 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.sql.execution.streaming.state + +import java.io.File +import java.nio.file.Files + +import scala.util.Random + +import org.scalatest.{BeforeAndAfter, BeforeAndAfterAll} + +import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite} +import org.apache.spark.LocalSparkContext._ +import org.apache.spark.rdd.RDD +import org.apache.spark.scheduler.ExecutorCacheTaskLocation +import org.apache.spark.sql.catalyst.util.quietly +import org.apache.spark.util.Utils + +class StateStoreRDDSuite extends SparkFunSuite with BeforeAndAfter with BeforeAndAfterAll { + + private val conf = new SparkConf().setMaster("local").setAppName(this.getClass.getCanonicalName) + private var tempDir = Files.createTempDirectory("StateStoreRDDSuite").toString + + import StateStoreCoordinatorSuite._ + import StateStoreSuite._ + + after { + StateStore.stop() + } + + override def afterAll(): Unit = { + super.afterAll() + Utils.deleteRecursively(new File(tempDir)) + } + + test("versioning and immutability") { + quietly { + withSpark(new SparkContext(conf)) { sc => + val path = Utils.createDirectory(tempDir, Random.nextString(10)).toString + val increment = (store: StateStore, iter: Iterator[String]) => { + iter.foreach { s => + store.update( + wrapKey(s), oldRow => { + val oldValue = oldRow.map(unwrapValue).getOrElse(0) + wrapValue(oldValue + 1) + }) + } + store.commit() + store.iterator().map(unwrapKeyValue) + } + val opId = 0 + val rdd1 = makeRDD(sc, Seq("a", "b", "a")) + .withStateStores(increment, opId, storeVersion = 0, path) + assert(rdd1.collect().toSet === Set("a" -> 2, "b" -> 1)) + + // Generate next version of stores + val rdd2 = makeRDD(sc, Seq("a", "c")) + .withStateStores(increment, opId, storeVersion = 1, path) + assert(rdd2.collect().toSet === Set("a" -> 3, "b" -> 1, "c" -> 1)) + + // Make sure the previous RDD still has the same data. + assert(rdd1.collect().toSet === Set("a" -> 2, "b" -> 1)) + } + } + } + + test("recovering from files") { + quietly { + val opId = 0 + val path = Utils.createDirectory(tempDir, Random.nextString(10)).toString --- End diff -- Temp dir gets deleted when SparkContext is shutdown, so cannot be used for this test. Rather the root tempDir gets deleted after all the tests in afterAll()
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org