Skip to content

TEST: Expect the cloud address the environment gives in engine tests - #229

Merged
jwrosewell merged 1 commit into
rcfrom
fix/cloud-endpoint-tests
Nov 23, 2026
Merged

jwrosewell merged 1 commit into
rcfrom
fix/cloud-endpoint-tests

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The release pull request #190 (rc into main) fails on every runner in Release Pull Request run 45130693280. Three tests in CloudRequestEngineTests error with The method 'toString' should not have been called.:

[ERROR]   CloudRequestEngineTests.OriginHeader:997 »  The method 'toString' should not h...
[ERROR]   CloudRequestEngineTests.Process:99 »  The method 'toString' should not have be...
[ERROR]   CloudRequestEngineTests.Process_LicenseKey:237 »  The method 'toString' should...

Each test checks that the data request went to expectedUrl, which CloudRequestEngineTestsBase.java line 49 fixed at https://cloud.51degrees.com/api/v4/resource_key.json. CI sets _51DEGREES_CLOUD_ENDPOINT to another service, so the engine correctly sent the request there, the argThat match failed, and Mockito called toString on the strict mock while writing its failure message.

The rule

The cloud request engine takes its address in this order.

  1. An address given in code (setEndpoint) or in configuration (Endpoint).
  2. The _51DEGREES_CLOUD_ENDPOINT environment variable.
  3. https://cloud.51degrees.com/api/v4/ when both are blank.

Every language reads the variable, so the whole suite can be run against a different service. The tests must follow the rule rather than give the engine the default address, which would stop the variable from being tested.

What was checked

  • CloudRequestEngineBuilder.java lines 98 to 106 apply the order above at build time, reading the variable through the getEnvVar function at line 71, which CloudRequestEngineBuilderTests already replaces by reflection to test the order.
  • CloudRequestEngineBuilderTests already tests code over the variable (CloudEndPoint_Explicit_Setting), the variable over the default (CloudEndPoint_Environment_Setting) and the default when the variable is unset (CloudEndPoint_Default_Setting).
  • No other test in this module, or in the Device Detection, IP Intelligence and Geo Location cloud modules, compares against the default address. Those modules were skipped in the failed run because the reactor stopped at this module.

What changed

Test code only, no change to the engine.

  • ExpectedEndpoint.java (new) works out the address a test that gives none should expect, in one place. That is the variable when it is set and not empty, otherwise Constants.END_POINT_DEFAULT, ending in / as the builder makes it.
  • CloudRequestEngineTestsBase.java builds expectedUrl from ExpectedEndpoint.root(), which fixes the three failing tests.
  • CloudRequestEngineBuilderTests.java gains three tests.
    • CloudEndPoint_Blank_Environment_Setting: an empty variable gives the default.
    • CloudEndPoint_Matches_Expected: an engine built in the real environment uses the address ExpectedEndpoint gives.
    • CloudEndPoint_Matches_Expected_For_Each_Variable: through the getEnvVar hook, the engine and ExpectedEndpoint.root(value) agree for a missing, empty, unslashed and slashed variable.
    • CloudEndPoint_Configuration_Setting: the pipeline is given a builder whose variable is set through the getEnvVar hook (with PipelineBuilder.addElementBuilder), and an address given in configuration (Endpoint in PipelineOptions) is used for every request instead of the variable.

How it was verified

On Windows with JDK 21 and the Maven wrapper.

  1. With _51DEGREES_CLOUD_ENDPOINT set to another cloud address, ./mvnw -pl pipeline/pipeline.cloudrequestengine -am test -Dtest='CloudRequestEngineTests,CloudRequestEngineBuilderTests' -Dsurefire.failIfNoSpecifiedTests=false gave Tests run: 55, Failures: 0, Errors: 0, Skipped: 0 and BUILD SUCCESS.
  2. The same with the variable unset gave Tests run: 55, Failures: 0, Errors: 0, Skipped: 0 and BUILD SUCCESS.
  3. Every test in pipeline.cloudrequestengine (./mvnw -o -pl pipeline/pipeline.cloudrequestengine -am test "-Dtest=fiftyone.pipeline.cloudrequestengine.**") ran with Tests run: 170, Failures: 0, Errors: 0 (166 before plus the four new ones), both with the variable unset and with it set to another cloud address without a trailing slash. Set to an address that does not resolve, only HttpDataSetInException and CloudRequestEngineLiveTests fail, because both call the real service at the variable's address. The Geo Location cloud tests gave 15 passed, and the cloud engine developer example tests gave 6 run, 3 skipped (EndpointTests skips itself when the variable is set).
  4. ci/check-environment-variable-names.ps1 passed.

Not run here: the full CI matrix (JDK 8, 11 and 17, Linux and macOS). Locally, ValueCloudTests in the Device Detection and IP Intelligence cloud modules could not run because the data submodule was not checked out (Cannot find device-detection/20000 Evidence Records.yml), which is unrelated to the address.

Outstanding

Notes for the engine, not changed here.

  1. setEndpoint (CloudRequestEngineBuilder.java lines 227 to 230) adds / before storing the address, so a blank address given in code or configuration is stored as /, and the blank check at line 98 never sees it as blank. A blank address given in code or configuration therefore does not fall through to the variable or the default. setEndpoint(null) throws at line 227.
  2. Addresses given in code with setDataEndpoint, setPropertiesEndpoint or setEvidenceKeysEndpoint (lines 248, 262 and 276), without setEndpoint, are replaced at build time when line 98 finds no root address and calls setEndpoint with the variable or the default (lines 101 and 104).
  3. The variable is treated as blank only when empty (line 100), so a value of spaces is used as an address.

Other failures in the same run, not fixed here.

  • MacOS_X64_Java_17 stopped at IP Intelligence :: Translation because Maven could not download a plugin: Plugin org.apache.maven.plugins:maven-resources-plugin:3.3.1 or one of its dependencies could not be resolved: ... Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:3.3.1 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: nodename nor servname provided, or not known.

The cloud request engine takes its address from code or configuration
first, then the _51DEGREES_CLOUD_ENDPOINT environment variable, then
https://cloud.51degrees.com/api/v4/ when both are blank. CI sets the
variable to another service, so Process, Process_LicenseKey and
OriginHeader in CloudRequestEngineTests failed because they expected
the default address.

ExpectedEndpoint works out the address a test that gives none should
expect, the variable when it is set and not empty and the default
otherwise, and CloudRequestEngineTestsBase builds expectedUrl from it.

CloudRequestEngineBuilderTests gains three tests. An empty variable
gives the default, the engine built in the real environment uses the
address ExpectedEndpoint gives, and an address given in configuration
is used for every request whatever the variable holds.
@jwrosewell jwrosewell mentioned this pull request Nov 23, 2026
@jwrosewell
jwrosewell marked this pull request as ready for review November 23, 2026 09:09
@jwrosewell
jwrosewell merged commit 64adf85 into rc Nov 23, 2026
5 checks passed
@jwrosewell
jwrosewell deleted the fix/cloud-endpoint-tests branch November 23, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant