Skip to content

Commit

Permalink
Fix NPE in BenchmarkQueryResult
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Apr 21, 2015
1 parent 1cd360d commit 6918b42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Expand Up @@ -16,7 +16,10 @@
import com.google.common.base.MoreObjects;
import io.airlift.units.Duration;

import java.util.Optional;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

public class BenchmarkQueryResult
Expand All @@ -35,13 +38,13 @@ public static BenchmarkQueryResult passResult(Suite suite, BenchmarkQuery benchm

public static BenchmarkQueryResult failResult(Suite suite, BenchmarkQuery benchmarkQuery, String errorMessage)
{
return new BenchmarkQueryResult(suite, benchmarkQuery, Status.FAIL, errorMessage, FAIL_STAT, FAIL_STAT, FAIL_STAT);
return new BenchmarkQueryResult(suite, benchmarkQuery, Status.FAIL, Optional.of(errorMessage), FAIL_STAT, FAIL_STAT, FAIL_STAT);
}

private final Suite suite;
private final BenchmarkQuery benchmarkQuery;
private final Status status;
private final String errorMessage;
private final Optional<String> errorMessage;
private final Stat wallTimeNanos;
private final Stat processCpuTimeNanos;
private final Stat queryCpuTimeNanos;
Expand All @@ -50,15 +53,15 @@ private BenchmarkQueryResult(
Suite suite,
BenchmarkQuery benchmarkQuery,
Status status,
String errorMessage,
Optional<String> errorMessage,
Stat wallTimeNanos,
Stat processCpuTimeNanos,
Stat queryCpuTimeNanos)
{
this.suite = checkNotNull(suite, "suite is null");
this.benchmarkQuery = checkNotNull(benchmarkQuery, "benchmarkQuery is null");
this.status = checkNotNull(status, "status is null");
this.errorMessage = checkNotNull(errorMessage, "error is null");
this.errorMessage = requireNonNull(errorMessage, "errorMessage is null");
this.wallTimeNanos = checkNotNull(wallTimeNanos, "wallTimeNanos is null");
this.processCpuTimeNanos = checkNotNull(processCpuTimeNanos, "processCpuTimeNanos is null");
this.queryCpuTimeNanos = checkNotNull(queryCpuTimeNanos, "queryCpuTimeNanos is null");
Expand All @@ -79,7 +82,7 @@ public Status getStatus()
return status;
}

public String getErrorMessage()
public Optional<String> getErrorMessage()
{
return errorMessage;
}
Expand Down
Expand Up @@ -20,10 +20,10 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.SortedSet;
import java.util.TreeSet;

import static com.facebook.presto.benchmark.driver.BenchmarkQueryResult.Status.FAIL;
import static com.google.common.base.CharMatcher.anyOf;
import static com.google.common.base.Functions.forMap;
import static com.google.common.base.Preconditions.checkNotNull;
Expand Down Expand Up @@ -86,11 +86,8 @@ public void store(BenchmarkSchema benchmarkSchema, BenchmarkQueryResult result)
tags.putAll(result.getBenchmarkQuery().getTags());
tags.putAll(benchmarkSchema.getTags());

String errorMessage = "";
if (result.getStatus() == FAIL) {
// only print first line of error message
errorMessage = getFirst(Splitter.on(anyOf("\r\n")).trimResults().split(result.getErrorMessage()), "");
}
// only print first line of error message
Optional<String> errorMessage = result.getErrorMessage().map(error -> getFirst(Splitter.on(anyOf("\r\n")).trimResults().split(error), ""));

printRow(ImmutableList.builder()
.add(result.getSuite().getName())
Expand All @@ -106,7 +103,7 @@ public void store(BenchmarkSchema benchmarkSchema, BenchmarkQueryResult result)
.add(NANOSECONDS.toMillis((long) result.getQueryCpuTimeNanos().getMean()))
.add(NANOSECONDS.toMillis((long) result.getQueryCpuTimeNanos().getStandardDeviation()))
.add(result.getStatus().toString().toLowerCase())
.add(errorMessage)
.add(errorMessage.orElse(""))
.build());
}

Expand Down

0 comments on commit 6918b42

Please sign in to comment.