Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
make TemporaryJobs more friendly to use outside of JUnit
Browse files Browse the repository at this point in the history
The `after(..)` method should not require a parameter which cannot be
constructed by end-users (the `TemporaryJobReports.ReportWriter`).
  • Loading branch information
mattnworb committed Feb 29, 2016
1 parent 7c9731c commit c9037df
Showing 1 changed file with 25 additions and 7 deletions.
Expand Up @@ -17,6 +17,8 @@


package com.spotify.helios.testing; package com.spotify.helios.testing;


import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -165,8 +167,18 @@ public void before() {
* Perform teardown. This is normally called by JUnit when TemporaryJobs is used with @Rule. * Perform teardown. This is normally called by JUnit when TemporaryJobs is used with @Rule.
* If @Rule cannot be used, call this method after running tests. * If @Rule cannot be used, call this method after running tests.
*/ */
public void after(final TemporaryJobReports.ReportWriter writer) { public void after() {
final TemporaryJobReports.Step undeploy = writer.step("undeploy"); after(Optional.<TemporaryJobReports.ReportWriter>absent());
}

void after(final Optional<TemporaryJobReports.ReportWriter> writer) {
final Optional<TemporaryJobReports.Step> undeploy = writer
.transform(new Function<TemporaryJobReports.ReportWriter, TemporaryJobReports.Step>() {
@Override
public TemporaryJobReports.Step apply(final TemporaryJobReports.ReportWriter writer) {
return writer.step("undeploy");
}
});
final List<JobId> jobIds = Lists.newArrayListWithCapacity(jobs.size()); final List<JobId> jobIds = Lists.newArrayListWithCapacity(jobs.size());


// Stop the test runner thread // Stop the test runner thread
Expand All @@ -186,7 +198,9 @@ public void after(final TemporaryJobReports.ReportWriter writer) {
job.undeploy(errors); job.undeploy(errors);
} }


undeploy.tag("jobs", jobIds); for (TemporaryJobReports.Step step : undeploy.asSet()) {
step.tag("jobs", jobIds);
}


for (AssertionError error : errors) { for (AssertionError error : errors) {
log.error(error.getMessage()); log.error(error.getMessage());
Expand All @@ -196,10 +210,14 @@ public void after(final TemporaryJobReports.ReportWriter writer) {
// try to undeploy them the next time TemporaryJobs is run. // try to undeploy them the next time TemporaryJobs is run.
if (errors.isEmpty()) { if (errors.isEmpty()) {
jobPrefixFile.delete(); jobPrefixFile.delete();
undeploy.markSuccess(); for (TemporaryJobReports.Step step : undeploy.asSet()) {
step.markSuccess();
}
} }


undeploy.finish(); for (TemporaryJobReports.Step step : undeploy.asSet()) {
step.finish();
}
} }


public TemporaryJobBuilder job() { public TemporaryJobBuilder job() {
Expand Down Expand Up @@ -325,7 +343,7 @@ public void evaluate() throws Throwable {
perform(base, writer); perform(base, writer);
test.markSuccess(); test.markSuccess();
} finally { } finally {
after(writer); after(Optional.of(writer));


test.finish(); test.finish();
writer.close(); writer.close();
Expand Down Expand Up @@ -670,7 +688,7 @@ public Builder jobDeployedMessageFormat(final String jobLinkFormat) {
this.jobDeployedMessageFormat = jobLinkFormat; this.jobDeployedMessageFormat = jobLinkFormat;
return this; return this;
} }

public Builder prober(final Prober prober) { public Builder prober(final Prober prober) {
this.prober = prober; this.prober = prober;
return this; return this;
Expand Down

0 comments on commit c9037df

Please sign in to comment.