Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minor][DOC] Fix nits in JavaStreamingTestExample #11821

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
* batches processed exceeds `numBatchesTimeout`.
*/
public class JavaStreamingTestExample {

private static int timeoutCounter = 0;

public static void main(String[] args) {
if (args.length != 3) {
System.err.println("Usage: JavaStreamingTestExample " +
Expand All @@ -76,7 +79,7 @@ public static void main(String[] args) {
JavaDStream<BinarySample> data = ssc.textFileStream(dataDir).map(
new Function<String, BinarySample>() {
@Override
public BinarySample call(String line) throws Exception {
public BinarySample call(String line) {
String[] ts = line.split(",");
boolean label = Boolean.valueOf(ts[0]);
double value = Double.valueOf(ts[1]);
Expand All @@ -94,22 +97,21 @@ public BinarySample call(String line) throws Exception {
// $example off$

// Stop processing if test becomes significant or we time out
final Accumulator<Integer> timeoutCounter =
ssc.sparkContext().accumulator(numBatchesTimeout);
timeoutCounter = numBatchesTimeout;

out.foreachRDD(new VoidFunction<JavaRDD<StreamingTestResult>>() {
@Override
public void call(JavaRDD<StreamingTestResult> rdd) throws Exception {
timeoutCounter.add(-1);
public void call(JavaRDD<StreamingTestResult> rdd) {
timeoutCounter -= 1;

long cntSignificant = rdd.filter(new Function<StreamingTestResult, Boolean>() {
boolean anySignificant = !rdd.filter(new Function<StreamingTestResult, Boolean>() {
@Override
public Boolean call(StreamingTestResult v) throws Exception {
public Boolean call(StreamingTestResult v) {
return v.pValue() < 0.05;
}
}).count();
}).isEmpty();

if (timeoutCounter.value() <= 0 || cntSignificant > 0) {
if (timeoutCounter <= 0 || anySignificant) {
rdd.context().stop();
}
}
Expand Down