Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pipeline/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ plugins {
}

tasks.withType<JavaExec> {
jvmArgs = listOf("--add-exports=java.base/sun.nio.ch=ALL-UNNAMED")
if (JavaVersion.current().isJava9Compatible) {
jvmArgs = listOf("--add-exports=java.base/sun.nio.ch=ALL-UNNAMED")
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kakao.actionbase.pipeline

import org.apache.spark.sql.SparkSession

/**
* Mix-in for unit tests that need an `implicit SparkSession`. The session is `local[2]` and shared across all
* `SparkTest` mixers in the JVM (Spark's own `getOrCreate` semantics).
*/
trait SparkTest {

protected implicit lazy val spark: SparkSession = SparkSession
.builder()
.master("local[2]")
.config("spark.driver.bindAddress", "127.0.0.1")
.config("spark.ui.enabled", "false")
.appName(getClass.getSimpleName)
.getOrCreate()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.kakao.actionbase.pipeline.app

import com.kakao.actionbase.pipeline.SparkTest
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class SparkPiDemoTest extends SparkTest {

@Test
def testEstimatePiIsCloseToPi(): Unit = {
val pi = SparkPiDemo.estimatePi(spark, slices = 2)
assertTrue(pi > 3.0 && pi < 3.3, s"Estimated Pi=$pi out of expected range [3.0, 3.3]")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kakao.actionbase.pipeline.app

import org.apache.spark.sql.SparkSession

/** Minimal standalone Spark entry point — useful for ad-hoc exploration in an IDE.
*
* Unlike `SparkPiDemo` (which goes through `AbstractPipelineApplication`), this object builds the `SparkSession`
* directly so the full boilerplate is visible.
*/
object SparkPiMain {

def main(args: Array[String]): Unit = {
val spark = SparkSession
.builder()
.master("local[2]")
.config("spark.ui.enabled", "false")
.appName("SparkPiMain")
.getOrCreate()

try {
val pi = SparkPiDemo.estimatePi(spark, slices = 2)
println(s"Pi is roughly $pi")
} finally {
spark.stop()
}
}
}
Loading