Skip to content

Commit

Permalink
finish tests for HW bigtable
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomarquezp committed Jan 22, 2024
1 parent 1ccdce8 commit ac63e21
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 68 deletions.
3 changes: 2 additions & 1 deletion library_generation/generate_composed_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def generate_composed_library(
base_arguments += util.create_argument('protobuf_version', config)

destination_path = f'java-{library.api_shortname}'
if config.destination_path is not None:
if config.destination_path == 'google-cloud-java':
destination_path = config.destination_path + '/' + destination_path

versions_file = ''
Expand All @@ -77,6 +77,7 @@ def generate_composed_library(
versions_file = f'{output_folder}/google-cloud-java/versions.txt'
else:
print('this is a HW library')
util.delete_if_exists(f'{output_folder}/{destination_path}')
clone_out = util.sh_util(f'git clone "https://github.com/googleapis/{destination_path}.git"', cwd=output_folder)
print(clone_out)
versions_file = f'{output_folder}/{destination_path}/versions.txt'
Expand Down
148 changes: 81 additions & 67 deletions library_generation/test/generate_library_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,78 +51,92 @@ if [ -f "${output_folder}/generation_times" ];then
rm "${output_folder}/generation_times"
fi

configuration_yaml="${script_dir}/resources/integration/google-cloud-java/generation_config.yaml"
library_api_shortnames=$(py_util "get_configuration_yaml_library_api_shortnames" "${configuration_yaml}")

for api_shortname in ${library_api_shortnames}; do
pushd "${output_folder}"

echo "Generating library ${api_shortname}..."
generation_start=$(date "+%s")
python3 "${library_generation_dir}"/main.py generate-from-yaml \
--generation-config-yaml "${configuration_yaml}" \
--enable-postprocessing "${enable_postprocessing}" \
--target-library-api-shortname "${api_shortname}"
generation_end=$(date "+%s")

# some generations are less than 1 second (0 produces exit code 1 in `expr`)
generation_duration_seconds=$(expr "${generation_end}" - "${generation_start}" || true)
echo "Generation time for ${api_shortname} was ${generation_duration_seconds} seconds."
pushd "${output_folder}"
echo "${proto_path} ${generation_duration_seconds}" >> generation_times

echo "Generate library finished."
echo "Compare generation result..."
if [ ${enable_postprocessing} == "true" ]; then
echo "Checking out repository..."
target_folder="${output_folder}/google-cloud-java/java-${api_shortname}"
pushd "${target_folder}"
source_diff_result=0
git diff \
--ignore-space-at-eol \
-r \
--exit-code \
-- \
':!*pom.xml' \
':!*README.md' \
':!*gapic_metadata.json' \
':!*reflect-config.json' \
':!*package-info.java' \
|| source_diff_result=$?

pom_diff_result=$(compare_poms "${target_folder}")
popd # target_folder
if [[ ${source_diff_result} == 0 ]] && [[ ${pom_diff_result} == 0 ]] ; then
echo "SUCCESS: Comparison finished, no difference is found."
# Delete google-cloud-java to allow a sparse clone of the next library
rm -rdf google-cloud-java
elif [ ${source_diff_result} != 0 ]; then
echo "FAILURE: Differences found in proto path: java-${api_shortname}."
exit "${source_diff_result}"
elif [ ${pom_diff_result} != 0 ]; then
echo "FAILURE: Differences found in generated java-${api_shortname}'s poms"
exit "${pom_diff_result}"
fi
elif [ "${enable_postprocessing}" == "false" ]; then
for proto_path in "${proto_paths[@]}"; do
destination_path=$(compute_destination_path "${proto_path}" "${output_folder}")
# include gapic_metadata.json and package-info.java after
# resolving https://github.com/googleapis/sdk-platform-java/issues/1986
#configuration_yaml="${script_dir}/resources/integration/google-cloud-java/generation_config.yaml"
declare -a configuration_yamls=(
"${script_dir}/resources/integration/java-bigtable/generation_config.yaml"
"${script_dir}/resources/integration/google-cloud-java/generation_config.yaml"
)


for configuration_yaml in ${configuration_yamls[@]}; do
library_api_shortnames=$(py_util "get_configuration_yaml_library_api_shortnames" "${configuration_yaml}")
destination_path=$(py_util "get_configuration_yaml_destination_path" "${configuration_yaml}")

for api_shortname in ${library_api_shortnames}; do
pushd "${output_folder}"

echo "Generating library ${api_shortname}..."
generation_start=$(date "+%s")
python3 "${library_generation_dir}"/main.py generate-from-yaml \
--generation-config-yaml "${configuration_yaml}" \
--enable-postprocessing "${enable_postprocessing}" \
--target-library-api-shortname "${api_shortname}"
generation_end=$(date "+%s")

# some generations are less than 1 second (0 produces exit code 1 in `expr`)
generation_duration_seconds=$(expr "${generation_end}" - "${generation_start}" || true)
echo "Generation time for ${api_shortname} was ${generation_duration_seconds} seconds."
pushd "${output_folder}"
echo "${proto_path} ${generation_duration_seconds}" >> generation_times

echo "Generate library finished."
echo "Compare generation result..."
if [ ${enable_postprocessing} == "true" ]; then
echo "Checking out repository..."
if [[ "${destination_path}" == *google-cloud-java* ]]; then
target_folder="${output_folder}/google-cloud-java/java-${api_shortname}"
else
target_folder="${output_folder}/java-${api_shortname}"
fi

pushd "${target_folder}"
source_diff_result=0
diff --strip-trailing-cr -r "googleapis-gen/${proto_path}/${destination_path}" "${output_folder}/${destination_path}" \
-x "*gradle*" \
-x "gapic_metadata.json" \
-x "package-info.java" || source_diff_result=$?
if [ ${source_diff_result} == 0 ] ; then
git diff \
--ignore-space-at-eol \
-r \
--exit-code \
-- \
':!*pom.xml' \
':!*README.md' \
':!*gapic_metadata.json' \
':!*reflect-config.json' \
':!*package-info.java' \
|| source_diff_result=$?

pom_diff_result=$(compare_poms "${target_folder}")
popd # target_folder
if [[ ${source_diff_result} == 0 ]] && [[ ${pom_diff_result} == 0 ]] ; then
echo "SUCCESS: Comparison finished, no difference is found."
else
echo "FAILURE: Differences found in proto path: ${proto_path}."
# Delete google-cloud-java to allow a sparse clone of the next library
rm -rdf google-cloud-java
elif [ ${source_diff_result} != 0 ]; then
echo "FAILURE: Differences found in proto path: java-${api_shortname}."
exit "${source_diff_result}"
elif [ ${pom_diff_result} != 0 ]; then
echo "FAILURE: Differences found in generated java-${api_shortname}'s poms"
exit "${pom_diff_result}"
fi
done
fi
elif [ "${enable_postprocessing}" == "false" ]; then
for proto_path in "${proto_paths[@]}"; do
destination_path=$(compute_destination_path "${proto_path}" "${output_folder}")
# include gapic_metadata.json and package-info.java after
# resolving https://github.com/googleapis/sdk-platform-java/issues/1986
source_diff_result=0
diff --strip-trailing-cr -r "googleapis-gen/${proto_path}/${destination_path}" "${output_folder}/${destination_path}" \
-x "*gradle*" \
-x "gapic_metadata.json" \
-x "package-info.java" || source_diff_result=$?
if [ ${source_diff_result} == 0 ] ; then
echo "SUCCESS: Comparison finished, no difference is found."
else
echo "FAILURE: Differences found in proto path: ${proto_path}."
exit "${source_diff_result}"
fi
done
fi

popd # output_folder
popd # output_folder
done
done
echo "ALL TESTS SUCCEEDED"
echo "generation times in seconds (does not consider repo checkout):"
Expand Down
9 changes: 9 additions & 0 deletions library_generation/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def get_configuration_yaml_library_api_shortnames(generation_config_yaml):
result += f'{library.api_shortname} '
return result[:-1]

"""
For a given configuration yaml path, it returns the destination_path
entry at the root of the yaml
"""
def get_configuration_yaml_destination_path(generation_config_yaml):
config = GenerationConfig.from_yaml(generation_config_yaml)
return config.destination_path or ''


"""
Calls a function defined in library_generation/utilities.sh
"""
Expand Down

0 comments on commit ac63e21

Please sign in to comment.