Skip to content

Commit

Permalink
test: add language starter module back to sonar analysis (#1816)
Browse files Browse the repository at this point in the history
* Update sonar exclusion on spring-cloud-previews so that analysis runs on google-cloud-language-spring-starter, which contain the handwritten unit tests. This allows for some indication of missing coverage should there be broader configuration code changes introduced by the generator.
* Also update tests so that existing code coverage is sufficient (previously missing for some method-level retry property setters)
  • Loading branch information
emmileaf authored May 15, 2023
1 parent 7553d04 commit 5347d40
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<integration-test.pattern>**/*IntegrationTest*</integration-test.pattern>
<!-- exclude preview module code from sonar cloud analysis -->
<sonar.exclusions>spring-cloud-previews/**/*</sonar.exclusions>
<sonar.exclusions>spring-cloud-previews/!(google-cloud-language-spring-starter)/**</sonar.exclusions>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,49 @@ void testRetrySettingsFromProperties_serviceAndMethodLevel_allRetrySettings() {
.isEqualTo(customServiceMaxAttempts);
});
}

@Test
void testRetrySettingsFromProperties_methodLevel_totalTimeout() {
String customTimeoutString = "PT10S";
Duration customTimeoutDuration = Duration.ofSeconds(10);

this.contextRunner
.withPropertyValues(
// configure total timeout on method-level
"com.google.cloud.language.v1.language-service.analyze-sentiment-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.analyze-entities-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.analyze-entity-sentiment-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.analyze-syntax-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.classify-text-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.annotate-text-retry.total-timeout="
+ customTimeoutString)
.run(
ctx -> {
LanguageServiceClient client = ctx.getBean(LanguageServiceClient.class);
LanguageServiceSettings settings = client.getSettings();

// Method-level configurations
assertThat(settings.analyzeEntitiesSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.analyzeEntitiesSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(
settings
.analyzeEntitySentimentSettings()
.getRetrySettings()
.getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.analyzeSyntaxSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.classifyTextSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.annotateTextSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,49 @@ void testRetrySettingsFromProperties_serviceAndMethodLevel_allRetrySettings() {
.isEqualTo(customServiceMaxAttempts);
});
}

@Test
void testRetrySettingsFromProperties_methodLevel_totalTimeout() {
String customTimeoutString = "PT10S";
Duration customTimeoutDuration = Duration.ofSeconds(10);

this.contextRunner
.withPropertyValues(
// configure total timeout on method-level
"com.google.cloud.language.v1.language-service.analyze-sentiment-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.analyze-entities-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.analyze-entity-sentiment-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.analyze-syntax-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.classify-text-retry.total-timeout="
+ customTimeoutString,
"com.google.cloud.language.v1.language-service.annotate-text-retry.total-timeout="
+ customTimeoutString)
.run(
ctx -> {
LanguageServiceClient client = ctx.getBean(LanguageServiceClient.class);
LanguageServiceSettings settings = client.getSettings();

// Method-level configurations
assertThat(settings.analyzeEntitiesSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.analyzeEntitiesSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(
settings
.analyzeEntitySentimentSettings()
.getRetrySettings()
.getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.analyzeSyntaxSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.classifyTextSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
assertThat(settings.annotateTextSettings().getRetrySettings().getTotalTimeout())
.isEqualTo(customTimeoutDuration);
});
}
}

0 comments on commit 5347d40

Please sign in to comment.