-
Notifications
You must be signed in to change notification settings - Fork 292
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
Add SpannerHealthIndicator and AutoConfiguration #643
Add SpannerHealthIndicator and AutoConfiguration #643
Conversation
I fixed and added tests. Please review. |
Thanks for the execution of checks. |
I see the tests passed but "Don't merge. Work in progress:" in the pull request description. |
@suztomo |
Actually documentation is not completed. |
Hey @ikeyat, we still need a few more days to review your PR. Thank you for your patience! We appreciate your contribution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, and sorry for the delay.
Please add @since 2.0.6
tags to new classes, and there is one more inline comment. Otherwise looks very good.
|
||
@Override | ||
protected void doHealthCheck(Builder builder) throws Exception { | ||
ResultSet resultSet = spannerTemplate.executeQuery(Statement.of(validationQuery), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this will be the same Statement
every time, it would be better to create the Statement
in constructor and store that as a field instead of String validationQuery;
.
|
||
@Test | ||
public void testdoHealthCheckUp() throws Exception { | ||
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); | |
SpannerHealthIndicator spannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
|
||
Health.Builder builder = new Health.Builder(); | ||
|
||
SpannerHealthIndicator.doHealthCheck(builder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator.doHealthCheck(builder); | |
spannerHealthIndicator.doHealthCheck(builder); |
|
||
@Test(expected = Exception.class) | ||
public void testdoHealthCheckDownSpannerTemplate() throws Exception { | ||
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); | |
SpannerHealthIndicator spannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
|
||
Health.Builder builder = new Health.Builder(); | ||
|
||
SpannerHealthIndicator.doHealthCheck(builder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator.doHealthCheck(builder); | |
spannerHealthIndicator.doHealthCheck(builder); |
|
||
@Test | ||
public void testHealthy() { | ||
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); | |
spannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
|
||
@Test | ||
public void testUnhealthySpannerTemplate() { | ||
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); | |
SpannerHealthIndicator spannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
|
||
when(spannerTemplate.executeQuery(any(), any())).thenThrow(new RuntimeException("Cloud Spanner is down!!!")); | ||
|
||
assertThat(SpannerHealthIndicator.health().getStatus()).isEqualTo(Status.DOWN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(SpannerHealthIndicator.health().getStatus()).isEqualTo(Status.DOWN); | |
assertThat(spannerHealthIndicator.health().getStatus()).isEqualTo(Status.DOWN); |
|
||
@Test | ||
public void testUnhealthyResultSet() { | ||
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerHealthIndicator SpannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); | |
SpannerHealthIndicator spannerHealthIndicator = new SpannerHealthIndicator(spannerTemplate, QUERY); |
when(spannerTemplate.executeQuery(any(), any())).thenReturn(resultSet); | ||
when(resultSet.next()).thenThrow(new RuntimeException("Cloud Spanner is down!!!")); | ||
|
||
assertThat(SpannerHealthIndicator.health().getStatus()).isEqualTo(Status.DOWN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(SpannerHealthIndicator.health().getStatus()).isEqualTo(Status.DOWN); | |
assertThat(spannerHealthIndicator.health().getStatus()).isEqualTo(Status.DOWN); |
@elefeint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you! Could you add documentation to spanner.adoc
? Especially around turning the indicator off.
@elefeint |
Kudos, SonarCloud Quality Gate passed! |
@ikeyat Thank you! |
…#643) Add SpannerHealthIndicator and AutoConfiguration.
Fixes #640
Following tasks have been completed. Please review.
Don't merge. Work in progress: