gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:27:06 40 4
gpt4 key购买 nike

我对 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,我的印象是测试框架应该处理所有依赖项。我在这里缺少什么吗?

最佳答案

在 Artifact 名称中

<artifactId>spark-testing-base_2.11</artifactId>
<artifactId>spark-core_2.10</artifactId>

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

关于java - 我是否需要安装 Apache Spark 和/或 Scala 才能运行 jUnit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45374176/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com