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

fix: npe on transient query close (#7530) #7533

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
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 @@ -66,12 +66,22 @@ public void onCreate(

@Override
public void onStateChange(final QueryMetadata query, final State before, final State after) {
perQuery.get(query.getQueryId()).onChange(before, after);
// this may be called after the query is deregistered, because shutdown is ansynchronous and
// may time out. when ths happens, the shutdown thread in streams may call this method.
final PerQueryListener listener = perQuery.get(query.getQueryId());
if (listener != null) {
listener.onChange(before, after);
}
}

@Override
public void onError(final QueryMetadata query, final QueryError error) {
perQuery.get(query.getQueryId()).onError(error);
// this may be called after the query is deregistered, because shutdown is ansynchronous and
// may time out. when ths happens, the shutdown thread in streams may call this method.
final PerQueryListener listener = perQuery.get(query.getQueryId());
if (listener != null) {
listener.onError(error);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ public void shouldAddMetricOnCreation() {
verify(metrics).addMetric(eq(METRIC_NAME_2), isA(Gauge.class));
}

@Test
public void shouldGracefullyHandleStateCallbackAfterDeregister() {
// Given:
listener.onCreate(serviceContext, metaStore, query);
listener.onDeregister(query);

// When/Then(don't throw)
listener.onStateChange(query, State.RUNNING, State.NOT_RUNNING);
}

@Test
public void shouldGracefullyHandleErrorCallbackAfterDeregister() {
// Given:
listener.onCreate(serviceContext, metaStore, query);
listener.onDeregister(query);

// When/Then(don't throw)
listener.onError(query, new QueryError(123, "foo", Type.USER));
}

@Test
public void shouldAddMetricWithSuppliedPrefix() {
// Given:
Expand Down