Skip to content

Conversation

@kinyoklion
Copy link
Member

No description provided.

return;
}

boolean initialized = client.getDataSourceStatusProvider().waitFor(DataSourceStatusProvider.State.VALID,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a couple problems here. The waitFor method just not handle FOREVER, and so was doing some invalid math.

Also it really needs to check for either OFF or VALID, which this API doesn't really have an ergonomic way to do.

So instead we use synchronized blocks with wait. Whenever the state changes the checking code wakes up and checks if initialization is complete.

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class DelayedDataSource implements DataSource {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data source which allow initialization to complete or fail after some duration. Allowing us to test the path where the client is not immediately initialized (as it is in offline mode).

@kinyoklion kinyoklion marked this pull request as ready for review June 6, 2024 17:28
@kinyoklion kinyoklion requested a review from a team June 6, 2024 17:28
@kinyoklion kinyoklion marked this pull request as draft June 6, 2024 18:02
handleDataSourceStatus(res);
});

handleDataSourceStatus(client.getDataSourceStatusProvider().getStatus());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually fetch data source status in case it updated before the callback was registered.

@kinyoklion kinyoklion marked this pull request as ready for review June 6, 2024 19:15
@kinyoklion kinyoklion merged commit cf0ed18 into main Jun 6, 2024
@kinyoklion kinyoklion deleted the rlamb/better-initialization-process branch June 6, 2024 21:52
kinyoklion pushed a commit that referenced this pull request Jun 7, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.2.3](0.2.2...0.2.3)
(2024-06-06)


### Bug Fixes

* Improve client initialization handling.
([#27](#27))
([cf0ed18](cf0ed18))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants