Skip to content

Commit

Permalink
Add ResetSystemProperties test fixture mixin; use it in SparkSubmitSu…
Browse files Browse the repository at this point in the history
…ite.
  • Loading branch information
JoshRosen committed Dec 19, 2014
1 parent 4dcea38 commit 9e3e0dd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import scala.collection.mutable.ArrayBuffer

import org.apache.spark._
import org.apache.spark.deploy.SparkSubmit._
import org.apache.spark.util.Utils
import org.apache.spark.util.{ResetSystemProperties, Utils}
import org.scalatest.FunSuite
import org.scalatest.Matchers

class SparkSubmitSuite extends FunSuite with Matchers {
class SparkSubmitSuite extends FunSuite with Matchers with ResetSystemProperties {
def beforeAll() {
System.setProperty("spark.testing", "true")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.util

import java.util.Properties

import org.scalatest.{Suite, SuiteMixin}


/**
* Mixin for automatically resetting system properties that are modified in ScalaTest tests.
* This resets the properties after each individual test.
*
* See the "Composing fixtures by stacking traits" section at
* http://www.scalatest.org/user_guide/sharing_fixtures for more details about this pattern.
*/
private[spark] trait ResetSystemProperties extends SuiteMixin { this: Suite =>
abstract override def withFixture(test: NoArgTest) = {
val oldProperties = new Properties(System.getProperties)
try {
super.withFixture(test)
} finally {
System.setProperties(oldProperties)
}
}
}

0 comments on commit 9e3e0dd

Please sign in to comment.