in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java [144:269]
public void setUpBase() throws ExecutionException {
testId = PipelineUtils.createJobName("test", 10);
TemplateIntegrationTest annotation = null;
MultiTemplateIntegrationTest multiAnnotation =
getClass().getAnnotation(MultiTemplateIntegrationTest.class);
usingDirectRunner = System.getProperty("directRunnerTest") != null;
try {
Method testMethod = getClass().getMethod(testName);
annotation = testMethod.getAnnotation(TemplateIntegrationTest.class);
Category category = testMethod.getAnnotation(Category.class);
if (category != null) {
usingDirectRunner =
Arrays.asList(category.value()).contains(DirectRunnerTest.class) || usingDirectRunner;
skipRunnerV2 = Arrays.asList(category.value()).contains(SkipRunnerV2Test.class);
}
} catch (NoSuchMethodException e) {
// ignore error
}
if (annotation == null) {
annotation = getClass().getAnnotation(TemplateIntegrationTest.class);
}
if (annotation == null && multiAnnotation == null) {
LOG.warn(
"{} did not specify which template is tested using @TemplateIntegrationTest or"
+ " @MultiTemplateIntegrationTest, skipping.",
getClass());
return;
}
if (annotation != null && multiAnnotation != null) {
LOG.warn(
"{} specifies both @TemplateIntegrationTest or @MultiTemplateIntegrationTest, please use"
+ " only of either.",
getClass());
return;
}
if (TestProperties.hasAccessToken()) {
credentials = TestProperties.googleCredentials();
} else {
credentials = TestProperties.buildCredentialsFromEnv();
}
// Prefer artifactBucket, but use the staging one if none given
if (TestProperties.hasArtifactBucket()) {
artifactBucketName = TestProperties.artifactBucket();
} else if (TestProperties.hasStageBucket()) {
artifactBucketName = TestProperties.stageBucket();
}
if (artifactBucketName != null) {
gcsClient =
GcsResourceManager.builder(artifactBucketName, getClass().getSimpleName(), credentials)
.build();
// Keep name compatibility, for now
artifactClient = gcsClient;
} else {
LOG.warn(
"Both -DartifactBucket and -DstageBucket were not given. Storage Client will not be"
+ " created automatically.");
}
credentialsProvider = FixedCredentialsProvider.create(credentials);
// If annotation is not null, that means single template tests are being run.
if (annotation != null) {
templateClass = annotation.value();
template = getTemplateAnnotation(annotation, templateClass);
if (template == null) {
return;
}
if (template.placeholderClass() != void.class) {
templateClass = template.placeholderClass();
}
pipelineLauncher = buildLauncher(templateClass, template);
if (usingDirectRunner) {
// Using direct runner, not needed to stage.
return;
}
specPath = getSpecPath(templateClass, template, "pom.xml");
} else {
// If multiAnnotation is not null, that means multi template tests are being run.
TemplateIntegrationTest[] templateIntegrationTests = multiAnnotation.value();
String[] pomPaths = multiAnnotation.pomPaths();
if (pomPaths.length != templateIntegrationTests.length) {
LOG.warn(
"@MultiTemplateIntegrationTest fields value and pomPaths specified in {} have unequal"
+ " lengths. Every template class in value should have its corresponding pom file"
+ " in pomPath at the same index.",
getClass());
return;
}
if (pomPaths.length == 0) {
LOG.warn(
"{} specifies @MultiTemplateIntegrationTest with empty pomPaths field. Please provide"
+ " pomPaths for the corresponding templates to launch.",
getClass());
return;
}
for (int i = 0; i < templateIntegrationTests.length; i++) {
TemplateIntegrationTest templateIntegrationTest = templateIntegrationTests[i];
String pomPath = pomPaths[i];
templateClass = templateIntegrationTest.value();
template = getTemplateAnnotation(templateIntegrationTest, templateClass);
if (template == null) {
return;
}
if (template.placeholderClass() != void.class) {
templateClass = template.placeholderClass();
}
multiTemplates.add(template);
multiTemplateClasses.add(templateClass);
if (pipelineLauncher == null) {
pipelineLauncher = buildLauncher(templateClass, template);
}
if (usingDirectRunner) {
// Using direct runner, not needed to stage.
return;
}
multiTemplateSpecPaths.add(getSpecPath(templateClass, template, pomPath));
}
}
}