apache/beam · error · AssertionError
BigQuery test was not shutdown previously. Table is
Error message
BigQuery test was not shutdown previously. Table is'${table}'. Current test: ${description.getDisplayName()} What it means
TestBigQuery is a JUnit TestRule managing a temporary BigQuery dataset. Its state (datasetService) is initialized in evaluate() and cleared afterward; if it is still non-null when a new statement is applied, the previous test never shut the rule down, so this AssertionError fires naming the leftover table and current test.
Solutions
- Ensure each test's evaluate() completes so TestBigQuery shutdown runs; check that prior tests are not hung or aborted mid-rule
- Verify the rule is declared with @Rule (per-test) and not shared as a static field without @ClassRule semantics
- Check for custom Statement/RunRule wrappers that bypass the rule's cleanup
- Clear the leftover state (datasetService) before the next test or create a fresh TestBigQuery instance per test
- Upgrade/inspect Beam test utilities if a framework bug leaks state
Example fix
// before static TestBigQuery bigquery = new TestBigQuery(); // shared, leaked state // after @Rule public TestBigQuery bigquery = new TestBigQuery(); // fresh per test
Defensive patterns
Strategy: validation
Validate before calling
assert bigqueryRules.isEmpty() : "TestBigQuery rule still active from previous test";
Try / catch
try {
statement.evaluate();
} catch (AssertionError e) {
if (e.getMessage() != null && e.getMessage().contains("was not shutdown previously")) {
// reset leftover rule state before retrying the test
} else throw e;
} Prevention
- Declare TestBigQuery with @Rule per test rather than sharing instances
- Ensure prior tests finish normally so cleanup runs
- Avoid wrapping the rule's Statement in code that skips evaluate
- Investigate hangs/timeouts in earlier tests that bypass cleanup
When it happens
Trigger: Reusing a single TestBigQuery rule across tests without the previous test completing (skipped or failed cleanup), applying the rule twice, or a prior test throwing in a way that bypassed the rule's finally cleanup.
Common situations: Suite-level rule reuse, tests aborted by timeout/interrupt before cleanup, custom Statement wrappers that swallow the rule's evaluate, or misconfigured @Rule vs @ClassRule usage.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot call refreshSchema after the object has been stopped!
- Table ' ' already exists. It should have been cleaned up by…
- Unexpected null pipeline option for DynamicDestination…
- Buffer counter not initialized for UUID:
- Cannot access FinishBundleContext outside of @FinishBundle…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/b2235923047c3489.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TestBigQuery.java:100
* <p>Loads GCP configuration from {@link TestPipelineOptions}.
*/
public static TestBigQuery create(Schema tableSchema) {
return new TestBigQuery(
TestPipeline.testingPipelineOptions().as(TestBigQueryOptions.class), tableSchema);
}
private TestBigQuery(TestBigQueryOptions pipelineOptions, Schema tableSchema) {
this.pipelineOptions = pipelineOptions;
this.schema = tableSchema;
}
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (TestBigQuery.this.datasetService != null) {
throw new AssertionError(
"BigQuery test was not shutdown previously. "
+ "Table is'"
+ table
+ "'. "
+ "Current test: "
+ description.getDisplayName());
}
try {
initializeBigQuery(description);
base.evaluate();
} finally {
tearDown();
}
}
};
}
View on GitHub (pinned to 12126d8942)