我是否需要安装Apache Spark和/或Scala才能运行jUnit?

时间:2017-07-28 12:56:42

标签: java maven apache-spark junit

我是Apache Spark框架的新手,尝试设置我的第一个jUnit,如下所示:

package com.sample.ccspark;

import com.holdenkarau.spark.testing.SharedJavaSparkContext;
import org.apache.spark.api.java.JavaRDD;
import org.junit.Test;

import java.util.List;

import static java.util.Arrays.asList;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class SimpleTest extends SharedJavaSparkContext {

    @Test
    public void initializationWorks()  {
        List<Integer> list = asList(1, 2, 3, 4);
        JavaRDD<Integer> rdd = jsc().parallelize(list);
        assertThat(rdd.count(), is(list.size()));
    }
}

在pom.xml中具有以下依赖项

    <dependency>
        <groupId>com.holdenkarau</groupId>
        <artifactId>spark-testing-base_2.11</artifactId>
        <version>2.2.0_0.7.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.10</artifactId>
        <version>2.2.0</version>
    </dependency>

一切都很愉快地编译,但是在运行时我得到以下异常:

Exception in thread "dispatcher-event-loop-6" java.lang.NoClassDefFoundError: 
scala/runtime/AbstractPartialFunction$mcVL$sp

我还没有在本地安装Spark或Scala,但是我觉得测试框架应该处理所有依赖项。我在这里缺少什么吗?

1 个答案:

答案 0 :(得分:2)

在文物名称中 auto_key0

最后一个数字是Scala的版本。我想你应该只为这两种情况选择一种。