简体   繁体   中英

Quarkus Testing: Caching a Mocked Service (Cafine)

Purpose: Building a Report Engine and I have multiple service calls:

  • The first Service gets a list of individuals applying for apprenticeship (this is mocked and generated randomly with IDs etc.)
  • The second Service gets the required content to which individuals must respond (mocked and generated to mirror valid data)
  • The third Service first calls The First and Second Services, and then generates all the responses for everyone in the list of submitted applications. (this is mocked and automatically generated by randomly responding to all of the second service calls by each of the first service calls.)

Problem: While testing my report engine, I would like to run the report that needs all three services. Unfortunately, I need to inject the mocked applications from service one (1) into service three (3) or cache the mocked results for use. Otherwise, the random IDs generated during the MockedApplications Service do not match those of the Mocked Responses Service (which calls the Former to iterate and generate mocked responses). However, if I create a method that takes an injected set of applications, it is not correctly implementing the basic service.

Posted on zulip here.

Any thoughts on how to accurately set up this test scenario?

Kindest Regards!

Attempted to Cache Mocked Service Method

@Mock
@ApplicationScoped
@CacheResult(cacheName = "mock-streams")
public class MockStreamsResource extends StreamsResource {
...

However, this did not work. While there were no errors, it did not re-use the applications from the initial call while running the third (which, also mocked, calls the first mocked and second mocked services.)

Instead of randomly generating the discriminating ID during the Application Service, I used an available pool of UUIDs. This made each test predictable and repeatable.

Therefore, when the Mocked Service that generates answers calls the Application Service, it will match the results on the account_id for both the application and response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM