Compare commits
254 Commits
Author | SHA1 | Date |
---|---|---|
|
ac3344c7f6 | |
|
ecc8f7e3ad | |
|
cbf7a58622 | |
|
1382b367d9 | |
|
5b3e3656f6 | |
|
1d3fab6184 | |
|
006ae75e2b | |
|
aa0569379b | |
|
bf68cbdedf | |
|
62738f7f16 | |
|
1e8f5c880c | |
|
488196656a | |
|
26716a51cf | |
|
908755c2c2 | |
|
d2b1dc3a41 | |
|
85d89ee79a | |
|
6194186b3e | |
|
5425a34a12 | |
|
957c0d1ba3 | |
|
ebea0fdf1c | |
|
08f549afd1 | |
|
a5d1cbced4 | |
|
0fd9d3dcfb | |
|
0515ad54c4 | |
|
69519b1ef7 | |
|
2e3b479cb1 | |
|
49214b7282 | |
|
fc430c3e1d | |
|
86a5916f0d | |
|
34b22e8d93 | |
|
300a705e0a | |
|
b64efe82d9 | |
|
6f67b06f71 | |
|
e67f598357 | |
|
312b6df5d2 | |
|
8fad544b17 | |
|
c3eaecdb8b | |
|
7c2af57a36 | |
|
8bf777a7e9 | |
|
936ff60fac | |
|
99a3006de8 | |
|
8e51e6fe10 | |
|
844d5e244b | |
|
0b57bcafc1 | |
|
3dd7d5d426 | |
|
6cca721be5 | |
|
4481537ceb | |
|
b5d873e44d | |
|
545d6aac09 | |
|
2dcd6a1dd0 | |
|
3ed65cfb0c | |
|
6597de7a98 | |
|
376f81f5c3 | |
|
1558a86249 | |
|
f8260a1c3a | |
|
50a6b168a7 | |
|
b6ceff2ecb | |
|
2de7616676 | |
|
f10aaaa357 | |
|
40b319c5de | |
|
5e922cf3ef | |
|
6a95c008e9 | |
|
dcbfd265a3 | |
|
e17b0b2975 | |
|
b45a937017 | |
|
36eed065e7 | |
|
e3379395e6 | |
|
b667aa3251 | |
|
1714efe81a | |
|
d9a72d2aaf | |
|
cfd9512728 | |
|
f6bd30db93 | |
|
e2813b2e5d | |
|
bc10bacb5a | |
|
7182a7fc41 | |
|
d0ae548277 | |
|
e568f3a4f5 | |
|
58454b4eaa | |
|
78657ee79e | |
|
3403510515 | |
|
4dc988b637 | |
|
f2348ea370 | |
|
85b200a08b | |
|
f965cbcb37 | |
|
b09e88798f | |
|
7e74f2aa3a | |
|
62ba6db457 | |
|
96cf9c7f54 | |
|
99faaf88aa | |
|
1cc851b293 | |
|
32137bfa82 | |
|
45ec4b1b77 | |
|
014f8a59da | |
|
1c4d2efafd | |
|
844374a42b | |
|
a7828e73a8 | |
|
6b6849f3a3 | |
|
495da271be | |
|
e19ccaa35d | |
|
498fd38265 | |
|
a3e2a59aeb | |
|
665dd51eb2 | |
|
a6389e89f6 | |
|
97b442ed6e | |
|
0c77c84460 | |
|
4607c62f15 | |
|
a5789038ac | |
|
e066d3f749 | |
|
5b327eeb77 | |
|
e25181982a | |
|
3c69f2f36c | |
|
345cdcfa10 | |
|
ca160cab7c | |
|
e211397d51 | |
|
5b2f1513ab | |
|
f834e11acc | |
|
ef32f11571 | |
|
07301bda3f | |
|
384953d30e | |
|
1f2d071508 | |
|
d6ebc161a9 | |
|
1fcf0e77d9 | |
|
37d76be697 | |
|
d7b591c9f9 | |
|
7f54c334da | |
|
24ef9dd290 | |
|
753667925a | |
|
87c06d9edd | |
|
85fd5e0997 | |
|
d8f6514598 | |
|
cb574d93b6 | |
|
4125ae8380 | |
|
387e5f2e3b | |
|
b6becac2c4 | |
|
922e17e677 | |
|
d61c33e466 | |
|
2239f054b9 | |
|
8359ef13bb | |
|
dbf92df33b | |
|
706565581d | |
|
9750f75d04 | |
|
de3e213ac8 | |
|
6b65e26c74 | |
|
d233480912 | |
|
69b571eda7 | |
|
f8df5fb84a | |
|
d54c68a8e9 | |
|
c550d59722 | |
|
d00e4b5b24 | |
|
c37d249776 | |
|
959e675e4c | |
|
67b34f84a3 | |
|
30b6d004aa | |
|
ecea9df932 | |
|
6c03e5d84a | |
|
31444d6c8f | |
|
dd83114c4d | |
|
2a1adca8c2 | |
|
59017977a4 | |
|
989f4ae542 | |
|
b133c2fa52 | |
|
7df9565691 | |
|
2ec7c6c7ff | |
|
698756856b | |
|
5de33c02a6 | |
|
de64eddfb3 | |
|
d95e270653 | |
|
1504d0f798 | |
|
88a778cc03 | |
|
50b45b2be4 | |
|
dd9227a924 | |
|
cdcdc143ea | |
|
3920c638a4 | |
|
4e535fd10f | |
|
4817864fd7 | |
|
90217b2083 | |
|
88baa65dd0 | |
|
e163ce1c06 | |
|
5436eb0d5d | |
|
859a36cbfa | |
|
9e782308d3 | |
|
4ba5695eee | |
|
9ab26182ea | |
|
c33ac2d9b2 | |
|
08c38fb553 | |
|
3baf0df966 | |
|
69cdc772a6 | |
|
8f3ced5907 | |
|
538140dfe7 | |
|
b7978832b7 | |
|
26e1d7fff3 | |
|
46903c6f27 | |
|
37ed6a424c | |
|
208411e723 | |
|
9a1e9abd64 | |
|
40fa173338 | |
|
cda34053f7 | |
|
99d818572a | |
|
6f36434c52 | |
|
ba9cc4b85a | |
|
7916d76635 | |
|
6874de64ce | |
|
f9fa54be49 | |
|
78adc77c23 | |
|
f7f6586d72 | |
|
34919561b7 | |
|
531fc385b6 | |
|
305e0329e7 | |
|
874e86df5c | |
|
122e82f843 | |
|
5671184e7f | |
|
6071932cb4 | |
|
0af9f2901f | |
|
a5eb21d1a2 | |
|
6c4205a008 | |
|
0b5b423bdd | |
|
882d2dd5bd | |
|
c69d3a4bd1 | |
|
640e35e853 | |
|
32a39335de | |
|
45b3995bda | |
|
b390d5f0b0 | |
|
8a1ab7ea18 | |
|
a3854d6ab1 | |
|
b997946db1 | |
|
c2a82dbdba | |
|
9274c117ab | |
|
9c92ebb1bd | |
|
d825ff8363 | |
|
ae85278c30 | |
|
3c97b7baaf | |
|
4086dea703 | |
|
a1c558f4ff | |
|
2e10d34920 | |
|
20bbb2337c | |
|
64ec68bcf5 | |
|
f1817d8fef | |
|
fc6f35e581 | |
|
c62ade3878 | |
|
6d60c962fb | |
|
992c00396c | |
|
d274cdac37 | |
|
6a7987455e | |
|
f39c4b5af5 | |
|
482a5aef10 | |
|
834f720718 | |
|
6772d3f394 | |
|
6d169f55e2 | |
|
4440cda6a5 | |
|
86e18c5d28 | |
|
9acc8612a5 | |
|
fd1c1702c6 | |
|
884f8fbf77 | |
|
b0abfd02cf |
|
@ -0,0 +1,72 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
ij_continuation_indent_size = 8
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
# Following the rules of the Google Java Style Guide.
|
||||
# See https://google.github.io/styleguide/javaguide.html
|
||||
[*.java]
|
||||
max_line_length = 120
|
||||
|
||||
ij_java_do_not_wrap_after_single_annotation_in_parameter = true
|
||||
ij_java_insert_inner_class_imports = false
|
||||
ij_java_class_count_to_use_import_on_demand = 999
|
||||
ij_java_names_count_to_use_import_on_demand = 999
|
||||
ij_java_packages_to_use_import_on_demand = unset
|
||||
ij_java_imports_layout = $*,|,*
|
||||
ij_java_doc_align_param_comments = true
|
||||
ij_java_doc_align_exception_comments = true
|
||||
ij_java_doc_add_p_tag_on_empty_lines = false
|
||||
ij_java_doc_do_not_wrap_if_one_line = true
|
||||
ij_java_doc_keep_empty_parameter_tag = false
|
||||
ij_java_doc_keep_empty_throws_tag = false
|
||||
ij_java_doc_keep_empty_return_tag = false
|
||||
ij_java_doc_preserve_line_breaks = true
|
||||
ij_java_doc_indent_on_continuation = true
|
||||
ij_java_keep_control_statement_in_one_line = false
|
||||
ij_java_keep_blank_lines_in_code = 1
|
||||
ij_java_align_multiline_parameters = false
|
||||
ij_java_align_multiline_resources = false
|
||||
ij_java_align_multiline_for = true
|
||||
ij_java_space_before_array_initializer_left_brace = true
|
||||
ij_java_call_parameters_wrap = normal
|
||||
ij_java_method_parameters_wrap = normal
|
||||
ij_java_extends_list_wrap = normal
|
||||
ij_java_throws_keyword_wrap = normal
|
||||
ij_java_method_call_chain_wrap = normal
|
||||
ij_java_binary_operation_wrap = normal
|
||||
ij_java_binary_operation_sign_on_next_line = true
|
||||
ij_java_ternary_operation_wrap = normal
|
||||
ij_java_ternary_operation_signs_on_next_line = true
|
||||
ij_java_keep_simple_methods_in_one_line = true
|
||||
ij_java_keep_simple_lambdas_in_one_line = true
|
||||
ij_java_keep_simple_classes_in_one_line = true
|
||||
ij_java_for_statement_wrap = normal
|
||||
ij_java_array_initializer_wrap = normal
|
||||
ij_java_wrap_comments = true
|
||||
ij_java_if_brace_force = always
|
||||
ij_java_do_while_brace_force = always
|
||||
ij_java_while_brace_force = always
|
||||
ij_java_for_brace_force = always
|
||||
ij_java_space_after_closing_angle_bracket_in_type_argument = false
|
||||
|
||||
[{*.json,*.json5}]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
ij_smart_tabs = false
|
||||
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
|
@ -3,4 +3,3 @@
|
|||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
||||
|
|
|
@ -18,6 +18,6 @@ jobs:
|
|||
name: Validate PR title
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: amannn/action-semantic-pull-request@40166f00814508ec3201fc8595b393d451c8cd80
|
||||
- uses: amannn/action-semantic-pull-request@335288255954904a41ddda8947c8f2c844b8bfeb
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
@ -9,35 +9,36 @@ name: on-merge
|
|||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, main ]
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
environment: publish
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
|
||||
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@ae2b61dbc685e60e4427b2e8ed4f0135c6ea8597
|
||||
with:
|
||||
java-version: '8'
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
server-id: ossrh
|
||||
server-username: ${{ secrets.OSSRH_USERNAME }}
|
||||
server-password: ${{ secrets.OSSRH_PASSWORD }}
|
||||
server-id: central
|
||||
server-username: ${{ secrets.CENTRAL_USERNAME }}
|
||||
server-password: ${{ secrets.CENTRAL_PASSWORD }}
|
||||
|
||||
- name: Cache local Maven repository
|
||||
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
|
||||
uses: actions/cache@640a1c2554105b57832a23eea0b4672fc7a790d5
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
key: ${{ runner.os }}-17-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
${{ runner.os }}-17-maven-
|
||||
|
||||
- name: Configure GPG Key
|
||||
run: |
|
||||
|
@ -49,7 +50,7 @@ jobs:
|
|||
run: mvn --batch-mode --update-snapshots verify
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5.1.1
|
||||
uses: codecov/codecov-action@v5.4.3
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
|
||||
flags: unittests # optional
|
||||
|
@ -60,11 +61,11 @@ jobs:
|
|||
# Add -SNAPSHOT before deploy
|
||||
- name: Add SNAPSHOT
|
||||
run: mvn versions:set -DnewVersion='${project.version}-SNAPSHOT'
|
||||
|
||||
|
||||
- name: Deploy
|
||||
run: |
|
||||
mvn --batch-mode \
|
||||
--settings release/m2-settings.xml clean deploy
|
||||
--settings release/m2-settings.xml -DskipTests clean deploy
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
||||
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
|
||||
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
|
||||
|
|
|
@ -7,36 +7,46 @@ permissions:
|
|||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
build:
|
||||
- java: 17
|
||||
profile: codequality
|
||||
- java: 11
|
||||
profile: java11
|
||||
name: with Java ${{ matrix.build.java }}
|
||||
runs-on: ${{ matrix.os}}
|
||||
steps:
|
||||
- name: Check out the code
|
||||
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
|
||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@ae2b61dbc685e60e4427b2e8ed4f0135c6ea8597
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
java-version: ${{ matrix.build.java }}
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@6f9e628e6f9a18c785dd746325ba455111df1b67
|
||||
uses: github/codeql-action/init@7710ed11e398ea99c7f7004c2b2e0f580458db42
|
||||
with:
|
||||
languages: java
|
||||
|
||||
- name: Cache local Maven repository
|
||||
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
|
||||
uses: actions/cache@640a1c2554105b57832a23eea0b4672fc7a790d5
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}${{ matrix.build.java }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}${{ matrix.build.java }}-maven-
|
||||
|
||||
- name: Verify with Maven
|
||||
run: mvn --batch-mode --update-snapshots --activate-profiles e2e verify
|
||||
run: mvn --batch-mode --update-snapshots --activate-profiles e2e,${{ matrix.build.profile }} verify
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5.1.1
|
||||
- if: matrix.build.java == '17'
|
||||
name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5.4.3
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
|
||||
flags: unittests # optional
|
||||
|
@ -45,4 +55,4 @@ jobs:
|
|||
verbose: true # optional (default = false)
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@6f9e628e6f9a18c785dd746325ba455111df1b67
|
||||
uses: github/codeql-action/analyze@7710ed11e398ea99c7f7004c2b2e0f580458db42
|
||||
|
|
|
@ -12,46 +12,53 @@ permissions: # added using https://github.com/step-security/secure-workflows
|
|||
|
||||
jobs:
|
||||
release-please:
|
||||
permissions:
|
||||
contents: write # for google-github-actions/release-please-action to create release commit
|
||||
pull-requests: write # for google-github-actions/release-please-action to create release PR
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write # for googleapis/release-please-action to create release commit
|
||||
pull-requests: write # for googleapis/release-please-action to create release PR
|
||||
issues: write # for googleapis/release-please-action to create labels
|
||||
|
||||
# Release-please creates a PR that tracks all changes
|
||||
steps:
|
||||
- uses: google-github-actions/release-please-action@e4dc86ba9405554aeba3c6bb2d169500e7d3b4ee
|
||||
- uses: googleapis/release-please-action@v4
|
||||
id: release
|
||||
with:
|
||||
token: ${{secrets.GITHUB_TOKEN}}
|
||||
default-branch: main
|
||||
token: ${{secrets.RELEASE_PLEASE_ACTION_TOKEN}}
|
||||
outputs:
|
||||
release_created: ${{ fromJSON(steps.release.outputs.paths_released)[0] != null }} # if we have a single release path, do the release
|
||||
|
||||
# These steps are only run if this was a merged release-please PR
|
||||
- name: checkout
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
|
||||
- name: Set up JDK 8
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
|
||||
publish:
|
||||
environment: publish
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
needs: release-please
|
||||
if: ${{ fromJSON(needs.release-please.outputs.release_created || false) }}
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@ae2b61dbc685e60e4427b2e8ed4f0135c6ea8597
|
||||
with:
|
||||
java-version: '8'
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
server-id: ossrh
|
||||
server-username: ${{ secrets.OSSRH_USERNAME }}
|
||||
server-password: ${{ secrets.OSSRH_PASSWORD }}
|
||||
server-id: central
|
||||
server-username: ${{ secrets.CENTRAL_USERNAME }}
|
||||
server-password: ${{ secrets.CENTRAL_PASSWORD }}
|
||||
|
||||
- name: Configure GPG Key
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
run: |
|
||||
echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import
|
||||
env:
|
||||
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
|
||||
|
||||
- name: Deploy
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
run: |
|
||||
mvn --batch-mode \
|
||||
--settings release/m2-settings.xml clean deploy
|
||||
--settings release/m2-settings.xml -DskipTests clean deploy
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
||||
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
|
||||
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
|
||||
|
|
|
@ -29,16 +29,16 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
|
||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@6f9e628e6f9a18c785dd746325ba455111df1b67
|
||||
uses: github/codeql-action/init@7710ed11e398ea99c7f7004c2b2e0f580458db42
|
||||
with:
|
||||
languages: java
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@6f9e628e6f9a18c785dd746325ba455111df1b67
|
||||
uses: github/codeql-action/autobuild@7710ed11e398ea99c7f7004c2b2e0f580458db42
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@6f9e628e6f9a18c785dd746325ba455111df1b67
|
||||
uses: github/codeql-action/analyze@7710ed11e398ea99c7f7004c2b2e0f580458db42
|
||||
|
|
|
@ -16,4 +16,4 @@
|
|||
# under the License.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
|
||||
|
|
|
@ -1 +1 @@
|
|||
{".":"1.13.0"}
|
||||
{".":"1.16.0"}
|
||||
|
|
308
CHANGELOG.md
308
CHANGELOG.md
|
@ -1,5 +1,313 @@
|
|||
# Changelog
|
||||
|
||||
## [1.16.0](https://github.com/open-feature/java-sdk/compare/v1.15.1...v1.16.0) (2025-07-07)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
* **deps:** update dependency io.cucumber:cucumber-bom to v7.23.0 ([#1466](https://github.com/open-feature/java-sdk/issues/1466)) ([50a6b16](https://github.com/open-feature/java-sdk/commit/50a6b168a7de40337aa51ef3d79d122030956cb9))
|
||||
* **deps:** update dependency org.junit:junit-bom to v5.13.1 ([#1475](https://github.com/open-feature/java-sdk/issues/1475)) ([545d6aa](https://github.com/open-feature/java-sdk/commit/545d6aac09dbc74c00a0a4e5c26f4ef80be22379))
|
||||
* **deps:** update dependency org.junit:junit-bom to v5.13.2 ([#1492](https://github.com/open-feature/java-sdk/issues/1492)) ([34b22e8](https://github.com/open-feature/java-sdk/commit/34b22e8d93a986fdb81500ab539b4d2fe038b618))
|
||||
* **deps:** update dependency org.junit:junit-bom to v5.13.3 ([#1505](https://github.com/open-feature/java-sdk/issues/1505)) ([957c0d1](https://github.com/open-feature/java-sdk/commit/957c0d1ba38ecc758c1ec164e40070ac93a01d68))
|
||||
* **deps:** update junit5 monorepo ([#1467](https://github.com/open-feature/java-sdk/issues/1467)) ([f8260a1](https://github.com/open-feature/java-sdk/commit/f8260a1c3a345c877eba95bfe41184ad11f6555e))
|
||||
* Reduce locking and concurrency issues ([#1478](https://github.com/open-feature/java-sdk/issues/1478)) ([ebea0fd](https://github.com/open-feature/java-sdk/commit/ebea0fdf1cf3e6f4d2e8aebf2dcb7c7e1f31acc2))
|
||||
|
||||
|
||||
### ✨ New Features
|
||||
|
||||
* add means of awaiting event emission, fix flaky build ([#1463](https://github.com/open-feature/java-sdk/issues/1463)) ([3dd7d5d](https://github.com/open-feature/java-sdk/commit/3dd7d5d4262f1f4461e13c13a7d64d2fa8bfd764)), closes [#1449](https://github.com/open-feature/java-sdk/issues/1449)
|
||||
|
||||
|
||||
### 🧹 Chore
|
||||
|
||||
* **deps:** update actions/cache digest to 640a1c2 ([#1485](https://github.com/open-feature/java-sdk/issues/1485)) ([7c2af57](https://github.com/open-feature/java-sdk/commit/7c2af57a362ee11f757a431ee17eff3ee448bf6c))
|
||||
* **deps:** update actions/checkout digest to 09d2aca ([#1473](https://github.com/open-feature/java-sdk/issues/1473)) ([b5d873e](https://github.com/open-feature/java-sdk/commit/b5d873e44d3c41b42f11569b0fafccc0a002ebdd))
|
||||
* **deps:** update actions/setup-java digest to 67aec00 ([#1504](https://github.com/open-feature/java-sdk/issues/1504)) ([08f549a](https://github.com/open-feature/java-sdk/commit/08f549afd1fd26581b2a8e063832ec986c5e3267))
|
||||
* **deps:** update actions/setup-java digest to ebb356c ([#1490](https://github.com/open-feature/java-sdk/issues/1490)) ([e67f598](https://github.com/open-feature/java-sdk/commit/e67f5983573afff805a56ef18584d1a7291ccafc))
|
||||
* **deps:** update codecov/codecov-action action to v5.4.3 ([#1454](https://github.com/open-feature/java-sdk/issues/1454)) ([e337939](https://github.com/open-feature/java-sdk/commit/e3379395e6bfb0ce811d8372761a3cb015ad2cde))
|
||||
* **deps:** update dependency com.diffplug.spotless:spotless-maven-plugin to v2.44.5 ([#1462](https://github.com/open-feature/java-sdk/issues/1462)) ([40b319c](https://github.com/open-feature/java-sdk/commit/40b319c5de0461bec13f76978ae09edc958310cd))
|
||||
* **deps:** update dependency com.github.spotbugs:spotbugs-maven-plugin to v4.9.3.1 ([#1493](https://github.com/open-feature/java-sdk/issues/1493)) ([b64efe8](https://github.com/open-feature/java-sdk/commit/b64efe82d993defe070dfeb9aa60e740ccf757cd))
|
||||
* **deps:** update dependency com.github.spotbugs:spotbugs-maven-plugin to v4.9.3.2 ([#1496](https://github.com/open-feature/java-sdk/issues/1496)) ([fc430c3](https://github.com/open-feature/java-sdk/commit/fc430c3e1d57a532d8c0c879c3e7e25c46d4ad84))
|
||||
* **deps:** update dependency com.puppycrawl.tools:checkstyle to v10.24.0 ([#1458](https://github.com/open-feature/java-sdk/issues/1458)) ([dcbfd26](https://github.com/open-feature/java-sdk/commit/dcbfd265a3875271695af760fce9870e53c69f13))
|
||||
* **deps:** update dependency com.puppycrawl.tools:checkstyle to v10.25.0 ([#1468](https://github.com/open-feature/java-sdk/issues/1468)) ([1558a86](https://github.com/open-feature/java-sdk/commit/1558a862497c0e133d11d53ff6d7f28437653d43))
|
||||
* **deps:** update dependency com.puppycrawl.tools:checkstyle to v10.25.1 ([#1489](https://github.com/open-feature/java-sdk/issues/1489)) ([312b6df](https://github.com/open-feature/java-sdk/commit/312b6df5d2c891ac758bf398f8399ecd25b7597e))
|
||||
* **deps:** update dependency com.puppycrawl.tools:checkstyle to v10.26.0 ([#1494](https://github.com/open-feature/java-sdk/issues/1494)) ([300a705](https://github.com/open-feature/java-sdk/commit/300a705e0af959da7ed0e88e9975379ff6fc4138))
|
||||
* **deps:** update dependency com.puppycrawl.tools:checkstyle to v10.26.1 ([#1498](https://github.com/open-feature/java-sdk/issues/1498)) ([2e3b479](https://github.com/open-feature/java-sdk/commit/2e3b479cb1e8b0b65652ee813eaa2e1940d53c8e))
|
||||
* **deps:** update dependency maven to v3.9.10 ([#1474](https://github.com/open-feature/java-sdk/issues/1474)) ([4481537](https://github.com/open-feature/java-sdk/commit/4481537cebc213dcfe19bb8cd9b70a4c91a682b2))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.6 ([#1482](https://github.com/open-feature/java-sdk/issues/1482)) ([8e51e6f](https://github.com/open-feature/java-sdk/commit/8e51e6fe101882184a5d09be31fa65563d82c673))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.6 ([#1483](https://github.com/open-feature/java-sdk/issues/1483)) ([936ff60](https://github.com/open-feature/java-sdk/commit/936ff60fac471a83a7c14412d2e825b2a7f9704c))
|
||||
* **deps:** update dependency org.apache.maven.plugins:maven-gpg-plugin to v3.2.8 ([#1501](https://github.com/open-feature/java-sdk/issues/1501)) ([0515ad5](https://github.com/open-feature/java-sdk/commit/0515ad54c4f71863373eb1b7f429393923b27d90))
|
||||
* **deps:** update dependency org.codehaus.mojo:exec-maven-plugin to v3.5.1 ([#1461](https://github.com/open-feature/java-sdk/issues/1461)) ([b6ceff2](https://github.com/open-feature/java-sdk/commit/b6ceff2ecb0e34be2ccdb83f7f37c1177de6f27e))
|
||||
* **deps:** update dependency org.mockito:mockito-core to v5.18.0 ([#1457](https://github.com/open-feature/java-sdk/issues/1457)) ([e17b0b2](https://github.com/open-feature/java-sdk/commit/e17b0b29758ae7cdbdac9ddb2178382c55eb1277))
|
||||
* **deps:** update github/codeql-action digest to 075e08a ([#1470](https://github.com/open-feature/java-sdk/issues/1470)) ([6597de7](https://github.com/open-feature/java-sdk/commit/6597de7a98e0fae10a541a8a9b60837623c133a8))
|
||||
* **deps:** update github/codeql-action digest to 33f8489 ([#1502](https://github.com/open-feature/java-sdk/issues/1502)) ([0fd9d3d](https://github.com/open-feature/java-sdk/commit/0fd9d3dcfb1fd65197a42885b12d40a1cc152d3b))
|
||||
* **deps:** update github/codeql-action digest to 396fd27 ([#1456](https://github.com/open-feature/java-sdk/issues/1456)) ([b45a937](https://github.com/open-feature/java-sdk/commit/b45a9370173e3d3b97c78449dfc99225fb572228))
|
||||
* **deps:** update github/codeql-action digest to 3de706a ([#1481](https://github.com/open-feature/java-sdk/issues/1481)) ([99a3006](https://github.com/open-feature/java-sdk/commit/99a3006de878ab0ba1f0e61a4cb5432914425795))
|
||||
* **deps:** update github/codeql-action digest to 466d6ce ([#1477](https://github.com/open-feature/java-sdk/issues/1477)) ([0b57bca](https://github.com/open-feature/java-sdk/commit/0b57bcafc14b946000feb4a3421d73b9616e83cb))
|
||||
* **deps:** update github/codeql-action digest to 4a00331 ([#1469](https://github.com/open-feature/java-sdk/issues/1469)) ([376f81f](https://github.com/open-feature/java-sdk/commit/376f81f5c3b66d7e3e298aac30ac7544b84e7362))
|
||||
* **deps:** update github/codeql-action digest to 4c57370 ([#1497](https://github.com/open-feature/java-sdk/issues/1497)) ([49214b7](https://github.com/open-feature/java-sdk/commit/49214b7282ddde1ee16cf80f92c11cc90ef7612a))
|
||||
* **deps:** update github/codeql-action digest to 510dfa3 ([#1450](https://github.com/open-feature/java-sdk/issues/1450)) ([d9a72d2](https://github.com/open-feature/java-sdk/commit/d9a72d2aafd787a1814132f000897ad1c94181e4))
|
||||
* **deps:** update github/codeql-action digest to 57eebf6 ([#1455](https://github.com/open-feature/java-sdk/issues/1455)) ([36eed06](https://github.com/open-feature/java-sdk/commit/36eed065e763bbfa0f8f97d704202bbd219332ca))
|
||||
* **deps:** update github/codeql-action digest to 66d7255 ([#1487](https://github.com/open-feature/java-sdk/issues/1487)) ([c3eaecd](https://github.com/open-feature/java-sdk/commit/c3eaecdb8b34d3b33946bd205ee92d49584602bd))
|
||||
* **deps:** update github/codeql-action digest to 7b0fb5a ([#1459](https://github.com/open-feature/java-sdk/issues/1459)) ([6a95c00](https://github.com/open-feature/java-sdk/commit/6a95c008e975dd3c7328c32f1d7cf626bbaecfa6))
|
||||
* **deps:** update github/codeql-action digest to 7cb9b16 ([#1476](https://github.com/open-feature/java-sdk/issues/1476)) ([6cca721](https://github.com/open-feature/java-sdk/commit/6cca721be5bc6f5926fe64668a7c03728cab3cb0))
|
||||
* **deps:** update github/codeql-action digest to 7fd6215 ([#1464](https://github.com/open-feature/java-sdk/issues/1464)) ([f10aaaa](https://github.com/open-feature/java-sdk/commit/f10aaaa357581b573895f4d6e2329abb705582aa))
|
||||
* **deps:** update github/codeql-action digest to 8ef1782 ([#1495](https://github.com/open-feature/java-sdk/issues/1495)) ([86a5916](https://github.com/open-feature/java-sdk/commit/86a5916f0dc6116b5b9e5dc897ff4b8705ac01e3))
|
||||
* **deps:** update github/codeql-action digest to 9b02dc2 ([#1491](https://github.com/open-feature/java-sdk/issues/1491)) ([6f67b06](https://github.com/open-feature/java-sdk/commit/6f67b06f712c461f331681a76f5cb2c3ddb0d36b))
|
||||
* **deps:** update github/codeql-action digest to ac30a39 ([#1488](https://github.com/open-feature/java-sdk/issues/1488)) ([8fad544](https://github.com/open-feature/java-sdk/commit/8fad544b17ee08b4280d7975073d00a874c374db))
|
||||
* **deps:** update github/codeql-action digest to b1e4dc3 ([#1471](https://github.com/open-feature/java-sdk/issues/1471)) ([2dcd6a1](https://github.com/open-feature/java-sdk/commit/2dcd6a1dd0c80ee676b9860afd6a6002d0ea4aea))
|
||||
* **deps:** update github/codeql-action digest to b694213 ([#1503](https://github.com/open-feature/java-sdk/issues/1503)) ([a5d1cbc](https://github.com/open-feature/java-sdk/commit/a5d1cbced4658fadb63f362b4512bdbd68ae7d6a))
|
||||
* **deps:** update github/codeql-action digest to b86edfc ([#1453](https://github.com/open-feature/java-sdk/issues/1453)) ([b667aa3](https://github.com/open-feature/java-sdk/commit/b667aa325136b78c01867d40342f81eeb7e16f46))
|
||||
* **deps:** update github/codeql-action digest to bc02a25 ([#1460](https://github.com/open-feature/java-sdk/issues/1460)) ([5e922cf](https://github.com/open-feature/java-sdk/commit/5e922cf3efc156135563707de92e508b0a4d19f3))
|
||||
* **deps:** update github/codeql-action digest to be30325 ([#1479](https://github.com/open-feature/java-sdk/issues/1479)) ([844d5e2](https://github.com/open-feature/java-sdk/commit/844d5e244b02703b624cf75e5bf8448c07e62d3d))
|
||||
* **deps:** update github/codeql-action digest to dcc1a66 ([#1499](https://github.com/open-feature/java-sdk/issues/1499)) ([69519b1](https://github.com/open-feature/java-sdk/commit/69519b1ef7274ceae39d6746c5a5a98dc69f562f))
|
||||
* **deps:** update github/codeql-action digest to ef36b69 ([#1484](https://github.com/open-feature/java-sdk/issues/1484)) ([8bf777a](https://github.com/open-feature/java-sdk/commit/8bf777a7e99be4dfac8917b8e61cb6c23385b8ce))
|
||||
* **deps:** update io.cucumber.version to v7.23.0 ([#1465](https://github.com/open-feature/java-sdk/issues/1465)) ([2de7616](https://github.com/open-feature/java-sdk/commit/2de76166764bacd34883b13220dd0bad824c8b1a))
|
||||
* improvements to release workflow ([#1451](https://github.com/open-feature/java-sdk/issues/1451)) ([1714efe](https://github.com/open-feature/java-sdk/commit/1714efe81aa6ae025f4f8b12c9c042561498d25e))
|
||||
* migrate to new publish ([5425a34](https://github.com/open-feature/java-sdk/commit/5425a34a12baa04f9583b83fd1bfdd7e2a6ab5e8))
|
||||
* remove unneeded version information ([#1428](https://github.com/open-feature/java-sdk/issues/1428)) ([3ed65cf](https://github.com/open-feature/java-sdk/commit/3ed65cfb0cb5ee5b70793cd68a27909c81cd4fab))
|
||||
* skip tests on publish ([6194186](https://github.com/open-feature/java-sdk/commit/6194186b3e791f3cb28da24f5acb3ff96788d65e))
|
||||
* update publish env vars ([85d89ee](https://github.com/open-feature/java-sdk/commit/85d89ee79a52d960322731fb786c0f60245f0d75))
|
||||
|
||||
## [1.15.1](https://github.com/open-feature/java-sdk/compare/v1.14.2...v1.15.1) (2025-05-14)
|
||||
|
||||
|
||||
### NOTABLE CHANGES
|
||||
|
||||
* Raise required Java version to 11 ([#1393](https://github.com/open-feature/java-sdk/issues/1393))
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
* **deps:** update dependency io.cucumber:cucumber-bom to v7.22.0 ([#1411](https://github.com/open-feature/java-sdk/issues/1411)) ([e251819](https://github.com/open-feature/java-sdk/commit/e25181982af8e5d37be4876b71b337ca86e8454b))
|
||||
* **deps:** update dependency io.cucumber:cucumber-bom to v7.22.1 ([#1427](https://github.com/open-feature/java-sdk/issues/1427)) ([1c4d2ef](https://github.com/open-feature/java-sdk/commit/1c4d2efafdebb562f099ba1ec3a6a29eabc8ff91))
|
||||
* **deps:** update dependency io.cucumber:cucumber-bom to v7.22.2 ([#1442](https://github.com/open-feature/java-sdk/issues/1442)) ([e568f3a](https://github.com/open-feature/java-sdk/commit/e568f3a4f560187586d5473aa7bc12a673340e24))
|
||||
* **deps:** update dependency org.projectlombok:lombok to v1.18.38 ([#1403](https://github.com/open-feature/java-sdk/issues/1403)) ([ef32f11](https://github.com/open-feature/java-sdk/commit/ef32f11571de4d3a981efec4f61113eb8b0d7d9d))
|
||||
* **deps:** update junit5 monorepo ([#1418](https://github.com/open-feature/java-sdk/issues/1418)) ([97b442e](https://github.com/open-feature/java-sdk/commit/97b442ed6e8f2b99ca949ffd63e5cbf57718c796))
|
||||
|
||||
|
||||
### ✨ New Features
|
||||
|
||||
* add logging on provider state transitions ([#1444](https://github.com/open-feature/java-sdk/issues/1444)) ([e2813b2](https://github.com/open-feature/java-sdk/commit/e2813b2e5df8e548caf16e3e425b35962045ca6c))
|
||||
* add telemetry helper utils ([#1346](https://github.com/open-feature/java-sdk/issues/1346)) ([d0ae548](https://github.com/open-feature/java-sdk/commit/d0ae5482771f4d1701bce25381cdf4e92e2d4882))
|
||||
* Raise required Java version to 11 ([#1393](https://github.com/open-feature/java-sdk/issues/1393)) ([4dc988b](https://github.com/open-feature/java-sdk/commit/4dc988b637a9e9c377edf7df7b29bf6407319f16))
|
||||
|
||||
|
||||
### 🧹 Chore
|
||||
|
||||
* add DCO to release please ([45ec4b1](https://github.com/open-feature/java-sdk/commit/45ec4b1b7734c9117f43abf8fe5105c2903c3986))
|
||||
* add DCO to release please ([#1429](https://github.com/open-feature/java-sdk/issues/1429)) ([32137bf](https://github.com/open-feature/java-sdk/commit/32137bfa82e9c0391c999bf0be2a36f201620931))
|
||||
* add publish env ([#1420](https://github.com/open-feature/java-sdk/issues/1420)) ([665dd51](https://github.com/open-feature/java-sdk/commit/665dd51eb2b3b79d3ffccb6cef64d544aa5e7206))
|
||||
* **deps:** update actions/setup-java digest to 148017a ([#1404](https://github.com/open-feature/java-sdk/issues/1404)) ([f834e11](https://github.com/open-feature/java-sdk/commit/f834e11acc7ecf903e972d80e9dab324be97847e))
|
||||
* **deps:** update actions/setup-java digest to c5195ef ([#1415](https://github.com/open-feature/java-sdk/issues/1415)) ([a578903](https://github.com/open-feature/java-sdk/commit/a5789038acc36cb2b0ddf12e534a1317e1c9b8e8))
|
||||
* **deps:** update actions/setup-java digest to f4f1212 ([#1421](https://github.com/open-feature/java-sdk/issues/1421)) ([a3e2a59](https://github.com/open-feature/java-sdk/commit/a3e2a59aebee051ae8c7eb1c5769a04dc9da8de3))
|
||||
* **deps:** update amannn/action-semantic-pull-request digest to 3352882 ([#1434](https://github.com/open-feature/java-sdk/issues/1434)) ([62ba6db](https://github.com/open-feature/java-sdk/commit/62ba6db457358d759fe83f23318b1cf4200756ac))
|
||||
* **deps:** update codecov/codecov-action action to v5.4.2 ([#1419](https://github.com/open-feature/java-sdk/issues/1419)) ([a6389e8](https://github.com/open-feature/java-sdk/commit/a6389e89f60aa7f4871f47d78fedd27a7f9991b4))
|
||||
* **deps:** update dependency com.diffplug.spotless:spotless-maven-plugin to v2.44.4 ([#1414](https://github.com/open-feature/java-sdk/issues/1414)) ([e066d3f](https://github.com/open-feature/java-sdk/commit/e066d3f749c09bb1ef79e3bcace1d205a39787df))
|
||||
* **deps:** update dependency com.h3xstream.findsecbugs:findsecbugs-plugin to v1.14.0 ([#1422](https://github.com/open-feature/java-sdk/issues/1422)) ([495da27](https://github.com/open-feature/java-sdk/commit/495da271bee976a942973cd23012f60db895bf24))
|
||||
* **deps:** update dependency com.puppycrawl.tools:checkstyle to v10 ([#103](https://github.com/open-feature/java-sdk/issues/103)) ([3403510](https://github.com/open-feature/java-sdk/commit/34035105154b7945c02de2a88fe83eb2414526ef))
|
||||
* **deps:** update dependency com.tngtech.archunit:archunit-junit5 to v1.4.1 ([#1440](https://github.com/open-feature/java-sdk/issues/1440)) ([78657ee](https://github.com/open-feature/java-sdk/commit/78657ee79efdc94018387cdf8263a73d4abf7191))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.5 ([#1400](https://github.com/open-feature/java-sdk/issues/1400)) ([1f2d071](https://github.com/open-feature/java-sdk/commit/1f2d0715087ebd4554826d8552b250e4b8b950c8))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.5 ([#1401](https://github.com/open-feature/java-sdk/issues/1401)) ([07301bd](https://github.com/open-feature/java-sdk/commit/07301bda3f5b65550eff1e025fc9c0bec3c25275))
|
||||
* **deps:** update dependency org.apache.maven.plugins:maven-failsafe-plugin to v3.5.3 ([#1398](https://github.com/open-feature/java-sdk/issues/1398)) ([1fcf0e7](https://github.com/open-feature/java-sdk/commit/1fcf0e77d956c88c54e10942d96d2afd4d79315c))
|
||||
* **deps:** update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.5.3 ([#1399](https://github.com/open-feature/java-sdk/issues/1399)) ([d6ebc16](https://github.com/open-feature/java-sdk/commit/d6ebc161a93ad703e25592abdb0bf0fd9e281bbc))
|
||||
* **deps:** update dependency org.jacoco:jacoco-maven-plugin to v0.8.13 ([#1407](https://github.com/open-feature/java-sdk/issues/1407)) ([e19ccaa](https://github.com/open-feature/java-sdk/commit/e19ccaa35d9ac4d89d72ea58a70d416d202078db))
|
||||
* **deps:** update dependency org.mockito:mockito-core to v5.17.0 ([#1409](https://github.com/open-feature/java-sdk/issues/1409)) ([345cdcf](https://github.com/open-feature/java-sdk/commit/345cdcfa10da64c61d769746f335f38ac564e9ad))
|
||||
* **deps:** update github/codeql-action digest to 15bce5b ([#1443](https://github.com/open-feature/java-sdk/issues/1443)) ([bc10bac](https://github.com/open-feature/java-sdk/commit/bc10bacb5a68d0d2e498cb41c087505490f19de8))
|
||||
* **deps:** update github/codeql-action digest to 2a8cbad ([#1423](https://github.com/open-feature/java-sdk/issues/1423)) ([6b6849f](https://github.com/open-feature/java-sdk/commit/6b6849f3a3ee8a7b66d859c8e522bc101d1ccd44))
|
||||
* **deps:** update github/codeql-action digest to 362ef4c ([#1408](https://github.com/open-feature/java-sdk/issues/1408)) ([ca160ca](https://github.com/open-feature/java-sdk/commit/ca160cab7ccd71527e06a0851502353ac50b8d0d))
|
||||
* **deps:** update github/codeql-action digest to 40e16ed ([#1437](https://github.com/open-feature/java-sdk/issues/1437)) ([f965cbc](https://github.com/open-feature/java-sdk/commit/f965cbcb37d20724e15b76c15842a88574810b1a))
|
||||
* **deps:** update github/codeql-action digest to 4c3e536 ([#1417](https://github.com/open-feature/java-sdk/issues/1417)) ([0c77c84](https://github.com/open-feature/java-sdk/commit/0c77c8446032eaac7e068d48901e1423c21db326))
|
||||
* **deps:** update github/codeql-action digest to 4ffa236 ([#1425](https://github.com/open-feature/java-sdk/issues/1425)) ([a7828e7](https://github.com/open-feature/java-sdk/commit/a7828e73a8f2e30f71bd2d9d4da180b2fa436424))
|
||||
* **deps:** update github/codeql-action digest to 56dd02f ([#1416](https://github.com/open-feature/java-sdk/issues/1416)) ([4607c62](https://github.com/open-feature/java-sdk/commit/4607c62f15f7ee572207b8ec012ad4b3626e0184))
|
||||
* **deps:** update github/codeql-action digest to 5eb3ed6 ([#1439](https://github.com/open-feature/java-sdk/issues/1439)) ([f2348ea](https://github.com/open-feature/java-sdk/commit/f2348ea370412351389c60eef390f36edbea68b0))
|
||||
* **deps:** update github/codeql-action digest to 83605b3 ([#1435](https://github.com/open-feature/java-sdk/issues/1435)) ([7e74f2a](https://github.com/open-feature/java-sdk/commit/7e74f2aa3ad2dc8f7a3e4ad398e7705b3e3db364))
|
||||
* **deps:** update github/codeql-action digest to 97a2bfd ([#1438](https://github.com/open-feature/java-sdk/issues/1438)) ([85b200a](https://github.com/open-feature/java-sdk/commit/85b200a08b9f8a71de3b5a19eaa057ec04e0801e))
|
||||
* **deps:** update github/codeql-action digest to 9f45e74 ([#1396](https://github.com/open-feature/java-sdk/issues/1396)) ([37d76be](https://github.com/open-feature/java-sdk/commit/37d76be697e83f524250a82b2a67cdb4a953d7bc))
|
||||
* **deps:** update github/codeql-action digest to d26c46a ([#1413](https://github.com/open-feature/java-sdk/issues/1413)) ([5b327ee](https://github.com/open-feature/java-sdk/commit/5b327eeb770d0a4222f3599be79543b7bed9abc2))
|
||||
* **deps:** update github/codeql-action digest to dab8a02 ([#1405](https://github.com/open-feature/java-sdk/issues/1405)) ([5b2f151](https://github.com/open-feature/java-sdk/commit/5b2f1513ab75ef6692978830e59eba87ffa494d5))
|
||||
* **deps:** update github/codeql-action digest to e13fe0d ([#1406](https://github.com/open-feature/java-sdk/issues/1406)) ([e211397](https://github.com/open-feature/java-sdk/commit/e211397d517e1263e1251f9c99093bf05cecd93f))
|
||||
* **deps:** update github/codeql-action digest to ed51cb5 ([#1436](https://github.com/open-feature/java-sdk/issues/1436)) ([b09e887](https://github.com/open-feature/java-sdk/commit/b09e88798fed529161c61b96c20a8f257d355d3c))
|
||||
* **deps:** update github/codeql-action digest to efffb48 ([#1402](https://github.com/open-feature/java-sdk/issues/1402)) ([384953d](https://github.com/open-feature/java-sdk/commit/384953d30ecff83d60a2e5b9790e8228d1a52ac7))
|
||||
* **deps:** update github/codeql-action digest to f843d94 ([#1432](https://github.com/open-feature/java-sdk/issues/1432)) ([99faaf8](https://github.com/open-feature/java-sdk/commit/99faaf88aa07bd45fc473db5bafce3b8eafaf9e0))
|
||||
* **deps:** update io.cucumber.version to v7.22.0 ([#1410](https://github.com/open-feature/java-sdk/issues/1410)) ([3c69f2f](https://github.com/open-feature/java-sdk/commit/3c69f2f36c4e975d690ecc2e790df632a33001ba))
|
||||
* **deps:** update io.cucumber.version to v7.22.1 ([#1426](https://github.com/open-feature/java-sdk/issues/1426)) ([844374a](https://github.com/open-feature/java-sdk/commit/844374a42b94deffab6856e978766354a6f46576))
|
||||
* **deps:** update io.cucumber.version to v7.22.2 ([#1441](https://github.com/open-feature/java-sdk/issues/1441)) ([58454b4](https://github.com/open-feature/java-sdk/commit/58454b4eaabfd3327f7ceaff4bf335a5a839ed41))
|
||||
* **main:** release 1.15.0 ([#1431](https://github.com/open-feature/java-sdk/issues/1431)) ([7182a7f](https://github.com/open-feature/java-sdk/commit/7182a7fc4197e70218e829971dae2cff09f948c9))
|
||||
* update boostrap sha for release please ([f6bd30d](https://github.com/open-feature/java-sdk/commit/f6bd30db93e37e596d211d899315a62d9f810199))
|
||||
* update codeowners to give global maintainers code ownership ([#1412](https://github.com/open-feature/java-sdk/issues/1412)) ([498fd38](https://github.com/open-feature/java-sdk/commit/498fd382659669315b0db61db5f19ce054467bc9))
|
||||
* update release please action ([#1430](https://github.com/open-feature/java-sdk/issues/1430)) ([1cc851b](https://github.com/open-feature/java-sdk/commit/1cc851b293008a8dd273e904e4c77a650ad71146))
|
||||
* use PAT for release please ([014f8a5](https://github.com/open-feature/java-sdk/commit/014f8a59da8f1e976e440ed1ea17e85561f98e2d))
|
||||
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
* add try-catch example for setProviderAndWait usage ([#1433](https://github.com/open-feature/java-sdk/issues/1433)) ([96cf9c7](https://github.com/open-feature/java-sdk/commit/96cf9c7f5463e4e0de394117845aebdd9a69425f))
|
||||
|
||||
## [1.14.2](https://github.com/open-feature/java-sdk/compare/v1.14.1...v1.14.2) (2025-03-27)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
* **deps:** update dependency org.slf4j:slf4j-api to v2.0.17 ([#1348](https://github.com/open-feature/java-sdk/issues/1348)) ([2ec7c6c](https://github.com/open-feature/java-sdk/commit/2ec7c6c7ff704380fdfd8116378adf78734e4f2b))
|
||||
* **deps:** update junit5 monorepo ([#1344](https://github.com/open-feature/java-sdk/issues/1344)) ([d95e270](https://github.com/open-feature/java-sdk/commit/d95e2706532259bd5739e5b4ea4813ef9f2196a6))
|
||||
* **deps:** update junit5 monorepo ([#1373](https://github.com/open-feature/java-sdk/issues/1373)) ([6b65e26](https://github.com/open-feature/java-sdk/commit/6b65e26c7439895652c3f64f2b4a7307a7ca582e))
|
||||
* equals and hashcode of several classes ([69b571e](https://github.com/open-feature/java-sdk/commit/69b571eda73b6f43c99864420b8663ae54ebf0ad))
|
||||
* equals and hashcode of several classes ([#1364](https://github.com/open-feature/java-sdk/issues/1364)) ([69b571e](https://github.com/open-feature/java-sdk/commit/69b571eda73b6f43c99864420b8663ae54ebf0ad))
|
||||
* hooks not run in NOT_READY/FATAL ([#1392](https://github.com/open-feature/java-sdk/issues/1392)) ([24ef9dd](https://github.com/open-feature/java-sdk/commit/24ef9dd2903d01ec029b70cd1e39e71ffe327499))
|
||||
|
||||
|
||||
### 🧹 Chore
|
||||
|
||||
* **deps:** update actions/cache digest to 5a3ec84 ([#1380](https://github.com/open-feature/java-sdk/issues/1380)) ([8359ef1](https://github.com/open-feature/java-sdk/commit/8359ef13bb935ac1d144787cfd7181814a0b286c))
|
||||
* **deps:** update actions/cache digest to 7921ae2 ([#1337](https://github.com/open-feature/java-sdk/issues/1337)) ([3920c63](https://github.com/open-feature/java-sdk/commit/3920c638a49caddfb07041f812cc6bc0bf3101f9))
|
||||
* **deps:** update actions/cache digest to d4323d4 ([#1353](https://github.com/open-feature/java-sdk/issues/1353)) ([5901797](https://github.com/open-feature/java-sdk/commit/59017977a487a36c8a39f63b83299bc657134c0d))
|
||||
* **deps:** update actions/setup-java digest to 3b6c050 ([#1391](https://github.com/open-feature/java-sdk/issues/1391)) ([7536679](https://github.com/open-feature/java-sdk/commit/753667925a8803b3b227f762936ae397dde95484))
|
||||
* **deps:** update actions/setup-java digest to 799ee7c ([#1359](https://github.com/open-feature/java-sdk/issues/1359)) ([31444d6](https://github.com/open-feature/java-sdk/commit/31444d6c8f30f0dd35debacc9dab8da7397e11ed))
|
||||
* **deps:** update actions/setup-java digest to b8ebb8b ([#1381](https://github.com/open-feature/java-sdk/issues/1381)) ([2239f05](https://github.com/open-feature/java-sdk/commit/2239f054b90734dde6cdd4a23daec1c1daa96f07))
|
||||
* **deps:** update amannn/action-semantic-pull-request digest to 04501d4 ([#1390](https://github.com/open-feature/java-sdk/issues/1390)) ([87c06d9](https://github.com/open-feature/java-sdk/commit/87c06d9edd935287daf7ebc8db1e7da4831531de))
|
||||
* **deps:** update codecov/codecov-action action to v5.4.0 ([#1351](https://github.com/open-feature/java-sdk/issues/1351)) ([b133c2f](https://github.com/open-feature/java-sdk/commit/b133c2fa527a0dddb6de7f7781a00fc84feaa813))
|
||||
* **deps:** update dependency com.diffplug.spotless:spotless-maven-plugin to v2.44.3 ([#1341](https://github.com/open-feature/java-sdk/issues/1341)) ([5de33c0](https://github.com/open-feature/java-sdk/commit/5de33c02a675db6ca5966bfa3f58d99c8e53e36b))
|
||||
* **deps:** update dependency com.github.spotbugs:spotbugs-maven-plugin to v4.9.1.0 ([#1332](https://github.com/open-feature/java-sdk/issues/1332)) ([cdcdc14](https://github.com/open-feature/java-sdk/commit/cdcdc143ea5ad2f003cb3f5450ec78314e619ea3))
|
||||
* **deps:** update dependency com.github.spotbugs:spotbugs-maven-plugin to v4.9.2.0 ([#1360](https://github.com/open-feature/java-sdk/issues/1360)) ([ecea9df](https://github.com/open-feature/java-sdk/commit/ecea9df932ee4874613f219b73640fe964c99593))
|
||||
* **deps:** update dependency com.github.spotbugs:spotbugs-maven-plugin to v4.9.3.0 ([#1375](https://github.com/open-feature/java-sdk/issues/1375)) ([de3e213](https://github.com/open-feature/java-sdk/commit/de3e213ac8b8931121904a3d12929405512e74dd))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.2 ([#1355](https://github.com/open-feature/java-sdk/issues/1355)) ([2a1adca](https://github.com/open-feature/java-sdk/commit/2a1adca8c2ed8d61d51530969290793a5d3d15f3))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.3 ([#1384](https://github.com/open-feature/java-sdk/issues/1384)) ([b6becac](https://github.com/open-feature/java-sdk/commit/b6becac2c4e0f98a8651cc2f77d4c0b081548991))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.4 ([#1387](https://github.com/open-feature/java-sdk/issues/1387)) ([cb574d9](https://github.com/open-feature/java-sdk/commit/cb574d93b6210c89a188aa104ef4f1db68daf1c0))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.2 ([#1356](https://github.com/open-feature/java-sdk/issues/1356)) ([dd83114](https://github.com/open-feature/java-sdk/commit/dd83114c4d9389753575392fafcd56585d7178ae))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.3 ([#1385](https://github.com/open-feature/java-sdk/issues/1385)) ([4125ae8](https://github.com/open-feature/java-sdk/commit/4125ae83801a9f485059a9edaca090ee47b7632f))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.4 ([#1388](https://github.com/open-feature/java-sdk/issues/1388)) ([d8f6514](https://github.com/open-feature/java-sdk/commit/d8f6514598d53f43cb084ee746742a59d271363b))
|
||||
* **deps:** update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.14.0 ([#1342](https://github.com/open-feature/java-sdk/issues/1342)) ([88a778c](https://github.com/open-feature/java-sdk/commit/88a778cc03e112d45756428d1f0ae1ef0fe02c84))
|
||||
* **deps:** update dependency org.awaitility:awaitility to v4.3.0 ([#1343](https://github.com/open-feature/java-sdk/issues/1343)) ([1504d0f](https://github.com/open-feature/java-sdk/commit/1504d0f7982757a2b413eda593ce7057b90519e5))
|
||||
* **deps:** update dependency org.mockito:mockito-core to v5.15.2 ([#1339](https://github.com/open-feature/java-sdk/issues/1339)) ([4817864](https://github.com/open-feature/java-sdk/commit/4817864fd7ae70c1e19c3c09e82e1fb03dd88942))
|
||||
* **deps:** update dependency org.mockito:mockito-core to v5.16.0 ([#1358](https://github.com/open-feature/java-sdk/issues/1358)) ([30b6d00](https://github.com/open-feature/java-sdk/commit/30b6d004aaf3464547805f7eda6fad0e122de4f9))
|
||||
* **deps:** update dependency org.mockito:mockito-core to v5.16.1 ([#1376](https://github.com/open-feature/java-sdk/issues/1376)) ([9750f75](https://github.com/open-feature/java-sdk/commit/9750f75d04beb8339fc2e972f0ee97120eaff354))
|
||||
* **deps:** update github/codeql-action digest to 1bb15d0 ([#1336](https://github.com/open-feature/java-sdk/issues/1336)) ([e163ce1](https://github.com/open-feature/java-sdk/commit/e163ce1c060d0dc8812e4a8a3b37f52b0156324d))
|
||||
* **deps:** update github/codeql-action digest to 486ab5a ([#1389](https://github.com/open-feature/java-sdk/issues/1389)) ([85fd5e0](https://github.com/open-feature/java-sdk/commit/85fd5e0997ff1a5e5d7226d8bbfe2775769a6ca6))
|
||||
* **deps:** update github/codeql-action digest to 56b25d5 ([#1365](https://github.com/open-feature/java-sdk/issues/1365)) ([959e675](https://github.com/open-feature/java-sdk/commit/959e675e4c2363e5fd80d1d2f1edbfab11794fc8))
|
||||
* **deps:** update github/codeql-action digest to 608ccd6 ([#1361](https://github.com/open-feature/java-sdk/issues/1361)) ([67b34f8](https://github.com/open-feature/java-sdk/commit/67b34f84a373512013ab2f7649faaddfd2d61048))
|
||||
* **deps:** update github/codeql-action digest to 6349095 ([#1378](https://github.com/open-feature/java-sdk/issues/1378)) ([dbf92df](https://github.com/open-feature/java-sdk/commit/dbf92df33bf5657d50dc3b2f129207b0097c1f27))
|
||||
* **deps:** update github/codeql-action digest to 6a151cd ([#1377](https://github.com/open-feature/java-sdk/issues/1377)) ([7065655](https://github.com/open-feature/java-sdk/commit/706565581d78856dd73605b1a16b131f974c0731))
|
||||
* **deps:** update github/codeql-action digest to 70df9de ([#1372](https://github.com/open-feature/java-sdk/issues/1372)) ([d233480](https://github.com/open-feature/java-sdk/commit/d233480912f1d5e095f5034f36a838535d1ecdff))
|
||||
* **deps:** update github/codeql-action digest to 7254660 ([#1368](https://github.com/open-feature/java-sdk/issues/1368)) ([d54c68a](https://github.com/open-feature/java-sdk/commit/d54c68a8e9e4a0f67c99e7d76621a1c5724e4cd1))
|
||||
* **deps:** update github/codeql-action digest to 80f9930 ([#1357](https://github.com/open-feature/java-sdk/issues/1357)) ([6c03e5d](https://github.com/open-feature/java-sdk/commit/6c03e5d84aacee11f5b8e608a6114c11fced72b8))
|
||||
* **deps:** update github/codeql-action digest to 8392354 ([#1352](https://github.com/open-feature/java-sdk/issues/1352)) ([989f4ae](https://github.com/open-feature/java-sdk/commit/989f4ae54263b46ca2c81561acc70b39918c382d))
|
||||
* **deps:** update github/codeql-action digest to 8c1551c ([#1333](https://github.com/open-feature/java-sdk/issues/1333)) ([859a36c](https://github.com/open-feature/java-sdk/commit/859a36cbfafc94d4601b87d304237e6ddf97c08d))
|
||||
* **deps:** update github/codeql-action digest to 8c69433 ([#1347](https://github.com/open-feature/java-sdk/issues/1347)) ([6987568](https://github.com/open-feature/java-sdk/commit/698756856ba40e98d91ccf661dab409798861aa5))
|
||||
* **deps:** update github/codeql-action digest to 97aac9b ([#1350](https://github.com/open-feature/java-sdk/issues/1350)) ([7df9565](https://github.com/open-feature/java-sdk/commit/7df9565691731d164b534116b8a6b933b171d103))
|
||||
* **deps:** update github/codeql-action digest to a8849fb ([#1345](https://github.com/open-feature/java-sdk/issues/1345)) ([de64edd](https://github.com/open-feature/java-sdk/commit/de64eddfb3a6cc117bb108dbcf167830e9f6729d))
|
||||
* **deps:** update github/codeql-action digest to acadfed ([#1335](https://github.com/open-feature/java-sdk/issues/1335)) ([5436eb0](https://github.com/open-feature/java-sdk/commit/5436eb0d5db3a0e9bd9289fbef57b9eeada0a667))
|
||||
* **deps:** update github/codeql-action digest to b2e6519 ([#1366](https://github.com/open-feature/java-sdk/issues/1366)) ([d00e4b5](https://github.com/open-feature/java-sdk/commit/d00e4b5b24621aa55085827fbe6ea982491376de))
|
||||
* **deps:** update github/codeql-action digest to b46b37a ([#1367](https://github.com/open-feature/java-sdk/issues/1367)) ([c550d59](https://github.com/open-feature/java-sdk/commit/c550d597227bfc1e0e17357139f1fd8a87593be0))
|
||||
* **deps:** update github/codeql-action digest to bd1d9ab ([#1383](https://github.com/open-feature/java-sdk/issues/1383)) ([922e17e](https://github.com/open-feature/java-sdk/commit/922e17e677e15690e3df2fe93a961f16f21ff283))
|
||||
* **deps:** update github/codeql-action digest to c50c157 ([#1379](https://github.com/open-feature/java-sdk/issues/1379)) ([d61c33e](https://github.com/open-feature/java-sdk/commit/d61c33e466336c7120b870ca5e3843eba5f7175c))
|
||||
* **deps:** update github/codeql-action digest to d99c7e8 ([#1338](https://github.com/open-feature/java-sdk/issues/1338)) ([4e535fd](https://github.com/open-feature/java-sdk/commit/4e535fd10fac742ca472faa62c941fa51b282ca7))
|
||||
* **deps:** update github/codeql-action digest to dc49dca ([#1369](https://github.com/open-feature/java-sdk/issues/1369)) ([f8df5fb](https://github.com/open-feature/java-sdk/commit/f8df5fb84a765af917587dd509f9cec38103f787))
|
||||
* **deps:** update github/codeql-action digest to e0ea141 ([#1386](https://github.com/open-feature/java-sdk/issues/1386)) ([387e5f2](https://github.com/open-feature/java-sdk/commit/387e5f2e3bd24ccea6691b0d6dbfe542cfd05b52))
|
||||
* **deps:** update github/codeql-action digest to ff79de6 ([#1340](https://github.com/open-feature/java-sdk/issues/1340)) ([50b45b2](https://github.com/open-feature/java-sdk/commit/50b45b2be442bb89a431c9bcc45d825f63bd93a6))
|
||||
* update build and tooling to utilize new java version ([#1321](https://github.com/open-feature/java-sdk/issues/1321)) ([90217b2](https://github.com/open-feature/java-sdk/commit/90217b2083a2ba92c623365dc450326d49b46fab))
|
||||
|
||||
## [1.14.1](https://github.com/open-feature/java-sdk/compare/v1.14.0...v1.14.1) (2025-02-14)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
* **deps:** update dependency io.cucumber:cucumber-bom to v7.21.0 ([#1312](https://github.com/open-feature/java-sdk/issues/1312)) ([208411e](https://github.com/open-feature/java-sdk/commit/208411e72338e37bf477ac0b784bbbbe0309b922))
|
||||
* **deps:** update dependency io.cucumber:cucumber-bom to v7.21.1 ([#1317](https://github.com/open-feature/java-sdk/issues/1317)) ([b797883](https://github.com/open-feature/java-sdk/commit/b7978832b786fe081169ff0efeb702218300c622))
|
||||
* possible event-related deadlocks with some providers ([#1314](https://github.com/open-feature/java-sdk/issues/1314)) ([c33ac2d](https://github.com/open-feature/java-sdk/commit/c33ac2d9b2e91b85fffb3c21653912fe82006351))
|
||||
* TrackingEventDetails interface to include numeric getValue() call ([#1328](https://github.com/open-feature/java-sdk/issues/1328)) ([08c38fb](https://github.com/open-feature/java-sdk/commit/08c38fb553d82a42682c3eb9239329f770063898))
|
||||
|
||||
|
||||
### 🧹 Chore
|
||||
|
||||
* **deps:** update actions/cache digest to 9fa7e61 ([#1324](https://github.com/open-feature/java-sdk/issues/1324)) ([69cdc77](https://github.com/open-feature/java-sdk/commit/69cdc772a639470dd223bf70ef6e9f8bc4d93dea))
|
||||
* **deps:** update actions/checkout digest to 85e6279 ([#1287](https://github.com/open-feature/java-sdk/issues/1287)) ([640e35e](https://github.com/open-feature/java-sdk/commit/640e35e85375e3098f61b7397432d80a95502bdd))
|
||||
* **deps:** update actions/setup-java digest to 28b532b ([#1296](https://github.com/open-feature/java-sdk/issues/1296)) ([874e86d](https://github.com/open-feature/java-sdk/commit/874e86df5c22a1e5771ca16c76aa13039b5f9b65))
|
||||
* **deps:** update actions/setup-java digest to 3a4f6e1 ([#1306](https://github.com/open-feature/java-sdk/issues/1306)) ([ba9cc4b](https://github.com/open-feature/java-sdk/commit/ba9cc4b85a1082d638d49b9d2d0a4ed5a45f09ee))
|
||||
* **deps:** update actions/setup-java digest to 51ab6d2 ([#1288](https://github.com/open-feature/java-sdk/issues/1288)) ([c69d3a4](https://github.com/open-feature/java-sdk/commit/c69d3a4bd137c1d6baa47c14228bfe8f96555676))
|
||||
* **deps:** update actions/setup-java digest to 99d3141 ([#1285](https://github.com/open-feature/java-sdk/issues/1285)) ([32a3933](https://github.com/open-feature/java-sdk/commit/32a39335de8e61650905fc96dc1a73e65f1fe9f8))
|
||||
* **deps:** update codecov/codecov-action action to v5.2.0 ([#1298](https://github.com/open-feature/java-sdk/issues/1298)) ([531fc38](https://github.com/open-feature/java-sdk/commit/531fc385b662c5b7b334fee298fc9fe1283c78fb))
|
||||
* **deps:** update codecov/codecov-action action to v5.3.0 ([#1301](https://github.com/open-feature/java-sdk/issues/1301)) ([f7f6586](https://github.com/open-feature/java-sdk/commit/f7f6586d72e3f112a7dafc8f77de273ed49ccc4b))
|
||||
* **deps:** update codecov/codecov-action action to v5.3.1 ([#1303](https://github.com/open-feature/java-sdk/issues/1303)) ([f9fa54b](https://github.com/open-feature/java-sdk/commit/f9fa54be493e1d0843b709008eb0f047e7580d47))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.16.0 ([#1289](https://github.com/open-feature/java-sdk/issues/1289)) ([0b5b423](https://github.com/open-feature/java-sdk/commit/0b5b423bdd378bb1db3e10fe5da7fa2c937a4610))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.16.1 ([#1292](https://github.com/open-feature/java-sdk/issues/1292)) ([0af9f29](https://github.com/open-feature/java-sdk/commit/0af9f2901f88b5ef9bed0c570d426939a55af3cf))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.0 ([#1309](https://github.com/open-feature/java-sdk/issues/1309)) ([cda3405](https://github.com/open-feature/java-sdk/commit/cda34053f7e39318205a181ef93c825bab2ed9fc))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.17.1 ([#1329](https://github.com/open-feature/java-sdk/issues/1329)) ([9ab2618](https://github.com/open-feature/java-sdk/commit/9ab26182eae4974b60d166777c51dfcb07957150))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.16.0 ([#1290](https://github.com/open-feature/java-sdk/issues/1290)) ([6c4205a](https://github.com/open-feature/java-sdk/commit/6c4205a00817af260ef9b90f54ce878cad33f75a))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.16.1 ([#1293](https://github.com/open-feature/java-sdk/issues/1293)) ([6071932](https://github.com/open-feature/java-sdk/commit/6071932cb4207dc83cdedfa67c8a69ed71d9c26a))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.0 ([#1310](https://github.com/open-feature/java-sdk/issues/1310)) ([40fa173](https://github.com/open-feature/java-sdk/commit/40fa1733382f4c476a1228c6499044ad83c8f3c4))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.17.1 ([#1330](https://github.com/open-feature/java-sdk/issues/1330)) ([4ba5695](https://github.com/open-feature/java-sdk/commit/4ba5695eeea6a7ab2fe1d2c595fa482d4b7868dc))
|
||||
* **deps:** update dependency org.assertj:assertj-core to v3.27.3 ([#1291](https://github.com/open-feature/java-sdk/issues/1291)) ([a5eb21d](https://github.com/open-feature/java-sdk/commit/a5eb21d1a2e6945a4455cacde898bc913bddb96d))
|
||||
* **deps:** update github/codeql-action digest to 0701025 ([#1311](https://github.com/open-feature/java-sdk/issues/1311)) ([9a1e9ab](https://github.com/open-feature/java-sdk/commit/9a1e9abd64220c8d8706f2a64e041ef3f37e1a43))
|
||||
* **deps:** update github/codeql-action digest to 08bc0cf ([#1313](https://github.com/open-feature/java-sdk/issues/1313)) ([37ed6a4](https://github.com/open-feature/java-sdk/commit/37ed6a424cdc013ed74c9881826cc56c93ae8228))
|
||||
* **deps:** update github/codeql-action digest to 0a35e8f ([#1316](https://github.com/open-feature/java-sdk/issues/1316)) ([26e1d7f](https://github.com/open-feature/java-sdk/commit/26e1d7fff342a32880542efa87b017aec506667e))
|
||||
* **deps:** update github/codeql-action digest to 0f1559a ([#1286](https://github.com/open-feature/java-sdk/issues/1286)) ([882d2dd](https://github.com/open-feature/java-sdk/commit/882d2dd5bdac007e8a3783efc54fa45faed22054))
|
||||
* **deps:** update github/codeql-action digest to 10a3f07 ([#1280](https://github.com/open-feature/java-sdk/issues/1280)) ([a3854d6](https://github.com/open-feature/java-sdk/commit/a3854d6ab1dba99f4db18f868e89fcc04418e306))
|
||||
* **deps:** update github/codeql-action digest to 1c15a48 ([#1325](https://github.com/open-feature/java-sdk/issues/1325)) ([3baf0df](https://github.com/open-feature/java-sdk/commit/3baf0df966f8212864aa7e57bc3d3d09d324fe11))
|
||||
* **deps:** update github/codeql-action digest to 1efc6bb ([#1281](https://github.com/open-feature/java-sdk/issues/1281)) ([8a1ab7e](https://github.com/open-feature/java-sdk/commit/8a1ab7ea18aff4ee5a6a2fdd1f805b08e51a50a3))
|
||||
* **deps:** update github/codeql-action digest to 24e1c2d ([#1315](https://github.com/open-feature/java-sdk/issues/1315)) ([46903c6](https://github.com/open-feature/java-sdk/commit/46903c6f275e5f9dc8884acf3f76f76efcfc58bd))
|
||||
* **deps:** update github/codeql-action digest to 3b4f4d9 ([#1282](https://github.com/open-feature/java-sdk/issues/1282)) ([b390d5f](https://github.com/open-feature/java-sdk/commit/b390d5f0b0945948cd6b87e6486725d095d5ac8a))
|
||||
* **deps:** update github/codeql-action digest to 43cffee ([#1304](https://github.com/open-feature/java-sdk/issues/1304)) ([6874de6](https://github.com/open-feature/java-sdk/commit/6874de64ce589e853f5523019bfa9e1d60840baf))
|
||||
* **deps:** update github/codeql-action digest to 54b1c84 ([#1307](https://github.com/open-feature/java-sdk/issues/1307)) ([6f36434](https://github.com/open-feature/java-sdk/commit/6f36434c520dcef27deb04e04941693dc15acb2f))
|
||||
* **deps:** update github/codeql-action digest to 5f4f998 ([#1305](https://github.com/open-feature/java-sdk/issues/1305)) ([7916d76](https://github.com/open-feature/java-sdk/commit/7916d76635c5ab59dafe6d72058aad9cfcf05f4b))
|
||||
* **deps:** update github/codeql-action digest to 6063925 ([#1320](https://github.com/open-feature/java-sdk/issues/1320)) ([538140d](https://github.com/open-feature/java-sdk/commit/538140dfe713a421623b179e69b399f82200fe61))
|
||||
* **deps:** update github/codeql-action digest to 7e3036b ([#1300](https://github.com/open-feature/java-sdk/issues/1300)) ([3491956](https://github.com/open-feature/java-sdk/commit/34919561b73faa0cca489ad480e93cca9a854167))
|
||||
* **deps:** update github/codeql-action digest to 87fc816 ([#1277](https://github.com/open-feature/java-sdk/issues/1277)) ([c2a82db](https://github.com/open-feature/java-sdk/commit/c2a82dbdbafa134fae4b0c9aef88cf589e09aefa))
|
||||
* **deps:** update github/codeql-action digest to 93da9f2 ([#1283](https://github.com/open-feature/java-sdk/issues/1283)) ([45b3995](https://github.com/open-feature/java-sdk/commit/45b3995bdad9f1b05abb01455a9c8f57028cfde5))
|
||||
* **deps:** update github/codeql-action digest to affec20 ([#1323](https://github.com/open-feature/java-sdk/issues/1323)) ([8f3ced5](https://github.com/open-feature/java-sdk/commit/8f3ced590764760244cc81ac10c939ca62504dfe))
|
||||
* **deps:** update github/codeql-action digest to b44b19f ([#1297](https://github.com/open-feature/java-sdk/issues/1297)) ([305e032](https://github.com/open-feature/java-sdk/commit/305e0329e78116fe697240e420879ac85012d698))
|
||||
* **deps:** update github/codeql-action digest to d90e07f ([#1294](https://github.com/open-feature/java-sdk/issues/1294)) ([5671184](https://github.com/open-feature/java-sdk/commit/5671184e7f76f979d631c18bb2ebfb15dccfb207))
|
||||
* **deps:** update github/codeql-action digest to db7177a ([#1279](https://github.com/open-feature/java-sdk/issues/1279)) ([b997946](https://github.com/open-feature/java-sdk/commit/b997946db1c7663b7ebb775ad45cdb2b0aaeb291))
|
||||
* **deps:** update github/codeql-action digest to e7c0c9d ([#1302](https://github.com/open-feature/java-sdk/issues/1302)) ([78adc77](https://github.com/open-feature/java-sdk/commit/78adc77c23da6116e1f58b3a45dc283c3c58837b))
|
||||
* **deps:** update github/codeql-action digest to e9987ad ([#1308](https://github.com/open-feature/java-sdk/issues/1308)) ([99d8185](https://github.com/open-feature/java-sdk/commit/99d818572a3407ca6b25f6e91f69ef3e83bdc657))
|
||||
* **deps:** update github/codeql-action digest to f89b8a7 ([#1295](https://github.com/open-feature/java-sdk/issues/1295)) ([122e82f](https://github.com/open-feature/java-sdk/commit/122e82f8431fb116ae3b147f7e2245d7f90b1c77))
|
||||
|
||||
## [1.14.0](https://github.com/open-feature/java-sdk/compare/v1.13.0...v1.14.0) (2025-01-10)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
The signature of the `finallyAfter` hook stage has been changed. The signature now includes the `evaluation details`, as per the [OpenFeature specification](https://openfeature.dev/specification/sections/hooks#requirement-438). Note that since hooks are still `experimental,` this does not constitute a change requiring a new major version. To migrate, update any hook that implements the `finallyAfter` stage to accept `evaluation details` as the second argument.
|
||||
|
||||
* Add evaluation details to finally hook stage [#1246](https://github.com/open-feature/java-sdk/issues/1246) ([#1262](https://github.com/open-feature/java-sdk/issues/1262)) ([ae85278](https://github.com/open-feature/java-sdk/commit/ae85278c30eb5279b80ea73ec6b92db040ad0bb7))
|
||||
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
* **deps:** update junit5 monorepo ([#1251](https://github.com/open-feature/java-sdk/issues/1251)) ([834f720](https://github.com/open-feature/java-sdk/commit/834f72071806680353f42c750b04e36956736a9e))
|
||||
|
||||
|
||||
### ✨ New Features
|
||||
|
||||
* Add evaluation details to finally hook stage [#1246](https://github.com/open-feature/java-sdk/issues/1246) ([#1262](https://github.com/open-feature/java-sdk/issues/1262)) ([ae85278](https://github.com/open-feature/java-sdk/commit/ae85278c30eb5279b80ea73ec6b92db040ad0bb7))
|
||||
|
||||
|
||||
### 🧹 Chore
|
||||
|
||||
* **deps:** update actions/cache digest to 36f1e14 ([#1274](https://github.com/open-feature/java-sdk/issues/1274)) ([d825ff8](https://github.com/open-feature/java-sdk/commit/d825ff83639a2bd902bf0559209c2b80e17e0316))
|
||||
* **deps:** update actions/cache digest to 53aa38c ([#1270](https://github.com/open-feature/java-sdk/issues/1270)) ([a1c558f](https://github.com/open-feature/java-sdk/commit/a1c558f4ffb95772bd141ab7660e2c5b065482f1))
|
||||
* **deps:** update actions/setup-java digest to 7136edc ([#1244](https://github.com/open-feature/java-sdk/issues/1244)) ([9acc861](https://github.com/open-feature/java-sdk/commit/9acc8612a5fa7ea086da476195154a007cb55b7e))
|
||||
* **deps:** update actions/setup-java digest to 7a6d8a8 ([#1248](https://github.com/open-feature/java-sdk/issues/1248)) ([86e18c5](https://github.com/open-feature/java-sdk/commit/86e18c5d28a9f5fdd7234274720ba7ddcb529268))
|
||||
* **deps:** update codecov/codecov-action action to v5.1.2 ([#1255](https://github.com/open-feature/java-sdk/issues/1255)) ([d274cda](https://github.com/open-feature/java-sdk/commit/d274cdac3780286a0b45865864b12c3e4cff9f4b))
|
||||
* **deps:** update dependency com.google.guava:guava to v33.4.0-jre ([#1253](https://github.com/open-feature/java-sdk/issues/1253)) ([f39c4b5](https://github.com/open-feature/java-sdk/commit/f39c4b5af5e341bfec230d4cecd2037fc5430400))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy to v1.15.11 ([#1249](https://github.com/open-feature/java-sdk/issues/1249)) ([4440cda](https://github.com/open-feature/java-sdk/commit/4440cda6a5b42a903ba11835a975bf6247de845f))
|
||||
* **deps:** update dependency net.bytebuddy:byte-buddy-agent to v1.15.11 ([#1250](https://github.com/open-feature/java-sdk/issues/1250)) ([6772d3f](https://github.com/open-feature/java-sdk/commit/6772d3f3943fb3b7f7522c80b732aa058fd03bb9))
|
||||
* **deps:** update dependency org.assertj:assertj-core to v3.27.0 ([#1258](https://github.com/open-feature/java-sdk/issues/1258)) ([c62ade3](https://github.com/open-feature/java-sdk/commit/c62ade3878dabf9194536d551f3316ba5c0ce5e1))
|
||||
* **deps:** update dependency org.assertj:assertj-core to v3.27.1 ([#1266](https://github.com/open-feature/java-sdk/issues/1266)) ([20bbb23](https://github.com/open-feature/java-sdk/commit/20bbb2337cb5afbee9b8d5143b45416673cb4154))
|
||||
* **deps:** update dependency org.assertj:assertj-core to v3.27.2 ([#1268](https://github.com/open-feature/java-sdk/issues/1268)) ([2e10d34](https://github.com/open-feature/java-sdk/commit/2e10d34920f57d863c09ce1522c9ccff20413f74))
|
||||
* **deps:** update github/codeql-action digest to 3407610 ([#1269](https://github.com/open-feature/java-sdk/issues/1269)) ([4086dea](https://github.com/open-feature/java-sdk/commit/4086dea703a950dcacc792be9a9346cc1fa8409d))
|
||||
* **deps:** update github/codeql-action digest to 4d64ab6 ([#1243](https://github.com/open-feature/java-sdk/issues/1243)) ([884f8fb](https://github.com/open-feature/java-sdk/commit/884f8fbf77c41e070526da0f73e136d4c3e41a4d))
|
||||
* **deps:** update github/codeql-action digest to 562042d ([#1254](https://github.com/open-feature/java-sdk/issues/1254)) ([6a79874](https://github.com/open-feature/java-sdk/commit/6a7987455ef7e46d40b835c7d8dbda29322e3b2d))
|
||||
* **deps:** update github/codeql-action digest to 5b6e617 ([#1263](https://github.com/open-feature/java-sdk/issues/1263)) ([f1817d8](https://github.com/open-feature/java-sdk/commit/f1817d8fef585f957de1cfb9222b03cb591ed2e9))
|
||||
* **deps:** update github/codeql-action digest to 64cc90b ([#1256](https://github.com/open-feature/java-sdk/issues/1256)) ([992c003](https://github.com/open-feature/java-sdk/commit/992c00396cb2fca6a6a7dc63d727b063a79386b6))
|
||||
* **deps:** update github/codeql-action digest to 7876007 ([#1260](https://github.com/open-feature/java-sdk/issues/1260)) ([fc6f35e](https://github.com/open-feature/java-sdk/commit/fc6f35e581cacb0ad149c58a5943ec1429ce25ca))
|
||||
* **deps:** update github/codeql-action digest to 78d0136 ([#1245](https://github.com/open-feature/java-sdk/issues/1245)) ([fd1c170](https://github.com/open-feature/java-sdk/commit/fd1c1702c6d4067c432c1522143266ddf470d18d))
|
||||
* **deps:** update github/codeql-action digest to 8975792 ([#1241](https://github.com/open-feature/java-sdk/issues/1241)) ([b0abfd0](https://github.com/open-feature/java-sdk/commit/b0abfd02cf9e97f7409df3296818ac990b429058))
|
||||
* **deps:** update github/codeql-action digest to 9d59969 ([#1252](https://github.com/open-feature/java-sdk/issues/1252)) ([482a5ae](https://github.com/open-feature/java-sdk/commit/482a5aef1005b2ebe2fdb9ee43243b6c2aeeadc8))
|
||||
* **deps:** update github/codeql-action digest to d01b25e ([#1257](https://github.com/open-feature/java-sdk/issues/1257)) ([6d60c96](https://github.com/open-feature/java-sdk/commit/6d60c962fbac48a13d86271b361fb0cfd91a5342))
|
||||
* **deps:** update github/codeql-action digest to dd75594 ([#1247](https://github.com/open-feature/java-sdk/issues/1247)) ([6d169f5](https://github.com/open-feature/java-sdk/commit/6d169f55e235a071033a9bf1138484f09a5e472d))
|
||||
* **deps:** update github/codeql-action digest to e83e0a4 ([#1275](https://github.com/open-feature/java-sdk/issues/1275)) ([9c92ebb](https://github.com/open-feature/java-sdk/commit/9c92ebb1bdb23c80461f143753f2fb42956462e3))
|
||||
* **deps:** update github/codeql-action digest to fb65b6c ([#1273](https://github.com/open-feature/java-sdk/issues/1273)) ([3c97b7b](https://github.com/open-feature/java-sdk/commit/3c97b7baaf9eee719479c059cb923d8d64f2c25f))
|
||||
|
||||
## [1.13.0](https://github.com/open-feature/java-sdk/compare/v1.12.2...v1.13.0) (2024-12-07)
|
||||
|
||||
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
#
|
||||
# Managed by Peribolos: https://github.com/open-feature/community/blob/main/config/open-feature/sdk-java/workgroup.yaml
|
||||
#
|
||||
* @open-feature/sdk-java-maintainers
|
||||
* @open-feature/sdk-java-maintainers @open-feature/maintainers
|
||||
|
|
|
@ -21,6 +21,38 @@ If you think we might be out of date with the spec, you can check that by invoki
|
|||
|
||||
If you're adding tests to cover something in the spec, use the `@Specification` annotation like you see throughout the test suites.
|
||||
|
||||
## Code Styles
|
||||
|
||||
### Overview
|
||||
Our project follows strict code formatting standards to maintain consistency and readability across the codebase. We use [Spotless](https://github.com/diffplug/spotless) integrated with the [Palantir Java Format](https://github.com/palantir/palantir-java-format) for code formatting.
|
||||
|
||||
**Spotless** ensures that all code complies with the formatting rules automatically, reducing style-related issues during code reviews.
|
||||
|
||||
### How to Format Your Code
|
||||
1. **Before Committing Changes:**
|
||||
Run the Spotless plugin to format your code. This will apply the Palantir Java Format style:
|
||||
```bash
|
||||
mvn spotless:apply
|
||||
```
|
||||
|
||||
2. **Verify Formatting:**
|
||||
To check if your code adheres to the style guidelines without making changes:
|
||||
```bash
|
||||
mvn spotless:check
|
||||
```
|
||||
|
||||
- If this command fails, your code does not follow the required formatting. Use `mvn spotless:apply` to fix it.
|
||||
|
||||
### CI/CD Integration
|
||||
Our Continuous Integration (CI) pipeline automatically checks code formatting using the Spotless plugin. Any code that does not pass the `spotless:check` step will cause the build to fail.
|
||||
|
||||
### Best Practices
|
||||
- Regularly run `mvn spotless:apply` during your work to ensure your code remains aligned with the standards.
|
||||
- Configure your IDE (e.g., IntelliJ IDEA or Eclipse) to follow the Palantir Java format guidelines to reduce discrepancies during development.
|
||||
|
||||
### Support
|
||||
If you encounter issues with code formatting, please raise a GitHub issue or contact the maintainers.
|
||||
|
||||
## End-to-End Tests
|
||||
|
||||
The continuous integration runs a set of [gherkin e2e tests](https://github.com/open-feature/spec/blob/main/specification/assets/gherkin/evaluation.feature) using `InMemoryProvider`.
|
||||
|
|
26
README.md
26
README.md
|
@ -18,8 +18,8 @@
|
|||
</a>
|
||||
<!-- x-release-please-start-version -->
|
||||
|
||||
<a href="https://github.com/open-feature/java-sdk/releases/tag/v1.13.0">
|
||||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.13.0&color=blue&style=for-the-badge" />
|
||||
<a href="https://github.com/open-feature/java-sdk/releases/tag/v1.16.0">
|
||||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.16.0&color=blue&style=for-the-badge" />
|
||||
</a>
|
||||
|
||||
<!-- x-release-please-end -->
|
||||
|
@ -46,7 +46,7 @@
|
|||
|
||||
### Requirements
|
||||
|
||||
- Java 8+ (compiler target is 1.8)
|
||||
- Java 11+ (compiler target is 11)
|
||||
|
||||
Note that this library is intended to be used in server-side contexts and has not been evaluated for use on mobile devices.
|
||||
|
||||
|
@ -59,7 +59,7 @@ Note that this library is intended to be used in server-side contexts and has no
|
|||
<dependency>
|
||||
<groupId>dev.openfeature</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.16.0</version>
|
||||
</dependency>
|
||||
```
|
||||
<!-- x-release-please-end-version -->
|
||||
|
@ -84,7 +84,7 @@ If you would like snapshot builds, this is the relevant repository information:
|
|||
<!-- x-release-please-start-version -->
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'dev.openfeature:sdk:1.13.0'
|
||||
implementation 'dev.openfeature:sdk:1.16.0'
|
||||
}
|
||||
```
|
||||
<!-- x-release-please-end-version -->
|
||||
|
@ -104,7 +104,12 @@ public void example(){
|
|||
|
||||
// configure a provider
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new InMemoryProvider(myFlags));
|
||||
try {
|
||||
api.setProviderAndWait(new InMemoryProvider(myFlags));
|
||||
} catch (Exception e) {
|
||||
// handle initialization failure
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// create a client
|
||||
Client client = api.getClient();
|
||||
|
@ -149,7 +154,12 @@ To register a provider in a blocking manner to ensure it is ready before further
|
|||
|
||||
```java
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new MyProvider());
|
||||
try {
|
||||
api.setProviderAndWait(new MyProvider());
|
||||
} catch (Exception e) {
|
||||
// handle initialization failure
|
||||
e.printStackTrace();
|
||||
}
|
||||
```
|
||||
|
||||
#### Asynchronous
|
||||
|
@ -426,7 +436,7 @@ class MyHook implements Hook {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void finallyAfter(HookContext ctx, Map hints) {
|
||||
public void finallyAfter(HookContext ctx, FlagEvaluationDetails details, Map hints) {
|
||||
// code that runs regardless of success or error
|
||||
}
|
||||
};
|
||||
|
|
261
checkstyle.xml
261
checkstyle.xml
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
|
||||
<!--
|
||||
Checkstyle configuration that checks the Google coding conventions from Google Java Style
|
||||
|
@ -13,17 +13,18 @@
|
|||
To completely disable a check, just comment it out or delete it from the file.
|
||||
To suppress certain violations please review suppression filters.
|
||||
|
||||
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
|
||||
Authors: Max Vetrenko, Mauryan Kansara, Ruslan Diachenko, Roman Ivanov.
|
||||
-->
|
||||
|
||||
<module name = "Checker">
|
||||
<module name="Checker">
|
||||
|
||||
<property name="charset" value="UTF-8"/>
|
||||
|
||||
<property name="severity" value="error"/>
|
||||
|
||||
<property name="fileExtensions" value="java, properties, xml"/>
|
||||
<!-- Excludes all 'module-info.java' files -->
|
||||
<!-- See https://checkstyle.org/config_filefilters.html -->
|
||||
<!-- See https://checkstyle.org/filefilters/index.html -->
|
||||
<module name="BeforeExecutionExclusionFileFilter">
|
||||
<property name="fileNamePattern" value="module\-info\.java$"/>
|
||||
</module>
|
||||
|
@ -34,9 +35,16 @@
|
|||
<property name="optional" value="true"/>
|
||||
</module>
|
||||
|
||||
<!-- https://checkstyle.org/filters/suppresswithnearbytextfilter.html -->
|
||||
<!--<module name="SuppressWithNearbyTextFilter">
|
||||
<property name="nearbyTextPattern"
|
||||
value="CHECKSTYLE.SUPPRESS\: (\w+) for ([+-]\d+) lines"/>
|
||||
<property name="checkPattern" value="$1"/>
|
||||
<property name="lineRange" value="$2"/>
|
||||
</module>-->
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.org/config_whitespace.html -->
|
||||
<!-- See http://checkstyle.org/checks/whitespace/index.html -->
|
||||
<module name="FileTabCharacter">
|
||||
<property name="eachLine" value="true"/>
|
||||
</module>
|
||||
|
@ -52,7 +60,7 @@
|
|||
<module name="TreeWalker">
|
||||
<!-- needed for SuppressWarningsFilter -->
|
||||
<module name="SuppressWarningsHolder" />
|
||||
|
||||
|
||||
<module name="SuppressWarnings">
|
||||
<property name="id" value="checkstyle:suppresswarnings"/>
|
||||
</module>
|
||||
|
@ -69,48 +77,68 @@
|
|||
<module name="IllegalTokenText">
|
||||
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
|
||||
<property name="format"
|
||||
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
||||
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
||||
<property name="message"
|
||||
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
|
||||
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
|
||||
</module>
|
||||
<module name="AvoidEscapedUnicodeCharacters">
|
||||
<property name="allowEscapesForControlCharacters" value="true"/>
|
||||
<property name="allowByTailComment" value="true"/>
|
||||
<property name="allowNonPrintableEscapes" value="true"/>
|
||||
</module>
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="OneTopLevelClass"/>
|
||||
<module name="NoLineWrap">
|
||||
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
|
||||
</module>
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="TEXT"/>
|
||||
<property name="tokens"
|
||||
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
|
||||
</module>
|
||||
<module name="NeedBraces">
|
||||
<property name="tokens"
|
||||
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
|
||||
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
|
||||
</module>
|
||||
<module name="LeftCurly">
|
||||
<property name="id" value="LeftCurlyEol"/>
|
||||
<property name="tokens"
|
||||
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
|
||||
INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT,
|
||||
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF,
|
||||
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF,
|
||||
OBJBLOCK, STATIC_INIT"/>
|
||||
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
|
||||
INTERFACE_DEF, LITERAL_CATCH,
|
||||
LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF,
|
||||
LITERAL_WHILE, METHOD_DEF,
|
||||
OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="LeftCurly">
|
||||
<property name="id" value="LeftCurlyNl"/>
|
||||
<property name="option" value="nl"/>
|
||||
<property name="tokens"
|
||||
value=" LITERAL_DEFAULT"/>
|
||||
</module>
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<!-- LITERAL_DEFAULT are reused in SWITCH_RULE -->
|
||||
<property name="id" value="LeftCurlyNl"/>
|
||||
<property name="query" value="//SWITCH_RULE/SLIST"/>
|
||||
</module>
|
||||
<module name="RightCurly">
|
||||
<property name="id" value="RightCurlySame"/>
|
||||
<property name="tokens"
|
||||
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
|
||||
value="LITERAL_IF, LITERAL_ELSE,
|
||||
LITERAL_DO"/>
|
||||
</module>
|
||||
<module name="RightCurly">
|
||||
<property name="id" value="RightCurlyAlone"/>
|
||||
<property name="option" value="alone"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
|
||||
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF"/>
|
||||
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
|
||||
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF, RECORD_DEF,
|
||||
COMPACT_CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<!-- suppression is required till https://github.com/checkstyle/checkstyle/issues/7541 -->
|
||||
<property name="id" value="RightCurlyAlone"/>
|
||||
<property name="query" value="//RCURLY[parent::SLIST[count(./*)=1]
|
||||
or preceding-sibling::*[last()][self::LCURLY]]"/>
|
||||
</module>
|
||||
<module name="WhitespaceAfter">
|
||||
<property name="tokens"
|
||||
value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE,
|
||||
LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE"/>
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors" value="true"/>
|
||||
|
@ -118,18 +146,35 @@
|
|||
<property name="allowEmptyMethods" value="true"/>
|
||||
<property name="allowEmptyTypes" value="true"/>
|
||||
<property name="allowEmptyLoops" value="true"/>
|
||||
<!--<property name="allowEmptySwitchBlockStatements" value="true"/>-->
|
||||
<property name="ignoreEnhancedForColon" value="false"/>
|
||||
<property name="tokens"
|
||||
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
|
||||
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
|
||||
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
|
||||
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
|
||||
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
|
||||
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
|
||||
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
|
||||
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
|
||||
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAND,
|
||||
LCURLY, LE, LITERAL_DO, LITERAL_ELSE,
|
||||
LITERAL_FOR, LITERAL_IF,
|
||||
LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
|
||||
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
|
||||
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT,
|
||||
TYPE_EXTENSION_AND"/>
|
||||
<message key="ws.notFollowed"
|
||||
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
|
||||
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks
|
||||
may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
|
||||
<message key="ws.notPreceded"
|
||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<property name="checks" value="WhitespaceAround"/>
|
||||
<property name="query" value="//*[self::LITERAL_IF or self::LITERAL_ELSE or self::STATIC_INIT
|
||||
or self::LITERAL_TRY or self::LITERAL_CATCH]/SLIST[count(./*)=1]
|
||||
| //*[self::STATIC_INIT or self::LITERAL_TRY or self::LITERAL_IF]
|
||||
//*[self::RCURLY][parent::SLIST[count(./*)=1]]"/>
|
||||
</module>
|
||||
<module name="RegexpSinglelineJava">
|
||||
<property name="format" value="\{[ ]+\}"/>
|
||||
<property name="message" value="Empty blocks should have no spaces. Empty blocks
|
||||
may only be represented as '{}' when not part of a
|
||||
multi-block statement (4.1.3)"/>
|
||||
</module>
|
||||
<module name="OneStatementPerLine"/>
|
||||
<module name="MultipleVariableDeclarations"/>
|
||||
|
@ -140,8 +185,9 @@
|
|||
<module name="ModifierOrder"/>
|
||||
<module name="EmptyLineSeparator">
|
||||
<property name="tokens"
|
||||
value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
|
||||
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||
value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
|
||||
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF,
|
||||
COMPACT_CTOR_DEF"/>
|
||||
<property name="allowNoEmptyLineBetweenFields" value="true"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
|
@ -155,13 +201,13 @@
|
|||
<property name="option" value="EOL"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
|
||||
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/259 -->
|
||||
<property name="id" value="SeparatorWrapEllipsis"/>
|
||||
<property name="tokens" value="ELLIPSIS"/>
|
||||
<property name="option" value="EOL"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
|
||||
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/258 -->
|
||||
<property name="id" value="SeparatorWrapArrayDeclarator"/>
|
||||
<property name="tokens" value="ARRAY_DECLARATOR"/>
|
||||
<property name="option" value="EOL"/>
|
||||
|
@ -174,22 +220,23 @@
|
|||
<module name="PackageName">
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Package name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Package name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="TypeName">
|
||||
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF"/>
|
||||
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
|
||||
ANNOTATION_DEF, RECORD_DEF"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MemberName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="ParameterName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="LambdaParameterName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
|
@ -199,38 +246,53 @@
|
|||
<module name="CatchParameterName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="LocalVariableName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="PatternVariableName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Pattern variable name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="ClassTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Class type name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Class type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="RecordComponentName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Record component name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="RecordTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Record type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MethodTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Method type name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Method type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="InterfaceTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="NoFinalizer"/>
|
||||
<module name="GenericWhitespace">
|
||||
<message key="ws.followed"
|
||||
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
|
||||
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
|
||||
<message key="ws.preceded"
|
||||
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
|
||||
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
|
||||
<message key="ws.illegalFollow"
|
||||
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
|
||||
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
|
||||
<message key="ws.notPreceded"
|
||||
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
|
||||
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
<module name="Indentation">
|
||||
<property name="basicOffset" value="4"/>
|
||||
|
@ -240,44 +302,62 @@
|
|||
<property name="lineWrappingIndentation" value="4"/>
|
||||
<property name="arrayInitIndent" value="4"/>
|
||||
</module>
|
||||
<!-- Suppression for block code until we find a way to detect them properly
|
||||
until https://github.com/checkstyle/checkstyle/issues/15769 -->
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<property name="checks" value="Indentation"/>
|
||||
<property name="query" value="//SLIST[not(parent::CASE_GROUP)]/SLIST
|
||||
| //SLIST[not(parent::CASE_GROUP)]/SLIST/RCURLY"/>
|
||||
</module>
|
||||
<module name="AbbreviationAsWordInName">
|
||||
<property name="ignoreFinal" value="true"/>
|
||||
<property name="allowedAbbreviations" value="API" />
|
||||
<property name="allowedAbbreviationLength" value="1"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
|
||||
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF"/>
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
|
||||
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF,
|
||||
RECORD_COMPONENT_DEF"/>
|
||||
</module>
|
||||
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
|
||||
<module name="OverloadMethodsDeclarationOrder"/>
|
||||
<!--<module name="ConstructorsDeclarationGrouping"/>-->
|
||||
<module name="VariableDeclarationUsageDistance"/>
|
||||
<module name="CustomImportOrder">
|
||||
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||
<property name="separateLineBetweenGroups" value="true"/>
|
||||
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
|
||||
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
|
||||
</module>
|
||||
<module name="MethodParamPad">
|
||||
<property name="tokens"
|
||||
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
|
||||
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
|
||||
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
|
||||
</module>
|
||||
<module name="NoWhitespaceBefore">
|
||||
<property name="tokens"
|
||||
value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>
|
||||
value="COMMA, SEMI, POST_INC, POST_DEC, DOT,
|
||||
LABELED_STAT, METHOD_REF"/>
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
</module>
|
||||
<module name="ParenPad">
|
||||
<property name="tokens"
|
||||
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
|
||||
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
|
||||
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
|
||||
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
|
||||
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
|
||||
EXPR, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
|
||||
LITERAL_WHILE, METHOD_CALL,
|
||||
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL"/>
|
||||
</module>
|
||||
<module name="OperatorWrap">
|
||||
<property name="option" value="NL"/>
|
||||
<property name="tokens"
|
||||
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
|
||||
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
|
||||
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
|
||||
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF,
|
||||
TYPE_EXTENSION_AND "/>
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="id" value="AnnotationLocationMostCases"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
|
||||
<property name="allowSamelineMultipleAnnotations" value="true"/>
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF,
|
||||
RECORD_DEF, COMPACT_CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="id" value="AnnotationLocationVariables"/>
|
||||
|
@ -289,46 +369,83 @@
|
|||
<module name="JavadocTagContinuationIndentation"/>
|
||||
<module name="SummaryJavadoc">
|
||||
<property name="forbiddenSummaryFragments"
|
||||
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
|
||||
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
|
||||
</module>
|
||||
<module name="JavadocParagraph"/>
|
||||
<module name="JavadocParagraph">
|
||||
</module>
|
||||
<module name="RequireEmptyLineBeforeBlockTagGroup"/>
|
||||
<module name="AtclauseOrder">
|
||||
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
|
||||
<property name="target"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||
</module>
|
||||
<module name="JavadocMethod">
|
||||
<property name="accessModifiers" value="public"/>
|
||||
<property name="allowMissingParamTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
<property name="allowedAnnotations" value="Override, Test"/>
|
||||
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
|
||||
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="MissingJavadocMethod">
|
||||
<property name="scope" value="public"/>
|
||||
<property name="minLineCount" value="2"/>
|
||||
<property name="allowMissingPropertyJavadoc" value="true"/>
|
||||
<property name="allowedAnnotations" value="Override, Test"/>
|
||||
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
|
||||
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF,
|
||||
COMPACT_CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<property name="checks" value="MissingJavadocMethod"/>
|
||||
<property name="query" value="//*[self::METHOD_DEF or self::CTOR_DEF
|
||||
or self::ANNOTATION_FIELD_DEF or self::COMPACT_CTOR_DEF]
|
||||
[ancestor::*[self::INTERFACE_DEF or self::CLASS_DEF
|
||||
or self::RECORD_DEF or self::ENUM_DEF]
|
||||
[not(./MODIFIERS/LITERAL_PUBLIC)]]"/>
|
||||
</module>
|
||||
<module name="MissingJavadocType">
|
||||
<property name="scope" value="protected"/>
|
||||
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
|
||||
RECORD_DEF, ANNOTATION_DEF"/>
|
||||
<property name="excludeScope" value="nothing"/>
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Method name ''{0}'' must match pattern ''{1}''."/>
|
||||
value="Method name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="SingleLineJavadoc">
|
||||
<property name="ignoreInlineTags" value="false"/>
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<property name="checks" value="MethodName"/>
|
||||
<property name="query" value="//METHOD_DEF[
|
||||
./MODIFIERS/ANNOTATION//IDENT[contains(@text, 'Test')]
|
||||
]/IDENT"/>
|
||||
<property name="message" value="'[a-z][a-z0-9][a-zA-Z0-9]*(?:_[a-z][a-z0-9][a-zA-Z0-9]*)*'"/>
|
||||
</module>
|
||||
<module name="SingleLineJavadoc"/>
|
||||
<module name="EmptyCatchBlock">
|
||||
<property name="exceptionVariableName" value="expected"/>
|
||||
</module>
|
||||
<module name="CommentsIndentation">
|
||||
<property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>
|
||||
</module>
|
||||
<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
|
||||
<module name="SuppressionXpathFilter">
|
||||
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
|
||||
default="checkstyle-xpath-suppressions.xml" />
|
||||
<property name="optional" value="true"/>
|
||||
</module>
|
||||
<module name="SuppressWarningsHolder" />
|
||||
<module name="SuppressionCommentFilter">
|
||||
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)" />
|
||||
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)" />
|
||||
<property name="checkFormat" value="$1" />
|
||||
</module>
|
||||
<module name="SuppressWithNearbyCommentFilter">
|
||||
<property name="commentFormat" value="CHECKSTYLE.SUPPRESS\: ([\w\|]+)"/>
|
||||
<!-- $1 refers to the first match group in the regex defined in commentFormat -->
|
||||
<property name="checkFormat" value="$1"/>
|
||||
<!-- The check is suppressed in the next line of code after the comment -->
|
||||
<property name="influenceFormat" value="1"/>
|
||||
</module>
|
||||
</module>
|
||||
</module>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"bootstrap-sha": "c701a6c4ebbe1170a25ca7636a31508b9628831c",
|
||||
"bootstrap-sha": "d7b591c9f910afad303d6d814f65c7f9dab33b89",
|
||||
"signoff": "OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>",
|
||||
"packages": {
|
||||
".": {
|
||||
"package-name": "dev.openfeature.sdk",
|
||||
|
|
|
@ -5,5 +5,10 @@
|
|||
<username>${env.OSSRH_USERNAME}</username>
|
||||
<password>${env.OSSRH_PASSWORD}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>central</id>
|
||||
<username>${env.CENTRAL_USERNAME}</username>
|
||||
<password>${env.CENTRAL_PASSWORD}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@SuppressWarnings({ "PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType" })
|
||||
@SuppressWarnings({"PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType"})
|
||||
@EqualsAndHashCode
|
||||
abstract class AbstractStructure implements Structure {
|
||||
|
||||
protected final Map<String, Value> attributes;
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return attributes == null || attributes.size() == 0;
|
||||
return attributes == null || attributes.isEmpty();
|
||||
}
|
||||
|
||||
AbstractStructure() {
|
||||
|
@ -24,6 +26,7 @@ abstract class AbstractStructure implements Structure {
|
|||
|
||||
/**
|
||||
* Returns an unmodifiable representation of the internal attribute map.
|
||||
*
|
||||
* @return immutable map
|
||||
*/
|
||||
public Map<String, Value> asUnmodifiableMap() {
|
||||
|
@ -37,14 +40,12 @@ abstract class AbstractStructure implements Structure {
|
|||
*/
|
||||
@Override
|
||||
public Map<String, Object> asObjectMap() {
|
||||
return attributes
|
||||
.entrySet()
|
||||
.stream()
|
||||
return attributes.entrySet().stream()
|
||||
// custom collector, workaround for Collectors.toMap in JDK8
|
||||
// https://bugs.openjdk.org/browse/JDK-8148463
|
||||
.collect(HashMap::new,
|
||||
.collect(
|
||||
HashMap::new,
|
||||
(accumulated, entry) -> accumulated.put(entry.getKey(), convertValue(entry.getValue())),
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
/**
|
||||
* A class to help with synchronization by allowing the optional awaiting of the associated action.
|
||||
*/
|
||||
public class Awaitable {
|
||||
|
||||
/**
|
||||
* An already-completed Awaitable. Awaiting this will return immediately.
|
||||
*/
|
||||
public static final Awaitable FINISHED = new Awaitable(true);
|
||||
|
||||
private boolean isDone = false;
|
||||
|
||||
public Awaitable() {}
|
||||
|
||||
private Awaitable(boolean isDone) {
|
||||
this.isDone = isDone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets the calling thread wait until some other thread calls {@link Awaitable#wakeup()}. If
|
||||
* {@link Awaitable#wakeup()} has been called before the current thread invokes this method, it will return
|
||||
* immediately.
|
||||
*/
|
||||
@SuppressWarnings("java:S2142")
|
||||
public synchronized void await() {
|
||||
while (!isDone) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException ignored) {
|
||||
// ignored, do not propagate the interrupted state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wakes up all threads that have called {@link Awaitable#await()} and lets them proceed.
|
||||
*/
|
||||
public synchronized void wakeup() {
|
||||
isDone = true;
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
|
@ -2,29 +2,34 @@ package dev.openfeature.sdk;
|
|||
|
||||
/**
|
||||
* This is a common interface between the evaluation results that providers return and what is given to the end users.
|
||||
*
|
||||
* @param <T> The type of flag being evaluated.
|
||||
*/
|
||||
public interface BaseEvaluation<T> {
|
||||
/**
|
||||
* Returns the resolved value of the evaluation.
|
||||
*
|
||||
* @return {T} the resolve value
|
||||
*/
|
||||
T getValue();
|
||||
|
||||
/**
|
||||
* Returns an identifier for this value, if applicable.
|
||||
*
|
||||
* @return {String} value identifier
|
||||
*/
|
||||
String getVariant();
|
||||
|
||||
/**
|
||||
* Describes how we came to the value that we're returning.
|
||||
*
|
||||
* @return {Reason}
|
||||
*/
|
||||
String getReason();
|
||||
|
||||
/**
|
||||
* The error code, if applicable. Should only be set when the Reason is ERROR.
|
||||
*
|
||||
* @return {ErrorCode}
|
||||
*/
|
||||
ErrorCode getErrorCode();
|
||||
|
@ -32,6 +37,7 @@ public interface BaseEvaluation<T> {
|
|||
/**
|
||||
* The error message (usually from exception.getMessage()), if applicable.
|
||||
* Should only be set when the Reason is ERROR.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
String getErrorMessage();
|
||||
|
|
|
@ -3,7 +3,7 @@ package dev.openfeature.sdk;
|
|||
/**
|
||||
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
|
||||
* to the lifecycle of flag evaluation.
|
||||
*
|
||||
*
|
||||
* @see Hook
|
||||
*/
|
||||
public interface BooleanHook extends Hook<Boolean> {
|
||||
|
|
|
@ -3,7 +3,7 @@ package dev.openfeature.sdk;
|
|||
/**
|
||||
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
|
||||
* to the lifecycle of flag evaluation.
|
||||
*
|
||||
*
|
||||
* @see Hook
|
||||
*/
|
||||
public interface DoubleHook extends Hook<Double> {
|
||||
|
@ -12,4 +12,4 @@ public interface DoubleHook extends Hook<Double> {
|
|||
default boolean supportsFlagValueType(FlagValueType flagValueType) {
|
||||
return FlagValueType.DOUBLE == flagValueType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,12 @@ package dev.openfeature.sdk;
|
|||
|
||||
@SuppressWarnings("checkstyle:MissingJavadocType")
|
||||
public enum ErrorCode {
|
||||
PROVIDER_NOT_READY, FLAG_NOT_FOUND, PARSE_ERROR, TYPE_MISMATCH, TARGETING_KEY_MISSING, INVALID_CONTEXT, GENERAL,
|
||||
PROVIDER_NOT_READY,
|
||||
FLAG_NOT_FOUND,
|
||||
PARSE_ERROR,
|
||||
TYPE_MISMATCH,
|
||||
TARGETING_KEY_MISSING,
|
||||
INVALID_CONTEXT,
|
||||
GENERAL,
|
||||
PROVIDER_FATAL
|
||||
}
|
||||
|
|
|
@ -28,12 +28,13 @@ public interface EvaluationContext extends Structure {
|
|||
* Recursively merges the overriding map into the base Value map.
|
||||
* The base map is mutated, the overriding map is not.
|
||||
* Null maps will cause no-op.
|
||||
*
|
||||
*
|
||||
* @param newStructure function to create the right structure(s) for Values
|
||||
* @param base base map to merge
|
||||
* @param overriding overriding map to merge
|
||||
* @param base base map to merge
|
||||
* @param overriding overriding map to merge
|
||||
*/
|
||||
static void mergeMaps(Function<Map<String, Value>, Structure> newStructure,
|
||||
static void mergeMaps(
|
||||
Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
|
||||
|
@ -46,12 +47,13 @@ public interface EvaluationContext extends Structure {
|
|||
|
||||
for (Entry<String, Value> overridingEntry : overriding.entrySet()) {
|
||||
String key = overridingEntry.getKey();
|
||||
if (overridingEntry.getValue().isStructure() && base.containsKey(key) && base.get(key).isStructure()) {
|
||||
if (overridingEntry.getValue().isStructure()
|
||||
&& base.containsKey(key)
|
||||
&& base.get(key).isStructure()) {
|
||||
Structure mergedValue = base.get(key).asStructure();
|
||||
Structure overridingValue = overridingEntry.getValue().asStructure();
|
||||
Map<String, Value> newMap = mergedValue.asMap();
|
||||
mergeMaps(newStructure, newMap,
|
||||
overridingValue.asUnmodifiableMap());
|
||||
mergeMaps(newStructure, newMap, overridingValue.asUnmodifiableMap());
|
||||
base.put(key, new Value(newStructure.apply(newMap)));
|
||||
} else {
|
||||
base.put(key, overridingEntry.getValue());
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
|
||||
/**
|
||||
* Represents an evaluation event.
|
||||
*/
|
||||
@Builder
|
||||
@Getter
|
||||
public class EvaluationEvent {
|
||||
|
||||
private String name;
|
||||
|
||||
@Singular("attribute")
|
||||
private Map<String, Object> attributes;
|
||||
|
||||
public Map<String, Object> getAttributes() {
|
||||
return new HashMap<>(attributes);
|
||||
}
|
||||
}
|
|
@ -6,38 +6,38 @@ import java.util.function.Consumer;
|
|||
* Interface for attaching event handlers.
|
||||
*/
|
||||
public interface EventBus<T> {
|
||||
|
||||
|
||||
/**
|
||||
* Add a handler for the {@link ProviderEvent#PROVIDER_READY} event.
|
||||
* Shorthand for {@link #on(ProviderEvent, Consumer)}
|
||||
*
|
||||
*
|
||||
* @param handler behavior to add with this event
|
||||
* @return this
|
||||
*/
|
||||
T onProviderReady(Consumer<EventDetails> handler);
|
||||
|
||||
|
||||
/**
|
||||
* Add a handler for the {@link ProviderEvent#PROVIDER_CONFIGURATION_CHANGED} event.
|
||||
* Shorthand for {@link #on(ProviderEvent, Consumer)}
|
||||
*
|
||||
*
|
||||
* @param handler behavior to add with this event
|
||||
* @return this
|
||||
*/
|
||||
T onProviderConfigurationChanged(Consumer<EventDetails> handler);
|
||||
|
||||
|
||||
/**
|
||||
* Add a handler for the {@link ProviderEvent#PROVIDER_STALE} event.
|
||||
* Shorthand for {@link #on(ProviderEvent, Consumer)}
|
||||
*
|
||||
*
|
||||
* @param handler behavior to add with this event
|
||||
* @return this
|
||||
*/
|
||||
T onProviderError(Consumer<EventDetails> handler);
|
||||
|
||||
|
||||
/**
|
||||
* Add a handler for the {@link ProviderEvent#PROVIDER_ERROR} event.
|
||||
* Shorthand for {@link #on(ProviderEvent, Consumer)}
|
||||
*
|
||||
*
|
||||
* @param handler behavior to add with this event
|
||||
* @return this
|
||||
*/
|
||||
|
@ -45,18 +45,18 @@ public interface EventBus<T> {
|
|||
|
||||
/**
|
||||
* Add a handler for the specified {@link ProviderEvent}.
|
||||
*
|
||||
* @param event event type
|
||||
*
|
||||
* @param event event type
|
||||
* @param handler behavior to add with this event
|
||||
* @return this
|
||||
*/
|
||||
T on(ProviderEvent event, Consumer<EventDetails> handler);
|
||||
|
||||
|
||||
/**
|
||||
* Remove the previously attached handler by reference.
|
||||
* If the handler doesn't exists, no-op.
|
||||
*
|
||||
* @param event event type
|
||||
*
|
||||
* @param event event type
|
||||
* @param handler to be removed
|
||||
* @return this
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* The details of a particular event.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class EventDetails extends ProviderEventDetails {
|
||||
|
@ -17,9 +19,7 @@ public class EventDetails extends ProviderEventDetails {
|
|||
}
|
||||
|
||||
static EventDetails fromProviderEventDetails(
|
||||
ProviderEventDetails providerEventDetails,
|
||||
String providerName,
|
||||
String domain) {
|
||||
ProviderEventDetails providerEventDetails, String providerName, String domain) {
|
||||
return builder()
|
||||
.domain(domain)
|
||||
.providerName(providerName)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.internal.TriConsumer;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Abstract EventProvider. Providers must extend this class to support events.
|
||||
|
@ -15,8 +18,10 @@ import dev.openfeature.sdk.internal.TriConsumer;
|
|||
*
|
||||
* @see FeatureProvider
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class EventProvider implements FeatureProvider {
|
||||
private EventProviderListener eventProviderListener;
|
||||
private final ExecutorService emitterExecutor = Executors.newCachedThreadPool();
|
||||
|
||||
void setEventProviderListener(EventProviderListener eventProviderListener) {
|
||||
this.eventProviderListener = eventProviderListener;
|
||||
|
@ -47,19 +52,56 @@ public abstract class EventProvider implements FeatureProvider {
|
|||
this.onEmit = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the event emitter executor and block until either termination has completed
|
||||
* or timeout period has elapsed.
|
||||
*/
|
||||
@Override
|
||||
public void shutdown() {
|
||||
emitterExecutor.shutdown();
|
||||
try {
|
||||
if (!emitterExecutor.awaitTermination(EventSupport.SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
|
||||
log.warn("Emitter executor did not terminate before the timeout period had elapsed");
|
||||
emitterExecutor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
emitterExecutor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the specified {@link ProviderEvent}.
|
||||
*
|
||||
* @param event The event type
|
||||
* @param details The details of the event
|
||||
*/
|
||||
public void emit(ProviderEvent event, ProviderEventDetails details) {
|
||||
if (eventProviderListener != null) {
|
||||
eventProviderListener.onEmit(event, details);
|
||||
}
|
||||
if (this.onEmit != null) {
|
||||
this.onEmit.accept(this, event, details);
|
||||
public Awaitable emit(final ProviderEvent event, final ProviderEventDetails details) {
|
||||
final var localEventProviderListener = this.eventProviderListener;
|
||||
final var localOnEmit = this.onEmit;
|
||||
|
||||
if (localEventProviderListener == null && localOnEmit == null) {
|
||||
return Awaitable.FINISHED;
|
||||
}
|
||||
|
||||
final var awaitable = new Awaitable();
|
||||
|
||||
// These calls need to be executed on a different thread to prevent deadlocks when the provider initialization
|
||||
// relies on a ready event to be emitted
|
||||
emitterExecutor.submit(() -> {
|
||||
try (var ignored = OpenFeatureAPI.lock.readLockAutoCloseable()) {
|
||||
if (localEventProviderListener != null) {
|
||||
localEventProviderListener.onEmit(event, details);
|
||||
}
|
||||
if (localOnEmit != null) {
|
||||
localOnEmit.accept(this, event, details);
|
||||
}
|
||||
} finally {
|
||||
awaitable.wakeup();
|
||||
}
|
||||
});
|
||||
|
||||
return awaitable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,8 +110,8 @@ public abstract class EventProvider implements FeatureProvider {
|
|||
*
|
||||
* @param details The details of the event
|
||||
*/
|
||||
public void emitProviderReady(ProviderEventDetails details) {
|
||||
emit(ProviderEvent.PROVIDER_READY, details);
|
||||
public Awaitable emitProviderReady(ProviderEventDetails details) {
|
||||
return emit(ProviderEvent.PROVIDER_READY, details);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,8 +121,8 @@ public abstract class EventProvider implements FeatureProvider {
|
|||
*
|
||||
* @param details The details of the event
|
||||
*/
|
||||
public void emitProviderConfigurationChanged(ProviderEventDetails details) {
|
||||
emit(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, details);
|
||||
public Awaitable emitProviderConfigurationChanged(ProviderEventDetails details) {
|
||||
return emit(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, details);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,8 +131,8 @@ public abstract class EventProvider implements FeatureProvider {
|
|||
*
|
||||
* @param details The details of the event
|
||||
*/
|
||||
public void emitProviderStale(ProviderEventDetails details) {
|
||||
emit(ProviderEvent.PROVIDER_STALE, details);
|
||||
public Awaitable emitProviderStale(ProviderEventDetails details) {
|
||||
return emit(ProviderEvent.PROVIDER_STALE, details);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +141,7 @@ public abstract class EventProvider implements FeatureProvider {
|
|||
*
|
||||
* @param details The details of the event
|
||||
*/
|
||||
public void emitProviderError(ProviderEventDetails details) {
|
||||
emit(ProviderEvent.PROVIDER_ERROR, details);
|
||||
public Awaitable emitProviderError(ProviderEventDetails details) {
|
||||
return emit(ProviderEvent.PROVIDER_ERROR, details);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Util class for storing and running handlers.
|
||||
|
@ -20,89 +19,79 @@ import java.util.function.Consumer;
|
|||
@Slf4j
|
||||
class EventSupport {
|
||||
|
||||
public static final int SHUTDOWN_TIMEOUT_SECONDS = 3;
|
||||
|
||||
// we use a v4 uuid as a "placeholder" for anonymous clients, since
|
||||
// ConcurrentHashMap doesn't support nulls
|
||||
private static final String defaultClientUuid = UUID.randomUUID().toString();
|
||||
private static final int SHUTDOWN_TIMEOUT_SECONDS = 3;
|
||||
private static final String DEFAULT_CLIENT_UUID = UUID.randomUUID().toString();
|
||||
private final Map<String, HandlerStore> handlerStores = new ConcurrentHashMap<>();
|
||||
private final HandlerStore globalHandlerStore = new HandlerStore();
|
||||
private final ExecutorService taskExecutor = Executors.newCachedThreadPool(runnable -> {
|
||||
final Thread thread = new Thread(runnable);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
private final ExecutorService taskExecutor = Executors.newCachedThreadPool();
|
||||
|
||||
/**
|
||||
* Run all the event handlers associated with this domain.
|
||||
* If the domain is null, handlers attached to unnamed clients will run.
|
||||
*
|
||||
*
|
||||
* @param domain the domain to run event handlers for, or null
|
||||
* @param event the event type
|
||||
* @param eventDetails the event details
|
||||
*/
|
||||
public void runClientHandlers(String domain, ProviderEvent event, EventDetails eventDetails) {
|
||||
domain = Optional.ofNullable(domain)
|
||||
.orElse(defaultClientUuid);
|
||||
domain = Optional.ofNullable(domain).orElse(DEFAULT_CLIENT_UUID);
|
||||
|
||||
// run handlers if they exist
|
||||
Optional.ofNullable(handlerStores.get(domain))
|
||||
.filter(store -> Optional.of(store).isPresent())
|
||||
.map(store -> store.handlerMap.get(event))
|
||||
.ifPresent(handlers -> handlers
|
||||
.forEach(handler -> runHandler(handler, eventDetails)));
|
||||
.ifPresent(handlers -> handlers.forEach(handler -> runHandler(handler, eventDetails)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all the API (global) event handlers.
|
||||
*
|
||||
*
|
||||
* @param event the event type
|
||||
* @param eventDetails the event details
|
||||
*/
|
||||
public void runGlobalHandlers(ProviderEvent event, EventDetails eventDetails) {
|
||||
globalHandlerStore.handlerMap.get(event)
|
||||
.forEach(handler -> {
|
||||
runHandler(handler, eventDetails);
|
||||
});
|
||||
globalHandlerStore.handlerMap.get(event).forEach(handler -> {
|
||||
runHandler(handler, eventDetails);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler for the specified domain, or all unnamed clients.
|
||||
*
|
||||
* @param domain the domain to add handlers for, or else unnamed
|
||||
* @param event the event type
|
||||
* @param handler the handler function to run
|
||||
*
|
||||
* @param domain the domain to add handlers for, or else unnamed
|
||||
* @param event the event type
|
||||
* @param handler the handler function to run
|
||||
*/
|
||||
public void addClientHandler(String domain, ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
final String name = Optional.ofNullable(domain)
|
||||
.orElse(defaultClientUuid);
|
||||
final String name = Optional.ofNullable(domain).orElse(DEFAULT_CLIENT_UUID);
|
||||
|
||||
// lazily create and cache a HandlerStore if it doesn't exist
|
||||
HandlerStore store = Optional.ofNullable(this.handlerStores.get(name))
|
||||
.orElseGet(() -> {
|
||||
HandlerStore newStore = new HandlerStore();
|
||||
this.handlerStores.put(name, newStore);
|
||||
return newStore;
|
||||
});
|
||||
HandlerStore store = Optional.ofNullable(this.handlerStores.get(name)).orElseGet(() -> {
|
||||
HandlerStore newStore = new HandlerStore();
|
||||
this.handlerStores.put(name, newStore);
|
||||
return newStore;
|
||||
});
|
||||
store.addHandler(event, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a client event handler for the specified event type.
|
||||
*
|
||||
* @param domain the domain of the client handler to remove, or null to remove
|
||||
* from unnamed clients
|
||||
* @param event the event type
|
||||
* @param handler the handler ref to be removed
|
||||
*
|
||||
* @param domain the domain of the client handler to remove, or null to remove
|
||||
* from unnamed clients
|
||||
* @param event the event type
|
||||
* @param handler the handler ref to be removed
|
||||
*/
|
||||
public void removeClientHandler(String domain, ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
domain = Optional.ofNullable(domain)
|
||||
.orElse(defaultClientUuid);
|
||||
domain = Optional.ofNullable(domain).orElse(DEFAULT_CLIENT_UUID);
|
||||
this.handlerStores.get(domain).removeHandler(event, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a global event handler of the specified event type.
|
||||
*
|
||||
*
|
||||
* @param event the event type
|
||||
* @param handler the handler to be added
|
||||
*/
|
||||
|
@ -112,7 +101,7 @@ class EventSupport {
|
|||
|
||||
/**
|
||||
* Remove a global event handler for the specified event type.
|
||||
*
|
||||
*
|
||||
* @param event the event type
|
||||
* @param handler the handler ref to be removed
|
||||
*/
|
||||
|
@ -122,7 +111,7 @@ class EventSupport {
|
|||
|
||||
/**
|
||||
* Get all domain names for which we have event handlers registered.
|
||||
*
|
||||
*
|
||||
* @return set of domain names
|
||||
*/
|
||||
public Set<String> getAllDomainNames() {
|
||||
|
@ -131,7 +120,7 @@ class EventSupport {
|
|||
|
||||
/**
|
||||
* Run the passed handler on the taskExecutor.
|
||||
*
|
||||
*
|
||||
* @param handler the handler to run
|
||||
* @param eventDetails the event details
|
||||
*/
|
||||
|
@ -167,14 +156,14 @@ class EventSupport {
|
|||
// instantiated when a handler is added to that client.
|
||||
static class HandlerStore {
|
||||
|
||||
private final Map<ProviderEvent, List<Consumer<EventDetails>>> handlerMap;
|
||||
private final Map<ProviderEvent, Collection<Consumer<EventDetails>>> handlerMap;
|
||||
|
||||
HandlerStore() {
|
||||
handlerMap = new ConcurrentHashMap<>();
|
||||
handlerMap.put(ProviderEvent.PROVIDER_READY, new ArrayList<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, new ArrayList<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_ERROR, new ArrayList<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_STALE, new ArrayList<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_READY, new ConcurrentLinkedQueue<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, new ConcurrentLinkedQueue<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_ERROR, new ConcurrentLinkedQueue<>());
|
||||
handlerMap.put(ProviderEvent.PROVIDER_STALE, new ConcurrentLinkedQueue<>());
|
||||
}
|
||||
|
||||
void addHandler(ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
|
|
|
@ -30,6 +30,7 @@ public interface FeatureProvider {
|
|||
* can overwrite this method,
|
||||
* if they have special initialization needed prior being called for flag
|
||||
* evaluation.
|
||||
*
|
||||
* <p>
|
||||
* It is ok if the method is expensive as it is executed in the background. All
|
||||
* runtime exceptions will be
|
||||
|
@ -45,6 +46,7 @@ public interface FeatureProvider {
|
|||
* flags, or the SDK is shut down.
|
||||
* Providers can overwrite this method, if they have special shutdown actions
|
||||
* needed.
|
||||
*
|
||||
* <p>
|
||||
* It is ok if the method is expensive as it is executed in the background. All
|
||||
* runtime exceptions will be
|
||||
|
@ -78,7 +80,5 @@ public interface FeatureProvider {
|
|||
* @param context Evaluation context used in flag evaluation (Optional)
|
||||
* @param details Data pertinent to a particular tracking event (Optional)
|
||||
*/
|
||||
default void track(String eventName, EvaluationContext context, TrackingEventDetails details) {
|
||||
|
||||
}
|
||||
default void track(String eventName, EvaluationContext context, TrackingEventDetails details) {}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.OpenFeatureError;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
class FeatureProviderStateManager implements EventProviderListener {
|
||||
private final FeatureProvider delegate;
|
||||
private final AtomicBoolean isInitialized = new AtomicBoolean();
|
||||
@Getter
|
||||
private ProviderState state = ProviderState.NOT_READY;
|
||||
private final AtomicReference<ProviderState> state = new AtomicReference<>(ProviderState.NOT_READY);
|
||||
|
||||
public FeatureProviderStateManager(FeatureProvider delegate) {
|
||||
this.delegate = delegate;
|
||||
|
@ -24,17 +24,17 @@ class FeatureProviderStateManager implements EventProviderListener {
|
|||
}
|
||||
try {
|
||||
delegate.initialize(evaluationContext);
|
||||
state = ProviderState.READY;
|
||||
setState(ProviderState.READY);
|
||||
} catch (OpenFeatureError openFeatureError) {
|
||||
if (ErrorCode.PROVIDER_FATAL.equals(openFeatureError.getErrorCode())) {
|
||||
state = ProviderState.FATAL;
|
||||
setState(ProviderState.FATAL);
|
||||
} else {
|
||||
state = ProviderState.ERROR;
|
||||
setState(ProviderState.ERROR);
|
||||
}
|
||||
isInitialized.set(false);
|
||||
throw openFeatureError;
|
||||
} catch (Exception e) {
|
||||
state = ProviderState.ERROR;
|
||||
setState(ProviderState.ERROR);
|
||||
isInitialized.set(false);
|
||||
throw e;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class FeatureProviderStateManager implements EventProviderListener {
|
|||
|
||||
public void shutdown() {
|
||||
delegate.shutdown();
|
||||
state = ProviderState.NOT_READY;
|
||||
setState(ProviderState.NOT_READY);
|
||||
isInitialized.set(false);
|
||||
}
|
||||
|
||||
|
@ -50,17 +50,34 @@ class FeatureProviderStateManager implements EventProviderListener {
|
|||
public void onEmit(ProviderEvent event, ProviderEventDetails details) {
|
||||
if (ProviderEvent.PROVIDER_ERROR.equals(event)) {
|
||||
if (details != null && details.getErrorCode() == ErrorCode.PROVIDER_FATAL) {
|
||||
state = ProviderState.FATAL;
|
||||
setState(ProviderState.FATAL);
|
||||
} else {
|
||||
state = ProviderState.ERROR;
|
||||
setState(ProviderState.ERROR);
|
||||
}
|
||||
} else if (ProviderEvent.PROVIDER_STALE.equals(event)) {
|
||||
state = ProviderState.STALE;
|
||||
setState(ProviderState.STALE);
|
||||
} else if (ProviderEvent.PROVIDER_READY.equals(event)) {
|
||||
state = ProviderState.READY;
|
||||
setState(ProviderState.READY);
|
||||
}
|
||||
}
|
||||
|
||||
private void setState(ProviderState state) {
|
||||
ProviderState oldState = this.state.getAndSet(state);
|
||||
if (oldState != state) {
|
||||
String providerName;
|
||||
if (delegate.getMetadata() == null || delegate.getMetadata().getName() == null) {
|
||||
providerName = "unknown";
|
||||
} else {
|
||||
providerName = delegate.getMetadata().getName();
|
||||
}
|
||||
log.info("Provider {} transitioned from state {} to state {}", providerName, oldState, state);
|
||||
}
|
||||
}
|
||||
|
||||
public ProviderState getState() {
|
||||
return state.get();
|
||||
}
|
||||
|
||||
FeatureProvider getProvider() {
|
||||
return delegate;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ public interface Features {
|
|||
|
||||
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx);
|
||||
|
||||
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options);
|
||||
FlagEvaluationDetails<Boolean> getBooleanDetails(
|
||||
String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
String getStringValue(String key, String defaultValue);
|
||||
|
||||
|
@ -28,8 +28,8 @@ public interface Features {
|
|||
|
||||
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx);
|
||||
|
||||
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options);
|
||||
FlagEvaluationDetails<String> getStringDetails(
|
||||
String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
Integer getIntegerValue(String key, Integer defaultValue);
|
||||
|
||||
|
@ -41,8 +41,8 @@ public interface Features {
|
|||
|
||||
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx);
|
||||
|
||||
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options);
|
||||
FlagEvaluationDetails<Integer> getIntegerDetails(
|
||||
String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
Double getDoubleValue(String key, Double defaultValue);
|
||||
|
||||
|
@ -54,22 +54,19 @@ public interface Features {
|
|||
|
||||
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx);
|
||||
|
||||
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options);
|
||||
FlagEvaluationDetails<Double> getDoubleDetails(
|
||||
String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
Value getObjectValue(String key, Value defaultValue);
|
||||
|
||||
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx);
|
||||
|
||||
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options);
|
||||
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue);
|
||||
|
||||
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
|
||||
EvaluationContext ctx);
|
||||
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue, EvaluationContext ctx);
|
||||
|
||||
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
|
||||
EvaluationContext ctx,
|
||||
FlagEvaluationOptions options);
|
||||
FlagEvaluationDetails<Value> getObjectDetails(
|
||||
String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
@ -25,6 +24,7 @@ public class FlagEvaluationDetails<T> implements BaseEvaluation<T> {
|
|||
private String reason;
|
||||
private ErrorCode errorCode;
|
||||
private String errorMessage;
|
||||
|
||||
@Builder.Default
|
||||
private ImmutableMetadata flagMetadata = ImmutableMetadata.builder().build();
|
||||
|
||||
|
@ -44,8 +44,8 @@ public class FlagEvaluationDetails<T> implements BaseEvaluation<T> {
|
|||
.reason(providerEval.getReason())
|
||||
.errorMessage(providerEval.getErrorMessage())
|
||||
.errorCode(providerEval.getErrorCode())
|
||||
.flagMetadata(
|
||||
Optional.ofNullable(providerEval.getFlagMetadata()).orElse(ImmutableMetadata.builder().build()))
|
||||
.flagMetadata(Optional.ofNullable(providerEval.getFlagMetadata())
|
||||
.orElse(ImmutableMetadata.builder().build()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package dev.openfeature.sdk;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Singular;
|
||||
|
||||
|
@ -13,6 +12,7 @@ import lombok.Singular;
|
|||
public class FlagEvaluationOptions {
|
||||
@Singular
|
||||
List<Hook> hooks;
|
||||
|
||||
@Builder.Default
|
||||
Map<String, Object> hookHints = new HashMap<>();
|
||||
}
|
||||
|
|
|
@ -2,5 +2,9 @@ package dev.openfeature.sdk;
|
|||
|
||||
@SuppressWarnings("checkstyle:MissingJavadocType")
|
||||
public enum FlagValueType {
|
||||
STRING, INTEGER, DOUBLE, OBJECT, BOOLEAN;
|
||||
STRING,
|
||||
INTEGER,
|
||||
DOUBLE,
|
||||
OBJECT,
|
||||
BOOLEAN;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public interface Hook<T> {
|
|||
* @param ctx Information about the particular flag evaluation
|
||||
* @param hints An immutable mapping of data for users to communicate to the hooks.
|
||||
* @return An optional {@link EvaluationContext}. If returned, it will be merged with the EvaluationContext
|
||||
* instances from other hooks, the client and API.
|
||||
* instances from other hooks, the client and API.
|
||||
*/
|
||||
default Optional<EvaluationContext> before(HookContext<T> ctx, Map<String, Object> hints) {
|
||||
return Optional.empty();
|
||||
|
@ -29,8 +29,7 @@ public interface Hook<T> {
|
|||
* @param details Information about how the flag was resolved, including any resolved values.
|
||||
* @param hints An immutable mapping of data for users to communicate to the hooks.
|
||||
*/
|
||||
default void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, Map<String, Object> hints) {
|
||||
}
|
||||
default void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, Map<String, Object> hints) {}
|
||||
|
||||
/**
|
||||
* Run when evaluation encounters an error. This will always run. Errors thrown will be swallowed.
|
||||
|
@ -39,8 +38,7 @@ public interface Hook<T> {
|
|||
* @param error The exception that was thrown.
|
||||
* @param hints An immutable mapping of data for users to communicate to the hooks.
|
||||
*/
|
||||
default void error(HookContext<T> ctx, Exception error, Map<String, Object> hints) {
|
||||
}
|
||||
default void error(HookContext<T> ctx, Exception error, Map<String, Object> hints) {}
|
||||
|
||||
/**
|
||||
* Run after flag evaluation, including any error processing. This will always run. Errors will be swallowed.
|
||||
|
@ -48,8 +46,7 @@ public interface Hook<T> {
|
|||
* @param ctx Information about the particular flag evaluation
|
||||
* @param hints An immutable mapping of data for users to communicate to the hooks.
|
||||
*/
|
||||
default void finallyAfter(HookContext<T> ctx, Map<String, Object> hints) {
|
||||
}
|
||||
default void finallyAfter(HookContext<T> ctx, FlagEvaluationDetails<T> details, Map<String, Object> hints) {}
|
||||
|
||||
default boolean supportsFlagValueType(FlagValueType flagValueType) {
|
||||
return true;
|
||||
|
|
|
@ -10,28 +10,40 @@ import lombok.With;
|
|||
*
|
||||
* @param <T> the type for the flag being evaluated
|
||||
*/
|
||||
@Value @Builder @With
|
||||
@Value
|
||||
@Builder
|
||||
@With
|
||||
public class HookContext<T> {
|
||||
@NonNull String flagKey;
|
||||
|
||||
@NonNull FlagValueType type;
|
||||
|
||||
@NonNull T defaultValue;
|
||||
|
||||
@NonNull EvaluationContext ctx;
|
||||
|
||||
ClientMetadata clientMetadata;
|
||||
Metadata providerMetadata;
|
||||
|
||||
/**
|
||||
* Builds a {@link HookContext} instances from request data.
|
||||
* @param key feature flag key
|
||||
* @param type flag value type
|
||||
* @param clientMetadata info on which client is calling
|
||||
*
|
||||
* @param key feature flag key
|
||||
* @param type flag value type
|
||||
* @param clientMetadata info on which client is calling
|
||||
* @param providerMetadata info on the provider
|
||||
* @param ctx Evaluation Context for the request
|
||||
* @param defaultValue Fallback value
|
||||
* @param <T> type that the flag is evaluating against
|
||||
* @param ctx Evaluation Context for the request
|
||||
* @param defaultValue Fallback value
|
||||
* @param <T> type that the flag is evaluating against
|
||||
* @return resulting context for hook
|
||||
*/
|
||||
public static <T> HookContext<T> from(String key, FlagValueType type, ClientMetadata clientMetadata,
|
||||
Metadata providerMetadata, EvaluationContext ctx, T defaultValue) {
|
||||
public static <T> HookContext<T> from(
|
||||
String key,
|
||||
FlagValueType type,
|
||||
ClientMetadata clientMetadata,
|
||||
Metadata providerMetadata,
|
||||
EvaluationContext ctx,
|
||||
T defaultValue) {
|
||||
return HookContext.<T>builder()
|
||||
.flagKey(key)
|
||||
.type(type)
|
||||
|
|
|
@ -6,39 +6,48 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class HookSupport {
|
||||
|
||||
public EvaluationContext beforeHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks,
|
||||
Map<String, Object> hints) {
|
||||
public EvaluationContext beforeHooks(
|
||||
FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks, Map<String, Object> hints) {
|
||||
return callBeforeHooks(flagValueType, hookCtx, hooks, hints);
|
||||
}
|
||||
|
||||
public void afterHooks(FlagValueType flagValueType, HookContext hookContext, FlagEvaluationDetails details,
|
||||
List<Hook> hooks, Map<String, Object> hints) {
|
||||
public void afterHooks(
|
||||
FlagValueType flagValueType,
|
||||
HookContext hookContext,
|
||||
FlagEvaluationDetails details,
|
||||
List<Hook> hooks,
|
||||
Map<String, Object> hints) {
|
||||
executeHooksUnchecked(flagValueType, hooks, hook -> hook.after(hookContext, details, hints));
|
||||
}
|
||||
|
||||
public void afterAllHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks,
|
||||
public void afterAllHooks(
|
||||
FlagValueType flagValueType,
|
||||
HookContext hookCtx,
|
||||
FlagEvaluationDetails details,
|
||||
List<Hook> hooks,
|
||||
Map<String, Object> hints) {
|
||||
executeHooks(flagValueType, hooks, "finally", hook -> hook.finallyAfter(hookCtx, hints));
|
||||
executeHooks(flagValueType, hooks, "finally", hook -> hook.finallyAfter(hookCtx, details, hints));
|
||||
}
|
||||
|
||||
public void errorHooks(FlagValueType flagValueType, HookContext hookCtx, Exception e, List<Hook> hooks,
|
||||
public void errorHooks(
|
||||
FlagValueType flagValueType,
|
||||
HookContext hookCtx,
|
||||
Exception e,
|
||||
List<Hook> hooks,
|
||||
Map<String, Object> hints) {
|
||||
executeHooks(flagValueType, hooks, "error", hook -> hook.error(hookCtx, e, hints));
|
||||
}
|
||||
|
||||
private <T> void executeHooks(
|
||||
FlagValueType flagValueType, List<Hook> hooks,
|
||||
String hookMethod,
|
||||
Consumer<Hook<T>> hookCode) {
|
||||
FlagValueType flagValueType, List<Hook> hooks, String hookMethod, Consumer<Hook<T>> hookCode) {
|
||||
if (hooks != null) {
|
||||
for (Hook hook : hooks) {
|
||||
if (hook.supportsFlagValueType(flagValueType)) {
|
||||
|
@ -53,15 +62,16 @@ class HookSupport {
|
|||
try {
|
||||
hookCode.accept(hook);
|
||||
} catch (Exception exception) {
|
||||
log.error("Unhandled exception when running {} hook {} (only 'after' hooks should throw)", hookMethod,
|
||||
hook.getClass(), exception);
|
||||
log.error(
|
||||
"Unhandled exception when running {} hook {} (only 'after' hooks should throw)",
|
||||
hookMethod,
|
||||
hook.getClass(),
|
||||
exception);
|
||||
}
|
||||
}
|
||||
|
||||
// after hooks can throw in order to do validation
|
||||
private <T> void executeHooksUnchecked(
|
||||
FlagValueType flagValueType, List<Hook> hooks,
|
||||
Consumer<Hook<T>> hookCode) {
|
||||
private <T> void executeHooksUnchecked(FlagValueType flagValueType, List<Hook> hooks, Consumer<Hook<T>> hookCode) {
|
||||
if (hooks != null) {
|
||||
for (Hook hook : hooks) {
|
||||
if (hook.supportsFlagValueType(flagValueType)) {
|
||||
|
@ -71,16 +81,16 @@ class HookSupport {
|
|||
}
|
||||
}
|
||||
|
||||
private EvaluationContext callBeforeHooks(FlagValueType flagValueType, HookContext hookCtx,
|
||||
List<Hook> hooks, Map<String, Object> hints) {
|
||||
private EvaluationContext callBeforeHooks(
|
||||
FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks, Map<String, Object> hints) {
|
||||
// These traverse backwards from normal.
|
||||
List<Hook> reversedHooks = new ArrayList<>(hooks);
|
||||
Collections.reverse(reversedHooks);
|
||||
EvaluationContext context = hookCtx.getCtx();
|
||||
for (Hook hook : reversedHooks) {
|
||||
if (hook.supportsFlagValueType(flagValueType)) {
|
||||
Optional<EvaluationContext> optional = Optional.ofNullable(hook.before(hookCtx, hints))
|
||||
.orElse(Optional.empty());
|
||||
Optional<EvaluationContext> optional =
|
||||
Optional.ofNullable(hook.before(hookCtx, hints)).orElse(Optional.empty());
|
||||
if (optional.isPresent()) {
|
||||
context = context.merge(optional.get());
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
|
@ -16,6 +16,7 @@ import lombok.experimental.Delegate;
|
|||
* not be modified after instantiation.
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
|
||||
public final class ImmutableContext implements EvaluationContext {
|
||||
|
||||
|
@ -88,15 +89,15 @@ public final class ImmutableContext implements EvaluationContext {
|
|||
}
|
||||
|
||||
Map<String, Value> attributes = this.asMap();
|
||||
EvaluationContext.mergeMaps(ImmutableStructure::new, attributes,
|
||||
overridingContext.asUnmodifiableMap());
|
||||
EvaluationContext.mergeMaps(ImmutableStructure::new, attributes, overridingContext.asUnmodifiableMap());
|
||||
return new ImmutableContext(attributes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private static class DelegateExclusions {
|
||||
@ExcludeFromGeneratedCoverageReport
|
||||
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
|
||||
public <T extends Structure> Map<String, Value> merge(
|
||||
Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
return null;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Immutable Flag Metadata representation. Implementation is backed by a {@link Map} and immutability is provided
|
||||
|
@ -98,6 +97,13 @@ public class ImmutableMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return metadata.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isNotEmpty() {
|
||||
return !metadata.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a builder for {@link ImmutableMetadata}.
|
||||
|
@ -188,6 +194,5 @@ public class ImmutableMetadata {
|
|||
public ImmutableMetadata build() {
|
||||
return new ImmutableMetadata(this.metadata);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
|
@ -19,8 +18,8 @@ import lombok.ToString;
|
|||
* not be modified after instantiation. All references are clones.
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@SuppressWarnings({ "PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType" })
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuppressWarnings({"PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType"})
|
||||
public final class ImmutableStructure extends AbstractStructure {
|
||||
|
||||
/**
|
||||
|
@ -39,7 +38,7 @@ public final class ImmutableStructure extends AbstractStructure {
|
|||
super(copyAttributes(attributes, null));
|
||||
}
|
||||
|
||||
protected ImmutableStructure(String targetingKey, Map<String, Value> attributes) {
|
||||
ImmutableStructure(String targetingKey, Map<String, Value> attributes) {
|
||||
super(copyAttributes(attributes, targetingKey));
|
||||
}
|
||||
|
||||
|
@ -71,14 +70,18 @@ public final class ImmutableStructure extends AbstractStructure {
|
|||
|
||||
private static Map<String, Value> copyAttributes(Map<String, Value> in, String targetingKey) {
|
||||
Map<String, Value> copy = new HashMap<>();
|
||||
for (Entry<String, Value> entry : in.entrySet()) {
|
||||
copy.put(entry.getKey(),
|
||||
Optional.ofNullable(entry.getValue()).map((Value val) -> val.clone()).orElse(null));
|
||||
if (in != null) {
|
||||
for (Entry<String, Value> entry : in.entrySet()) {
|
||||
copy.put(
|
||||
entry.getKey(),
|
||||
Optional.ofNullable(entry.getValue())
|
||||
.map((Value val) -> val.clone())
|
||||
.orElse(null));
|
||||
}
|
||||
}
|
||||
if (targetingKey != null) {
|
||||
copy.put(EvaluationContext.TARGETING_KEY, new Value(targetingKey));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
/**
|
||||
* ImmutableTrackingEventDetails represents data pertinent to a particular tracking event.
|
||||
|
@ -40,13 +38,13 @@ public class ImmutableTrackingEventDetails implements TrackingEventDetails {
|
|||
return Optional.ofNullable(value);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private static class DelegateExclusions {
|
||||
@ExcludeFromGeneratedCoverageReport
|
||||
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
public <T extends Structure> Map<String, Value> merge(
|
||||
Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package dev.openfeature.sdk;
|
|||
/**
|
||||
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
|
||||
* to the lifecycle of flag evaluation.
|
||||
*
|
||||
*
|
||||
* @see Hook
|
||||
*/
|
||||
public interface IntegerHook extends Hook<Integer> {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Delegate;
|
||||
|
@ -96,7 +96,6 @@ public class MutableContext implements EvaluationContext {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve targetingKey from the context.
|
||||
*/
|
||||
|
@ -122,8 +121,7 @@ public class MutableContext implements EvaluationContext {
|
|||
}
|
||||
|
||||
Map<String, Value> attributes = this.asMap();
|
||||
EvaluationContext.mergeMaps(
|
||||
MutableStructure::new, attributes, overridingContext.asUnmodifiableMap());
|
||||
EvaluationContext.mergeMaps(MutableStructure::new, attributes, overridingContext.asUnmodifiableMap());
|
||||
return new MutableContext(attributes);
|
||||
}
|
||||
|
||||
|
@ -134,7 +132,8 @@ public class MutableContext implements EvaluationContext {
|
|||
private static class DelegateExclusions {
|
||||
|
||||
@ExcludeFromGeneratedCoverageReport
|
||||
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
|
||||
public <T extends Structure> Map<String, Value> merge(
|
||||
Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
|
||||
|
|
|
@ -5,19 +5,18 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* {@link MutableStructure} represents a potentially nested object type which is used to represent
|
||||
* {@link MutableStructure} represents a potentially nested object type which is used to represent
|
||||
* structured data.
|
||||
* The MutableStructure is a Structure implementation which is not threadsafe, and whose attributes can
|
||||
* The MutableStructure is a Structure implementation which is not threadsafe, and whose attributes can
|
||||
* be modified after instantiation.
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@SuppressWarnings({"PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType"})
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MutableStructure extends AbstractStructure {
|
||||
|
||||
public MutableStructure() {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
/**
|
||||
* MutableTrackingEventDetails represents data pertinent to a particular tracking event.
|
||||
|
@ -19,6 +18,7 @@ import java.util.function.Function;
|
|||
public class MutableTrackingEventDetails implements TrackingEventDetails {
|
||||
|
||||
private final Number value;
|
||||
|
||||
@Delegate(excludes = MutableTrackingEventDetails.DelegateExclusions.class)
|
||||
private final MutableStructure structure;
|
||||
|
||||
|
@ -81,13 +81,13 @@ public class MutableTrackingEventDetails implements TrackingEventDetails {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private static class DelegateExclusions {
|
||||
@ExcludeFromGeneratedCoverageReport
|
||||
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
public <T extends Structure> Map<String, Value> merge(
|
||||
Function<Map<String, Value>, Structure> newStructure,
|
||||
Map<String, Value> base,
|
||||
Map<String, Value> overriding) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import lombok.Getter;
|
|||
*/
|
||||
public class NoOpProvider implements FeatureProvider {
|
||||
public static final String PASSED_IN_DEFAULT = "Passed in default";
|
||||
|
||||
@Getter
|
||||
private final String name = "No-op Provider";
|
||||
|
||||
|
@ -58,8 +59,8 @@ public class NoOpProvider implements FeatureProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
|
||||
EvaluationContext invocationContext) {
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(
|
||||
String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
return ProviderEvaluation.<Value>builder()
|
||||
.value(defaultValue)
|
||||
.variant(PASSED_IN_DEFAULT)
|
||||
|
|
|
@ -7,6 +7,7 @@ public class NoOpTransactionContextPropagator implements TransactionContextPropa
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return empty immutable context
|
||||
*/
|
||||
@Override
|
||||
|
@ -18,7 +19,5 @@ public class NoOpTransactionContextPropagator implements TransactionContextPropa
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTransactionContext(EvaluationContext evaluationContext) {
|
||||
|
||||
}
|
||||
public void setTransactionContext(EvaluationContext evaluationContext) {}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,16 @@ package dev.openfeature.sdk;
|
|||
import dev.openfeature.sdk.exceptions.OpenFeatureError;
|
||||
import dev.openfeature.sdk.internal.AutoCloseableLock;
|
||||
import dev.openfeature.sdk.internal.AutoCloseableReentrantReadWriteLock;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A global singleton which holds base configuration for the OpenFeature
|
||||
|
@ -18,15 +24,15 @@ import java.util.function.Consumer;
|
|||
public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
||||
// package-private multi-read/single-write lock
|
||||
static AutoCloseableReentrantReadWriteLock lock = new AutoCloseableReentrantReadWriteLock();
|
||||
private final List<Hook> apiHooks;
|
||||
private final ConcurrentLinkedQueue<Hook> apiHooks;
|
||||
private ProviderRepository providerRepository;
|
||||
private EventSupport eventSupport;
|
||||
private EvaluationContext evaluationContext;
|
||||
private final AtomicReference<EvaluationContext> evaluationContext = new AtomicReference<>();
|
||||
private TransactionContextPropagator transactionContextPropagator;
|
||||
|
||||
protected OpenFeatureAPI() {
|
||||
apiHooks = new ArrayList<>();
|
||||
providerRepository = new ProviderRepository();
|
||||
apiHooks = new ConcurrentLinkedQueue<>();
|
||||
providerRepository = new ProviderRepository(this);
|
||||
eventSupport = new EventSupport();
|
||||
transactionContextPropagator = new NoOpTransactionContextPropagator();
|
||||
}
|
||||
|
@ -102,11 +108,7 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @return a new client instance
|
||||
*/
|
||||
public Client getClient(String domain, String version) {
|
||||
return new OpenFeatureClient(
|
||||
this,
|
||||
domain,
|
||||
version
|
||||
);
|
||||
return new OpenFeatureClient(this, domain, version);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,9 +118,7 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @return api instance
|
||||
*/
|
||||
public OpenFeatureAPI setEvaluationContext(EvaluationContext evaluationContext) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
this.evaluationContext = evaluationContext;
|
||||
}
|
||||
this.evaluationContext.set(evaluationContext);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -128,16 +128,14 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @return evaluation context
|
||||
*/
|
||||
public EvaluationContext getEvaluationContext() {
|
||||
try (AutoCloseableLock __ = lock.readLockAutoCloseable()) {
|
||||
return this.evaluationContext;
|
||||
}
|
||||
return evaluationContext.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transaction context propagator.
|
||||
*/
|
||||
public TransactionContextPropagator getTransactionContextPropagator() {
|
||||
try (AutoCloseableLock __ = lock.readLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.readLockAutoCloseable()) {
|
||||
return this.transactionContextPropagator;
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +149,7 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
if (transactionContextPropagator == null) {
|
||||
throw new IllegalArgumentException("Transaction context propagator cannot be null");
|
||||
}
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
this.transactionContextPropagator = transactionContextPropagator;
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +175,7 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* Set the default provider.
|
||||
*/
|
||||
public void setProvider(FeatureProvider provider) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.setProvider(
|
||||
provider,
|
||||
this::attachEventProvider,
|
||||
|
@ -195,8 +193,9 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @param provider The provider to set.
|
||||
*/
|
||||
public void setProvider(String domain, FeatureProvider provider) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.setProvider(domain,
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.setProvider(
|
||||
domain,
|
||||
provider,
|
||||
this::attachEventProvider,
|
||||
this::emitReady,
|
||||
|
@ -207,10 +206,16 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the default provider and wait for initialization to finish.
|
||||
* Sets the default provider and waits for its initialization to complete.
|
||||
*
|
||||
* <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
|
||||
* It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
|
||||
*
|
||||
* @param provider the {@link FeatureProvider} to set as the default.
|
||||
* @throws OpenFeatureError if the provider fails during initialization.
|
||||
*/
|
||||
public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.setProvider(
|
||||
provider,
|
||||
this::attachEventProvider,
|
||||
|
@ -224,12 +229,17 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
/**
|
||||
* Add a provider for a domain and wait for initialization to finish.
|
||||
*
|
||||
* <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
|
||||
* It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
|
||||
*
|
||||
* @param domain The domain to bind the provider to.
|
||||
* @param provider The provider to set.
|
||||
* @throws OpenFeatureError if the provider fails during initialization.
|
||||
*/
|
||||
public void setProviderAndWait(String domain, FeatureProvider provider) throws OpenFeatureError {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.setProvider(domain,
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.setProvider(
|
||||
domain,
|
||||
provider,
|
||||
this::attachEventProvider,
|
||||
this::emitReady,
|
||||
|
@ -241,14 +251,15 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
|
||||
private void attachEventProvider(FeatureProvider provider) {
|
||||
if (provider instanceof EventProvider) {
|
||||
((EventProvider) provider).attach((p, event, details) -> {
|
||||
runHandlersForProvider(p, event, details);
|
||||
});
|
||||
((EventProvider) provider).attach(this::runHandlersForProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private void emitReady(FeatureProvider provider) {
|
||||
runHandlersForProvider(provider, ProviderEvent.PROVIDER_READY, ProviderEventDetails.builder().build());
|
||||
runHandlersForProvider(
|
||||
provider,
|
||||
ProviderEvent.PROVIDER_READY,
|
||||
ProviderEventDetails.builder().build());
|
||||
}
|
||||
|
||||
private void detachEventProvider(FeatureProvider provider) {
|
||||
|
@ -258,7 +269,9 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
}
|
||||
|
||||
private void emitError(FeatureProvider provider, OpenFeatureError exception) {
|
||||
runHandlersForProvider(provider, ProviderEvent.PROVIDER_ERROR,
|
||||
runHandlersForProvider(
|
||||
provider,
|
||||
ProviderEvent.PROVIDER_ERROR,
|
||||
ProviderEventDetails.builder().message(exception.getMessage()).build());
|
||||
}
|
||||
|
||||
|
@ -291,9 +304,7 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @param hooks The hook to add.
|
||||
*/
|
||||
public void addHooks(Hook... hooks) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
this.apiHooks.addAll(Arrays.asList(hooks));
|
||||
}
|
||||
this.apiHooks.addAll(Arrays.asList(hooks));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -302,18 +313,23 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @return A list of {@link Hook}s.
|
||||
*/
|
||||
public List<Hook> getHooks() {
|
||||
try (AutoCloseableLock __ = lock.readLockAutoCloseable()) {
|
||||
return this.apiHooks;
|
||||
}
|
||||
return new ArrayList<>(this.apiHooks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the collection of {@link Hook}s.
|
||||
*
|
||||
* @return The collection of {@link Hook}s.
|
||||
*/
|
||||
Collection<Hook> getMutableHooks() {
|
||||
return this.apiHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all hooks.
|
||||
*/
|
||||
public void clearHooks() {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
this.apiHooks.clear();
|
||||
}
|
||||
this.apiHooks.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,11 +339,11 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* Once shut down is complete, API is reset and ready to use again.
|
||||
*/
|
||||
public void shutdown() {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
providerRepository.shutdown();
|
||||
eventSupport.shutdown();
|
||||
|
||||
providerRepository = new ProviderRepository();
|
||||
providerRepository = new ProviderRepository(this);
|
||||
eventSupport = new EventSupport();
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +385,7 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
*/
|
||||
@Override
|
||||
public OpenFeatureAPI on(ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
this.eventSupport.addGlobalHandler(event, handler);
|
||||
return this;
|
||||
}
|
||||
|
@ -380,22 +396,26 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
*/
|
||||
@Override
|
||||
public OpenFeatureAPI removeHandler(ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
this.eventSupport.removeGlobalHandler(event, handler);
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
this.eventSupport.removeGlobalHandler(event, handler);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void removeHandler(String domain, ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
eventSupport.removeClientHandler(domain, event, handler);
|
||||
}
|
||||
}
|
||||
|
||||
void addHandler(String domain, ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.writeLockAutoCloseable()) {
|
||||
// if the provider is in the state associated with event, run immediately
|
||||
if (Optional.ofNullable(this.providerRepository.getProviderState(domain))
|
||||
.orElse(ProviderState.READY).matchesEvent(event)) {
|
||||
eventSupport.runHandler(handler, EventDetails.builder().domain(domain).build());
|
||||
.orElse(ProviderState.READY)
|
||||
.matchesEvent(event)) {
|
||||
eventSupport.runHandler(
|
||||
handler, EventDetails.builder().domain(domain).build());
|
||||
}
|
||||
eventSupport.addClientHandler(domain, event, handler);
|
||||
}
|
||||
|
@ -413,33 +433,28 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
* @param details the event details
|
||||
*/
|
||||
private void runHandlersForProvider(FeatureProvider provider, ProviderEvent event, ProviderEventDetails details) {
|
||||
try (AutoCloseableLock __ = lock.readLockAutoCloseable()) {
|
||||
try (AutoCloseableLock ignored = lock.readLockAutoCloseable()) {
|
||||
|
||||
List<String> domainsForProvider = providerRepository
|
||||
.getDomainsForProvider(provider);
|
||||
List<String> domainsForProvider = providerRepository.getDomainsForProvider(provider);
|
||||
|
||||
final String providerName = Optional.ofNullable(provider.getMetadata())
|
||||
.map(metadata -> metadata.getName())
|
||||
.map(Metadata::getName)
|
||||
.orElse(null);
|
||||
|
||||
// run the global handlers
|
||||
eventSupport.runGlobalHandlers(event, EventDetails.fromProviderEventDetails(details, providerName));
|
||||
|
||||
// run the handlers associated with domains for this provider
|
||||
domainsForProvider.forEach(domain -> {
|
||||
eventSupport.runClientHandlers(domain, event,
|
||||
EventDetails.fromProviderEventDetails(details, providerName, domain));
|
||||
});
|
||||
domainsForProvider.forEach(domain -> eventSupport.runClientHandlers(
|
||||
domain, event, EventDetails.fromProviderEventDetails(details, providerName, domain)));
|
||||
|
||||
if (providerRepository.isDefaultProvider(provider)) {
|
||||
// run handlers for clients that have no bound providers (since this is the default)
|
||||
Set<String> allDomainNames = eventSupport.getAllDomainNames();
|
||||
Set<String> boundDomains = providerRepository.getAllBoundDomains();
|
||||
allDomainNames.removeAll(boundDomains);
|
||||
allDomainNames.forEach(domain -> {
|
||||
eventSupport.runClientHandlers(domain, event,
|
||||
EventDetails.fromProviderEventDetails(details, providerName, domain));
|
||||
});
|
||||
allDomainNames.forEach(domain -> eventSupport.runClientHandlers(
|
||||
domain, event, EventDetails.fromProviderEventDetails(details, providerName, domain)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,8 @@ import dev.openfeature.sdk.exceptions.FatalError;
|
|||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import dev.openfeature.sdk.exceptions.OpenFeatureError;
|
||||
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
|
||||
import dev.openfeature.sdk.internal.AutoCloseableLock;
|
||||
import dev.openfeature.sdk.internal.AutoCloseableReentrantReadWriteLock;
|
||||
import dev.openfeature.sdk.internal.ObjectUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -18,7 +14,11 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* OpenFeature Client implementation.
|
||||
|
@ -29,21 +29,27 @@ import java.util.function.Consumer;
|
|||
* @deprecated // TODO: eventually we will make this non-public. See issue #872
|
||||
*/
|
||||
@Slf4j
|
||||
@SuppressWarnings({"PMD.DataflowAnomalyAnalysis", "PMD.BeanMembersShouldSerialize", "PMD.UnusedLocalVariable",
|
||||
"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({
|
||||
"PMD.DataflowAnomalyAnalysis",
|
||||
"PMD.BeanMembersShouldSerialize",
|
||||
"PMD.UnusedLocalVariable",
|
||||
"unchecked",
|
||||
"rawtypes"
|
||||
})
|
||||
@Deprecated() // TODO: eventually we will make this non-public. See issue #872
|
||||
public class OpenFeatureClient implements Client {
|
||||
|
||||
private final OpenFeatureAPI openfeatureApi;
|
||||
|
||||
@Getter
|
||||
private final String domain;
|
||||
|
||||
@Getter
|
||||
private final String version;
|
||||
private final List<Hook> clientHooks;
|
||||
|
||||
private final ConcurrentLinkedQueue<Hook> clientHooks;
|
||||
private final HookSupport hookSupport;
|
||||
AutoCloseableReentrantReadWriteLock hooksLock = new AutoCloseableReentrantReadWriteLock();
|
||||
AutoCloseableReentrantReadWriteLock contextLock = new AutoCloseableReentrantReadWriteLock();
|
||||
private EvaluationContext evaluationContext;
|
||||
private final AtomicReference<EvaluationContext> evaluationContext = new AtomicReference<>();
|
||||
|
||||
/**
|
||||
* Deprecated public constructor. Use OpenFeature.API.getClient() instead.
|
||||
|
@ -53,18 +59,15 @@ public class OpenFeatureClient implements Client {
|
|||
* providers (used by observability tools).
|
||||
* @param version Version of the client (used by observability tools).
|
||||
* @deprecated Do not use this constructor. It's for internal use only.
|
||||
* Clients created using it will not run event handlers.
|
||||
* Use the OpenFeatureAPI's getClient factory method instead.
|
||||
* Clients created using it will not run event handlers.
|
||||
* Use the OpenFeatureAPI's getClient factory method instead.
|
||||
*/
|
||||
@Deprecated() // TODO: eventually we will make this non-public. See issue #872
|
||||
public OpenFeatureClient(
|
||||
OpenFeatureAPI openFeatureAPI,
|
||||
String domain,
|
||||
String version) {
|
||||
public OpenFeatureClient(OpenFeatureAPI openFeatureAPI, String domain, String version) {
|
||||
this.openfeatureApi = openFeatureAPI;
|
||||
this.domain = domain;
|
||||
this.version = version;
|
||||
this.clientHooks = new ArrayList<>();
|
||||
this.clientHooks = new ConcurrentLinkedQueue<>();
|
||||
this.hookSupport = new HookSupport();
|
||||
}
|
||||
|
||||
|
@ -85,7 +88,6 @@ public class OpenFeatureClient implements Client {
|
|||
invokeTrack(trackingEventName, null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -117,15 +119,12 @@ public class OpenFeatureClient implements Client {
|
|||
invokeTrack(trackingEventName, mergeEvaluationContext(context), details);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public OpenFeatureClient addHooks(Hook... hooks) {
|
||||
try (AutoCloseableLock __ = this.hooksLock.writeLockAutoCloseable()) {
|
||||
this.clientHooks.addAll(Arrays.asList(hooks));
|
||||
}
|
||||
this.clientHooks.addAll(Arrays.asList(hooks));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -134,9 +133,7 @@ public class OpenFeatureClient implements Client {
|
|||
*/
|
||||
@Override
|
||||
public List<Hook> getHooks() {
|
||||
try (AutoCloseableLock __ = this.hooksLock.readLockAutoCloseable()) {
|
||||
return this.clientHooks;
|
||||
}
|
||||
return new ArrayList<>(this.clientHooks);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,9 +141,7 @@ public class OpenFeatureClient implements Client {
|
|||
*/
|
||||
@Override
|
||||
public OpenFeatureClient setEvaluationContext(EvaluationContext evaluationContext) {
|
||||
try (AutoCloseableLock __ = contextLock.writeLockAutoCloseable()) {
|
||||
this.evaluationContext = evaluationContext;
|
||||
}
|
||||
this.evaluationContext.set(evaluationContext);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -155,51 +150,62 @@ public class OpenFeatureClient implements Client {
|
|||
*/
|
||||
@Override
|
||||
public EvaluationContext getEvaluationContext() {
|
||||
try (AutoCloseableLock __ = contextLock.readLockAutoCloseable()) {
|
||||
return this.evaluationContext;
|
||||
}
|
||||
return this.evaluationContext.get();
|
||||
}
|
||||
|
||||
private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key, T defaultValue,
|
||||
EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
FlagEvaluationOptions flagOptions = ObjectUtils.defaultIfNull(options,
|
||||
() -> FlagEvaluationOptions.builder().build());
|
||||
Map<String, Object> hints = Collections.unmodifiableMap(flagOptions.getHookHints());
|
||||
@SuppressFBWarnings(
|
||||
value = {"REC_CATCH_EXCEPTION"},
|
||||
justification = "We don't want to allow any exception to reach the user. "
|
||||
+ "Instead, we return an evaluation result with the appropriate error code.")
|
||||
private <T> FlagEvaluationDetails<T> evaluateFlag(
|
||||
FlagValueType type, String key, T defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
var flagOptions = ObjectUtils.defaultIfNull(
|
||||
options, () -> FlagEvaluationOptions.builder().build());
|
||||
var hints = Collections.unmodifiableMap(flagOptions.getHookHints());
|
||||
|
||||
FlagEvaluationDetails<T> details = null;
|
||||
List<Hook> mergedHooks = null;
|
||||
HookContext<T> afterHookContext = null;
|
||||
FeatureProvider provider;
|
||||
|
||||
try {
|
||||
FeatureProviderStateManager stateManager = openfeatureApi.getFeatureProviderStateManager(this.domain);
|
||||
var stateManager = openfeatureApi.getFeatureProviderStateManager(this.domain);
|
||||
// provider must be accessed once to maintain a consistent reference
|
||||
provider = stateManager.getProvider();
|
||||
ProviderState state = stateManager.getState();
|
||||
var provider = stateManager.getProvider();
|
||||
var state = stateManager.getState();
|
||||
|
||||
mergedHooks = ObjectUtils.merge(
|
||||
provider.getProviderHooks(), flagOptions.getHooks(), clientHooks, openfeatureApi.getMutableHooks());
|
||||
|
||||
var mergedCtx = hookSupport.beforeHooks(
|
||||
type,
|
||||
HookContext.from(
|
||||
key,
|
||||
type,
|
||||
this.getMetadata(),
|
||||
provider.getMetadata(),
|
||||
mergeEvaluationContext(ctx),
|
||||
defaultValue),
|
||||
mergedHooks,
|
||||
hints);
|
||||
|
||||
afterHookContext =
|
||||
HookContext.from(key, type, this.getMetadata(), provider.getMetadata(), mergedCtx, defaultValue);
|
||||
|
||||
// "short circuit" if the provider is in NOT_READY or FATAL state
|
||||
if (ProviderState.NOT_READY.equals(state)) {
|
||||
throw new ProviderNotReadyError("provider not yet initialized");
|
||||
throw new ProviderNotReadyError("Provider not yet initialized");
|
||||
}
|
||||
if (ProviderState.FATAL.equals(state)) {
|
||||
throw new FatalError("provider is in an irrecoverable error state");
|
||||
throw new FatalError("Provider is in an irrecoverable error state");
|
||||
}
|
||||
|
||||
mergedHooks = ObjectUtils.merge(provider.getProviderHooks(), flagOptions.getHooks(), clientHooks,
|
||||
openfeatureApi.getHooks());
|
||||
|
||||
EvaluationContext mergedCtx = hookSupport.beforeHooks(type, HookContext.from(key, type, this.getMetadata(),
|
||||
provider.getMetadata(), mergeEvaluationContext(ctx), defaultValue), mergedHooks, hints);
|
||||
|
||||
afterHookContext = HookContext.from(key, type, this.getMetadata(),
|
||||
provider.getMetadata(), mergedCtx, defaultValue);
|
||||
|
||||
ProviderEvaluation<T> providerEval = (ProviderEvaluation<T>) createProviderEvaluation(type, key,
|
||||
defaultValue, provider, mergedCtx);
|
||||
var providerEval =
|
||||
(ProviderEvaluation<T>) createProviderEvaluation(type, key, defaultValue, provider, mergedCtx);
|
||||
|
||||
details = FlagEvaluationDetails.from(providerEval, key);
|
||||
if (details.getErrorCode() != null) {
|
||||
OpenFeatureError error = ExceptionUtils.instantiateErrorByErrorCode(
|
||||
details.getErrorCode(),
|
||||
details.getErrorMessage());
|
||||
var error =
|
||||
ExceptionUtils.instantiateErrorByErrorCode(details.getErrorCode(), details.getErrorMessage());
|
||||
enrichDetailsWithErrorDefaults(defaultValue, details);
|
||||
hookSupport.errorHooks(type, afterHookContext, error, mergedHooks, hints);
|
||||
} else {
|
||||
|
@ -207,7 +213,7 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
if (details == null) {
|
||||
details = FlagEvaluationDetails.<T>builder().build();
|
||||
details = FlagEvaluationDetails.<T>builder().flagKey(key).build();
|
||||
}
|
||||
if (e instanceof OpenFeatureError) {
|
||||
details.setErrorCode(((OpenFeatureError) e).getErrorCode());
|
||||
|
@ -218,7 +224,7 @@ public class OpenFeatureClient implements Client {
|
|||
enrichDetailsWithErrorDefaults(defaultValue, details);
|
||||
hookSupport.errorHooks(type, afterHookContext, e, mergedHooks, hints);
|
||||
} finally {
|
||||
hookSupport.afterAllHooks(type, afterHookContext, mergedHooks, hints);
|
||||
hookSupport.afterAllHooks(type, afterHookContext, details, mergedHooks, hints);
|
||||
}
|
||||
|
||||
return details;
|
||||
|
@ -237,7 +243,8 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
private void invokeTrack(String trackingEventName, EvaluationContext context, TrackingEventDetails details) {
|
||||
openfeatureApi.getFeatureProviderStateManager(domain)
|
||||
openfeatureApi
|
||||
.getFeatureProviderStateManager(domain)
|
||||
.getProvider()
|
||||
.track(trackingEventName, mergeEvaluationContext(context), details);
|
||||
}
|
||||
|
@ -251,7 +258,7 @@ public class OpenFeatureClient implements Client {
|
|||
*/
|
||||
private EvaluationContext mergeEvaluationContext(EvaluationContext invocationContext) {
|
||||
final EvaluationContext apiContext = openfeatureApi.getEvaluationContext();
|
||||
final EvaluationContext clientContext = this.getEvaluationContext();
|
||||
final EvaluationContext clientContext = evaluationContext.get();
|
||||
final EvaluationContext transactionContext = openfeatureApi.getTransactionContext();
|
||||
return mergeContextMaps(apiContext, transactionContext, clientContext, invocationContext);
|
||||
}
|
||||
|
@ -262,8 +269,7 @@ public class OpenFeatureClient implements Client {
|
|||
Map merged = new HashMap<>();
|
||||
for (EvaluationContext evaluationContext : contexts) {
|
||||
if (evaluationContext != null && !evaluationContext.isEmpty()) {
|
||||
EvaluationContext.mergeMaps(ImmutableStructure::new, merged,
|
||||
evaluationContext.asUnmodifiableMap());
|
||||
EvaluationContext.mergeMaps(ImmutableStructure::new, merged, evaluationContext.asUnmodifiableMap());
|
||||
}
|
||||
}
|
||||
return new ImmutableContext(merged);
|
||||
|
@ -302,8 +308,8 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean getBooleanValue(String key, Boolean defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public Boolean getBooleanValue(
|
||||
String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return getBooleanDetails(key, defaultValue, ctx, options).getValue();
|
||||
}
|
||||
|
||||
|
@ -314,12 +320,13 @@ public class OpenFeatureClient implements Client {
|
|||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx) {
|
||||
return getBooleanDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
return getBooleanDetails(
|
||||
key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public FlagEvaluationDetails<Boolean> getBooleanDetails(
|
||||
String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.BOOLEAN, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
|
@ -334,8 +341,8 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getStringValue(String key, String defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public String getStringValue(
|
||||
String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return getStringDetails(key, defaultValue, ctx, options).getValue();
|
||||
}
|
||||
|
||||
|
@ -346,12 +353,13 @@ public class OpenFeatureClient implements Client {
|
|||
|
||||
@Override
|
||||
public FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx) {
|
||||
return getStringDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
return getStringDetails(
|
||||
key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public FlagEvaluationDetails<String> getStringDetails(
|
||||
String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.STRING, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
|
@ -366,8 +374,8 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer getIntegerValue(String key, Integer defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public Integer getIntegerValue(
|
||||
String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return getIntegerDetails(key, defaultValue, ctx, options).getValue();
|
||||
}
|
||||
|
||||
|
@ -378,12 +386,13 @@ public class OpenFeatureClient implements Client {
|
|||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx) {
|
||||
return getIntegerDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
return getIntegerDetails(
|
||||
key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public FlagEvaluationDetails<Integer> getIntegerDetails(
|
||||
String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.INTEGER, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
|
@ -398,9 +407,10 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options).getValue();
|
||||
public Double getDoubleValue(
|
||||
String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options)
|
||||
.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -414,8 +424,8 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public FlagEvaluationDetails<Double> getDoubleDetails(
|
||||
String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
|
@ -430,8 +440,7 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return getObjectDetails(key, defaultValue, ctx, options).getValue();
|
||||
}
|
||||
|
||||
|
@ -441,14 +450,14 @@ public class OpenFeatureClient implements Client {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
|
||||
EvaluationContext ctx) {
|
||||
return getObjectDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue, EvaluationContext ctx) {
|
||||
return getObjectDetails(
|
||||
key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue, EvaluationContext ctx,
|
||||
FlagEvaluationOptions options) {
|
||||
public FlagEvaluationDetails<Value> getObjectDetails(
|
||||
String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.OBJECT, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
|
@ -494,7 +503,7 @@ public class OpenFeatureClient implements Client {
|
|||
*/
|
||||
@Override
|
||||
public Client on(ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
OpenFeatureAPI.getInstance().addHandler(domain, event, handler);
|
||||
openfeatureApi.addHandler(domain, event, handler);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -503,7 +512,7 @@ public class OpenFeatureClient implements Client {
|
|||
*/
|
||||
@Override
|
||||
public Client removeHandler(ProviderEvent event, Consumer<EventDetails> handler) {
|
||||
OpenFeatureAPI.getInstance().removeHandler(domain, event, handler);
|
||||
openfeatureApi.removeHandler(domain, event, handler);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public class ProviderEvaluation<T> implements BaseEvaluation<T> {
|
|||
private String reason;
|
||||
ErrorCode errorCode;
|
||||
private String errorMessage;
|
||||
|
||||
@Builder.Default
|
||||
private ImmutableMetadata flagMetadata = ImmutableMetadata.builder().build();
|
||||
}
|
||||
|
|
|
@ -4,5 +4,8 @@ package dev.openfeature.sdk;
|
|||
* Provider event types.
|
||||
*/
|
||||
public enum ProviderEvent {
|
||||
PROVIDER_READY, PROVIDER_CONFIGURATION_CHANGED, PROVIDER_ERROR, PROVIDER_STALE;
|
||||
PROVIDER_READY,
|
||||
PROVIDER_CONFIGURATION_CHANGED,
|
||||
PROVIDER_ERROR,
|
||||
PROVIDER_STALE;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* The details of a particular event.
|
||||
*/
|
||||
@Data @SuperBuilder(toBuilder = true)
|
||||
@Data
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class ProviderEventDetails {
|
||||
private List<String> flagsChanged;
|
||||
private String message;
|
||||
|
|
|
@ -2,8 +2,6 @@ package dev.openfeature.sdk;
|
|||
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import dev.openfeature.sdk.exceptions.OpenFeatureError;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
@ -16,20 +14,25 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
class ProviderRepository {
|
||||
|
||||
private final Map<String, FeatureProviderStateManager> stateManagers = new ConcurrentHashMap<>();
|
||||
private final AtomicReference<FeatureProviderStateManager> defaultStateManger = new AtomicReference<>(
|
||||
new FeatureProviderStateManager(new NoOpProvider())
|
||||
);
|
||||
private final AtomicReference<FeatureProviderStateManager> defaultStateManger =
|
||||
new AtomicReference<>(new FeatureProviderStateManager(new NoOpProvider()));
|
||||
private final ExecutorService taskExecutor = Executors.newCachedThreadPool(runnable -> {
|
||||
final Thread thread = new Thread(runnable);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
private final Object registerStateManagerLock = new Object();
|
||||
private final OpenFeatureAPI openFeatureAPI;
|
||||
|
||||
public ProviderRepository(OpenFeatureAPI openFeatureAPI) {
|
||||
this.openFeatureAPI = openFeatureAPI;
|
||||
}
|
||||
|
||||
FeatureProviderStateManager getFeatureProviderStateManager() {
|
||||
return defaultStateManger.get();
|
||||
|
@ -96,7 +99,8 @@ class ProviderRepository {
|
|||
public List<String> getDomainsForProvider(FeatureProvider provider) {
|
||||
return stateManagers.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().hasSameProvider(provider))
|
||||
.map(Map.Entry::getKey).collect(Collectors.toList());
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Set<String> getAllBoundDomains() {
|
||||
|
@ -110,12 +114,13 @@ class ProviderRepository {
|
|||
/**
|
||||
* Set the default provider.
|
||||
*/
|
||||
public void setProvider(FeatureProvider provider,
|
||||
Consumer<FeatureProvider> afterSet,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
boolean waitForInit) {
|
||||
public void setProvider(
|
||||
FeatureProvider provider,
|
||||
Consumer<FeatureProvider> afterSet,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
boolean waitForInit) {
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException("Provider cannot be null");
|
||||
}
|
||||
|
@ -130,13 +135,14 @@ class ProviderRepository {
|
|||
* @param waitForInit When true, wait for initialization to finish, then returns.
|
||||
* Otherwise, initialization happens in the background.
|
||||
*/
|
||||
public void setProvider(String domain,
|
||||
FeatureProvider provider,
|
||||
Consumer<FeatureProvider> afterSet,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
boolean waitForInit) {
|
||||
public void setProvider(
|
||||
String domain,
|
||||
FeatureProvider provider,
|
||||
Consumer<FeatureProvider> afterSet,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
boolean waitForInit) {
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException("Provider cannot be null");
|
||||
}
|
||||
|
@ -146,13 +152,14 @@ class ProviderRepository {
|
|||
prepareAndInitializeProvider(domain, provider, afterSet, afterInit, afterShutdown, afterError, waitForInit);
|
||||
}
|
||||
|
||||
private void prepareAndInitializeProvider(String domain,
|
||||
FeatureProvider newProvider,
|
||||
Consumer<FeatureProvider> afterSet,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
boolean waitForInit) {
|
||||
private void prepareAndInitializeProvider(
|
||||
String domain,
|
||||
FeatureProvider newProvider,
|
||||
Consumer<FeatureProvider> afterSet,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
boolean waitForInit) {
|
||||
final FeatureProviderStateManager newStateManager;
|
||||
final FeatureProviderStateManager oldStateManager;
|
||||
|
||||
|
@ -195,14 +202,15 @@ class ProviderRepository {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void initializeProvider(FeatureProviderStateManager newManager,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
FeatureProviderStateManager oldManager) {
|
||||
private void initializeProvider(
|
||||
FeatureProviderStateManager newManager,
|
||||
Consumer<FeatureProvider> afterInit,
|
||||
Consumer<FeatureProvider> afterShutdown,
|
||||
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
|
||||
FeatureProviderStateManager oldManager) {
|
||||
try {
|
||||
if (ProviderState.NOT_READY.equals(newManager.getState())) {
|
||||
newManager.initialize(OpenFeatureAPI.getInstance().getEvaluationContext());
|
||||
newManager.initialize(openFeatureAPI.getEvaluationContext());
|
||||
afterInit.accept(newManager.getProvider());
|
||||
}
|
||||
shutDownOld(oldManager, afterShutdown);
|
||||
|
@ -210,15 +218,13 @@ class ProviderRepository {
|
|||
log.error(
|
||||
"Exception when initializing feature provider {}",
|
||||
newManager.getProvider().getClass().getName(),
|
||||
e
|
||||
);
|
||||
e);
|
||||
afterError.accept(newManager.getProvider(), e);
|
||||
} catch (Exception e) {
|
||||
log.error(
|
||||
"Exception when initializing feature provider {}",
|
||||
newManager.getProvider().getClass().getName(),
|
||||
e
|
||||
);
|
||||
e);
|
||||
afterError.accept(newManager.getProvider(), new GeneralError(e));
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +244,8 @@ class ProviderRepository {
|
|||
*/
|
||||
private boolean isStateManagerRegistered(FeatureProviderStateManager manager) {
|
||||
return manager != null
|
||||
&& (this.stateManagers.containsValue(manager) || this.defaultStateManger.get().equals(manager));
|
||||
&& (this.stateManagers.containsValue(manager)
|
||||
|| this.defaultStateManger.get().equals(manager));
|
||||
}
|
||||
|
||||
private void shutdownProvider(FeatureProviderStateManager manager) {
|
||||
|
@ -253,7 +260,10 @@ class ProviderRepository {
|
|||
try {
|
||||
provider.shutdown();
|
||||
} catch (Exception e) {
|
||||
log.error("Exception when shutting down feature provider {}", provider.getClass().getName(), e);
|
||||
log.error(
|
||||
"Exception when shutting down feature provider {}",
|
||||
provider.getClass().getName(),
|
||||
e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -264,8 +274,7 @@ class ProviderRepository {
|
|||
* including the default feature provider.
|
||||
*/
|
||||
public void shutdown() {
|
||||
Stream
|
||||
.concat(Stream.of(this.defaultStateManger.get()), this.stateManagers.values().stream())
|
||||
Stream.concat(Stream.of(this.defaultStateManger.get()), this.stateManagers.values().stream())
|
||||
.distinct()
|
||||
.forEach(this::shutdownProvider);
|
||||
this.stateManagers.clear();
|
||||
|
|
|
@ -4,11 +4,15 @@ package dev.openfeature.sdk;
|
|||
* Indicates the state of the provider.
|
||||
*/
|
||||
public enum ProviderState {
|
||||
READY, NOT_READY, ERROR, STALE, FATAL;
|
||||
READY,
|
||||
NOT_READY,
|
||||
ERROR,
|
||||
STALE,
|
||||
FATAL;
|
||||
|
||||
/**
|
||||
* Returns true if the passed ProviderEvent maps to this ProviderState.
|
||||
*
|
||||
*
|
||||
* @param event event to compare
|
||||
* @return boolean if matches.
|
||||
*/
|
||||
|
|
|
@ -4,5 +4,12 @@ package dev.openfeature.sdk;
|
|||
* Predefined resolution reasons.
|
||||
*/
|
||||
public enum Reason {
|
||||
DISABLED, SPLIT, TARGETING_MATCH, DEFAULT, UNKNOWN, CACHED, STATIC, ERROR
|
||||
DISABLED,
|
||||
SPLIT,
|
||||
TARGETING_MATCH,
|
||||
DEFAULT,
|
||||
UNKNOWN,
|
||||
CACHED,
|
||||
STATIC,
|
||||
ERROR
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package dev.openfeature.sdk;
|
|||
/**
|
||||
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
|
||||
* to the lifecycle of flag evaluation.
|
||||
*
|
||||
*
|
||||
* @see Hook
|
||||
*/
|
||||
public interface StringHook extends Hook<String> {
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.ValueNotConvertableError;
|
||||
import static dev.openfeature.sdk.Value.objectToValue;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.ValueNotConvertableError;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.openfeature.sdk.Value.objectToValue;
|
||||
|
||||
/**
|
||||
* {@link Structure} represents a potentially nested object type which is used to represent
|
||||
* {@link Structure} represents a potentially nested object type which is used to represent
|
||||
* structured data.
|
||||
*/
|
||||
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
|
||||
public interface Structure {
|
||||
|
||||
|
||||
/**
|
||||
* Boolean indicating if this structure is empty.
|
||||
*
|
||||
* @return boolean for emptiness
|
||||
*/
|
||||
boolean isEmpty();
|
||||
|
@ -51,7 +51,6 @@ public interface Structure {
|
|||
*/
|
||||
Map<String, Value> asUnmodifiableMap();
|
||||
|
||||
|
||||
/**
|
||||
* Get all values, with as a map of Object.
|
||||
*
|
||||
|
@ -93,20 +92,15 @@ public interface Structure {
|
|||
}
|
||||
|
||||
if (value.isList()) {
|
||||
return value.asList()
|
||||
.stream()
|
||||
.map(this::convertValue)
|
||||
.collect(Collectors.toList());
|
||||
return value.asList().stream().map(this::convertValue).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (value.isStructure()) {
|
||||
Structure s = value.asStructure();
|
||||
return s.asUnmodifiableMap()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(HashMap::new,
|
||||
(accumulated, entry) -> accumulated.put(entry.getKey(),
|
||||
convertValue(entry.getValue())),
|
||||
return s.asUnmodifiableMap().entrySet().stream()
|
||||
.collect(
|
||||
HashMap::new,
|
||||
(accumulated, entry) -> accumulated.put(entry.getKey(), convertValue(entry.getValue())),
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
|
@ -121,9 +115,9 @@ public interface Structure {
|
|||
*/
|
||||
static Structure mapToStructure(Map<String, Object> map) {
|
||||
return new MutableStructure(map.entrySet().stream()
|
||||
.collect(HashMap::new,
|
||||
(accumulated, entry) -> accumulated.put(entry.getKey(),
|
||||
objectToValue(entry.getValue())),
|
||||
.collect(
|
||||
HashMap::new,
|
||||
(accumulated, entry) -> accumulated.put(entry.getKey(), objectToValue(entry.getValue())),
|
||||
HashMap::putAll));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
/**
|
||||
* The Telemetry class provides constants and methods for creating OpenTelemetry compliant
|
||||
* evaluation events.
|
||||
*/
|
||||
public class Telemetry {
|
||||
|
||||
private Telemetry() {}
|
||||
|
||||
/*
|
||||
The OpenTelemetry compliant event attributes for flag evaluation.
|
||||
Specification: https://opentelemetry.io/docs/specs/semconv/feature-flags/feature-flags-logs/
|
||||
*/
|
||||
public static final String TELEMETRY_KEY = "feature_flag.key";
|
||||
public static final String TELEMETRY_ERROR_CODE = "error.type";
|
||||
public static final String TELEMETRY_VARIANT = "feature_flag.result.variant";
|
||||
public static final String TELEMETRY_VALUE = "feature_flag.result.value";
|
||||
public static final String TELEMETRY_CONTEXT_ID = "feature_flag.context.id";
|
||||
public static final String TELEMETRY_ERROR_MSG = "feature_flag.evaluation.error.message";
|
||||
public static final String TELEMETRY_REASON = "feature_flag.result.reason";
|
||||
public static final String TELEMETRY_PROVIDER = "feature_flag.provider.name";
|
||||
public static final String TELEMETRY_FLAG_SET_ID = "feature_flag.set.id";
|
||||
public static final String TELEMETRY_VERSION = "feature_flag.version";
|
||||
|
||||
// Well-known flag metadata attributes for telemetry events.
|
||||
// Specification: https://openfeature.dev/specification/appendix-d#flag-metadata
|
||||
public static final String TELEMETRY_FLAG_META_CONTEXT_ID = "contextId";
|
||||
public static final String TELEMETRY_FLAG_META_FLAG_SET_ID = "flagSetId";
|
||||
public static final String TELEMETRY_FLAG_META_VERSION = "version";
|
||||
|
||||
public static final String FLAG_EVALUATION_EVENT_NAME = "feature_flag.evaluation";
|
||||
|
||||
/**
|
||||
* Creates an EvaluationEvent using the provided HookContext and ProviderEvaluation.
|
||||
*
|
||||
* @param hookContext the context containing flag evaluation details
|
||||
* @param evaluationDetails the evaluation result from the provider
|
||||
*
|
||||
* @return an EvaluationEvent populated with telemetry data
|
||||
*/
|
||||
public static EvaluationEvent createEvaluationEvent(
|
||||
HookContext<?> hookContext, FlagEvaluationDetails<?> evaluationDetails) {
|
||||
EvaluationEvent.EvaluationEventBuilder evaluationEventBuilder = EvaluationEvent.builder()
|
||||
.name(FLAG_EVALUATION_EVENT_NAME)
|
||||
.attribute(TELEMETRY_KEY, hookContext.getFlagKey())
|
||||
.attribute(TELEMETRY_PROVIDER, hookContext.getProviderMetadata().getName());
|
||||
|
||||
if (evaluationDetails.getReason() != null) {
|
||||
evaluationEventBuilder.attribute(
|
||||
TELEMETRY_REASON, evaluationDetails.getReason().toLowerCase());
|
||||
} else {
|
||||
evaluationEventBuilder.attribute(
|
||||
TELEMETRY_REASON, Reason.UNKNOWN.name().toLowerCase());
|
||||
}
|
||||
|
||||
if (evaluationDetails.getVariant() != null) {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_VARIANT, evaluationDetails.getVariant());
|
||||
} else {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_VALUE, evaluationDetails.getValue());
|
||||
}
|
||||
|
||||
String contextId = evaluationDetails.getFlagMetadata().getString(TELEMETRY_FLAG_META_CONTEXT_ID);
|
||||
if (contextId != null) {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_CONTEXT_ID, contextId);
|
||||
} else {
|
||||
evaluationEventBuilder.attribute(
|
||||
TELEMETRY_CONTEXT_ID, hookContext.getCtx().getTargetingKey());
|
||||
}
|
||||
|
||||
String setID = evaluationDetails.getFlagMetadata().getString(TELEMETRY_FLAG_META_FLAG_SET_ID);
|
||||
if (setID != null) {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_FLAG_SET_ID, setID);
|
||||
}
|
||||
|
||||
String version = evaluationDetails.getFlagMetadata().getString(TELEMETRY_FLAG_META_VERSION);
|
||||
if (version != null) {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_VERSION, version);
|
||||
}
|
||||
|
||||
if (Reason.ERROR.name().equals(evaluationDetails.getReason())) {
|
||||
if (evaluationDetails.getErrorCode() != null) {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_ERROR_CODE, evaluationDetails.getErrorCode());
|
||||
} else {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_ERROR_CODE, ErrorCode.GENERAL);
|
||||
}
|
||||
|
||||
if (evaluationDetails.getErrorMessage() != null) {
|
||||
evaluationEventBuilder.attribute(TELEMETRY_ERROR_MSG, evaluationDetails.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return evaluationEventBuilder.build();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,14 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Data pertinent to a particular tracking event.
|
||||
*/
|
||||
public interface TrackingEventDetails extends Structure {
|
||||
|
||||
/**
|
||||
* Returns the optional numeric tracking value.
|
||||
*/
|
||||
Optional<Number> getValue();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package dev.openfeature.sdk;
|
|||
* for the duration of a single transaction.
|
||||
* Examples of potential transaction specific context include: a user id, user agent, IP.
|
||||
* Transaction context is merged with evaluation context prior to flag evaluation.
|
||||
*
|
||||
* <p>
|
||||
* The precedence of merging context can be seen in
|
||||
* <a href=https://openfeature.dev/specification/sections/evaluation-context#requirement-323>the specification</a>.
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import static dev.openfeature.sdk.Structure.mapToStructure;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.TypeMismatchError;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.TypeMismatchError;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.ToString;
|
||||
|
||||
import static dev.openfeature.sdk.Structure.mapToStructure;
|
||||
|
||||
/**
|
||||
* Values serve as a generic return type for structure data from providers.
|
||||
* Providers may deal in JSON, protobuf, XML or some other data-interchange format.
|
||||
|
@ -37,33 +36,34 @@ public class Value implements Cloneable {
|
|||
|
||||
/**
|
||||
* Construct a new Value with an Object.
|
||||
*
|
||||
* @param value to be wrapped.
|
||||
* @throws InstantiationException if value is not a valid type
|
||||
* (boolean, string, int, double, list, structure, instant)
|
||||
* (boolean, string, int, double, list, structure, instant)
|
||||
*/
|
||||
public Value(Object value) throws InstantiationException {
|
||||
this.innerObject = value;
|
||||
if (!this.isNull()
|
||||
&& !this.isBoolean()
|
||||
&& !this.isString()
|
||||
&& !this.isNumber()
|
||||
&& !this.isStructure()
|
||||
&& !this.isList()
|
||||
&& !this.isInstant()) {
|
||||
&& !this.isBoolean()
|
||||
&& !this.isString()
|
||||
&& !this.isNumber()
|
||||
&& !this.isStructure()
|
||||
&& !this.isList()
|
||||
&& !this.isInstant()) {
|
||||
throw new InstantiationException("Invalid value type: " + value.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
public Value(Value value) {
|
||||
this.innerObject = value.innerObject;
|
||||
this.innerObject = value.innerObject;
|
||||
}
|
||||
|
||||
public Value(Boolean value) {
|
||||
this.innerObject = value;
|
||||
this.innerObject = value;
|
||||
}
|
||||
|
||||
public Value(String value) {
|
||||
this.innerObject = value;
|
||||
this.innerObject = value;
|
||||
}
|
||||
|
||||
public Value(Integer value) {
|
||||
|
@ -71,69 +71,69 @@ public class Value implements Cloneable {
|
|||
}
|
||||
|
||||
public Value(Double value) {
|
||||
this.innerObject = value;
|
||||
this.innerObject = value;
|
||||
}
|
||||
|
||||
public Value(Structure value) {
|
||||
this.innerObject = value;
|
||||
this.innerObject = value;
|
||||
}
|
||||
|
||||
public Value(List<Value> value) {
|
||||
this.innerObject = value;
|
||||
this.innerObject = value;
|
||||
}
|
||||
|
||||
public Value(Instant value) {
|
||||
this.innerObject = value;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if this Value represents null.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isNull() {
|
||||
return this.innerObject == null;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if this Value represents a Boolean.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isBoolean() {
|
||||
return this.innerObject instanceof Boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if this Value represents a String.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isString() {
|
||||
return this.innerObject instanceof String;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if this Value represents a numeric value.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isNumber() {
|
||||
return this.innerObject instanceof Number;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if this Value represents a Structure.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isStructure() {
|
||||
return this.innerObject instanceof Structure;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Check if this Value represents a List of Values.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isList() {
|
||||
|
@ -155,87 +155,88 @@ public class Value implements Cloneable {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if this Value represents an Instant.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isInstant() {
|
||||
return this.innerObject instanceof Instant;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Retrieve the underlying Boolean value, or null.
|
||||
*
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL",
|
||||
justification = "This is not a plain true/false method. It's understood it can return null.")
|
||||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
|
||||
value = "NP_BOOLEAN_RETURN_NULL",
|
||||
justification = "This is not a plain true/false method. It's understood it can return null.")
|
||||
public Boolean asBoolean() {
|
||||
if (this.isBoolean()) {
|
||||
return (Boolean)this.innerObject;
|
||||
return (Boolean) this.innerObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Retrieve the underlying object.
|
||||
*
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
public Object asObject() {
|
||||
return this.innerObject;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the underlying String value, or null.
|
||||
*
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String asString() {
|
||||
if (this.isString()) {
|
||||
return (String)this.innerObject;
|
||||
return (String) this.innerObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the underlying numeric value as an Integer, or null.
|
||||
* If the value is not an integer, it will be rounded using Math.round().
|
||||
*
|
||||
*
|
||||
* @return Integer
|
||||
*/
|
||||
public Integer asInteger() {
|
||||
if (this.isNumber() && !this.isNull()) {
|
||||
return ((Number)this.innerObject).intValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the underlying numeric value as a Double, or null.
|
||||
*
|
||||
* @return Double
|
||||
*/
|
||||
public Double asDouble() {
|
||||
if (this.isNumber() && !isNull()) {
|
||||
return ((Number)this.innerObject).doubleValue();
|
||||
return ((Number) this.innerObject).intValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the underlying numeric value as a Double, or null.
|
||||
*
|
||||
* @return Double
|
||||
*/
|
||||
public Double asDouble() {
|
||||
if (this.isNumber() && !isNull()) {
|
||||
return ((Number) this.innerObject).doubleValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the underlying Structure value, or null.
|
||||
*
|
||||
*
|
||||
* @return Structure
|
||||
*/
|
||||
public Structure asStructure() {
|
||||
if (this.isStructure()) {
|
||||
return (Structure)this.innerObject;
|
||||
return (Structure) this.innerObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the underlying List value, or null.
|
||||
*
|
||||
|
@ -249,14 +250,14 @@ public class Value implements Cloneable {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the underlying Instant value, or null.
|
||||
*
|
||||
*
|
||||
* @return Instant
|
||||
*/
|
||||
public Instant asInstant() {
|
||||
if (this.isInstant()) {
|
||||
return (Instant)this.innerObject;
|
||||
return (Instant) this.innerObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -305,9 +306,8 @@ public class Value implements Cloneable {
|
|||
} else if (object instanceof Structure) {
|
||||
return new Value((Structure) object);
|
||||
} else if (object instanceof List) {
|
||||
return new Value(((List<Object>) object).stream()
|
||||
.map(o -> objectToValue(o))
|
||||
.collect(Collectors.toList()));
|
||||
return new Value(
|
||||
((List<Object>) object).stream().map(o -> objectToValue(o)).collect(Collectors.toList()));
|
||||
} else if (object instanceof Instant) {
|
||||
return new Value((Instant) object);
|
||||
} else if (object instanceof Map) {
|
||||
|
|
|
@ -9,7 +9,8 @@ public class ExceptionUtils {
|
|||
|
||||
/**
|
||||
* Creates an Error for the specific error code.
|
||||
* @param errorCode the ErrorCode to use
|
||||
*
|
||||
* @param errorCode the ErrorCode to use
|
||||
* @param errorMessage the error message to include in the returned error
|
||||
* @return the specific OpenFeatureError for the errorCode
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,7 @@ import lombok.experimental.StandardException;
|
|||
@StandardException
|
||||
public class FatalError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.PROVIDER_FATAL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.experimental.StandardException;
|
|||
@StandardException
|
||||
public class FlagNotFoundError extends OpenFeatureErrorWithoutStacktrace {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.FLAG_NOT_FOUND;
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import lombok.experimental.StandardException;
|
|||
@StandardException
|
||||
public class GeneralError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.GENERAL;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ import lombok.experimental.StandardException;
|
|||
public class InvalidContextError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter private final ErrorCode errorCode = ErrorCode.INVALID_CONTEXT;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.INVALID_CONTEXT;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ import lombok.experimental.StandardException;
|
|||
public class ParseError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter private final ErrorCode errorCode = ErrorCode.PARSE_ERROR;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.PARSE_ERROR;
|
||||
}
|
||||
|
|
|
@ -8,5 +8,7 @@ import lombok.experimental.StandardException;
|
|||
@StandardException
|
||||
public class ProviderNotReadyError extends OpenFeatureErrorWithoutStacktrace {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Getter private final ErrorCode errorCode = ErrorCode.PROVIDER_NOT_READY;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.PROVIDER_NOT_READY;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ import lombok.experimental.StandardException;
|
|||
public class TargetingKeyMissingError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter private final ErrorCode errorCode = ErrorCode.TARGETING_KEY_MISSING;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.TARGETING_KEY_MISSING;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@ import lombok.experimental.StandardException;
|
|||
public class TypeMismatchError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter private final ErrorCode errorCode = ErrorCode.TYPE_MISMATCH;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.TYPE_MISMATCH;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import lombok.experimental.StandardException;
|
|||
@StandardException
|
||||
public class ValueNotConvertableError extends OpenFeatureError {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final ErrorCode errorCode = ErrorCode.GENERAL;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@ import org.slf4j.spi.LoggingEventBuilder;
|
|||
* Flag evaluation data is logged at debug and error in before/after stages and error stages, respectively.
|
||||
*/
|
||||
@Slf4j
|
||||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED",
|
||||
justification = "we can ignore return values of chainables (builders) here")
|
||||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
|
||||
value = "RV_RETURN_VALUE_IGNORED",
|
||||
justification = "we can ignore return values of chainables (builders) here")
|
||||
public class LoggingHook implements Hook<Object> {
|
||||
|
||||
static final String DOMAIN_KEY = "domain";
|
||||
|
@ -43,6 +44,7 @@ public class LoggingHook implements Hook<Object> {
|
|||
|
||||
/**
|
||||
* Construct a new LoggingHook.
|
||||
*
|
||||
* @param includeEvaluationContext include a serialized evaluation context in the log message (defaults to false)
|
||||
*/
|
||||
public LoggingHook(boolean includeEvaluationContext) {
|
||||
|
@ -59,8 +61,8 @@ public class LoggingHook implements Hook<Object> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Object> hookContext, FlagEvaluationDetails<Object> details,
|
||||
Map<String, Object> hints) {
|
||||
public void after(
|
||||
HookContext<Object> hookContext, FlagEvaluationDetails<Object> details, Map<String, Object> hints) {
|
||||
LoggingEventBuilder builder = log.atDebug()
|
||||
.addKeyValue(REASON_KEY, details.getReason())
|
||||
.addKeyValue(VARIANT_KEY, details.getVariant())
|
||||
|
@ -71,8 +73,7 @@ public class LoggingHook implements Hook<Object> {
|
|||
|
||||
@Override
|
||||
public void error(HookContext<Object> hookContext, Exception error, Map<String, Object> hints) {
|
||||
LoggingEventBuilder builder = log.atError()
|
||||
.addKeyValue(ERROR_MESSAGE_KEY, error.getMessage());
|
||||
LoggingEventBuilder builder = log.atError().addKeyValue(ERROR_MESSAGE_KEY, error.getMessage());
|
||||
addCommonProps(builder, hookContext);
|
||||
ErrorCode errorCode = error instanceof OpenFeatureError ? ((OpenFeatureError) error).getErrorCode() : null;
|
||||
builder.addKeyValue(ERROR_CODE_KEY, errorCode);
|
||||
|
@ -81,7 +82,8 @@ public class LoggingHook implements Hook<Object> {
|
|||
|
||||
private void addCommonProps(LoggingEventBuilder builder, HookContext<Object> hookContext) {
|
||||
builder.addKeyValue(DOMAIN_KEY, hookContext.getClientMetadata().getDomain())
|
||||
.addKeyValue(PROVIDER_NAME_KEY, hookContext.getProviderMetadata().getName())
|
||||
.addKeyValue(
|
||||
PROVIDER_NAME_KEY, hookContext.getProviderMetadata().getName())
|
||||
.addKeyValue(FLAG_KEY_KEY, hookContext.getFlagKey())
|
||||
.addKeyValue(DEFAULT_VALUE_KEY, hookContext.getDefaultValue());
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package dev.openfeature.sdk.internal;
|
|||
|
||||
@SuppressWarnings("checkstyle:MissingJavadocType")
|
||||
public interface AutoCloseableLock extends AutoCloseable {
|
||||
|
||||
|
||||
/**
|
||||
* Override the exception in AutoClosable.
|
||||
*/
|
||||
|
|
|
@ -10,6 +10,7 @@ public class AutoCloseableReentrantReadWriteLock extends ReentrantReadWriteLock
|
|||
|
||||
/**
|
||||
* Get the single write lock as an AutoCloseableLock.
|
||||
*
|
||||
* @return unlock method ref
|
||||
*/
|
||||
public AutoCloseableLock writeLockAutoCloseable() {
|
||||
|
@ -19,10 +20,11 @@ public class AutoCloseableReentrantReadWriteLock extends ReentrantReadWriteLock
|
|||
|
||||
/**
|
||||
* Get the multi read lock as an AutoCloseableLock.
|
||||
*
|
||||
* @return unlock method ref
|
||||
*/
|
||||
public AutoCloseableLock readLockAutoCloseable() {
|
||||
this.readLock().lock();
|
||||
return this.readLock()::unlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package dev.openfeature.sdk.internal;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* JaCoCo ignores coverage of methods annotated with any annotation with "generated" in the name.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ExcludeFromGeneratedCoverageReport {
|
||||
}
|
||||
public @interface ExcludeFromGeneratedCoverageReport {}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package dev.openfeature.sdk.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@SuppressWarnings("checkstyle:MissingJavadocType")
|
||||
|
@ -13,9 +13,10 @@ public class ObjectUtils {
|
|||
|
||||
/**
|
||||
* If the source param is null, return the default value.
|
||||
* @param source maybe null object
|
||||
*
|
||||
* @param source maybe null object
|
||||
* @param defaultValue thing to use if source is null
|
||||
* @param <T> list type
|
||||
* @param <T> list type
|
||||
* @return resulting object
|
||||
*/
|
||||
public static <T> List<T> defaultIfNull(List<T> source, Supplier<List<T>> defaultValue) {
|
||||
|
@ -27,10 +28,11 @@ public class ObjectUtils {
|
|||
|
||||
/**
|
||||
* If the source param is null, return the default value.
|
||||
* @param source maybe null object
|
||||
*
|
||||
* @param source maybe null object
|
||||
* @param defaultValue thing to use if source is null
|
||||
* @param <K> map key type
|
||||
* @param <V> map value type
|
||||
* @param <K> map key type
|
||||
* @param <V> map value type
|
||||
* @return resulting map
|
||||
*/
|
||||
public static <K, V> Map<K, V> defaultIfNull(Map<K, V> source, Supplier<Map<K, V>> defaultValue) {
|
||||
|
@ -42,9 +44,10 @@ public class ObjectUtils {
|
|||
|
||||
/**
|
||||
* If the source param is null, return the default value.
|
||||
* @param source maybe null object
|
||||
*
|
||||
* @param source maybe null object
|
||||
* @param defaultValue thing to use if source is null
|
||||
* @param <T> type
|
||||
* @param <T> type
|
||||
* @return resulting object
|
||||
*/
|
||||
public static <T> T defaultIfNull(T source, Supplier<T> defaultValue) {
|
||||
|
@ -56,14 +59,15 @@ public class ObjectUtils {
|
|||
|
||||
/**
|
||||
* Concatenate a bunch of lists.
|
||||
*
|
||||
* @param sources bunch of lists.
|
||||
* @param <T> list type
|
||||
* @param <T> list type
|
||||
* @return resulting object
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> List<T> merge(List<T>... sources) {
|
||||
public static <T> List<T> merge(Collection<T>... sources) {
|
||||
List<T> merged = new ArrayList<>();
|
||||
for (List<T> source : sources) {
|
||||
for (Collection<T> source : sources) {
|
||||
merged.addAll(source);
|
||||
}
|
||||
return merged;
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Objects;
|
|||
|
||||
/**
|
||||
* Like {@link java.util.function.BiConsumer} but with 3 params.
|
||||
*
|
||||
*
|
||||
* @see java.util.function.BiConsumer
|
||||
*/
|
||||
@FunctionalInterface
|
||||
|
@ -35,4 +35,4 @@ public interface TriConsumer<T, U, V> {
|
|||
after.accept(t, u, v);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.openfeature.sdk.EvaluationContext;
|
|||
|
||||
/**
|
||||
* Context evaluator - use for resolving flag according to evaluation context, for handling targeting.
|
||||
*
|
||||
* @param <T> expected value type
|
||||
*/
|
||||
public interface ContextEvaluator<T> {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package dev.openfeature.sdk.providers.memory;
|
||||
|
||||
import dev.openfeature.sdk.ImmutableMetadata;
|
||||
import java.util.Map;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Flag representation for the in-memory provider.
|
||||
*/
|
||||
|
@ -16,6 +16,8 @@ import java.util.Map;
|
|||
public class Flag<T> {
|
||||
@Singular
|
||||
private Map<String, Object> variants;
|
||||
|
||||
private String defaultVariant;
|
||||
private ContextEvaluator<T> contextEvaluator;
|
||||
private ImmutableMetadata flagMetadata;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,28 @@
|
|||
package dev.openfeature.sdk.providers.memory;
|
||||
|
||||
import dev.openfeature.sdk.*;
|
||||
import dev.openfeature.sdk.exceptions.*;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import dev.openfeature.sdk.EvaluationContext;
|
||||
import dev.openfeature.sdk.EventProvider;
|
||||
import dev.openfeature.sdk.Metadata;
|
||||
import dev.openfeature.sdk.ProviderEvaluation;
|
||||
import dev.openfeature.sdk.ProviderEventDetails;
|
||||
import dev.openfeature.sdk.ProviderState;
|
||||
import dev.openfeature.sdk.Reason;
|
||||
import dev.openfeature.sdk.Value;
|
||||
import dev.openfeature.sdk.exceptions.FatalError;
|
||||
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import dev.openfeature.sdk.exceptions.OpenFeatureError;
|
||||
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
|
||||
import dev.openfeature.sdk.exceptions.TypeMismatchError;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* In-memory provider.
|
||||
|
@ -38,6 +49,7 @@ public class InMemoryProvider extends EventProvider {
|
|||
|
||||
/**
|
||||
* Initializes the provider.
|
||||
*
|
||||
* @param evaluationContext evaluation context
|
||||
* @throws Exception on error
|
||||
*/
|
||||
|
@ -60,9 +72,9 @@ public class InMemoryProvider extends EventProvider {
|
|||
this.flags.putAll(newFlags);
|
||||
|
||||
ProviderEventDetails details = ProviderEventDetails.builder()
|
||||
.flagsChanged(new ArrayList<>(flagsChanged))
|
||||
.message("flags changed")
|
||||
.build();
|
||||
.flagsChanged(new ArrayList<>(flagsChanged))
|
||||
.message("flags changed")
|
||||
.build();
|
||||
emitProviderConfigurationChanged(details);
|
||||
}
|
||||
|
||||
|
@ -76,46 +88,45 @@ public class InMemoryProvider extends EventProvider {
|
|||
public void updateFlag(String flagKey, Flag<?> newFlag) {
|
||||
this.flags.put(flagKey, newFlag);
|
||||
ProviderEventDetails details = ProviderEventDetails.builder()
|
||||
.flagsChanged(Collections.singletonList(flagKey))
|
||||
.message("flag added/updated")
|
||||
.build();
|
||||
.flagsChanged(Collections.singletonList(flagKey))
|
||||
.message("flag added/updated")
|
||||
.build();
|
||||
emitProviderConfigurationChanged(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue,
|
||||
EvaluationContext evaluationContext) {
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(
|
||||
String key, Boolean defaultValue, EvaluationContext evaluationContext) {
|
||||
return getEvaluation(key, evaluationContext, Boolean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue,
|
||||
EvaluationContext evaluationContext) {
|
||||
public ProviderEvaluation<String> getStringEvaluation(
|
||||
String key, String defaultValue, EvaluationContext evaluationContext) {
|
||||
return getEvaluation(key, evaluationContext, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue,
|
||||
EvaluationContext evaluationContext) {
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(
|
||||
String key, Integer defaultValue, EvaluationContext evaluationContext) {
|
||||
return getEvaluation(key, evaluationContext, Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue,
|
||||
EvaluationContext evaluationContext) {
|
||||
public ProviderEvaluation<Double> getDoubleEvaluation(
|
||||
String key, Double defaultValue, EvaluationContext evaluationContext) {
|
||||
return getEvaluation(key, evaluationContext, Double.class);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
|
||||
EvaluationContext evaluationContext) {
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(
|
||||
String key, Value defaultValue, EvaluationContext evaluationContext) {
|
||||
return getEvaluation(key, evaluationContext, Value.class);
|
||||
}
|
||||
|
||||
private <T> ProviderEvaluation<T> getEvaluation(
|
||||
String key, EvaluationContext evaluationContext, Class<?> expectedType
|
||||
) throws OpenFeatureError {
|
||||
String key, EvaluationContext evaluationContext, Class<?> expectedType) throws OpenFeatureError {
|
||||
if (!ProviderState.READY.equals(state)) {
|
||||
if (ProviderState.NOT_READY.equals(state)) {
|
||||
throw new ProviderNotReadyError("provider not yet initialized");
|
||||
|
@ -138,9 +149,10 @@ public class InMemoryProvider extends EventProvider {
|
|||
value = (T) flag.getVariants().get(flag.getDefaultVariant());
|
||||
}
|
||||
return ProviderEvaluation.<T>builder()
|
||||
.value(value)
|
||||
.variant(flag.getDefaultVariant())
|
||||
.reason(Reason.STATIC.toString())
|
||||
.build();
|
||||
.value(value)
|
||||
.variant(flag.getDefaultVariant())
|
||||
.reason(Reason.STATIC.toString())
|
||||
.flagMetadata(flag.getFlagMetadata())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
|
||||
|
||||
public class AlwaysBrokenWithDetailsProvider implements FeatureProvider {
|
||||
|
||||
private final String name = "always broken with details";
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return () -> {
|
||||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE);
|
||||
};
|
||||
return () -> name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +42,8 @@ public class AlwaysBrokenWithDetailsProvider implements FeatureProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(
|
||||
String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
return ProviderEvaluation.<Value>builder()
|
||||
.errorMessage(TestConstants.BROKEN_MESSAGE)
|
||||
.errorCode(ErrorCode.FLAG_NOT_FOUND)
|
||||
|
|
|
@ -2,7 +2,7 @@ package dev.openfeature.sdk;
|
|||
|
||||
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
|
||||
|
||||
public class AlwaysBrokenProvider implements FeatureProvider {
|
||||
public class AlwaysBrokenWithExceptionProvider implements FeatureProvider {
|
||||
|
||||
private final String name = "always broken";
|
||||
|
||||
|
@ -32,7 +32,8 @@ public class AlwaysBrokenProvider implements FeatureProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(
|
||||
String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
@Timeout(value = 5, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
|
||||
class AwaitableTest {
|
||||
@Test
|
||||
void waitingForFinishedIsANoOp() {
|
||||
var startTime = System.currentTimeMillis();
|
||||
Awaitable.FINISHED.await();
|
||||
var endTime = System.currentTimeMillis();
|
||||
assertTrue(endTime - startTime < 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
void waitingForNotFinishedWaitsEvenWhenInterrupted() throws InterruptedException {
|
||||
var awaitable = new Awaitable();
|
||||
var mayProceed = new AtomicBoolean(false);
|
||||
|
||||
var thread = new Thread(() -> {
|
||||
awaitable.await();
|
||||
if (!mayProceed.get()) {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
|
||||
var startTime = System.currentTimeMillis();
|
||||
do {
|
||||
thread.interrupt();
|
||||
} while (startTime + 1000 > System.currentTimeMillis());
|
||||
mayProceed.set(true);
|
||||
awaitable.wakeup();
|
||||
thread.join();
|
||||
}
|
||||
|
||||
@Test
|
||||
void callingWakeUpWakesUpAllWaitingThreads() throws InterruptedException {
|
||||
var awaitable = new Awaitable();
|
||||
var isRunning = new AtomicInteger();
|
||||
|
||||
Runnable runnable = () -> {
|
||||
isRunning.incrementAndGet();
|
||||
var start = System.currentTimeMillis();
|
||||
awaitable.await();
|
||||
var end = System.currentTimeMillis();
|
||||
if (end - start > 10) {
|
||||
fail();
|
||||
}
|
||||
};
|
||||
|
||||
var numThreads = 2;
|
||||
var threads = new Thread[numThreads];
|
||||
for (int i = 0; i < numThreads; i++) {
|
||||
threads[i] = new Thread(runnable);
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
await().atMost(1, TimeUnit.SECONDS).until(() -> isRunning.get() == numThreads);
|
||||
|
||||
awaitable.wakeup();
|
||||
|
||||
for (int i = 0; i < numThreads; i++) {
|
||||
threads[i].join();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,17 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.testutils.FeatureProviderTestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ClientProviderMappingTest {
|
||||
|
||||
@Test
|
||||
void clientProviderTest() {
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
OpenFeatureAPI api = new OpenFeatureAPI();
|
||||
|
||||
FeatureProviderTestUtils.setFeatureProvider("client1", new DoSomethingProvider());
|
||||
FeatureProviderTestUtils.setFeatureProvider("client2", new NoOpProvider());
|
||||
api.setProviderAndWait("client1", new DoSomethingProvider());
|
||||
api.setProviderAndWait("client2", new NoOpProvider());
|
||||
|
||||
Client c1 = api.getClient("client1");
|
||||
Client c2 = api.getClient("client2");
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
import dev.openfeature.sdk.testutils.FeatureProviderTestUtils;
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -15,12 +7,28 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class DeveloperExperienceTest implements HookFixtures {
|
||||
transient String flagKey = "mykey";
|
||||
private OpenFeatureAPI api;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
api = new OpenFeatureAPI();
|
||||
}
|
||||
|
||||
@Test
|
||||
void simpleBooleanFlag() {
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new TestEventsProvider());
|
||||
Client client = api.getClient();
|
||||
Boolean retval = client.getBooleanValue(flagKey, false);
|
||||
|
@ -31,12 +39,11 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
void clientHooks() {
|
||||
Hook<Boolean> exampleHook = mockBooleanHook();
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new TestEventsProvider());
|
||||
Client client = api.getClient();
|
||||
client.addHooks(exampleHook);
|
||||
Boolean retval = client.getBooleanValue(flagKey, false);
|
||||
verify(exampleHook, times(1)).finallyAfter(any(), any());
|
||||
verify(exampleHook, times(1)).finallyAfter(any(), any(), any());
|
||||
assertFalse(retval);
|
||||
}
|
||||
|
||||
|
@ -45,14 +52,16 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
Hook<Boolean> clientHook = mockBooleanHook();
|
||||
Hook<Boolean> evalHook = mockBooleanHook();
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new TestEventsProvider());
|
||||
Client client = api.getClient();
|
||||
client.addHooks(clientHook);
|
||||
Boolean retval = client.getBooleanValue(flagKey, false, null,
|
||||
Boolean retval = client.getBooleanValue(
|
||||
flagKey,
|
||||
false,
|
||||
null,
|
||||
FlagEvaluationOptions.builder().hook(evalHook).build());
|
||||
verify(clientHook, times(1)).finallyAfter(any(), any());
|
||||
verify(evalHook, times(1)).finallyAfter(any(), any());
|
||||
verify(clientHook, times(1)).finallyAfter(any(), any(), any());
|
||||
verify(evalHook, times(1)).finallyAfter(any(), any(), any());
|
||||
assertFalse(retval);
|
||||
}
|
||||
|
||||
|
@ -63,7 +72,6 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
@Test
|
||||
void providingContext() {
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new TestEventsProvider());
|
||||
Client client = api.getClient();
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
|
@ -80,8 +88,7 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
|
||||
@Test
|
||||
void brokenProvider() {
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
FeatureProviderTestUtils.setFeatureProvider(new AlwaysBrokenProvider());
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client client = api.getClient();
|
||||
FlagEvaluationDetails<Boolean> retval = client.getBooleanDetails(flagKey, false);
|
||||
assertEquals(ErrorCode.FLAG_NOT_FOUND, retval.getErrorCode());
|
||||
|
@ -93,6 +100,9 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
@Test
|
||||
void providerLockedPerTransaction() {
|
||||
|
||||
final String defaultValue = "string-value";
|
||||
final OpenFeatureAPI api = new OpenFeatureAPI();
|
||||
|
||||
class MutatingHook implements Hook {
|
||||
|
||||
@Override
|
||||
|
@ -100,16 +110,14 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
// change the provider during a before hook - this should not impact the evaluation in progress
|
||||
public Optional before(HookContext ctx, Map hints) {
|
||||
|
||||
FeatureProviderTestUtils.setFeatureProvider(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
api.setProviderAndWait(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
final String defaultValue = "string-value";
|
||||
final OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
final Client client = api.getClient();
|
||||
FeatureProviderTestUtils.setFeatureProvider(new DoSomethingProvider());
|
||||
api.setProviderAndWait(new DoSomethingProvider());
|
||||
api.addHooks(new MutatingHook());
|
||||
|
||||
// if provider is changed during an evaluation transaction it should proceed with the original provider
|
||||
|
@ -126,50 +134,55 @@ class DeveloperExperienceTest implements HookFixtures {
|
|||
@Test
|
||||
void setProviderAndWaitShouldPutTheProviderInReadyState() {
|
||||
String domain = "domain";
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(domain, new TestEventsProvider());
|
||||
Client client = api.getClient(domain);
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldPutTheProviderInStateErrorAfterEmittingErrorEvent() {
|
||||
String domain = "domain";
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
TestEventsProvider provider = new TestEventsProvider();
|
||||
api.setProviderAndWait(domain, provider);
|
||||
Client client = api.getClient(domain);
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
provider.emitProviderError(ProviderEventDetails.builder().build());
|
||||
provider.emitProviderError(ProviderEventDetails.builder().build()).await();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.ERROR);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldPutTheProviderInStateStaleAfterEmittingStaleEvent() {
|
||||
String domain = "domain";
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
TestEventsProvider provider = new TestEventsProvider();
|
||||
api.setProviderAndWait(domain, provider);
|
||||
Client client = api.getClient(domain);
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
provider.emitProviderStale(ProviderEventDetails.builder().build());
|
||||
provider.emitProviderStale(ProviderEventDetails.builder().build()).await();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.STALE);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldPutTheProviderInStateReadyAfterEmittingReadyEvent() {
|
||||
String domain = "domain";
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
TestEventsProvider provider = new TestEventsProvider();
|
||||
api.setProviderAndWait(domain, provider);
|
||||
Client client = api.getClient(domain);
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
provider.emitProviderStale(ProviderEventDetails.builder().build());
|
||||
provider.emitProviderStale(ProviderEventDetails.builder().build()).await();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.STALE);
|
||||
provider.emitProviderReady(ProviderEventDetails.builder().build());
|
||||
provider.emitProviderReady(ProviderEventDetails.builder().build()).await();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ class DoSomethingProvider implements FeatureProvider {
|
|||
|
||||
static final String name = "Something";
|
||||
// Flag evaluation metadata
|
||||
static final ImmutableMetadata DEFAULT_METADATA = ImmutableMetadata.builder().build();
|
||||
static final ImmutableMetadata DEFAULT_METADATA =
|
||||
ImmutableMetadata.builder().build();
|
||||
private ImmutableMetadata flagMetadata;
|
||||
|
||||
public DoSomethingProvider() {
|
||||
|
@ -53,7 +54,8 @@ class DoSomethingProvider implements FeatureProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(
|
||||
String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
return ProviderEvaluation.<Value>builder()
|
||||
.value(null)
|
||||
.flagMetadata(flagMetadata)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static dev.openfeature.sdk.EvaluationContext.TARGETING_KEY;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
@ -8,23 +9,26 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static dev.openfeature.sdk.EvaluationContext.TARGETING_KEY;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class EvalContextTest {
|
||||
@Specification(number="3.1.1",
|
||||
text="The `evaluation context` structure **MUST** define an optional `targeting key` field of " +
|
||||
"type string, identifying the subject of the flag evaluation.")
|
||||
@Test void requires_targeting_key() {
|
||||
@Specification(
|
||||
number = "3.1.1",
|
||||
text = "The `evaluation context` structure **MUST** define an optional `targeting key` field of "
|
||||
+ "type string, identifying the subject of the flag evaluation.")
|
||||
@Test
|
||||
void requires_targeting_key() {
|
||||
EvaluationContext ec = new ImmutableContext("targeting-key", new HashMap<>());
|
||||
assertEquals("targeting-key", ec.getTargetingKey());
|
||||
}
|
||||
|
||||
@Specification(number="3.1.2", text= "The evaluation context MUST support the inclusion of " +
|
||||
"custom fields, having keys of type `string`, and " +
|
||||
"values of type `boolean | string | number | datetime | structure`.")
|
||||
@Test void eval_context() {
|
||||
@Specification(
|
||||
number = "3.1.2",
|
||||
text = "The evaluation context MUST support the inclusion of "
|
||||
+ "custom fields, having keys of type `string`, and "
|
||||
+ "values of type `boolean | string | number | datetime | structure`.")
|
||||
@Test
|
||||
void eval_context() {
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
Instant dt = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
||||
attributes.put("str", new Value("test"));
|
||||
|
@ -42,16 +46,21 @@ public class EvalContextTest {
|
|||
assertEquals(dt, ec.getValue("dt").asInstant().truncatedTo(ChronoUnit.MILLIS));
|
||||
}
|
||||
|
||||
@Specification(number="3.1.2", text="The evaluation context MUST support the inclusion of " +
|
||||
"custom fields, having keys of type `string`, and " +
|
||||
"values of type `boolean | string | number | datetime | structure`.")
|
||||
@Test void eval_context_structure_array() {
|
||||
@Specification(
|
||||
number = "3.1.2",
|
||||
text = "The evaluation context MUST support the inclusion of "
|
||||
+ "custom fields, having keys of type `string`, and "
|
||||
+ "values of type `boolean | string | number | datetime | structure`.")
|
||||
@Test
|
||||
void eval_context_structure_array() {
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
attributes.put("obj", new Value(new MutableStructure().add("val1", 1).add("val2", "2")));
|
||||
List<Value> values = new ArrayList<Value>(){{
|
||||
add(new Value("one"));
|
||||
add(new Value("two"));
|
||||
}};
|
||||
List<Value> values = new ArrayList<Value>() {
|
||||
{
|
||||
add(new Value("one"));
|
||||
add(new Value("two"));
|
||||
}
|
||||
};
|
||||
attributes.put("arr", new Value(values));
|
||||
EvaluationContext ec = new ImmutableContext(attributes);
|
||||
|
||||
|
@ -64,11 +73,16 @@ public class EvalContextTest {
|
|||
assertEquals("two", arr.get(1).asString());
|
||||
}
|
||||
|
||||
@Specification(number="3.1.3", text="The evaluation context MUST support fetching the custom fields by key and also fetching all key value pairs.")
|
||||
@Test void fetch_all() {
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
@Specification(
|
||||
number = "3.1.3",
|
||||
text =
|
||||
"The evaluation context MUST support fetching the custom fields by key and also fetching all key value pairs.")
|
||||
@Test
|
||||
void fetch_all() {
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
Instant dt = Instant.now();
|
||||
MutableStructure mutableStructure = new MutableStructure().add("val1", 1).add("val2", "2");
|
||||
MutableStructure mutableStructure =
|
||||
new MutableStructure().add("val1", 1).add("val2", "2");
|
||||
attributes.put("str", new Value("test"));
|
||||
attributes.put("str2", new Value("test2"));
|
||||
attributes.put("bool", new Value(true));
|
||||
|
@ -96,8 +110,9 @@ public class EvalContextTest {
|
|||
assertEquals("2", foundObj.getValue("val2").asString());
|
||||
}
|
||||
|
||||
@Specification(number="3.1.4", text="The evaluation context fields MUST have an unique key.")
|
||||
@Test void unique_key_across_types() {
|
||||
@Specification(number = "3.1.4", text = "The evaluation context fields MUST have an unique key.")
|
||||
@Test
|
||||
void unique_key_across_types() {
|
||||
MutableContext ec = new MutableContext();
|
||||
ec.add("key", "val");
|
||||
ec.add("key", "val2");
|
||||
|
@ -107,8 +122,9 @@ public class EvalContextTest {
|
|||
assertEquals(3, ec.getValue("key").asInteger());
|
||||
}
|
||||
|
||||
@Test void unique_key_across_types_immutableContext() {
|
||||
HashMap<String, Value> attributes = new HashMap<>();
|
||||
@Test
|
||||
void unique_key_across_types_immutableContext() {
|
||||
HashMap<String, Value> attributes = new HashMap<>();
|
||||
attributes.put("key", new Value("val"));
|
||||
attributes.put("key", new Value("val2"));
|
||||
attributes.put("key", new Value(3));
|
||||
|
@ -117,23 +133,23 @@ public class EvalContextTest {
|
|||
assertEquals(3, ec.getValue("key").asInteger());
|
||||
}
|
||||
|
||||
@Test void can_chain_attribute_addition() {
|
||||
@Test
|
||||
void can_chain_attribute_addition() {
|
||||
MutableContext ec = new MutableContext();
|
||||
MutableContext out = ec.add("str", "test")
|
||||
.add("int", 4)
|
||||
.add("bool", false)
|
||||
.add("str", new MutableStructure());
|
||||
MutableContext out =
|
||||
ec.add("str", "test").add("int", 4).add("bool", false).add("str", new MutableStructure());
|
||||
assertEquals(MutableContext.class, out.getClass());
|
||||
}
|
||||
|
||||
@Test void can_add_key_with_null() {
|
||||
@Test
|
||||
void can_add_key_with_null() {
|
||||
MutableContext ec = new MutableContext()
|
||||
.add("Boolean", (Boolean)null)
|
||||
.add("String", (String)null)
|
||||
.add("Double", (Double)null)
|
||||
.add("Structure", (MutableStructure)null)
|
||||
.add("List", (List<Value>)null)
|
||||
.add("Instant", (Instant)null);
|
||||
.add("Boolean", (Boolean) null)
|
||||
.add("String", (String) null)
|
||||
.add("Double", (Double) null)
|
||||
.add("Structure", (MutableStructure) null)
|
||||
.add("List", (List<Value>) null)
|
||||
.add("Instant", (Instant) null);
|
||||
assertEquals(6, ec.asMap().size());
|
||||
assertEquals(null, ec.getValue("Boolean").asBoolean());
|
||||
assertEquals(null, ec.getValue("String").asString());
|
||||
|
@ -143,7 +159,8 @@ public class EvalContextTest {
|
|||
assertEquals(null, ec.getValue("Instant").asString());
|
||||
}
|
||||
|
||||
@Test void Immutable_context_merge_targeting_key() {
|
||||
@Test
|
||||
void Immutable_context_merge_targeting_key() {
|
||||
String key1 = "key1";
|
||||
EvaluationContext ctx1 = new ImmutableContext(key1, new HashMap<>());
|
||||
EvaluationContext ctx2 = new ImmutableContext(new HashMap<>());
|
||||
|
@ -156,19 +173,21 @@ public class EvalContextTest {
|
|||
ctxMerged = ctx1.merge(ctx2);
|
||||
assertEquals(key2, ctxMerged.getTargetingKey());
|
||||
|
||||
ctx2 = new ImmutableContext(" ",new HashMap<>());
|
||||
ctx2 = new ImmutableContext(" ", new HashMap<>());
|
||||
ctxMerged = ctx1.merge(ctx2);
|
||||
assertEquals(key1, ctxMerged.getTargetingKey());
|
||||
}
|
||||
|
||||
@Test void merge_null_returns_value() {
|
||||
@Test
|
||||
void merge_null_returns_value() {
|
||||
MutableContext ctx1 = new MutableContext("key");
|
||||
ctx1.add("mything", "value");
|
||||
EvaluationContext result = ctx1.merge(null);
|
||||
assertEquals(ctx1, result);
|
||||
}
|
||||
|
||||
@Test void merge_targeting_key() {
|
||||
@Test
|
||||
void merge_targeting_key() {
|
||||
String key1 = "key1";
|
||||
MutableContext ctx1 = new MutableContext(key1);
|
||||
MutableContext ctx2 = new MutableContext();
|
||||
|
@ -186,14 +205,15 @@ public class EvalContextTest {
|
|||
assertEquals(key2, ctxMerged.getTargetingKey());
|
||||
}
|
||||
|
||||
@Test void asObjectMap() {
|
||||
@Test
|
||||
void asObjectMap() {
|
||||
String key1 = "key1";
|
||||
MutableContext ctx = new MutableContext(key1);
|
||||
ctx.add("stringItem", "stringValue");
|
||||
ctx.add("boolItem", false);
|
||||
ctx.add("integerItem", 1);
|
||||
ctx.add("doubleItem", 1.2);
|
||||
ctx.add("instantItem", Instant.ofEpochSecond(1663331342));
|
||||
ctx.add("instantItem", Instant.ofEpochSecond(1663331342));
|
||||
List<Value> listItem = new ArrayList<>();
|
||||
listItem.add(new Value("item1"));
|
||||
listItem.add(new Value("item2"));
|
||||
|
@ -207,18 +227,17 @@ public class EvalContextTest {
|
|||
structureValue.put("structBoolItem", new Value(false));
|
||||
structureValue.put("structIntegerItem", new Value(1));
|
||||
structureValue.put("structDoubleItem", new Value(1.2));
|
||||
structureValue.put("structInstantItem", new Value(Instant.ofEpochSecond(1663331342)));
|
||||
structureValue.put("structInstantItem", new Value(Instant.ofEpochSecond(1663331342)));
|
||||
Structure structure = new MutableStructure(structureValue);
|
||||
ctx.add("structureItem", structure);
|
||||
|
||||
|
||||
Map<String, Object> want = new HashMap<>();
|
||||
want.put(TARGETING_KEY, key1);
|
||||
want.put("stringItem", "stringValue");
|
||||
want.put("boolItem", false);
|
||||
want.put("integerItem", 1);
|
||||
want.put("doubleItem", 1.2);
|
||||
want.put("instantItem", Instant.ofEpochSecond(1663331342));
|
||||
want.put("instantItem", Instant.ofEpochSecond(1663331342));
|
||||
List<String> wantListItem = new ArrayList<>();
|
||||
wantListItem.add("item1");
|
||||
wantListItem.add("item2");
|
||||
|
@ -232,9 +251,9 @@ public class EvalContextTest {
|
|||
wantStructureValue.put("structBoolItem", false);
|
||||
wantStructureValue.put("structIntegerItem", 1);
|
||||
wantStructureValue.put("structDoubleItem", 1.2);
|
||||
wantStructureValue.put("structInstantItem", Instant.ofEpochSecond(1663331342));
|
||||
want.put("structureItem",wantStructureValue);
|
||||
wantStructureValue.put("structInstantItem", Instant.ofEpochSecond(1663331342));
|
||||
want.put("structureItem", wantStructureValue);
|
||||
|
||||
assertEquals(want,ctx.asObjectMap());
|
||||
assertEquals(want, ctx.asObjectMap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.FatalError;
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import dev.openfeature.sdk.internal.TriConsumer;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import dev.openfeature.sdk.internal.TriConsumer;
|
||||
import dev.openfeature.sdk.testutils.TestStackedEmitCallsProvider;
|
||||
import io.cucumber.java.AfterAll;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
class EventProviderTest {
|
||||
|
||||
private static final int TIMEOUT = 300;
|
||||
|
||||
private TestEventProvider eventProvider;
|
||||
|
||||
@BeforeEach
|
||||
|
@ -26,7 +26,13 @@ class EventProviderTest {
|
|||
eventProvider.initialize(null);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void resetDefaultProvider() {
|
||||
new OpenFeatureAPI().setProviderAndWait(new NoOpProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
|
||||
@DisplayName("should run attached onEmit with emitters")
|
||||
void emitsEventsWhenAttached() {
|
||||
TriConsumer<EventProvider, ProviderEvent, ProviderEventDetails> onEmit = mockOnEmit();
|
||||
|
@ -39,10 +45,10 @@ class EventProviderTest {
|
|||
eventProvider.emitProviderStale(details);
|
||||
eventProvider.emitProviderError(details);
|
||||
|
||||
verify(onEmit, times(2)).accept(eventProvider, ProviderEvent.PROVIDER_READY, details);
|
||||
verify(onEmit, times(1)).accept(eventProvider, ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, details);
|
||||
verify(onEmit, times(1)).accept(eventProvider, ProviderEvent.PROVIDER_STALE, details);
|
||||
verify(onEmit, times(1)).accept(eventProvider, ProviderEvent.PROVIDER_ERROR, details);
|
||||
verify(onEmit, timeout(TIMEOUT).times(2)).accept(eventProvider, ProviderEvent.PROVIDER_READY, details);
|
||||
verify(onEmit, timeout(TIMEOUT)).accept(eventProvider, ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, details);
|
||||
verify(onEmit, timeout(TIMEOUT)).accept(eventProvider, ProviderEvent.PROVIDER_STALE, details);
|
||||
verify(onEmit, timeout(TIMEOUT)).accept(eventProvider, ProviderEvent.PROVIDER_ERROR, details);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -71,7 +77,6 @@ class EventProviderTest {
|
|||
assertThrows(IllegalStateException.class, () -> eventProvider.attach(onEmit2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("should not throw if second same onEmit attached")
|
||||
void doesNotThrowWhenOnEmitSame() {
|
||||
|
@ -81,6 +86,15 @@ class EventProviderTest {
|
|||
eventProvider.attach(onEmit2); // should not throw, same instance. noop
|
||||
}
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
@Timeout(value = 2, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
|
||||
@DisplayName("should not deadlock on emit called during emit")
|
||||
void doesNotDeadlockOnEmitStackedCalls() {
|
||||
TestStackedEmitCallsProvider provider = new TestStackedEmitCallsProvider();
|
||||
new OpenFeatureAPI().setProviderAndWait(provider);
|
||||
}
|
||||
|
||||
static class TestEventProvider extends EventProvider {
|
||||
|
||||
private static final String NAME = "TestEventProvider";
|
||||
|
@ -91,32 +105,29 @@ class EventProviderTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue,
|
||||
EvaluationContext ctx) {
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(
|
||||
String key, Boolean defaultValue, EvaluationContext ctx) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getBooleanEvaluation'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue,
|
||||
EvaluationContext ctx) {
|
||||
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getStringEvaluation'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue,
|
||||
EvaluationContext ctx) {
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(
|
||||
String key, Integer defaultValue, EvaluationContext ctx) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getIntegerEvaluation'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue,
|
||||
EvaluationContext ctx) {
|
||||
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getDoubleEvaluation'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
|
||||
EvaluationContext ctx) {
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getObjectEvaluation'");
|
||||
}
|
||||
|
||||
|
@ -130,4 +141,4 @@ class EventProviderTest {
|
|||
private TriConsumer<EventProvider, ProviderEvent, ProviderEventDetails> mockOnEmit() {
|
||||
return (TriConsumer<EventProvider, ProviderEvent, ProviderEventDetails>) mock(TriConsumer.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import io.cucumber.java.AfterAll;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
class EventsTest {
|
||||
|
||||
private static final int TIMEOUT = 300;
|
||||
private static final int TIMEOUT = 500;
|
||||
private static final int INIT_DELAY = TIMEOUT / 2;
|
||||
private OpenFeatureAPI api;
|
||||
|
||||
@AfterAll
|
||||
public static void resetDefaultProvider() {
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(new NoOpProvider());
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
api = new OpenFeatureAPI();
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
@ -41,31 +41,34 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("should fire initial READY event when provider init succeeds")
|
||||
@Specification(number = "5.3.1", text = "If the provider's initialize function terminates normally," +
|
||||
" PROVIDER_READY handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.3.1",
|
||||
text = "If the provider's initialize function terminates normally,"
|
||||
+ " PROVIDER_READY handlers MUST run.")
|
||||
void apiInitReady() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "apiInitReady";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().onProviderReady(handler);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
verify(handler, timeout(TIMEOUT).atLeastOnce())
|
||||
.accept(any());
|
||||
api.onProviderReady(handler);
|
||||
api.setProviderAndWait(name, provider);
|
||||
verify(handler, timeout(TIMEOUT).atLeastOnce()).accept(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fire initial ERROR event when provider init errors")
|
||||
@Specification(number = "5.3.2", text = "If the provider's initialize function terminates abnormally," +
|
||||
" PROVIDER_ERROR handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.3.2",
|
||||
text = "If the provider's initialize function terminates abnormally,"
|
||||
+ " PROVIDER_ERROR handlers MUST run.")
|
||||
void apiInitError() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "apiInitError";
|
||||
final String errMessage = "oh no!";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY, true, errMessage);
|
||||
OpenFeatureAPI.getInstance().onProviderError(handler);
|
||||
OpenFeatureAPI.getInstance().setProvider(name, provider);
|
||||
api.onProviderError(handler);
|
||||
api.setProvider(name, provider);
|
||||
verify(handler, timeout(TIMEOUT)).accept(argThat(details -> {
|
||||
return errMessage.equals(details.getMessage());
|
||||
}));
|
||||
|
@ -78,29 +81,36 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("should propagate events")
|
||||
@Specification(number = "5.1.2", text = "When a provider signals the occurrence of a particular event, "
|
||||
+
|
||||
"the associated client and API event handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.1.2",
|
||||
text = "When a provider signals the occurrence of a particular event, "
|
||||
+ "the associated client and API event handlers MUST run.")
|
||||
void apiShouldPropagateEvents() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "apiShouldPropagateEvents";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
OpenFeatureAPI.getInstance().onProviderConfigurationChanged(handler);
|
||||
api.setProviderAndWait(name, provider);
|
||||
api.onProviderConfigurationChanged(handler);
|
||||
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, EventDetails.builder().build());
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT)).accept(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should support all event types")
|
||||
@Specification(number = "5.1.1", text = "The provider MAY define a mechanism for signaling the occurrence "
|
||||
+ "of one of a set of events, including PROVIDER_READY, PROVIDER_ERROR, "
|
||||
+ "PROVIDER_CONFIGURATION_CHANGED and PROVIDER_STALE, with a provider event details payload.")
|
||||
@Specification(number = "5.2.2", text = "The API MUST provide a function for associating handler functions"
|
||||
+
|
||||
" with a particular provider event type.")
|
||||
@Specification(
|
||||
number = "5.1.1",
|
||||
text =
|
||||
"The provider MAY define a mechanism for signaling the occurrence "
|
||||
+ "of one of a set of events, including PROVIDER_READY, PROVIDER_ERROR, "
|
||||
+ "PROVIDER_CONFIGURATION_CHANGED and PROVIDER_STALE, with a provider event details payload.")
|
||||
@Specification(
|
||||
number = "5.2.2",
|
||||
text = "The API MUST provide a function for associating handler functions"
|
||||
+ " with a particular provider event type.")
|
||||
void apiShouldSupportAllEventTypes() {
|
||||
final String name = "apiShouldSupportAllEventTypes";
|
||||
final Consumer<EventDetails> handler1 = mockHandler();
|
||||
|
@ -109,15 +119,16 @@ class EventsTest {
|
|||
final Consumer<EventDetails> handler4 = mockHandler();
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
api.setProviderAndWait(name, provider);
|
||||
|
||||
OpenFeatureAPI.getInstance().onProviderReady(handler1);
|
||||
OpenFeatureAPI.getInstance().onProviderConfigurationChanged(handler2);
|
||||
OpenFeatureAPI.getInstance().onProviderStale(handler3);
|
||||
OpenFeatureAPI.getInstance().onProviderError(handler4);
|
||||
api.onProviderReady(handler1);
|
||||
api.onProviderConfigurationChanged(handler2);
|
||||
api.onProviderStale(handler3);
|
||||
api.onProviderError(handler4);
|
||||
|
||||
Arrays.asList(ProviderEvent.values()).stream().forEach(eventType -> {
|
||||
provider.mockEvent(eventType, ProviderEventDetails.builder().build());
|
||||
provider.mockEvent(
|
||||
eventType, ProviderEventDetails.builder().build());
|
||||
});
|
||||
|
||||
verify(handler1, timeout(TIMEOUT).atLeastOnce()).accept(any());
|
||||
|
@ -143,34 +154,42 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("should propagate events for default provider and anonymous client")
|
||||
@Specification(number = "5.1.2", text = "When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.1.2",
|
||||
text =
|
||||
"When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
void shouldPropagateDefaultAndAnon() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
// set provider before getting a client
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient();
|
||||
api.setProviderAndWait(provider);
|
||||
Client client = api.getClient();
|
||||
client.onProviderStale(handler);
|
||||
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_STALE, EventDetails.builder().build());
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_STALE, EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT)).accept(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should propagate events for default provider and named client")
|
||||
@Specification(number = "5.1.2", text = "When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.1.2",
|
||||
text =
|
||||
"When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
void shouldPropagateDefaultAndNamed() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "shouldPropagateDefaultAndNamed";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
// set provider before getting a client
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(provider);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderStale(handler);
|
||||
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_STALE, EventDetails.builder().build());
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_STALE, EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT)).accept(any());
|
||||
}
|
||||
}
|
||||
|
@ -186,31 +205,37 @@ class EventsTest {
|
|||
class Initialization {
|
||||
@Test
|
||||
@DisplayName("should fire initial READY event when provider init succeeds after client retrieved")
|
||||
@Specification(number = "5.3.1", text = "If the provider's initialize function terminates normally, PROVIDER_READY handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.3.1",
|
||||
text =
|
||||
"If the provider's initialize function terminates normally, PROVIDER_READY handlers MUST run.")
|
||||
void initReadyProviderBefore() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "initReadyProviderBefore";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderReady(handler);
|
||||
// set provider after getting a client
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
api.setProviderAndWait(name, provider);
|
||||
verify(handler, timeout(TIMEOUT).atLeastOnce())
|
||||
.accept(argThat(details -> details.getDomain().equals(name)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fire initial READY event when provider init succeeds before client retrieved")
|
||||
@Specification(number = "5.3.1", text = "If the provider's initialize function terminates normally, PROVIDER_READY handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.3.1",
|
||||
text =
|
||||
"If the provider's initialize function terminates normally, PROVIDER_READY handlers MUST run.")
|
||||
void initReadyProviderAfter() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "initReadyProviderAfter";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
// set provider before getting a client
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderReady(handler);
|
||||
verify(handler, timeout(TIMEOUT).atLeastOnce())
|
||||
.accept(argThat(details -> details.getDomain().equals(name)));
|
||||
|
@ -218,26 +243,31 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("should fire initial ERROR event when provider init errors after client retrieved")
|
||||
@Specification(number = "5.3.2", text = "If the provider's initialize function terminates abnormally, PROVIDER_ERROR handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.3.2",
|
||||
text =
|
||||
"If the provider's initialize function terminates abnormally, PROVIDER_ERROR handlers MUST run.")
|
||||
void initErrorProviderAfter() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "initErrorProviderAfter";
|
||||
final String errMessage = "oh no!";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY, true, errMessage);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderError(handler);
|
||||
// set provider after getting a client
|
||||
OpenFeatureAPI.getInstance().setProvider(name, provider);
|
||||
api.setProvider(name, provider);
|
||||
verify(handler, timeout(TIMEOUT)).accept(argThat(details -> {
|
||||
return name.equals(details.getDomain())
|
||||
&& errMessage.equals(details.getMessage());
|
||||
return name.equals(details.getDomain()) && errMessage.equals(details.getMessage());
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fire initial ERROR event when provider init errors before client retrieved")
|
||||
@Specification(number = "5.3.2", text = "If the provider's initialize function terminates abnormally, PROVIDER_ERROR handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.3.2",
|
||||
text =
|
||||
"If the provider's initialize function terminates abnormally, PROVIDER_ERROR handlers MUST run.")
|
||||
void initErrorProviderBefore() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "initErrorProviderBefore";
|
||||
|
@ -245,12 +275,11 @@ class EventsTest {
|
|||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY, true, errMessage);
|
||||
// set provider after getting a client
|
||||
OpenFeatureAPI.getInstance().setProvider(name, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProvider(name, provider);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderError(handler);
|
||||
verify(handler, timeout(TIMEOUT)).accept(argThat(details -> {
|
||||
return name.equals(details.getDomain())
|
||||
&& errMessage.equals(details.getMessage());
|
||||
return name.equals(details.getDomain()) && errMessage.equals(details.getMessage());
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -261,47 +290,63 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("should propagate events when provider set before client retrieved")
|
||||
@Specification(number = "5.1.2", text = "When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.1.2",
|
||||
text =
|
||||
"When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
void shouldPropagateBefore() {
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "shouldPropagateBefore";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
// set provider before getting a client
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderConfigurationChanged(handler);
|
||||
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT)).accept(argThat(details -> details.getDomain().equals(name)));
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT))
|
||||
.accept(argThat(details -> details.getDomain().equals(name)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should propagate events when provider set after client retrieved")
|
||||
@Specification(number = "5.1.2", text = "When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
@Specification(
|
||||
number = "5.1.2",
|
||||
text =
|
||||
"When a provider signals the occurrence of a particular event, the associated client and API event handlers MUST run.")
|
||||
void shouldPropagateAfter() {
|
||||
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
final String name = "shouldPropagateAfter";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderConfigurationChanged(handler);
|
||||
// set provider after getting a client
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
api.setProviderAndWait(name, provider);
|
||||
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT)).accept(argThat(details -> details.getDomain().equals(name)));
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
EventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT))
|
||||
.accept(argThat(details -> details.getDomain().equals(name)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should support all event types")
|
||||
@Specification(number = "5.1.1", text = "The provider MAY define a mechanism for signaling the occurrence "
|
||||
+ "of one of a set of events, including PROVIDER_READY, PROVIDER_ERROR, "
|
||||
+ "PROVIDER_CONFIGURATION_CHANGED and PROVIDER_STALE, with a provider event details payload.")
|
||||
@Specification(number = "5.2.1", text = "The client MUST provide a function for associating handler functions"
|
||||
+
|
||||
" with a particular provider event type.")
|
||||
@Specification(
|
||||
number = "5.1.1",
|
||||
text =
|
||||
"The provider MAY define a mechanism for signaling the occurrence "
|
||||
+ "of one of a set of events, including PROVIDER_READY, PROVIDER_ERROR, "
|
||||
+ "PROVIDER_CONFIGURATION_CHANGED and PROVIDER_STALE, with a provider event details payload.")
|
||||
@Specification(
|
||||
number = "5.2.1",
|
||||
text = "The client MUST provide a function for associating handler functions"
|
||||
+ " with a particular provider event type.")
|
||||
void shouldSupportAllEventTypes() {
|
||||
final String name = "shouldSupportAllEventTypes";
|
||||
final Consumer<EventDetails> handler1 = mockHandler();
|
||||
|
@ -310,8 +355,8 @@ class EventsTest {
|
|||
final Consumer<EventDetails> handler4 = mockHandler();
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
Client client = api.getClient(name);
|
||||
|
||||
client.onProviderReady(handler1);
|
||||
client.onProviderConfigurationChanged(handler2);
|
||||
|
@ -321,8 +366,8 @@ class EventsTest {
|
|||
Arrays.asList(ProviderEvent.values()).stream().forEach(eventType -> {
|
||||
provider.mockEvent(eventType, ProviderEventDetails.builder().build());
|
||||
});
|
||||
ArgumentMatcher<EventDetails> nameMatches = (EventDetails details) -> details.getDomain()
|
||||
.equals(name);
|
||||
ArgumentMatcher<EventDetails> nameMatches =
|
||||
(EventDetails details) -> details.getDomain().equals(name);
|
||||
verify(handler1, timeout(TIMEOUT).atLeastOnce()).accept(argThat(nameMatches));
|
||||
verify(handler2, timeout(TIMEOUT).atLeastOnce()).accept(argThat(nameMatches));
|
||||
verify(handler3, timeout(TIMEOUT).atLeastOnce()).accept(argThat(nameMatches));
|
||||
|
@ -340,20 +385,22 @@ class EventsTest {
|
|||
|
||||
TestEventsProvider provider1 = new TestEventsProvider(INIT_DELAY);
|
||||
TestEventsProvider provider2 = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider1);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider1);
|
||||
Client client = api.getClient(name);
|
||||
|
||||
// attached handlers
|
||||
OpenFeatureAPI.getInstance().onProviderConfigurationChanged(handler1);
|
||||
api.onProviderConfigurationChanged(handler1);
|
||||
client.onProviderConfigurationChanged(handler2);
|
||||
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider2);
|
||||
api.setProviderAndWait(name, provider2);
|
||||
|
||||
// wait for the new provider to be ready and make sure things are cleaned up.
|
||||
await().until(() -> provider1.isShutDown());
|
||||
|
||||
// fire old event
|
||||
provider1.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, EventDetails.builder().build());
|
||||
provider1.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
EventDetails.builder().build());
|
||||
|
||||
// a bit of waiting here, but we want to make sure these are indeed never
|
||||
// called.
|
||||
|
@ -363,8 +410,10 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("other client handlers should not run")
|
||||
@Specification(number = "5.1.3", text = "When a provider signals the occurrence of a particular event, " +
|
||||
"event handlers on clients which are not associated with that provider MUST NOT run.")
|
||||
@Specification(
|
||||
number = "5.1.3",
|
||||
text = "When a provider signals the occurrence of a particular event, "
|
||||
+ "event handlers on clients which are not associated with that provider MUST NOT run.")
|
||||
void otherClientHandlersShouldNotRun() {
|
||||
final String name1 = "otherClientHandlersShouldNotRun1";
|
||||
final String name2 = "otherClientHandlersShouldNotRun2";
|
||||
|
@ -373,16 +422,18 @@ class EventsTest {
|
|||
|
||||
TestEventsProvider provider1 = new TestEventsProvider(INIT_DELAY);
|
||||
TestEventsProvider provider2 = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name1, provider1);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name2, provider2);
|
||||
api.setProviderAndWait(name1, provider1);
|
||||
api.setProviderAndWait(name2, provider2);
|
||||
|
||||
Client client1 = OpenFeatureAPI.getInstance().getClient(name1);
|
||||
Client client2 = OpenFeatureAPI.getInstance().getClient(name2);
|
||||
Client client1 = api.getClient(name1);
|
||||
Client client2 = api.getClient(name2);
|
||||
|
||||
client1.onProviderConfigurationChanged(handlerToRun);
|
||||
client2.onProviderConfigurationChanged(handlerNotToRun);
|
||||
|
||||
provider1.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
provider1.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
|
||||
verify(handlerToRun, timeout(TIMEOUT)).accept(any());
|
||||
verify(handlerNotToRun, never()).accept(any());
|
||||
|
@ -390,57 +441,67 @@ class EventsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("bound named client handlers should not run with default")
|
||||
@Specification(number = "5.1.3", text = "When a provider signals the occurrence of a particular event, " +
|
||||
"event handlers on clients which are not associated with that provider MUST NOT run.")
|
||||
@Specification(
|
||||
number = "5.1.3",
|
||||
text = "When a provider signals the occurrence of a particular event, "
|
||||
+ "event handlers on clients which are not associated with that provider MUST NOT run.")
|
||||
void boundShouldNotRunWithDefault() {
|
||||
final String name = "boundShouldNotRunWithDefault";
|
||||
final Consumer<EventDetails> handlerNotToRun = mockHandler();
|
||||
|
||||
TestEventsProvider namedProvider = new TestEventsProvider(INIT_DELAY);
|
||||
TestEventsProvider defaultProvider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(defaultProvider);
|
||||
api.setProviderAndWait(defaultProvider);
|
||||
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderConfigurationChanged(handlerNotToRun);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, namedProvider);
|
||||
api.setProviderAndWait(name, namedProvider);
|
||||
|
||||
// await the new provider to make sure the old one is shut down
|
||||
await().until(() -> namedProvider.getState().equals(ProviderState.READY));
|
||||
|
||||
// fire event on default provider
|
||||
defaultProvider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
defaultProvider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
|
||||
verify(handlerNotToRun, after(TIMEOUT).never()).accept(any());
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(new NoOpProvider());
|
||||
api.setProviderAndWait(new NoOpProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("unbound named client handlers should run with default")
|
||||
@Specification(number = "5.1.3", text = "When a provider signals the occurrence of a particular event, " +
|
||||
"event handlers on clients which are not associated with that provider MUST NOT run.")
|
||||
@Specification(
|
||||
number = "5.1.3",
|
||||
text = "When a provider signals the occurrence of a particular event, "
|
||||
+ "event handlers on clients which are not associated with that provider MUST NOT run.")
|
||||
void unboundShouldRunWithDefault() {
|
||||
final String name = "unboundShouldRunWithDefault";
|
||||
final Consumer<EventDetails> handlerToRun = mockHandler();
|
||||
|
||||
TestEventsProvider defaultProvider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(defaultProvider);
|
||||
api.setProviderAndWait(defaultProvider);
|
||||
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderConfigurationChanged(handlerToRun);
|
||||
|
||||
// await the new provider to make sure the old one is shut down
|
||||
await().until(() -> defaultProvider.getState().equals(ProviderState.READY));
|
||||
|
||||
// fire event on default provider
|
||||
defaultProvider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
defaultProvider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
|
||||
verify(handlerToRun, timeout(TIMEOUT)).accept(any());
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(new NoOpProvider());
|
||||
api.setProviderAndWait(new NoOpProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("subsequent handlers run if earlier throws")
|
||||
@Specification(number = "5.2.5", text = "If a handler function terminates abnormally, other handler functions MUST run.")
|
||||
@Specification(
|
||||
number = "5.2.5",
|
||||
text = "If a handler function terminates abnormally, other handler functions MUST run.")
|
||||
void handlersRunIfOneThrows() {
|
||||
final String name = "handlersRunIfOneThrows";
|
||||
final Consumer<EventDetails> errorHandler = mockHandler();
|
||||
|
@ -449,15 +510,17 @@ class EventsTest {
|
|||
final Consumer<EventDetails> lastHandler = mockHandler();
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
api.setProviderAndWait(name, provider);
|
||||
|
||||
Client client1 = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client1 = api.getClient(name);
|
||||
|
||||
client1.onProviderConfigurationChanged(errorHandler);
|
||||
client1.onProviderConfigurationChanged(nextHandler);
|
||||
client1.onProviderConfigurationChanged(lastHandler);
|
||||
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
verify(errorHandler, timeout(TIMEOUT)).accept(any());
|
||||
verify(nextHandler, timeout(TIMEOUT)).accept(any());
|
||||
verify(lastHandler, timeout(TIMEOUT)).accept(any());
|
||||
|
@ -466,22 +529,25 @@ class EventsTest {
|
|||
@Test
|
||||
@DisplayName("should have all properties")
|
||||
@Specification(number = "5.2.4", text = "The handler function MUST accept a event details parameter.")
|
||||
@Specification(number = "5.2.3", text = "The `event details` MUST contain the `provider name` associated with the event.")
|
||||
@Specification(
|
||||
number = "5.2.3",
|
||||
text = "The `event details` MUST contain the `provider name` associated with the event.")
|
||||
void shouldHaveAllProperties() {
|
||||
final Consumer<EventDetails> handler1 = mockHandler();
|
||||
final Consumer<EventDetails> handler2 = mockHandler();
|
||||
final String name = "shouldHaveAllProperties";
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
Client client = api.getClient(name);
|
||||
|
||||
// attached handlers
|
||||
OpenFeatureAPI.getInstance().onProviderConfigurationChanged(handler1);
|
||||
api.onProviderConfigurationChanged(handler1);
|
||||
client.onProviderConfigurationChanged(handler2);
|
||||
|
||||
List<String> flagsChanged = Arrays.asList("flag");
|
||||
ImmutableMetadata metadata = ImmutableMetadata.builder().addInteger("int", 1).build();
|
||||
ImmutableMetadata metadata =
|
||||
ImmutableMetadata.builder().addInteger("int", 1).build();
|
||||
String message = "a message";
|
||||
ProviderEventDetails details = ProviderEventDetails.builder()
|
||||
.eventMetadata(metadata)
|
||||
|
@ -492,76 +558,78 @@ class EventsTest {
|
|||
provider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, details);
|
||||
|
||||
// both global and client handler should have all the fields.
|
||||
verify(handler1, timeout(TIMEOUT))
|
||||
.accept(argThat((EventDetails eventDetails) -> {
|
||||
return metadata.equals(eventDetails.getEventMetadata())
|
||||
// TODO: issue for client name in events
|
||||
&& flagsChanged.equals(eventDetails.getFlagsChanged())
|
||||
&& message.equals(eventDetails.getMessage());
|
||||
}));
|
||||
verify(handler2, timeout(TIMEOUT))
|
||||
.accept(argThat((EventDetails eventDetails) -> {
|
||||
return metadata.equals(eventDetails.getEventMetadata())
|
||||
&& flagsChanged.equals(eventDetails.getFlagsChanged())
|
||||
&& message.equals(eventDetails.getMessage())
|
||||
&& name.equals(eventDetails.getDomain());
|
||||
}));
|
||||
verify(handler1, timeout(TIMEOUT)).accept(argThat((EventDetails eventDetails) -> {
|
||||
return metadata.equals(eventDetails.getEventMetadata())
|
||||
// TODO: issue for client name in events
|
||||
&& flagsChanged.equals(eventDetails.getFlagsChanged())
|
||||
&& message.equals(eventDetails.getMessage());
|
||||
}));
|
||||
verify(handler2, timeout(TIMEOUT)).accept(argThat((EventDetails eventDetails) -> {
|
||||
return metadata.equals(eventDetails.getEventMetadata())
|
||||
&& flagsChanged.equals(eventDetails.getFlagsChanged())
|
||||
&& message.equals(eventDetails.getMessage())
|
||||
&& name.equals(eventDetails.getDomain());
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("if the provider is ready handlers must run immediately")
|
||||
@Specification(number = "5.3.3", text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
|
||||
@Specification(
|
||||
number = "5.3.3",
|
||||
text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
|
||||
void matchingReadyEventsMustRunImmediately() {
|
||||
final String name = "matchingEventsMustRunImmediately";
|
||||
final String name = "matchingReadyEventsMustRunImmediately";
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
|
||||
// provider which is already ready
|
||||
TestEventsProvider provider = new TestEventsProvider();
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
api.setProviderAndWait(name, provider);
|
||||
|
||||
// should run even thought handler was added after ready
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderReady(handler);
|
||||
verify(handler, timeout(TIMEOUT)).accept(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("if the provider is ready handlers must run immediately")
|
||||
@Specification(number = "5.3.3", text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
|
||||
@Specification(
|
||||
number = "5.3.3",
|
||||
text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
|
||||
void matchingStaleEventsMustRunImmediately() {
|
||||
final String name = "matchingEventsMustRunImmediately";
|
||||
final String name = "matchingStaleEventsMustRunImmediately";
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
|
||||
// provider which is already stale
|
||||
TestEventsProvider provider = TestEventsProvider.newInitializedTestEventsProvider();
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
Client client = api.getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
provider.emitProviderStale(ProviderEventDetails.builder().build());
|
||||
provider.emitProviderStale(ProviderEventDetails.builder().build()).await();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.STALE);
|
||||
|
||||
// should run even thought handler was added after stale
|
||||
// should run even though handler was added after stale
|
||||
client.onProviderStale(handler);
|
||||
verify(handler, timeout(TIMEOUT)).accept(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("if the provider is ready handlers must run immediately")
|
||||
@Specification(number = "5.3.3", text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
|
||||
@Specification(
|
||||
number = "5.3.3",
|
||||
text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
|
||||
void matchingErrorEventsMustRunImmediately() {
|
||||
final String name = "matchingEventsMustRunImmediately";
|
||||
final String name = "matchingErrorEventsMustRunImmediately";
|
||||
final Consumer<EventDetails> handler = mockHandler();
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
|
||||
// provider which is already in error
|
||||
TestEventsProvider provider = new TestEventsProvider();
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
Client client = api.getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
provider.emitProviderError(ProviderEventDetails.builder().build());
|
||||
provider.emitProviderError(ProviderEventDetails.builder().build()).await();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.ERROR);
|
||||
|
||||
|
||||
// should run even thought handler was added after error
|
||||
verify(handler, never()).accept(any());
|
||||
// should run even though handler was added after error
|
||||
client.onProviderError(handler);
|
||||
verify(handler, timeout(TIMEOUT)).accept(any());
|
||||
}
|
||||
|
@ -576,27 +644,34 @@ class EventsTest {
|
|||
TestEventsProvider provider1 = new TestEventsProvider(INIT_DELAY);
|
||||
TestEventsProvider provider2 = new TestEventsProvider(INIT_DELAY);
|
||||
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider1);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider1);
|
||||
Client client = api.getClient(name);
|
||||
client.onProviderConfigurationChanged(handler);
|
||||
|
||||
provider1.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
ArgumentMatcher<EventDetails> nameMatches = (EventDetails details) -> details.getDomain().equals(name);
|
||||
provider1.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
ArgumentMatcher<EventDetails> nameMatches =
|
||||
(EventDetails details) -> details.getDomain().equals(name);
|
||||
|
||||
verify(handler, timeout(TIMEOUT).times(1)).accept(argThat(nameMatches));
|
||||
|
||||
// wait for the new provider to be ready.
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider2);
|
||||
api.setProviderAndWait(name, provider2);
|
||||
|
||||
// verify that with the new provider under the same name, the handler is called
|
||||
// again.
|
||||
provider2.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
provider2.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
verify(handler, timeout(TIMEOUT).times(2)).accept(argThat(nameMatches));
|
||||
}
|
||||
|
||||
@Nested
|
||||
class HandlerRemoval {
|
||||
@Specification(number = "5.2.7", text = "The API and client MUST provide a function allowing the removal of event handlers.")
|
||||
@Specification(
|
||||
number = "5.2.7",
|
||||
text = "The API and client MUST provide a function allowing the removal of event handlers.")
|
||||
@Test
|
||||
@DisplayName("should not run removed events")
|
||||
@SneakyThrows
|
||||
|
@ -606,29 +681,32 @@ class EventsTest {
|
|||
final Consumer<EventDetails> handler2 = mockHandler();
|
||||
|
||||
TestEventsProvider provider = new TestEventsProvider(INIT_DELAY);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(name, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(name);
|
||||
api.setProviderAndWait(name, provider);
|
||||
Client client = api.getClient(name);
|
||||
|
||||
// attached handlers
|
||||
OpenFeatureAPI.getInstance().onProviderStale(handler1);
|
||||
api.onProviderStale(handler1);
|
||||
client.onProviderConfigurationChanged(handler2);
|
||||
|
||||
OpenFeatureAPI.getInstance().removeHandler(ProviderEvent.PROVIDER_STALE, handler1);
|
||||
api.removeHandler(ProviderEvent.PROVIDER_STALE, handler1);
|
||||
client.removeHandler(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, handler2);
|
||||
|
||||
// emit event
|
||||
provider.mockEvent(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, ProviderEventDetails.builder().build());
|
||||
|
||||
provider.mockEvent(
|
||||
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED,
|
||||
ProviderEventDetails.builder().build());
|
||||
|
||||
// both global and client handlers should not run.
|
||||
verify(handler1, after(TIMEOUT).never()).accept(any());
|
||||
verify(handler2, never()).accept(any());
|
||||
}
|
||||
}
|
||||
|
||||
@Specification(number = "5.1.4", text = "PROVIDER_ERROR events SHOULD populate the provider event details's error message field.")
|
||||
@Specification(
|
||||
number = "5.1.4",
|
||||
text = "PROVIDER_ERROR events SHOULD populate the provider event details's error message field.")
|
||||
@Test
|
||||
void thisIsAProviderRequirement() {
|
||||
}
|
||||
void thisIsAProviderRequirement() {}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Consumer<EventDetails> mockHandler() {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.FatalError;
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
|
||||
public class FatalErrorProvider implements FeatureProvider {
|
||||
|
||||
private final String name = "fatal";
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return () -> name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(EvaluationContext evaluationContext) throws Exception {
|
||||
throw new FatalError(); // throw a fatal error on startup (this will cause the SDK to short circuit evaluations)
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
|
||||
throw new GeneralError(TestConstants.BROKEN_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
|
||||
throw new GeneralError(TestConstants.BROKEN_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
|
||||
throw new GeneralError(TestConstants.BROKEN_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
|
||||
throw new GeneralError(TestConstants.BROKEN_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Value> getObjectEvaluation(
|
||||
String key, Value defaultValue, EvaluationContext invocationContext) {
|
||||
throw new GeneralError(TestConstants.BROKEN_MESSAGE);
|
||||
}
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.FatalError;
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.FatalError;
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class FeatureProviderStateManagerTest {
|
||||
|
||||
private FeatureProviderStateManager wrapper;
|
||||
|
@ -48,7 +47,10 @@ class FeatureProviderStateManagerTest {
|
|||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
@Specification(number = "1.7.3", text = "The client's provider status accessor MUST indicate READY if the initialize function of the associated provider terminates normally.")
|
||||
@Specification(
|
||||
number = "1.7.3",
|
||||
text =
|
||||
"The client's provider status accessor MUST indicate READY if the initialize function of the associated provider terminates normally.")
|
||||
void shouldSetStateToReadyAfterInit() {
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.NOT_READY);
|
||||
wrapper.initialize(null);
|
||||
|
@ -65,7 +67,10 @@ class FeatureProviderStateManagerTest {
|
|||
assertThat(wrapper.getState()).isEqualTo(ProviderState.NOT_READY);
|
||||
}
|
||||
|
||||
@Specification(number = "1.7.4", text = "The client's provider status accessor MUST indicate ERROR if the initialize function of the associated provider terminates abnormally.")
|
||||
@Specification(
|
||||
number = "1.7.4",
|
||||
text =
|
||||
"The client's provider status accessor MUST indicate ERROR if the initialize function of the associated provider terminates abnormally.")
|
||||
@Test
|
||||
void shouldSetStateToErrorAfterErrorOnInit() {
|
||||
testDelegate.throwOnInit = new Exception();
|
||||
|
@ -74,7 +79,10 @@ class FeatureProviderStateManagerTest {
|
|||
assertThat(wrapper.getState()).isEqualTo(ProviderState.ERROR);
|
||||
}
|
||||
|
||||
@Specification(number = "1.7.4", text = "The client's provider status accessor MUST indicate ERROR if the initialize function of the associated provider terminates abnormally.")
|
||||
@Specification(
|
||||
number = "1.7.4",
|
||||
text =
|
||||
"The client's provider status accessor MUST indicate ERROR if the initialize function of the associated provider terminates abnormally.")
|
||||
@Test
|
||||
void shouldSetStateToErrorAfterOpenFeatureErrorOnInit() {
|
||||
testDelegate.throwOnInit = new GeneralError();
|
||||
|
@ -83,7 +91,10 @@ class FeatureProviderStateManagerTest {
|
|||
assertThat(wrapper.getState()).isEqualTo(ProviderState.ERROR);
|
||||
}
|
||||
|
||||
@Specification(number = "1.7.5", text = "The client's provider status accessor MUST indicate FATAL if the initialize function of the associated provider terminates abnormally and indicates error code PROVIDER_FATAL.")
|
||||
@Specification(
|
||||
number = "1.7.5",
|
||||
text =
|
||||
"The client's provider status accessor MUST indicate FATAL if the initialize function of the associated provider terminates abnormally and indicates error code PROVIDER_FATAL.")
|
||||
@Test
|
||||
void shouldSetStateToErrorAfterFatalErrorOnInit() {
|
||||
testDelegate.throwOnInit = new FatalError();
|
||||
|
@ -92,7 +103,10 @@ class FeatureProviderStateManagerTest {
|
|||
assertThat(wrapper.getState()).isEqualTo(ProviderState.FATAL);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldSetTheStateToReadyWhenAReadyEventIsEmitted() {
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.NOT_READY);
|
||||
|
@ -100,7 +114,10 @@ class FeatureProviderStateManagerTest {
|
|||
assertThat(wrapper.getState()).isEqualTo(ProviderState.READY);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldSetTheStateToStaleWhenAStaleEventIsEmitted() {
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.NOT_READY);
|
||||
|
@ -108,25 +125,31 @@ class FeatureProviderStateManagerTest {
|
|||
assertThat(wrapper.getState()).isEqualTo(ProviderState.STALE);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldSetTheStateToErrorWhenAnErrorEventIsEmitted() {
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.NOT_READY);
|
||||
wrapper.onEmit(
|
||||
ProviderEvent.PROVIDER_ERROR,
|
||||
ProviderEventDetails.builder().errorCode(ErrorCode.GENERAL).build()
|
||||
);
|
||||
ProviderEventDetails.builder().errorCode(ErrorCode.GENERAL).build());
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.ERROR);
|
||||
}
|
||||
|
||||
@Specification(number = "5.3.5", text = "If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Specification(
|
||||
number = "5.3.5",
|
||||
text =
|
||||
"If the provider emits an event, the value of the client's provider status MUST be updated accordingly.")
|
||||
@Test
|
||||
void shouldSetTheStateToFatalWhenAFatalErrorEventIsEmitted() {
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.NOT_READY);
|
||||
wrapper.onEmit(
|
||||
ProviderEvent.PROVIDER_ERROR,
|
||||
ProviderEventDetails.builder().errorCode(ErrorCode.PROVIDER_FATAL).build()
|
||||
);
|
||||
ProviderEventDetails.builder()
|
||||
.errorCode(ErrorCode.PROVIDER_FATAL)
|
||||
.build());
|
||||
assertThat(wrapper.getState()).isEqualTo(ProviderState.FATAL);
|
||||
}
|
||||
|
||||
|
@ -141,7 +164,8 @@ class FeatureProviderStateManagerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
|
||||
public ProviderEvaluation<Boolean> getBooleanEvaluation(
|
||||
String key, Boolean defaultValue, EvaluationContext ctx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -151,7 +175,8 @@ class FeatureProviderStateManagerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
|
||||
public ProviderEvaluation<Integer> getIntegerEvaluation(
|
||||
String key, Integer defaultValue, EvaluationContext ctx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -178,4 +203,4 @@ class FeatureProviderStateManagerTest {
|
|||
shutdownCalled.incrementAndGet();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,13 +29,7 @@ class FlagEvaluationDetailsTest {
|
|||
ImmutableMetadata metadata = ImmutableMetadata.builder().build();
|
||||
|
||||
FlagEvaluationDetails<Integer> details = new FlagEvaluationDetails<>(
|
||||
flagKey,
|
||||
value,
|
||||
variant,
|
||||
reason.toString(),
|
||||
errorCode,
|
||||
errorMessage,
|
||||
metadata);
|
||||
flagKey, value, variant, reason.toString(), errorCode, errorMessage, metadata);
|
||||
|
||||
assertEquals(flagKey, details.getFlagKey());
|
||||
assertEquals(value, details.getValue());
|
||||
|
@ -48,13 +42,14 @@ class FlagEvaluationDetailsTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("should be able to compare 2 FlagEvaluationDetails")
|
||||
public void compareFlagEvaluationDetails(){
|
||||
public void compareFlagEvaluationDetails() {
|
||||
FlagEvaluationDetails fed1 = FlagEvaluationDetails.builder()
|
||||
.reason(Reason.ERROR.toString())
|
||||
.value(false)
|
||||
.errorCode(ErrorCode.GENERAL)
|
||||
.errorMessage("error XXX")
|
||||
.flagMetadata(ImmutableMetadata.builder().addString("metadata","1").build())
|
||||
.flagMetadata(
|
||||
ImmutableMetadata.builder().addString("metadata", "1").build())
|
||||
.build();
|
||||
|
||||
FlagEvaluationDetails fed2 = FlagEvaluationDetails.builder()
|
||||
|
@ -62,9 +57,10 @@ class FlagEvaluationDetailsTest {
|
|||
.value(false)
|
||||
.errorCode(ErrorCode.GENERAL)
|
||||
.errorMessage("error XXX")
|
||||
.flagMetadata(ImmutableMetadata.builder().addString("metadata","1").build())
|
||||
.flagMetadata(
|
||||
ImmutableMetadata.builder().addString("metadata", "1").build())
|
||||
.build();
|
||||
|
||||
assertEquals(fed1,fed2);
|
||||
assertEquals(fed1, fed2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,5 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
|
||||
import dev.openfeature.sdk.testutils.FeatureProviderTestUtils;
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.simplify4u.slf4jmock.LoggerMock;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static dev.openfeature.sdk.DoSomethingProvider.DEFAULT_METADATA;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
@ -25,13 +7,28 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.GeneralError;
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.simplify4u.slf4jmock.LoggerMock;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
class FlagEvaluationSpecTest implements HookFixtures {
|
||||
|
||||
private Logger logger;
|
||||
private OpenFeatureAPI api;
|
||||
|
||||
private Client _client() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new NoOpProvider());
|
||||
api.setProviderAndWait(new NoOpProvider());
|
||||
return api.getClient();
|
||||
}
|
||||
|
||||
|
@ -39,58 +36,63 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
private Client _initializedClient() {
|
||||
TestEventsProvider provider = new TestEventsProvider();
|
||||
provider.initialize(null);
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
return api.getClient();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void getApiInstance() {
|
||||
api = OpenFeatureAPI.getInstance();
|
||||
api = new OpenFeatureAPI();
|
||||
}
|
||||
|
||||
@AfterEach void reset_ctx() {
|
||||
api.setEvaluationContext(null);
|
||||
}
|
||||
|
||||
@BeforeEach void set_logger() {
|
||||
@BeforeEach
|
||||
void set_logger() {
|
||||
logger = Mockito.mock(Logger.class);
|
||||
LoggerMock.setMock(OpenFeatureClient.class, logger);
|
||||
}
|
||||
|
||||
@AfterEach void reset_logs() {
|
||||
@AfterEach
|
||||
void reset_logs() {
|
||||
LoggerMock.setMock(OpenFeatureClient.class, logger);
|
||||
}
|
||||
|
||||
@Specification(number="1.1.1", text="The API, and any state it maintains SHOULD exist as a global singleton, even in cases wherein multiple versions of the API are present at runtime.")
|
||||
@Test void global_singleton() {
|
||||
assertSame(OpenFeatureAPI.getInstance(), OpenFeatureAPI.getInstance());
|
||||
}
|
||||
|
||||
@Specification(number="1.1.2.1", text="The API MUST define a provider mutator, a function to set the default provider, which accepts an API-conformant provider implementation.")
|
||||
@Test void provider() {
|
||||
@Specification(
|
||||
number = "1.1.2.1",
|
||||
text =
|
||||
"The API MUST define a provider mutator, a function to set the default provider, which accepts an API-conformant provider implementation.")
|
||||
@Test
|
||||
void provider() {
|
||||
FeatureProvider mockProvider = mock(FeatureProvider.class);
|
||||
FeatureProviderTestUtils.setFeatureProvider(mockProvider);
|
||||
api.setProviderAndWait(mockProvider);
|
||||
assertThat(api.getProvider()).isEqualTo(mockProvider);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Specification(number="1.1.8", text="The API SHOULD provide functions to set a provider and wait for the initialize function to return or throw.")
|
||||
@Test void providerAndWait() {
|
||||
@Specification(
|
||||
number = "1.1.8",
|
||||
text =
|
||||
"The API SHOULD provide functions to set a provider and wait for the initialize function to return or throw.")
|
||||
@Test
|
||||
void providerAndWait() {
|
||||
FeatureProvider provider = new TestEventsProvider(500);
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
Client client = api.getClient();
|
||||
assertThat(client.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
|
||||
provider = new TestEventsProvider(500);
|
||||
String providerName = "providerAndWait";
|
||||
OpenFeatureAPI.getInstance().setProviderAndWait(providerName, provider);
|
||||
api.setProviderAndWait(providerName, provider);
|
||||
Client client2 = api.getClient(providerName);
|
||||
assertThat(client2.getProviderState()).isEqualTo(ProviderState.READY);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Specification(number="1.1.8", text="The API SHOULD provide functions to set a provider and wait for the initialize function to return or throw.")
|
||||
@Test void providerAndWaitError() {
|
||||
@Specification(
|
||||
number = "1.1.8",
|
||||
text =
|
||||
"The API SHOULD provide functions to set a provider and wait for the initialize function to return or throw.")
|
||||
@Test
|
||||
void providerAndWaitError() {
|
||||
FeatureProvider provider1 = new TestEventsProvider(500, true, "fake error");
|
||||
assertThrows(GeneralError.class, () -> api.setProviderAndWait(provider1));
|
||||
|
||||
|
@ -99,25 +101,36 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertThrows(GeneralError.class, () -> api.setProviderAndWait(providerName, provider2));
|
||||
}
|
||||
|
||||
@Specification(number="2.4.5", text="The provider SHOULD indicate an error if flag resolution is attempted before the provider is ready.")
|
||||
@Test void shouldReturnNotReadyIfNotInitialized() {
|
||||
@Specification(
|
||||
number = "2.4.5",
|
||||
text =
|
||||
"The provider SHOULD indicate an error if flag resolution is attempted before the provider is ready.")
|
||||
@Test
|
||||
void shouldReturnNotReadyIfNotInitialized() {
|
||||
FeatureProvider provider = new TestEventsProvider(100);
|
||||
String providerName = "shouldReturnNotReadyIfNotInitialized";
|
||||
OpenFeatureAPI.getInstance().setProvider(providerName, provider);
|
||||
Client client = OpenFeatureAPI.getInstance().getClient(providerName);
|
||||
api.setProvider(providerName, provider);
|
||||
Client client = api.getClient(providerName);
|
||||
FlagEvaluationDetails<Boolean> details = client.getBooleanDetails("return_error_when_not_initialized", false);
|
||||
assertEquals(ErrorCode.PROVIDER_NOT_READY, details.getErrorCode());
|
||||
assertEquals(Reason.ERROR.toString(), details.getReason());
|
||||
}
|
||||
|
||||
@Specification(number="1.1.5", text="The API MUST provide a function for retrieving the metadata field of the configured provider.")
|
||||
@Test void provider_metadata() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new DoSomethingProvider());
|
||||
@Specification(
|
||||
number = "1.1.5",
|
||||
text = "The API MUST provide a function for retrieving the metadata field of the configured provider.")
|
||||
@Test
|
||||
void provider_metadata() {
|
||||
api.setProviderAndWait(new DoSomethingProvider());
|
||||
assertThat(api.getProviderMetadata().getName()).isEqualTo(DoSomethingProvider.name);
|
||||
}
|
||||
|
||||
@Specification(number="1.1.4", text="The API MUST provide a function to add hooks which accepts one or more API-conformant hooks, and appends them to the collection of any previously added hooks. When new hooks are added, previously added hooks are not removed.")
|
||||
@Test void hook_addition() {
|
||||
@Specification(
|
||||
number = "1.1.4",
|
||||
text =
|
||||
"The API MUST provide a function to add hooks which accepts one or more API-conformant hooks, and appends them to the collection of any previously added hooks. When new hooks are added, previously added hooks are not removed.")
|
||||
@Test
|
||||
void hook_addition() {
|
||||
Hook h1 = mock(Hook.class);
|
||||
Hook h2 = mock(Hook.class);
|
||||
api.addHooks(h1);
|
||||
|
@ -130,8 +143,12 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(h2, api.getHooks().get(1));
|
||||
}
|
||||
|
||||
@Specification(number="1.1.6", text="The API MUST provide a function for creating a client which accepts the following options: - domain (optional): A logical string identifier for binding clients to provider.")
|
||||
@Test void domainName() {
|
||||
@Specification(
|
||||
number = "1.1.6",
|
||||
text =
|
||||
"The API MUST provide a function for creating a client which accepts the following options: - domain (optional): A logical string identifier for binding clients to provider.")
|
||||
@Test
|
||||
void domainName() {
|
||||
assertNull(api.getClient().getMetadata().getDomain());
|
||||
|
||||
String domain = "Sir Calls-a-lot";
|
||||
|
@ -139,8 +156,12 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(domain, clientForDomain.getMetadata().getDomain());
|
||||
}
|
||||
|
||||
@Specification(number="1.2.1", text="The client MUST provide a method to add hooks which accepts one or more API-conformant hooks, and appends them to the collection of any previously added hooks. When new hooks are added, previously added hooks are not removed.")
|
||||
@Test void hookRegistration() {
|
||||
@Specification(
|
||||
number = "1.2.1",
|
||||
text =
|
||||
"The client MUST provide a method to add hooks which accepts one or more API-conformant hooks, and appends them to the collection of any previously added hooks. When new hooks are added, previously added hooks are not removed.")
|
||||
@Test
|
||||
void hookRegistration() {
|
||||
Client c = _client();
|
||||
Hook m1 = mock(Hook.class);
|
||||
Hook m2 = mock(Hook.class);
|
||||
|
@ -152,43 +173,98 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertTrue(hooks.contains(m2));
|
||||
}
|
||||
|
||||
@Specification(number="1.3.1.1", text="The client MUST provide methods for typed flag evaluation, including boolean, numeric, string, and structure, with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns the flag value.")
|
||||
@Specification(number="1.3.3.1", text="The client SHOULD provide functions for floating-point numbers and integers, consistent with language idioms.")
|
||||
@Test void value_flags() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new DoSomethingProvider());
|
||||
@Specification(
|
||||
number = "1.3.1.1",
|
||||
text =
|
||||
"The client MUST provide methods for typed flag evaluation, including boolean, numeric, string, and structure, with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns the flag value.")
|
||||
@Specification(
|
||||
number = "1.3.3.1",
|
||||
text =
|
||||
"The client SHOULD provide functions for floating-point numbers and integers, consistent with language idioms.")
|
||||
@Test
|
||||
void value_flags() {
|
||||
api.setProviderAndWait(new DoSomethingProvider());
|
||||
|
||||
Client c = api.getClient();
|
||||
String key = "key";
|
||||
|
||||
assertEquals(true, c.getBooleanValue(key, false));
|
||||
assertEquals(true, c.getBooleanValue(key, false, new ImmutableContext()));
|
||||
assertEquals(true, c.getBooleanValue(key, false, new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
true,
|
||||
c.getBooleanValue(
|
||||
key,
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
assertEquals("gnirts-ym", c.getStringValue(key, "my-string"));
|
||||
assertEquals("gnirts-ym", c.getStringValue(key, "my-string", new ImmutableContext()));
|
||||
assertEquals("gnirts-ym", c.getStringValue(key, "my-string", new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
"gnirts-ym",
|
||||
c.getStringValue(
|
||||
key,
|
||||
"my-string",
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
assertEquals(400, c.getIntegerValue(key, 4));
|
||||
assertEquals(400, c.getIntegerValue(key, 4, new ImmutableContext()));
|
||||
assertEquals(400, c.getIntegerValue(key, 4, new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
400,
|
||||
c.getIntegerValue(
|
||||
key,
|
||||
4,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
assertEquals(40.0, c.getDoubleValue(key, .4));
|
||||
assertEquals(40.0, c.getDoubleValue(key, .4, new ImmutableContext()));
|
||||
assertEquals(40.0, c.getDoubleValue(key, .4, new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
40.0,
|
||||
c.getDoubleValue(
|
||||
key,
|
||||
.4,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
assertEquals(null, c.getObjectValue(key, new Value()));
|
||||
assertEquals(null, c.getObjectValue(key, new Value(), new ImmutableContext()));
|
||||
assertEquals(null, c.getObjectValue(key, new Value(), new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
null,
|
||||
c.getObjectValue(
|
||||
key,
|
||||
new Value(),
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
}
|
||||
|
||||
@Specification(number="1.4.1.1", text="The client MUST provide methods for detailed flag value evaluation with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns an evaluation details structure.")
|
||||
@Specification(number="1.4.3", text="The evaluation details structure's value field MUST contain the evaluated flag value.")
|
||||
@Specification(number="1.4.4.1", text="The evaluation details structure SHOULD accept a generic argument (or use an equivalent language feature) which indicates the type of the wrapped value field.")
|
||||
@Specification(number="1.4.5", text="The evaluation details structure's flag key field MUST contain the flag key argument passed to the detailed flag evaluation method.")
|
||||
@Specification(number="1.4.6", text="In cases of normal execution, the evaluation details structure's variant field MUST contain the value of the variant field in the flag resolution structure returned by the configured provider, if the field is set.")
|
||||
@Specification(number="1.4.7", text="In cases of normal execution, the `evaluation details` structure's `reason` field MUST contain the value of the `reason` field in the `flag resolution` structure returned by the configured `provider`, if the field is set.")
|
||||
@Test void detail_flags() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new DoSomethingProvider());
|
||||
@Specification(
|
||||
number = "1.4.1.1",
|
||||
text =
|
||||
"The client MUST provide methods for detailed flag value evaluation with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns an evaluation details structure.")
|
||||
@Specification(
|
||||
number = "1.4.3",
|
||||
text = "The evaluation details structure's value field MUST contain the evaluated flag value.")
|
||||
@Specification(
|
||||
number = "1.4.4.1",
|
||||
text =
|
||||
"The evaluation details structure SHOULD accept a generic argument (or use an equivalent language feature) which indicates the type of the wrapped value field.")
|
||||
@Specification(
|
||||
number = "1.4.5",
|
||||
text =
|
||||
"The evaluation details structure's flag key field MUST contain the flag key argument passed to the detailed flag evaluation method.")
|
||||
@Specification(
|
||||
number = "1.4.6",
|
||||
text =
|
||||
"In cases of normal execution, the evaluation details structure's variant field MUST contain the value of the variant field in the flag resolution structure returned by the configured provider, if the field is set.")
|
||||
@Specification(
|
||||
number = "1.4.7",
|
||||
text =
|
||||
"In cases of normal execution, the `evaluation details` structure's `reason` field MUST contain the value of the `reason` field in the `flag resolution` structure returned by the configured `provider`, if the field is set.")
|
||||
@Test
|
||||
void detail_flags() {
|
||||
api.setProviderAndWait(new DoSomethingProvider());
|
||||
Client c = api.getClient();
|
||||
String key = "key";
|
||||
|
||||
|
@ -200,7 +276,13 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
.build();
|
||||
assertEquals(bd, c.getBooleanDetails(key, true));
|
||||
assertEquals(bd, c.getBooleanDetails(key, true, new ImmutableContext()));
|
||||
assertEquals(bd, c.getBooleanDetails(key, true, new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
bd,
|
||||
c.getBooleanDetails(
|
||||
key,
|
||||
true,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
FlagEvaluationDetails<String> sd = FlagEvaluationDetails.<String>builder()
|
||||
.flagKey(key)
|
||||
|
@ -210,7 +292,13 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
.build();
|
||||
assertEquals(sd, c.getStringDetails(key, "test"));
|
||||
assertEquals(sd, c.getStringDetails(key, "test", new ImmutableContext()));
|
||||
assertEquals(sd, c.getStringDetails(key, "test", new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
sd,
|
||||
c.getStringDetails(
|
||||
key,
|
||||
"test",
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
FlagEvaluationDetails<Integer> id = FlagEvaluationDetails.<Integer>builder()
|
||||
.flagKey(key)
|
||||
|
@ -219,7 +307,13 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
.build();
|
||||
assertEquals(id, c.getIntegerDetails(key, 4));
|
||||
assertEquals(id, c.getIntegerDetails(key, 4, new ImmutableContext()));
|
||||
assertEquals(id, c.getIntegerDetails(key, 4, new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
id,
|
||||
c.getIntegerDetails(
|
||||
key,
|
||||
4,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
FlagEvaluationDetails<Double> dd = FlagEvaluationDetails.<Double>builder()
|
||||
.flagKey(key)
|
||||
|
@ -228,31 +322,56 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
.build();
|
||||
assertEquals(dd, c.getDoubleDetails(key, .4));
|
||||
assertEquals(dd, c.getDoubleDetails(key, .4, new ImmutableContext()));
|
||||
assertEquals(dd, c.getDoubleDetails(key, .4, new ImmutableContext(), FlagEvaluationOptions.builder().build()));
|
||||
assertEquals(
|
||||
dd,
|
||||
c.getDoubleDetails(
|
||||
key,
|
||||
.4,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().build()));
|
||||
|
||||
// TODO: Structure detail tests.
|
||||
}
|
||||
|
||||
@Specification(number="1.5.1", text="The evaluation options structure's hooks field denotes an ordered collection of hooks that the client MUST execute for the respective flag evaluation, in addition to those already configured.")
|
||||
@Specification(
|
||||
number = "1.5.1",
|
||||
text =
|
||||
"The evaluation options structure's hooks field denotes an ordered collection of hooks that the client MUST execute for the respective flag evaluation, in addition to those already configured.")
|
||||
@SneakyThrows
|
||||
@Test void hooks() {
|
||||
@Test
|
||||
void hooks() {
|
||||
Client c = _initializedClient();
|
||||
Hook<Boolean> clientHook = mockBooleanHook();
|
||||
Hook<Boolean> invocationHook = mockBooleanHook();
|
||||
c.addHooks(clientHook);
|
||||
c.getBooleanValue("key", false, null, FlagEvaluationOptions.builder()
|
||||
.hook(invocationHook)
|
||||
.build());
|
||||
c.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
null,
|
||||
FlagEvaluationOptions.builder().hook(invocationHook).build());
|
||||
verify(clientHook, times(1)).before(any(), any());
|
||||
verify(invocationHook, times(1)).before(any(), any());
|
||||
}
|
||||
|
||||
@Specification(number="1.4.8", text="In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** contain an `error code`.")
|
||||
@Specification(number="1.4.9", text="In cases of abnormal execution (network failure, unhandled error, etc) the `reason` field in the `evaluation details` SHOULD indicate an error.")
|
||||
@Specification(number="1.4.10", text="Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.")
|
||||
@Specification(number="1.4.13", text="In cases of abnormal execution, the `evaluation details` structure's `error message` field **MAY** contain a string containing additional details about the nature of the error.")
|
||||
@Test void broken_provider() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new AlwaysBrokenProvider());
|
||||
@Specification(
|
||||
number = "1.4.8",
|
||||
text =
|
||||
"In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** contain an `error code`.")
|
||||
@Specification(
|
||||
number = "1.4.9",
|
||||
text =
|
||||
"In cases of abnormal execution (network failure, unhandled error, etc) the `reason` field in the `evaluation details` SHOULD indicate an error.")
|
||||
@Specification(
|
||||
number = "1.4.10",
|
||||
text =
|
||||
"Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.")
|
||||
@Specification(
|
||||
number = "1.4.13",
|
||||
text =
|
||||
"In cases of abnormal execution, the `evaluation details` structure's `error message` field **MAY** contain a string containing additional details about the nature of the error.")
|
||||
@Test
|
||||
void broken_provider() {
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client c = api.getClient();
|
||||
boolean defaultValue = false;
|
||||
assertFalse(c.getBooleanValue("key", defaultValue));
|
||||
|
@ -263,12 +382,25 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(defaultValue, details.getValue());
|
||||
}
|
||||
|
||||
@Specification(number="1.4.8", text="In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** contain an `error code`.")
|
||||
@Specification(number="1.4.9", text="In cases of abnormal execution (network failure, unhandled error, etc) the `reason` field in the `evaluation details` SHOULD indicate an error.")
|
||||
@Specification(number="1.4.10", text="Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.")
|
||||
@Specification(number="1.4.13", text="In cases of abnormal execution, the `evaluation details` structure's `error message` field **MAY** contain a string containing additional details about the nature of the error.")
|
||||
@Test void broken_provider_withDetails() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new AlwaysBrokenWithDetailsProvider());
|
||||
@Specification(
|
||||
number = "1.4.8",
|
||||
text =
|
||||
"In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** contain an `error code`.")
|
||||
@Specification(
|
||||
number = "1.4.9",
|
||||
text =
|
||||
"In cases of abnormal execution (network failure, unhandled error, etc) the `reason` field in the `evaluation details` SHOULD indicate an error.")
|
||||
@Specification(
|
||||
number = "1.4.10",
|
||||
text =
|
||||
"Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.")
|
||||
@Specification(
|
||||
number = "1.4.13",
|
||||
text =
|
||||
"In cases of abnormal execution, the `evaluation details` structure's `error message` field **MAY** contain a string containing additional details about the nature of the error.")
|
||||
@Test
|
||||
void broken_provider_withDetails() throws InterruptedException {
|
||||
api.setProviderAndWait(new AlwaysBrokenWithDetailsProvider());
|
||||
Client c = api.getClient();
|
||||
boolean defaultValue = false;
|
||||
assertFalse(c.getBooleanValue("key", defaultValue));
|
||||
|
@ -279,55 +411,68 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(defaultValue, details.getValue());
|
||||
}
|
||||
|
||||
@Specification(number="1.4.11", text="Methods, functions, or operations on the client SHOULD NOT write log messages.")
|
||||
@Test void log_on_error() throws NotImplementedException {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new AlwaysBrokenProvider());
|
||||
@Specification(
|
||||
number = "1.4.11",
|
||||
text = "Methods, functions, or operations on the client SHOULD NOT write log messages.")
|
||||
@Test
|
||||
void log_on_error() throws NotImplementedException {
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client c = api.getClient();
|
||||
FlagEvaluationDetails<Boolean> result = c.getBooleanDetails("test", false);
|
||||
|
||||
assertEquals(Reason.ERROR.toString(), result.getReason());
|
||||
Mockito.verify(logger, never()).error(
|
||||
any(String.class),
|
||||
any(),
|
||||
any());
|
||||
Mockito.verify(logger, never()).error(any(String.class), any(), any());
|
||||
}
|
||||
|
||||
@Specification(number="1.2.2", text="The client interface MUST define a metadata member or accessor, containing an immutable domain field or accessor of type string, which corresponds to the domain value supplied during client creation. In previous drafts, this property was called name. For backwards compatibility, implementations should consider name an alias to domain.")
|
||||
@Test void clientMetadata() {
|
||||
@Specification(
|
||||
number = "1.2.2",
|
||||
text =
|
||||
"The client interface MUST define a metadata member or accessor, containing an immutable domain field or accessor of type string, which corresponds to the domain value supplied during client creation. In previous drafts, this property was called name. For backwards compatibility, implementations should consider name an alias to domain.")
|
||||
@Test
|
||||
void clientMetadata() {
|
||||
Client c = _client();
|
||||
assertNull(c.getMetadata().getName());
|
||||
assertNull(c.getMetadata().getDomain());
|
||||
|
||||
String domainName = "test domain";
|
||||
FeatureProviderTestUtils.setFeatureProvider(new AlwaysBrokenProvider());
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client c2 = api.getClient(domainName);
|
||||
|
||||
assertEquals(domainName, c2.getMetadata().getName());
|
||||
assertEquals(domainName, c2.getMetadata().getDomain());
|
||||
}
|
||||
|
||||
@Specification(number="1.4.9", text="In cases of abnormal execution (network failure, unhandled error, etc) the reason field in the evaluation details SHOULD indicate an error.")
|
||||
@Test void reason_is_error_when_there_are_errors() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new AlwaysBrokenProvider());
|
||||
@Specification(
|
||||
number = "1.4.9",
|
||||
text =
|
||||
"In cases of abnormal execution (network failure, unhandled error, etc) the reason field in the evaluation details SHOULD indicate an error.")
|
||||
@Test
|
||||
void reason_is_error_when_there_are_errors() {
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client c = api.getClient();
|
||||
FlagEvaluationDetails<Boolean> result = c.getBooleanDetails("test", false);
|
||||
assertEquals(Reason.ERROR.toString(), result.getReason());
|
||||
}
|
||||
|
||||
@Specification(number="1.4.14", text="If the flag metadata field in the flag resolution structure returned by the configured provider is set, the evaluation details structure's flag metadata field MUST contain that value. Otherwise, it MUST contain an empty record.")
|
||||
@Test void flag_metadata_passed() {
|
||||
FeatureProviderTestUtils.setFeatureProvider(new DoSomethingProvider(null));
|
||||
@Specification(
|
||||
number = "1.4.14",
|
||||
text =
|
||||
"If the flag metadata field in the flag resolution structure returned by the configured provider is set, the evaluation details structure's flag metadata field MUST contain that value. Otherwise, it MUST contain an empty record.")
|
||||
@Test
|
||||
void flag_metadata_passed() {
|
||||
api.setProviderAndWait(new DoSomethingProvider(null));
|
||||
Client c = api.getClient();
|
||||
FlagEvaluationDetails<Boolean> result = c.getBooleanDetails("test", false);
|
||||
assertNotNull(result.getFlagMetadata());
|
||||
}
|
||||
|
||||
@Specification(number="3.2.2.1", text="The API MUST have a method for setting the global evaluation context.")
|
||||
@Test void api_context() {
|
||||
@Specification(number = "3.2.2.1", text = "The API MUST have a method for setting the global evaluation context.")
|
||||
@Test
|
||||
void api_context() {
|
||||
String contextKey = "some-key";
|
||||
String contextValue = "some-value";
|
||||
DoSomethingProvider provider = spy( new DoSomethingProvider());
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
DoSomethingProvider provider = spy(new DoSomethingProvider());
|
||||
api.setProviderAndWait(provider);
|
||||
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
attributes.put(contextKey, new Value(contextValue));
|
||||
|
@ -339,14 +484,22 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
client.getBooleanValue("any-flag", false);
|
||||
|
||||
// assert that the value from the global context was passed to the provider
|
||||
verify(provider).getBooleanEvaluation(any(), any(), argThat((arg) -> arg.getValue(contextKey).asString().equals(contextValue)));
|
||||
verify(provider).getBooleanEvaluation(any(), any(), argThat((arg) -> arg.getValue(contextKey)
|
||||
.asString()
|
||||
.equals(contextValue)));
|
||||
}
|
||||
|
||||
@Specification(number="3.2.1.1", text="The API, Client and invocation MUST have a method for supplying evaluation context.")
|
||||
@Specification(number="3.2.3", text="Evaluation context MUST be merged in the order: API (global; lowest precedence) -> transaction -> client -> invocation -> before hooks (highest precedence), with duplicate values being overwritten.")
|
||||
@Test void multi_layer_context_merges_correctly() {
|
||||
@Specification(
|
||||
number = "3.2.1.1",
|
||||
text = "The API, Client and invocation MUST have a method for supplying evaluation context.")
|
||||
@Specification(
|
||||
number = "3.2.3",
|
||||
text =
|
||||
"Evaluation context MUST be merged in the order: API (global; lowest precedence) -> transaction -> client -> invocation -> before hooks (highest precedence), with duplicate values being overwritten.")
|
||||
@Test
|
||||
void multi_layer_context_merges_correctly() {
|
||||
DoSomethingProvider provider = spy(new DoSomethingProvider());
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
TransactionContextPropagator transactionContextPropagator = new ThreadLocalTransactionContextPropagator();
|
||||
api.setTransactionContextPropagator(transactionContextPropagator);
|
||||
Hook<Boolean> hook = spy(new Hook<Boolean>() {
|
||||
|
@ -357,8 +510,10 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
attrs.put("common7", new Value("5"));
|
||||
return Optional.ofNullable(new ImmutableContext(attrs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
public void after(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
Hook.super.after(ctx, details, hints);
|
||||
}
|
||||
});
|
||||
|
@ -404,71 +559,149 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
invocationAttributes.put("invocation", new Value("4"));
|
||||
EvaluationContext invocationCtx = new ImmutableContext(invocationAttributes);
|
||||
|
||||
c.getBooleanValue("key", false, invocationCtx, FlagEvaluationOptions.builder().hook(hook).build());
|
||||
c.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
invocationCtx,
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
// assert the correct overrides in before hook
|
||||
verify(hook).before(argThat((arg) -> {
|
||||
EvaluationContext evaluationContext = arg.getCtx();
|
||||
return evaluationContext.getValue("api").asString().equals("1") &&
|
||||
evaluationContext.getValue("transaction").asString().equals("2") &&
|
||||
evaluationContext.getValue("client").asString().equals("3") &&
|
||||
evaluationContext.getValue("invocation").asString().equals("4") &&
|
||||
evaluationContext.getValue("common1").asString().equals("2") &&
|
||||
evaluationContext.getValue("common2").asString().equals("3") &&
|
||||
evaluationContext.getValue("common3").asString().equals("4") &&
|
||||
evaluationContext.getValue("common4").asString().equals("3") &&
|
||||
evaluationContext.getValue("common5").asString().equals("4") &&
|
||||
evaluationContext.getValue("common6").asString().equals("4");
|
||||
}), any());
|
||||
verify(hook)
|
||||
.before(
|
||||
argThat((arg) -> {
|
||||
EvaluationContext evaluationContext = arg.getCtx();
|
||||
return evaluationContext.getValue("api").asString().equals("1")
|
||||
&& evaluationContext
|
||||
.getValue("transaction")
|
||||
.asString()
|
||||
.equals("2")
|
||||
&& evaluationContext
|
||||
.getValue("client")
|
||||
.asString()
|
||||
.equals("3")
|
||||
&& evaluationContext
|
||||
.getValue("invocation")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("common1")
|
||||
.asString()
|
||||
.equals("2")
|
||||
&& evaluationContext
|
||||
.getValue("common2")
|
||||
.asString()
|
||||
.equals("3")
|
||||
&& evaluationContext
|
||||
.getValue("common3")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("common4")
|
||||
.asString()
|
||||
.equals("3")
|
||||
&& evaluationContext
|
||||
.getValue("common5")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("common6")
|
||||
.asString()
|
||||
.equals("4");
|
||||
}),
|
||||
any());
|
||||
|
||||
// assert the correct overrides in evaluation
|
||||
verify(provider).getBooleanEvaluation(any(), any(), argThat((arg) -> {
|
||||
return arg.getValue("api").asString().equals("1") &&
|
||||
arg.getValue("transaction").asString().equals("2") &&
|
||||
arg.getValue("client").asString().equals("3") &&
|
||||
arg.getValue("invocation").asString().equals("4") &&
|
||||
arg.getValue("before").asString().equals("5") &&
|
||||
arg.getValue("common1").asString().equals("2") &&
|
||||
arg.getValue("common2").asString().equals("3") &&
|
||||
arg.getValue("common3").asString().equals("4") &&
|
||||
arg.getValue("common4").asString().equals("3") &&
|
||||
arg.getValue("common5").asString().equals("4") &&
|
||||
arg.getValue("common6").asString().equals("4") &&
|
||||
arg.getValue("common7").asString().equals("5");
|
||||
return arg.getValue("api").asString().equals("1")
|
||||
&& arg.getValue("transaction").asString().equals("2")
|
||||
&& arg.getValue("client").asString().equals("3")
|
||||
&& arg.getValue("invocation").asString().equals("4")
|
||||
&& arg.getValue("before").asString().equals("5")
|
||||
&& arg.getValue("common1").asString().equals("2")
|
||||
&& arg.getValue("common2").asString().equals("3")
|
||||
&& arg.getValue("common3").asString().equals("4")
|
||||
&& arg.getValue("common4").asString().equals("3")
|
||||
&& arg.getValue("common5").asString().equals("4")
|
||||
&& arg.getValue("common6").asString().equals("4")
|
||||
&& arg.getValue("common7").asString().equals("5");
|
||||
}));
|
||||
|
||||
// assert the correct overrides in after hook
|
||||
verify(hook).after(argThat((arg) -> {
|
||||
EvaluationContext evaluationContext = arg.getCtx();
|
||||
return evaluationContext.getValue("api").asString().equals("1") &&
|
||||
evaluationContext.getValue("transaction").asString().equals("2") &&
|
||||
evaluationContext.getValue("client").asString().equals("3") &&
|
||||
evaluationContext.getValue("invocation").asString().equals("4") &&
|
||||
evaluationContext.getValue("before").asString().equals("5") &&
|
||||
evaluationContext.getValue("common1").asString().equals("2") &&
|
||||
evaluationContext.getValue("common2").asString().equals("3") &&
|
||||
evaluationContext.getValue("common3").asString().equals("4") &&
|
||||
evaluationContext.getValue("common4").asString().equals("3") &&
|
||||
evaluationContext.getValue("common5").asString().equals("4") &&
|
||||
evaluationContext.getValue("common6").asString().equals("4") &&
|
||||
evaluationContext.getValue("common7").asString().equals("5");
|
||||
}), any(), any());
|
||||
verify(hook)
|
||||
.after(
|
||||
argThat((arg) -> {
|
||||
EvaluationContext evaluationContext = arg.getCtx();
|
||||
return evaluationContext.getValue("api").asString().equals("1")
|
||||
&& evaluationContext
|
||||
.getValue("transaction")
|
||||
.asString()
|
||||
.equals("2")
|
||||
&& evaluationContext
|
||||
.getValue("client")
|
||||
.asString()
|
||||
.equals("3")
|
||||
&& evaluationContext
|
||||
.getValue("invocation")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("before")
|
||||
.asString()
|
||||
.equals("5")
|
||||
&& evaluationContext
|
||||
.getValue("common1")
|
||||
.asString()
|
||||
.equals("2")
|
||||
&& evaluationContext
|
||||
.getValue("common2")
|
||||
.asString()
|
||||
.equals("3")
|
||||
&& evaluationContext
|
||||
.getValue("common3")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("common4")
|
||||
.asString()
|
||||
.equals("3")
|
||||
&& evaluationContext
|
||||
.getValue("common5")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("common6")
|
||||
.asString()
|
||||
.equals("4")
|
||||
&& evaluationContext
|
||||
.getValue("common7")
|
||||
.asString()
|
||||
.equals("5");
|
||||
}),
|
||||
any(),
|
||||
any());
|
||||
}
|
||||
|
||||
@Specification(number="3.3.1.1", text="The API SHOULD have a method for setting a transaction context propagator.")
|
||||
@Test void setting_transaction_context_propagator() {
|
||||
@Specification(
|
||||
number = "3.3.1.1",
|
||||
text = "The API SHOULD have a method for setting a transaction context propagator.")
|
||||
@Test
|
||||
void setting_transaction_context_propagator() {
|
||||
DoSomethingProvider provider = new DoSomethingProvider();
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
|
||||
TransactionContextPropagator transactionContextPropagator = new ThreadLocalTransactionContextPropagator();
|
||||
api.setTransactionContextPropagator(transactionContextPropagator);
|
||||
assertEquals(transactionContextPropagator, api.getTransactionContextPropagator());
|
||||
}
|
||||
|
||||
@Specification(number="3.3.1.2.1", text="The API MUST have a method for setting the evaluation context of the transaction context propagator for the current transaction.")
|
||||
@Test void setting_transaction_context() {
|
||||
@Specification(
|
||||
number = "3.3.1.2.1",
|
||||
text =
|
||||
"The API MUST have a method for setting the evaluation context of the transaction context propagator for the current transaction.")
|
||||
@Test
|
||||
void setting_transaction_context() {
|
||||
DoSomethingProvider provider = new DoSomethingProvider();
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
|
||||
TransactionContextPropagator transactionContextPropagator = new ThreadLocalTransactionContextPropagator();
|
||||
api.setTransactionContextPropagator(transactionContextPropagator);
|
||||
|
@ -481,9 +714,16 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(transactionContext, transactionContextPropagator.getTransactionContext());
|
||||
}
|
||||
|
||||
@Specification(number="3.3.1.2.2", text="A transaction context propagator MUST have a method for setting the evaluation context of the current transaction.")
|
||||
@Specification(number="3.3.1.2.3", text="A transaction context propagator MUST have a method for getting the evaluation context of the current transaction.")
|
||||
@Test void transaction_context_propagator_setting_context() {
|
||||
@Specification(
|
||||
number = "3.3.1.2.2",
|
||||
text =
|
||||
"A transaction context propagator MUST have a method for setting the evaluation context of the current transaction.")
|
||||
@Specification(
|
||||
number = "3.3.1.2.3",
|
||||
text =
|
||||
"A transaction context propagator MUST have a method for getting the evaluation context of the current transaction.")
|
||||
@Test
|
||||
void transaction_context_propagator_setting_context() {
|
||||
TransactionContextPropagator transactionContextPropagator = new ThreadLocalTransactionContextPropagator();
|
||||
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
|
@ -494,23 +734,46 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(transactionContext, transactionContextPropagator.getTransactionContext());
|
||||
}
|
||||
|
||||
@Specification(number="1.3.4", text="The client SHOULD guarantee the returned value of any typed flag evaluation method is of the expected type. If the value returned by the underlying provider implementation does not match the expected type, it's to be considered abnormal execution, and the supplied default value should be returned.")
|
||||
@Test void type_system_prevents_this() {}
|
||||
@Specification(
|
||||
number = "1.3.4",
|
||||
text =
|
||||
"The client SHOULD guarantee the returned value of any typed flag evaluation method is of the expected type. If the value returned by the underlying provider implementation does not match the expected type, it's to be considered abnormal execution, and the supplied default value should be returned.")
|
||||
@Test
|
||||
void type_system_prevents_this() {}
|
||||
|
||||
@Specification(number="1.1.7", text="The client creation function MUST NOT throw, or otherwise abnormally terminate.")
|
||||
@Test void constructor_does_not_throw() {}
|
||||
@Specification(
|
||||
number = "1.1.7",
|
||||
text = "The client creation function MUST NOT throw, or otherwise abnormally terminate.")
|
||||
@Test
|
||||
void constructor_does_not_throw() {}
|
||||
|
||||
@Specification(number="1.4.12", text="The client SHOULD provide asynchronous or non-blocking mechanisms for flag evaluation.")
|
||||
@Test void one_thread_per_request_model() {}
|
||||
@Specification(
|
||||
number = "1.4.12",
|
||||
text = "The client SHOULD provide asynchronous or non-blocking mechanisms for flag evaluation.")
|
||||
@Test
|
||||
void one_thread_per_request_model() {}
|
||||
|
||||
@Specification(number="1.4.14.1", text="Condition: Flag metadata MUST be immutable.")
|
||||
@Test void compiler_enforced() {}
|
||||
|
||||
@Specification(number="1.4.2.1", text="The client MUST provide methods for detailed flag value evaluation with parameters flag key (string, required), default value (boolean | number | string | structure, required), and evaluation options (optional), which returns an evaluation details structure.")
|
||||
@Specification(number="1.3.2.1", text="The client MUST provide methods for typed flag evaluation, including boolean, numeric, string, and structure, with parameters flag key (string, required), default value (boolean | number | string | structure, required), and evaluation options (optional), which returns the flag value.")
|
||||
@Specification(number="3.2.2.2", text="The Client and invocation MUST NOT have a method for supplying evaluation context.")
|
||||
@Specification(number="3.2.4.1", text="When the global evaluation context is set, the on context changed handler MUST run.")
|
||||
@Specification(number="3.3.2.1", text="The API MUST NOT have a method for setting a transaction context propagator.")
|
||||
@Test void not_applicable_for_dynamic_context() {}
|
||||
@Specification(number = "1.4.14.1", text = "Condition: Flag metadata MUST be immutable.")
|
||||
@Test
|
||||
void compiler_enforced() {}
|
||||
|
||||
@Specification(
|
||||
number = "1.4.2.1",
|
||||
text =
|
||||
"The client MUST provide methods for detailed flag value evaluation with parameters flag key (string, required), default value (boolean | number | string | structure, required), and evaluation options (optional), which returns an evaluation details structure.")
|
||||
@Specification(
|
||||
number = "1.3.2.1",
|
||||
text =
|
||||
"The client MUST provide methods for typed flag evaluation, including boolean, numeric, string, and structure, with parameters flag key (string, required), default value (boolean | number | string | structure, required), and evaluation options (optional), which returns the flag value.")
|
||||
@Specification(
|
||||
number = "3.2.2.2",
|
||||
text = "The Client and invocation MUST NOT have a method for supplying evaluation context.")
|
||||
@Specification(
|
||||
number = "3.2.4.1",
|
||||
text = "When the global evaluation context is set, the on context changed handler MUST run.")
|
||||
@Specification(
|
||||
number = "3.3.2.1",
|
||||
text = "The API MUST NOT have a method for setting a transaction context propagator.")
|
||||
@Test
|
||||
void not_applicable_for_dynamic_context() {}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class FlagMetadataTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Test metadata payload construction and retrieval")
|
||||
public void builder_validation() {
|
||||
void builder_validation() {
|
||||
// given
|
||||
ImmutableMetadata flagMetadata = ImmutableMetadata.builder()
|
||||
.addString("string", "string")
|
||||
|
@ -42,11 +44,10 @@ class FlagMetadataTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("Value type mismatch returns a null")
|
||||
public void value_type_validation() {
|
||||
void value_type_validation() {
|
||||
// given
|
||||
ImmutableMetadata flagMetadata = ImmutableMetadata.builder()
|
||||
.addString("string", "string")
|
||||
.build();
|
||||
ImmutableMetadata flagMetadata =
|
||||
ImmutableMetadata.builder().addString("string", "string").build();
|
||||
|
||||
// then
|
||||
assertThat(flagMetadata.getBoolean("string")).isNull();
|
||||
|
@ -54,11 +55,34 @@ class FlagMetadataTest {
|
|||
|
||||
@Test
|
||||
@DisplayName("A null is returned if key does not exist")
|
||||
public void notfound_error_validation() {
|
||||
void notfound_error_validation() {
|
||||
// given
|
||||
ImmutableMetadata flagMetadata = ImmutableMetadata.builder().build();
|
||||
|
||||
// then
|
||||
assertThat(flagMetadata.getBoolean("string")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("isEmpty and isNotEmpty return correctly when the metadata is empty")
|
||||
void isEmpty_isNotEmpty_return_correctly_when_metadata_is_empty() {
|
||||
// given
|
||||
ImmutableMetadata flagMetadata = ImmutableMetadata.builder().build();
|
||||
|
||||
// then
|
||||
assertTrue(flagMetadata.isEmpty());
|
||||
assertFalse(flagMetadata.isNotEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("isEmpty and isNotEmpty return correctly when the metadata is not empty")
|
||||
void isEmpty_isNotEmpty_return_correctly_when_metadata_is_not_empty() {
|
||||
// given
|
||||
ImmutableMetadata flagMetadata =
|
||||
ImmutableMetadata.builder().addString("a", "b").build();
|
||||
|
||||
// then
|
||||
assertFalse(flagMetadata.isEmpty());
|
||||
assertTrue(flagMetadata.isNotEmpty());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HookContextTest {
|
||||
@Specification(number="4.2.2.2", text="Condition: The client metadata field in the hook context MUST be immutable.")
|
||||
@Specification(number="4.2.2.3", text="Condition: The provider metadata field in the hook context MUST be immutable.")
|
||||
@Test void metadata_field_is_type_metadata() {
|
||||
@Specification(
|
||||
number = "4.2.2.2",
|
||||
text = "Condition: The client metadata field in the hook context MUST be immutable.")
|
||||
@Specification(
|
||||
number = "4.2.2.3",
|
||||
text = "Condition: The provider metadata field in the hook context MUST be immutable.")
|
||||
@Test
|
||||
void metadata_field_is_type_metadata() {
|
||||
ClientMetadata clientMetadata = mock(ClientMetadata.class);
|
||||
Metadata meta = mock(Metadata.class);
|
||||
HookContext<Object> hc = HookContext.from(
|
||||
"key",
|
||||
FlagValueType.BOOLEAN,
|
||||
clientMetadata,
|
||||
meta,
|
||||
new ImmutableContext(),
|
||||
false
|
||||
);
|
||||
HookContext<Object> hc =
|
||||
HookContext.from("key", FlagValueType.BOOLEAN, clientMetadata, meta, new ImmutableContext(), false);
|
||||
|
||||
assertTrue(ClientMetadata.class.isAssignableFrom(hc.getClientMetadata().getClass()));
|
||||
assertTrue(Metadata.class.isAssignableFrom(hc.getProviderMetadata().getClass()));
|
||||
}
|
||||
|
||||
@Specification(number="4.3.3.1", text="The before stage MUST run before flag resolution occurs. It accepts a hook context (required) and hook hints (optional) as parameters. It has no return value.")
|
||||
@Test void not_applicable_for_dynamic_context() {}
|
||||
|
||||
}
|
||||
@Specification(
|
||||
number = "4.3.3.1",
|
||||
text =
|
||||
"The before stage MUST run before flag resolution occurs. It accepts a hook context (required) and hook hints (optional) as parameters. It has no return value.")
|
||||
@Test
|
||||
void not_applicable_for_dynamic_context() {}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,50 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
import dev.openfeature.sdk.testutils.FeatureProviderTestUtils;
|
||||
import dev.openfeature.sdk.testutils.TestEventsProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class HookSpecTest implements HookFixtures {
|
||||
@AfterEach
|
||||
void emptyApiHooks() {
|
||||
// it's a singleton. Don't pollute each test.
|
||||
OpenFeatureAPI.getInstance().clearHooks();
|
||||
|
||||
private OpenFeatureAPI api;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.api = new OpenFeatureAPI();
|
||||
}
|
||||
|
||||
@Specification(number = "4.1.3", text = "The flag key, flag type, and default value properties MUST be immutable. If the language does not support immutability, the hook MUST NOT modify these properties.")
|
||||
@Specification(
|
||||
number = "4.1.3",
|
||||
text =
|
||||
"The flag key, flag type, and default value properties MUST be immutable. If the language does not support immutability, the hook MUST NOT modify these properties.")
|
||||
@Test
|
||||
void immutableValues() {
|
||||
try {
|
||||
|
@ -50,7 +69,10 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
}
|
||||
|
||||
@Specification(number = "4.1.1", text = "Hook context MUST provide: the flag key, flag value type, evaluation context, and the default value.")
|
||||
@Specification(
|
||||
number = "4.1.1",
|
||||
text =
|
||||
"Hook context MUST provide: the flag key, flag value type, evaluation context, and the default value.")
|
||||
@Test
|
||||
void nullish_properties_on_hookcontext() {
|
||||
// missing ctx
|
||||
|
@ -112,10 +134,11 @@ class HookSpecTest implements HookFixtures {
|
|||
} catch (NullPointerException e) {
|
||||
fail("NPE after we provided all relevant info");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Specification(number = "4.1.2", text = "The hook context SHOULD provide: access to the client metadata and the provider metadata fields.")
|
||||
@Specification(
|
||||
number = "4.1.2",
|
||||
text = "The hook context SHOULD provide: access to the client metadata and the provider metadata fields.")
|
||||
@Test
|
||||
void optional_properties() {
|
||||
// don't specify
|
||||
|
@ -141,19 +164,25 @@ class HookSpecTest implements HookFixtures {
|
|||
.type(FlagValueType.INTEGER)
|
||||
.ctx(new ImmutableContext())
|
||||
.defaultValue(1)
|
||||
.clientMetadata(OpenFeatureAPI.getInstance().getClient().getMetadata())
|
||||
.clientMetadata(api.getClient().getMetadata())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Specification(number = "4.3.2.1", text = "The before stage MUST run before flag resolution occurs. It accepts a hook context (required) and hook hints (optional) as parameters and returns either an evaluation context or nothing.")
|
||||
@Specification(
|
||||
number = "4.3.2.1",
|
||||
text =
|
||||
"The before stage MUST run before flag resolution occurs. It accepts a hook context (required) and hook hints (optional) as parameters and returns either an evaluation context or nothing.")
|
||||
@Test
|
||||
void before_runs_ahead_of_evaluation() {
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new AlwaysBrokenProvider());
|
||||
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client client = api.getClient();
|
||||
Hook<Boolean> evalHook = mockBooleanHook();
|
||||
|
||||
client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(evalHook).build());
|
||||
|
||||
verify(evalHook, times(1)).before(any(), any());
|
||||
|
@ -161,8 +190,7 @@ class HookSpecTest implements HookFixtures {
|
|||
|
||||
@Test
|
||||
void feo_has_hook_list() {
|
||||
FlagEvaluationOptions feo = FlagEvaluationOptions.builder()
|
||||
.build();
|
||||
FlagEvaluationOptions feo = FlagEvaluationOptions.builder().build();
|
||||
assertNotNull(feo.getHooks());
|
||||
}
|
||||
|
||||
|
@ -170,12 +198,11 @@ class HookSpecTest implements HookFixtures {
|
|||
void error_hook_run_during_non_finally_stage() {
|
||||
final boolean[] error_called = {false};
|
||||
Hook h = mockBooleanHook();
|
||||
doThrow(RuntimeException.class).when(h).finallyAfter(any(), any());
|
||||
doThrow(RuntimeException.class).when(h).finallyAfter(any(), any(), any());
|
||||
|
||||
verify(h, times(0)).error(any(), any(), any());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void error_hook_must_run_if_resolution_details_returns_an_error_code() {
|
||||
|
||||
|
@ -184,24 +211,25 @@ class HookSpecTest implements HookFixtures {
|
|||
EvaluationContext invocationCtx = new ImmutableContext();
|
||||
Hook<Boolean> hook = mockBooleanHook();
|
||||
FeatureProvider provider = mock(FeatureProvider.class);
|
||||
when(provider.getBooleanEvaluation(any(), any(), any())).thenReturn(ProviderEvaluation.<Boolean>builder()
|
||||
.errorCode(ErrorCode.FLAG_NOT_FOUND)
|
||||
.errorMessage(errorMessage)
|
||||
.build());
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
FeatureProviderTestUtils.setFeatureProvider("errorHookMustRun", provider);
|
||||
Client client = api.getClient("errorHookMustRun");
|
||||
client.getBooleanValue("key", false, invocationCtx,
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(hook)
|
||||
when(provider.getBooleanEvaluation(any(), any(), any()))
|
||||
.thenReturn(ProviderEvaluation.<Boolean>builder()
|
||||
.errorCode(ErrorCode.FLAG_NOT_FOUND)
|
||||
.errorMessage(errorMessage)
|
||||
.build());
|
||||
|
||||
api.setProviderAndWait("errorHookMustRun", provider);
|
||||
Client client = api.getClient("errorHookMustRun");
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
invocationCtx,
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
|
||||
|
||||
verify(hook, times(1)).before(any(), any());
|
||||
verify(hook, times(1)).error(any(), captor.capture(), any());
|
||||
verify(hook, times(1)).finallyAfter(any(), any());
|
||||
verify(hook, times(1)).finallyAfter(any(), any(), any());
|
||||
verify(hook, never()).after(any(), any(), any());
|
||||
|
||||
Exception exception = captor.getValue();
|
||||
|
@ -209,16 +237,29 @@ class HookSpecTest implements HookFixtures {
|
|||
assertInstanceOf(FlagNotFoundError.class, exception);
|
||||
}
|
||||
|
||||
|
||||
@Specification(number = "4.3.6", text = "The after stage MUST run after flag resolution occurs. It accepts a hook context (required), flag evaluation details (required) and hook hints (optional). It has no return value.")
|
||||
@Specification(number = "4.3.7", text = "The error hook MUST run when errors are encountered in the before stage, the after stage or during flag resolution. It accepts hook context (required), exception representing what went wrong (required), and hook hints (optional). It has no return value.")
|
||||
@Specification(number = "4.3.8", text = "The finally hook MUST run after the before, after, and error stages. It accepts a hook context (required) and hook hints (optional). There is no return value.")
|
||||
@Specification(number = "4.4.1", text = "The API, Client, Provider, and invocation MUST have a method for registering hooks.")
|
||||
@Specification(number = "4.4.2", text = "Hooks MUST be evaluated in the following order: - before: API, Client, Invocation, Provider - after: Provider, Invocation, Client, API - error (if applicable): Provider, Invocation, Client, API - finally: Provider, Invocation, Client, API")
|
||||
@Specification(
|
||||
number = "4.3.6",
|
||||
text =
|
||||
"The after stage MUST run after flag resolution occurs. It accepts a hook context (required), flag evaluation details (required) and hook hints (optional). It has no return value.")
|
||||
@Specification(
|
||||
number = "4.3.7",
|
||||
text =
|
||||
"The error hook MUST run when errors are encountered in the before stage, the after stage or during flag resolution. It accepts hook context (required), exception representing what went wrong (required), and hook hints (optional). It has no return value.")
|
||||
@Specification(
|
||||
number = "4.3.8",
|
||||
text =
|
||||
"The finally hook MUST run after the before, after, and error stages. It accepts a hook context (required) and hook hints (optional). There is no return value.")
|
||||
@Specification(
|
||||
number = "4.4.1",
|
||||
text = "The API, Client, Provider, and invocation MUST have a method for registering hooks.")
|
||||
@Specification(
|
||||
number = "4.4.2",
|
||||
text =
|
||||
"Hooks MUST be evaluated in the following order: - before: API, Client, Invocation, Provider - after: Provider, Invocation, Client, API - error (if applicable): Provider, Invocation, Client, API - finally: Provider, Invocation, Client, API")
|
||||
@Test
|
||||
void hook_eval_order() {
|
||||
List<String> evalOrder = new ArrayList<>();
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
|
||||
api.setProviderAndWait("evalOrder", new TestEventsProvider() {
|
||||
public List<Hook> getProviderHooks() {
|
||||
return Collections.singletonList(new BooleanHook() {
|
||||
|
@ -230,8 +271,10 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String,
|
||||
Object> hints) {
|
||||
public void after(
|
||||
HookContext<Boolean> ctx,
|
||||
FlagEvaluationDetails<Boolean> details,
|
||||
Map<String, Object> hints) {
|
||||
evalOrder.add("provider after");
|
||||
}
|
||||
|
||||
|
@ -241,7 +284,10 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void finallyAfter(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
public void finallyAfter(
|
||||
HookContext<Boolean> ctx,
|
||||
FlagEvaluationDetails<Boolean> details,
|
||||
Map<String, Object> hints) {
|
||||
evalOrder.add("provider finally");
|
||||
}
|
||||
});
|
||||
|
@ -255,7 +301,8 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
public void after(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
evalOrder.add("api after");
|
||||
throw new RuntimeException(); // trigger error flows.
|
||||
}
|
||||
|
@ -266,7 +313,8 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void finallyAfter(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
public void finallyAfter(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
evalOrder.add("api finally");
|
||||
}
|
||||
});
|
||||
|
@ -280,7 +328,8 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
public void after(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
evalOrder.add("client after");
|
||||
}
|
||||
|
||||
|
@ -290,65 +339,94 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void finallyAfter(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
public void finallyAfter(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
evalOrder.add("client finally");
|
||||
}
|
||||
});
|
||||
|
||||
c.getBooleanValue("key", false, null, FlagEvaluationOptions
|
||||
.builder()
|
||||
.hook(new BooleanHook() {
|
||||
@Override
|
||||
public Optional<EvaluationContext> before(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
evalOrder.add("invocation before");
|
||||
return null;
|
||||
}
|
||||
c.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
null,
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(new BooleanHook() {
|
||||
@Override
|
||||
public Optional<EvaluationContext> before(
|
||||
HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
evalOrder.add("invocation before");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
evalOrder.add("invocation after");
|
||||
}
|
||||
@Override
|
||||
public void after(
|
||||
HookContext<Boolean> ctx,
|
||||
FlagEvaluationDetails<Boolean> details,
|
||||
Map<String, Object> hints) {
|
||||
evalOrder.add("invocation after");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(HookContext<Boolean> ctx, Exception error, Map<String, Object> hints) {
|
||||
evalOrder.add("invocation error");
|
||||
}
|
||||
@Override
|
||||
public void error(HookContext<Boolean> ctx, Exception error, Map<String, Object> hints) {
|
||||
evalOrder.add("invocation error");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finallyAfter(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
evalOrder.add("invocation finally");
|
||||
}
|
||||
})
|
||||
.build());
|
||||
@Override
|
||||
public void finallyAfter(
|
||||
HookContext<Boolean> ctx,
|
||||
FlagEvaluationDetails<Boolean> details,
|
||||
Map<String, Object> hints) {
|
||||
evalOrder.add("invocation finally");
|
||||
}
|
||||
})
|
||||
.build());
|
||||
|
||||
List<String> expectedOrder = Arrays.asList(
|
||||
"api before", "client before", "invocation before", "provider before",
|
||||
"provider after", "invocation after", "client after", "api after",
|
||||
"provider error", "invocation error", "client error", "api error",
|
||||
"provider finally", "invocation finally", "client finally", "api finally");
|
||||
"api before",
|
||||
"client before",
|
||||
"invocation before",
|
||||
"provider before",
|
||||
"provider after",
|
||||
"invocation after",
|
||||
"client after",
|
||||
"api after",
|
||||
"provider error",
|
||||
"invocation error",
|
||||
"client error",
|
||||
"api error",
|
||||
"provider finally",
|
||||
"invocation finally",
|
||||
"client finally",
|
||||
"api finally");
|
||||
assertEquals(expectedOrder, evalOrder);
|
||||
}
|
||||
|
||||
@Specification(number = "4.4.6", text = "If an error occurs during the evaluation of before or after hooks, any remaining hooks in the before or after stages MUST NOT be invoked.")
|
||||
@Specification(
|
||||
number = "4.4.6",
|
||||
text =
|
||||
"If an error occurs during the evaluation of before or after hooks, any remaining hooks in the before or after stages MUST NOT be invoked.")
|
||||
@Test
|
||||
void error_stops_before() {
|
||||
Hook<Boolean> h = mockBooleanHook();
|
||||
doThrow(RuntimeException.class).when(h).before(any(), any());
|
||||
Hook<Boolean> h2 = mockBooleanHook();
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new AlwaysBrokenProvider());
|
||||
api.setProviderAndWait(new AlwaysBrokenWithExceptionProvider());
|
||||
Client c = api.getClient();
|
||||
|
||||
c.getBooleanDetails("key", false, null, FlagEvaluationOptions.builder()
|
||||
.hook(h2)
|
||||
.hook(h)
|
||||
.build());
|
||||
verify(h, times(1)).before(any(), any());
|
||||
verify(h2, times(0)).before(any(), any());
|
||||
c.getBooleanDetails(
|
||||
"key",
|
||||
false,
|
||||
null,
|
||||
FlagEvaluationOptions.builder().hook(h2).hook(h).build());
|
||||
verify(h, times(1)).before(any(), any());
|
||||
verify(h2, times(0)).before(any(), any());
|
||||
}
|
||||
|
||||
@Specification(number = "4.4.6", text = "If an error occurs during the evaluation of before or after hooks, any remaining hooks in the before or after stages MUST NOT be invoked.")
|
||||
@Specification(
|
||||
number = "4.4.6",
|
||||
text =
|
||||
"If an error occurs during the evaluation of before or after hooks, any remaining hooks in the before or after stages MUST NOT be invoked.")
|
||||
@SneakyThrows
|
||||
@Test
|
||||
void error_stops_after() {
|
||||
|
@ -358,15 +436,19 @@ class HookSpecTest implements HookFixtures {
|
|||
|
||||
Client c = getClient(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
|
||||
c.getBooleanDetails("key", false, null, FlagEvaluationOptions.builder()
|
||||
.hook(h)
|
||||
.hook(h2)
|
||||
.build());
|
||||
c.getBooleanDetails(
|
||||
"key",
|
||||
false,
|
||||
null,
|
||||
FlagEvaluationOptions.builder().hook(h).hook(h2).build());
|
||||
verify(h, times(1)).after(any(), any(), any());
|
||||
verify(h2, times(0)).after(any(), any(), any());
|
||||
}
|
||||
|
||||
@Specification(number = "4.2.1", text = "hook hints MUST be a structure supports definition of arbitrary properties, with keys of type string, and values of type boolean | string | number | datetime | structure..")
|
||||
@Specification(
|
||||
number = "4.2.1",
|
||||
text =
|
||||
"hook hints MUST be a structure supports definition of arbitrary properties, with keys of type string, and values of type boolean | string | number | datetime | structure..")
|
||||
@Specification(number = "4.5.2", text = "hook hints MUST be passed to each hook.")
|
||||
@Specification(number = "4.2.2.1", text = "Condition: Hook hints MUST be immutable.")
|
||||
@Specification(number = "4.5.3", text = "The hook MUST NOT alter the hook hints structure.")
|
||||
|
@ -378,23 +460,29 @@ class HookSpecTest implements HookFixtures {
|
|||
Hook<Boolean> mutatingHook = new BooleanHook() {
|
||||
@Override
|
||||
public Optional<EvaluationContext> before(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value")).isInstanceOf(UnsupportedOperationException.class);
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value"))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value")).isInstanceOf(UnsupportedOperationException.class);
|
||||
public void after(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value"))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(HookContext<Boolean> ctx, Exception error, Map<String, Object> hints) {
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value")).isInstanceOf(UnsupportedOperationException.class);
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value"))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finallyAfter(HookContext<Boolean> ctx, Map<String, Object> hints) {
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value")).isInstanceOf(UnsupportedOperationException.class);
|
||||
public void finallyAfter(
|
||||
HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, Map<String, Object> hints) {
|
||||
assertThatCode(() -> hints.put(hintKey, "changed value"))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -402,13 +490,16 @@ class HookSpecTest implements HookFixtures {
|
|||
hh.put(hintKey, "My hint value");
|
||||
hh = Collections.unmodifiableMap(hh);
|
||||
|
||||
client.getBooleanValue("key", false, new ImmutableContext(), FlagEvaluationOptions.builder()
|
||||
.hook(mutatingHook)
|
||||
.hookHints(hh)
|
||||
.build());
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(mutatingHook).hookHints(hh).build());
|
||||
}
|
||||
|
||||
@Specification(number = "4.5.1", text = "Flag evaluation options MAY contain hook hints, a map of data to be provided to hook invocations.")
|
||||
@Specification(
|
||||
number = "4.5.1",
|
||||
text = "Flag evaluation options MAY contain hook hints, a map of data to be provided to hook invocations.")
|
||||
@Test
|
||||
void missing_hook_hints() {
|
||||
FlagEvaluationOptions feo = FlagEvaluationOptions.builder().build();
|
||||
|
@ -421,49 +512,132 @@ class HookSpecTest implements HookFixtures {
|
|||
Hook hook = mockBooleanHook();
|
||||
FeatureProvider provider = mock(FeatureProvider.class);
|
||||
when(provider.getBooleanEvaluation(any(), any(), any()))
|
||||
.thenReturn(ProviderEvaluation.<Boolean>builder()
|
||||
.value(true)
|
||||
.build());
|
||||
.thenReturn(ProviderEvaluation.<Boolean>builder().value(true).build());
|
||||
InOrder order = inOrder(hook, provider);
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
Client client = api.getClient();
|
||||
client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
order.verify(hook).before(any(), any());
|
||||
order.verify(provider).getBooleanEvaluation(any(), any(), any());
|
||||
order.verify(hook).after(any(), any(), any());
|
||||
order.verify(hook).finallyAfter(any(), any());
|
||||
order.verify(hook).finallyAfter(any(), any(), any());
|
||||
}
|
||||
|
||||
@Specification(number = "4.4.5", text = "If an error occurs in the before or after hooks, the error hooks MUST be invoked.")
|
||||
@Specification(number = "4.4.7", text = "If an error occurs in the before hooks, the default value MUST be returned.")
|
||||
@Specification(
|
||||
number = "4.4.5",
|
||||
text = "If an error occurs in the before or after hooks, the error hooks MUST be invoked.")
|
||||
@Specification(
|
||||
number = "4.4.7",
|
||||
text = "If an error occurs in the before hooks, the default value MUST be returned.")
|
||||
@Test
|
||||
void error_hooks__before() {
|
||||
Hook hook = mockBooleanHook();
|
||||
doThrow(RuntimeException.class).when(hook).before(any(), any());
|
||||
Client client = getClient(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
Boolean value = client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
Boolean value = client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
verify(hook, times(1)).before(any(), any());
|
||||
verify(hook, times(1)).error(any(), any(), any());
|
||||
assertEquals(false, value, "Falls through to the default.");
|
||||
}
|
||||
|
||||
@Specification(number = "4.4.5", text = "If an error occurs in the before or after hooks, the error hooks MUST be invoked.")
|
||||
@Specification(
|
||||
number = "4.4.5",
|
||||
text = "If an error occurs in the before or after hooks, the error hooks MUST be invoked.")
|
||||
@Test
|
||||
void error_hooks__after() {
|
||||
Hook hook = mockBooleanHook();
|
||||
doThrow(RuntimeException.class).when(hook).after(any(), any(), any());
|
||||
Client client = getClient(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
verify(hook, times(1)).after(any(), any(), any());
|
||||
verify(hook, times(1)).error(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void erroneous_flagResolution_setsAppropriateFieldsInFlagEvaluationDetails() {
|
||||
Hook hook = mockBooleanHook();
|
||||
doThrow(RuntimeException.class).when(hook).after(any(), any(), any());
|
||||
String flagKey = "test-flag-key";
|
||||
Client client = getClient(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
client.getBooleanValue(
|
||||
flagKey,
|
||||
true,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
ArgumentCaptor<FlagEvaluationDetails<Boolean>> captor = ArgumentCaptor.forClass(FlagEvaluationDetails.class);
|
||||
verify(hook).finallyAfter(any(), captor.capture(), any());
|
||||
|
||||
FlagEvaluationDetails<Boolean> evaluationDetails = captor.getValue();
|
||||
assertThat(evaluationDetails).isNotNull();
|
||||
|
||||
assertThat(evaluationDetails.getErrorCode()).isEqualTo(ErrorCode.GENERAL);
|
||||
assertThat(evaluationDetails.getReason()).isEqualTo("ERROR");
|
||||
assertThat(evaluationDetails.getVariant()).isEqualTo("Passed in default");
|
||||
assertThat(evaluationDetails.getFlagKey()).isEqualTo(flagKey);
|
||||
assertThat(evaluationDetails.getFlagMetadata())
|
||||
.isEqualTo(ImmutableMetadata.builder().build());
|
||||
assertThat(evaluationDetails.getValue()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shortCircuit_flagResolution_runsHooksWithAllFields() {
|
||||
String domain = "shortCircuit_flagResolution_setsAppropriateFieldsInFlagEvaluationDetails";
|
||||
api.setProvider(domain, new FatalErrorProvider());
|
||||
|
||||
Hook hook = mockBooleanHook();
|
||||
String flagKey = "test-flag-key";
|
||||
Client client = api.getClient(domain);
|
||||
client.getBooleanValue(
|
||||
flagKey,
|
||||
true,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
verify(hook).before(any(), any());
|
||||
verify(hook).error(any(HookContext.class), any(Exception.class), any(Map.class));
|
||||
verify(hook).finallyAfter(any(HookContext.class), any(FlagEvaluationDetails.class), any(Map.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void successful_flagResolution_setsAppropriateFieldsInFlagEvaluationDetails() {
|
||||
Hook hook = mockBooleanHook();
|
||||
String flagKey = "test-flag-key";
|
||||
Client client = getClient(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
client.getBooleanValue(
|
||||
flagKey,
|
||||
true,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
ArgumentCaptor<FlagEvaluationDetails<Boolean>> captor = ArgumentCaptor.forClass(FlagEvaluationDetails.class);
|
||||
verify(hook).finallyAfter(any(), captor.capture(), any());
|
||||
|
||||
FlagEvaluationDetails<Boolean> evaluationDetails = captor.getValue();
|
||||
assertThat(evaluationDetails).isNotNull();
|
||||
assertThat(evaluationDetails.getErrorCode()).isNull();
|
||||
assertThat(evaluationDetails.getReason()).isEqualTo("DEFAULT");
|
||||
assertThat(evaluationDetails.getVariant()).isEqualTo("Passed in default");
|
||||
assertThat(evaluationDetails.getFlagKey()).isEqualTo(flagKey);
|
||||
assertThat(evaluationDetails.getFlagMetadata())
|
||||
.isEqualTo(ImmutableMetadata.builder().build());
|
||||
assertThat(evaluationDetails.getValue()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void multi_hooks_early_out__before() {
|
||||
Hook<Boolean> hook = mockBooleanHook();
|
||||
|
@ -472,11 +646,11 @@ class HookSpecTest implements HookFixtures {
|
|||
|
||||
Client client = getClient(null);
|
||||
|
||||
client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(hook2)
|
||||
.hook(hook)
|
||||
.build());
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook2).hook(hook).build());
|
||||
|
||||
verify(hook, times(1)).before(any(), any());
|
||||
verify(hook2, times(0)).before(any(), any());
|
||||
|
@ -486,7 +660,10 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
@Specification(number = "4.1.4", text = "The evaluation context MUST be mutable only within the before hook.")
|
||||
@Specification(number = "4.3.4", text = "Any `evaluation context` returned from a `before` hook MUST be passed to subsequent `before` hooks (via `HookContext`).")
|
||||
@Specification(
|
||||
number = "4.3.4",
|
||||
text =
|
||||
"Any `evaluation context` returned from a `before` hook MUST be passed to subsequent `before` hooks (via `HookContext`).")
|
||||
@Test
|
||||
void beforeContextUpdated() {
|
||||
String targetingKey = "test-key";
|
||||
|
@ -498,11 +675,11 @@ class HookSpecTest implements HookFixtures {
|
|||
InOrder order = inOrder(hook, hook2);
|
||||
|
||||
Client client = getClient(null);
|
||||
client.getBooleanValue("key", false, ctx,
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(hook2)
|
||||
.hook(hook)
|
||||
.build());
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
ctx,
|
||||
FlagEvaluationOptions.builder().hook(hook2).hook(hook).build());
|
||||
|
||||
order.verify(hook).before(any(), any());
|
||||
ArgumentCaptor<HookContext<Boolean>> captor = ArgumentCaptor.forClass(HookContext.class);
|
||||
|
@ -510,10 +687,12 @@ class HookSpecTest implements HookFixtures {
|
|||
|
||||
HookContext<Boolean> hc = captor.getValue();
|
||||
assertEquals(hc.getCtx().getTargetingKey(), targetingKey);
|
||||
|
||||
}
|
||||
|
||||
@Specification(number = "4.3.5", text = "When before hooks have finished executing, any resulting evaluation context MUST be merged with the existing evaluation context.")
|
||||
@Specification(
|
||||
number = "4.3.5",
|
||||
text =
|
||||
"When before hooks have finished executing, any resulting evaluation context MUST be merged with the existing evaluation context.")
|
||||
@Test
|
||||
void mergeHappensCorrectly() {
|
||||
Map<String, Value> attributes = new HashMap<>();
|
||||
|
@ -521,7 +700,6 @@ class HookSpecTest implements HookFixtures {
|
|||
attributes.put("another", new Value("exists"));
|
||||
EvaluationContext hookCtx = new ImmutableContext(attributes);
|
||||
|
||||
|
||||
Map<String, Value> attributes1 = new HashMap<>();
|
||||
attributes1.put("something", new Value("here"));
|
||||
attributes1.put("test", new Value("broken"));
|
||||
|
@ -531,17 +709,16 @@ class HookSpecTest implements HookFixtures {
|
|||
when(hook.before(any(), any())).thenReturn(Optional.of(hookCtx));
|
||||
|
||||
FeatureProvider provider = mock(FeatureProvider.class);
|
||||
when(provider.getBooleanEvaluation(any(), any(), any())).thenReturn(ProviderEvaluation.<Boolean>builder()
|
||||
.value(true)
|
||||
.build());
|
||||
when(provider.getBooleanEvaluation(any(), any(), any()))
|
||||
.thenReturn(ProviderEvaluation.<Boolean>builder().value(true).build());
|
||||
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
Client client = api.getClient();
|
||||
client.getBooleanValue("key", false, invocationCtx,
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(hook)
|
||||
.build());
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
invocationCtx,
|
||||
FlagEvaluationOptions.builder().hook(hook).build());
|
||||
|
||||
ArgumentCaptor<ImmutableContext> captor = ArgumentCaptor.forClass(ImmutableContext.class);
|
||||
verify(provider).getBooleanEvaluation(any(), any(), captor.capture());
|
||||
|
@ -551,28 +728,34 @@ class HookSpecTest implements HookFixtures {
|
|||
assertEquals("here", ec.getValue("something").asString());
|
||||
}
|
||||
|
||||
@Specification(number = "4.4.3", text = "If a finally hook abnormally terminates, evaluation MUST proceed, including the execution of any remaining finally hooks.")
|
||||
@Specification(
|
||||
number = "4.4.3",
|
||||
text =
|
||||
"If a finally hook abnormally terminates, evaluation MUST proceed, including the execution of any remaining finally hooks.")
|
||||
@Test
|
||||
void first_finally_broken() {
|
||||
Hook hook = mockBooleanHook();
|
||||
doThrow(RuntimeException.class).when(hook).before(any(), any());
|
||||
doThrow(RuntimeException.class).when(hook).finallyAfter(any(), any());
|
||||
doThrow(RuntimeException.class).when(hook).finallyAfter(any(), any(), any());
|
||||
Hook hook2 = mockBooleanHook();
|
||||
InOrder order = inOrder(hook, hook2);
|
||||
|
||||
Client client = getClient(null);
|
||||
client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(hook2)
|
||||
.hook(hook)
|
||||
.build());
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook2).hook(hook).build());
|
||||
|
||||
order.verify(hook).before(any(), any());
|
||||
order.verify(hook2).finallyAfter(any(), any());
|
||||
order.verify(hook).finallyAfter(any(), any());
|
||||
order.verify(hook2).finallyAfter(any(), any(), any());
|
||||
order.verify(hook).finallyAfter(any(), any(), any());
|
||||
}
|
||||
|
||||
@Specification(number = "4.4.4", text = "If an error hook abnormally terminates, evaluation MUST proceed, including the execution of any remaining error hooks.")
|
||||
@Specification(
|
||||
number = "4.4.4",
|
||||
text =
|
||||
"If an error hook abnormally terminates, evaluation MUST proceed, including the execution of any remaining error hooks.")
|
||||
@Test
|
||||
void first_error_broken() {
|
||||
Hook hook = mockBooleanHook();
|
||||
|
@ -582,11 +765,11 @@ class HookSpecTest implements HookFixtures {
|
|||
InOrder order = inOrder(hook, hook2);
|
||||
|
||||
Client client = getClient(null);
|
||||
client.getBooleanValue("key", false, new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder()
|
||||
.hook(hook2)
|
||||
.hook(hook)
|
||||
.build());
|
||||
client.getBooleanValue(
|
||||
"key",
|
||||
false,
|
||||
new ImmutableContext(),
|
||||
FlagEvaluationOptions.builder().hook(hook2).hook(hook).build());
|
||||
|
||||
order.verify(hook).before(any(), any());
|
||||
order.verify(hook2).error(any(), any(), any());
|
||||
|
@ -594,19 +777,17 @@ class HookSpecTest implements HookFixtures {
|
|||
}
|
||||
|
||||
private Client getClient(FeatureProvider provider) {
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
if (provider == null) {
|
||||
FeatureProviderTestUtils.setFeatureProvider(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
api.setProviderAndWait(TestEventsProvider.newInitializedTestEventsProvider());
|
||||
} else {
|
||||
FeatureProviderTestUtils.setFeatureProvider(provider);
|
||||
api.setProviderAndWait(provider);
|
||||
}
|
||||
return api.getClient();
|
||||
}
|
||||
|
||||
@Specification(number = "4.3.1", text = "Hooks MUST specify at least one stage.")
|
||||
@Test
|
||||
void default_methods_so_impossible() {
|
||||
}
|
||||
void default_methods_so_impossible() {}
|
||||
|
||||
@Specification(number = "4.3.9.1", text = "Instead of finally, finallyAfter SHOULD be used.")
|
||||
@SneakyThrows
|
||||
|
@ -616,8 +797,8 @@ class HookSpecTest implements HookFixtures {
|
|||
.as("Not possible. Finally is a reserved word.")
|
||||
.isInstanceOf(NoSuchMethodException.class);
|
||||
|
||||
assertThatCode(() -> Hook.class.getMethod("finallyAfter", HookContext.class, Map.class))
|
||||
assertThatCode(() ->
|
||||
Hook.class.getMethod("finallyAfter", HookContext.class, FlagEvaluationDetails.class, Map.class))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,19 +5,17 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
import dev.openfeature.sdk.fixtures.HookFixtures;
|
||||
|
||||
class HookSupportTest implements HookFixtures {
|
||||
@Test
|
||||
@DisplayName("should merge EvaluationContexts on before hooks correctly")
|
||||
|
@ -25,14 +23,16 @@ class HookSupportTest implements HookFixtures {
|
|||
Map<String, Value> attributes = new HashMap<>();
|
||||
attributes.put("baseKey", new Value("baseValue"));
|
||||
EvaluationContext baseContext = new ImmutableContext(attributes);
|
||||
HookContext<String> hookContext = new HookContext<>("flagKey", FlagValueType.STRING, "defaultValue", baseContext, () -> "client", () -> "provider");
|
||||
HookContext<String> hookContext = new HookContext<>(
|
||||
"flagKey", FlagValueType.STRING, "defaultValue", baseContext, () -> "client", () -> "provider");
|
||||
Hook<String> hook1 = mockStringHook();
|
||||
Hook<String> hook2 = mockStringHook();
|
||||
when(hook1.before(any(), any())).thenReturn(Optional.of(evaluationContextWithValue("bla", "blubber")));
|
||||
when(hook2.before(any(), any())).thenReturn(Optional.of(evaluationContextWithValue("foo", "bar")));
|
||||
HookSupport hookSupport = new HookSupport();
|
||||
|
||||
EvaluationContext result = hookSupport.beforeHooks(FlagValueType.STRING, hookContext, Arrays.asList(hook1, hook2), Collections.emptyMap());
|
||||
EvaluationContext result = hookSupport.beforeHooks(
|
||||
FlagValueType.STRING, hookContext, Arrays.asList(hook1, hook2), Collections.emptyMap());
|
||||
|
||||
assertThat(result.getValue("bla").asString()).isEqualTo("blubber");
|
||||
assertThat(result.getValue("foo").asString()).isEqualTo("bar");
|
||||
|
@ -47,16 +47,38 @@ class HookSupportTest implements HookFixtures {
|
|||
HookSupport hookSupport = new HookSupport();
|
||||
EvaluationContext baseContext = new ImmutableContext();
|
||||
IllegalStateException expectedException = new IllegalStateException("All fine, just a test");
|
||||
HookContext<Object> hookContext = new HookContext<>("flagKey", flagValueType, createDefaultValue(flagValueType), baseContext, () -> "client", () -> "provider");
|
||||
HookContext<Object> hookContext = new HookContext<>(
|
||||
"flagKey",
|
||||
flagValueType,
|
||||
createDefaultValue(flagValueType),
|
||||
baseContext,
|
||||
() -> "client",
|
||||
() -> "provider");
|
||||
|
||||
hookSupport.beforeHooks(flagValueType, hookContext, Collections.singletonList(genericHook), Collections.emptyMap());
|
||||
hookSupport.afterHooks(flagValueType, hookContext, FlagEvaluationDetails.builder().build(), Collections.singletonList(genericHook), Collections.emptyMap());
|
||||
hookSupport.afterAllHooks(flagValueType, hookContext, Collections.singletonList(genericHook), Collections.emptyMap());
|
||||
hookSupport.errorHooks(flagValueType, hookContext, expectedException, Collections.singletonList(genericHook), Collections.emptyMap());
|
||||
hookSupport.beforeHooks(
|
||||
flagValueType, hookContext, Collections.singletonList(genericHook), Collections.emptyMap());
|
||||
hookSupport.afterHooks(
|
||||
flagValueType,
|
||||
hookContext,
|
||||
FlagEvaluationDetails.builder().build(),
|
||||
Collections.singletonList(genericHook),
|
||||
Collections.emptyMap());
|
||||
hookSupport.afterAllHooks(
|
||||
flagValueType,
|
||||
hookContext,
|
||||
FlagEvaluationDetails.builder().build(),
|
||||
Collections.singletonList(genericHook),
|
||||
Collections.emptyMap());
|
||||
hookSupport.errorHooks(
|
||||
flagValueType,
|
||||
hookContext,
|
||||
expectedException,
|
||||
Collections.singletonList(genericHook),
|
||||
Collections.emptyMap());
|
||||
|
||||
verify(genericHook).before(any(), any());
|
||||
verify(genericHook).after(any(), any(), any());
|
||||
verify(genericHook).finallyAfter(any(), any());
|
||||
verify(genericHook).finallyAfter(any(), any(), any());
|
||||
verify(genericHook).error(any(), any(), any());
|
||||
}
|
||||
|
||||
|
@ -83,5 +105,4 @@ class HookSupportTest implements HookFixtures {
|
|||
EvaluationContext baseContext = new ImmutableContext(attributes);
|
||||
return baseContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static dev.openfeature.sdk.EvaluationContext.TARGETING_KEY;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ImmutableContextTest {
|
||||
@DisplayName("attributes unable to allow mutation should not affect the immutable context")
|
||||
@Test
|
||||
|
@ -23,7 +22,8 @@ class ImmutableContextTest {
|
|||
// should check the usage of Map.of() which is a more likely use case, but that API isn't available in Java 8
|
||||
EvaluationContext ctx = new ImmutableContext("targeting key", Collections.unmodifiableMap(attributes));
|
||||
attributes.put("key3", new Value("val3"));
|
||||
assertArrayEquals(new Object[]{"key1", "key2", TARGETING_KEY}, ctx.keySet().toArray());
|
||||
assertArrayEquals(
|
||||
new Object[] {"key1", "key2", TARGETING_KEY}, ctx.keySet().toArray());
|
||||
}
|
||||
|
||||
@DisplayName("attributes mutation should not affect the immutable context")
|
||||
|
@ -34,7 +34,8 @@ class ImmutableContextTest {
|
|||
attributes.put("key2", new Value("val2"));
|
||||
EvaluationContext ctx = new ImmutableContext("targeting key", attributes);
|
||||
attributes.put("key3", new Value("val3"));
|
||||
assertArrayEquals(new Object[]{"key1", "key2", TARGETING_KEY}, ctx.keySet().toArray());
|
||||
assertArrayEquals(
|
||||
new Object[] {"key1", "key2", TARGETING_KEY}, ctx.keySet().toArray());
|
||||
}
|
||||
|
||||
@DisplayName("targeting key should be changed from the overriding context")
|
||||
|
@ -60,6 +61,7 @@ class ImmutableContextTest {
|
|||
EvaluationContext merge = ctx.merge(overriding);
|
||||
assertEquals("targeting_key", merge.getTargetingKey());
|
||||
}
|
||||
|
||||
@DisplayName("missing targeting key should return null")
|
||||
@Test
|
||||
void missingTargetingKeyShould() {
|
||||
|
@ -76,10 +78,12 @@ class ImmutableContextTest {
|
|||
EvaluationContext ctx = new ImmutableContext("targeting_key", attributes);
|
||||
EvaluationContext merge = ctx.merge(null);
|
||||
assertEquals("targeting_key", merge.getTargetingKey());
|
||||
assertArrayEquals(new Object[]{"key1", "key2", TARGETING_KEY}, merge.keySet().toArray());
|
||||
assertArrayEquals(
|
||||
new Object[] {"key1", "key2", TARGETING_KEY}, merge.keySet().toArray());
|
||||
}
|
||||
|
||||
@DisplayName("Merge should retain subkeys from the existing context when the overriding context has the same targeting key")
|
||||
@DisplayName(
|
||||
"Merge should retain subkeys from the existing context when the overriding context has the same targeting key")
|
||||
@Test
|
||||
void mergeShouldRetainItsSubkeysWhenOverridingContextHasTheSameKey() {
|
||||
HashMap<String, Value> attributes = new HashMap<>();
|
||||
|
@ -92,21 +96,24 @@ class ImmutableContextTest {
|
|||
attributes.put("key2", new Value("val2"));
|
||||
ovKey1Attributes.put("overriding_key1_1", new Value("overriding_val_1_1"));
|
||||
overridingAttributes.put("key1", new Value(new ImmutableStructure(ovKey1Attributes)));
|
||||
|
||||
|
||||
EvaluationContext ctx = new ImmutableContext("targeting_key", attributes);
|
||||
EvaluationContext overriding = new ImmutableContext("targeting_key", overridingAttributes);
|
||||
EvaluationContext merge = ctx.merge(overriding);
|
||||
assertEquals("targeting_key", merge.getTargetingKey());
|
||||
assertArrayEquals(new Object[]{"key1", "key2", TARGETING_KEY}, merge.keySet().toArray());
|
||||
|
||||
assertArrayEquals(
|
||||
new Object[] {"key1", "key2", TARGETING_KEY}, merge.keySet().toArray());
|
||||
|
||||
Value key1 = merge.getValue("key1");
|
||||
assertTrue(key1.isStructure());
|
||||
|
||||
|
||||
Structure value = key1.asStructure();
|
||||
assertArrayEquals(new Object[]{"key1_1","overriding_key1_1"}, value.keySet().toArray());
|
||||
assertArrayEquals(
|
||||
new Object[] {"key1_1", "overriding_key1_1"}, value.keySet().toArray());
|
||||
}
|
||||
|
||||
@DisplayName("Merge should retain subkeys from the existing context when the overriding context doesn't have targeting key")
|
||||
|
||||
@DisplayName(
|
||||
"Merge should retain subkeys from the existing context when the overriding context doesn't have targeting key")
|
||||
@Test
|
||||
void mergeShouldRetainItsSubkeysWhenOverridingContextHasNoTargetingKey() {
|
||||
HashMap<String, Value> attributes = new HashMap<>();
|
||||
|
@ -115,16 +122,43 @@ class ImmutableContextTest {
|
|||
key1Attributes.put("key1_1", new Value("val1_1"));
|
||||
attributes.put("key1", new Value(new ImmutableStructure(key1Attributes)));
|
||||
attributes.put("key2", new Value("val2"));
|
||||
|
||||
|
||||
EvaluationContext ctx = new ImmutableContext(attributes);
|
||||
EvaluationContext overriding = new ImmutableContext();
|
||||
EvaluationContext merge = ctx.merge(overriding);
|
||||
assertArrayEquals(new Object[]{"key1", "key2"}, merge.keySet().toArray());
|
||||
|
||||
assertArrayEquals(new Object[] {"key1", "key2"}, merge.keySet().toArray());
|
||||
|
||||
Value key1 = merge.getValue("key1");
|
||||
assertTrue(key1.isStructure());
|
||||
|
||||
|
||||
Structure value = key1.asStructure();
|
||||
assertArrayEquals(new Object[]{"key1_1"}, value.keySet().toArray());
|
||||
assertArrayEquals(new Object[] {"key1_1"}, value.keySet().toArray());
|
||||
}
|
||||
|
||||
@DisplayName("Two different MutableContext objects with the different contents are not considered equal")
|
||||
@Test
|
||||
void unequalImmutableContextsAreNotEqual() {
|
||||
final Map<String, Value> attributes = new HashMap<>();
|
||||
attributes.put("key1", new Value("val1"));
|
||||
final ImmutableContext ctx = new ImmutableContext(attributes);
|
||||
|
||||
final Map<String, Value> attributes2 = new HashMap<>();
|
||||
final ImmutableContext ctx2 = new ImmutableContext(attributes2);
|
||||
|
||||
assertNotEquals(ctx, ctx2);
|
||||
}
|
||||
|
||||
@DisplayName("Two different MutableContext objects with the same content are considered equal")
|
||||
@Test
|
||||
void equalImmutableContextsAreEqual() {
|
||||
final Map<String, Value> attributes = new HashMap<>();
|
||||
attributes.put("key1", new Value("val1"));
|
||||
final ImmutableContext ctx = new ImmutableContext(attributes);
|
||||
|
||||
final Map<String, Value> attributes2 = new HashMap<>();
|
||||
attributes2.put("key1", new Value("val1"));
|
||||
final ImmutableContext ctx2 = new ImmutableContext(attributes2);
|
||||
|
||||
assertEquals(ctx, ctx2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package dev.openfeature.sdk;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ImmutableMetadataTest {
|
||||
@Test
|
||||
void unequalImmutableMetadataAreUnequal() {
|
||||
ImmutableMetadata i1 =
|
||||
ImmutableMetadata.builder().addString("key1", "value1").build();
|
||||
ImmutableMetadata i2 =
|
||||
ImmutableMetadata.builder().addString("key1", "value2").build();
|
||||
|
||||
assertNotEquals(i1, i2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalImmutableMetadataAreEqual() {
|
||||
ImmutableMetadata i1 =
|
||||
ImmutableMetadata.builder().addString("key1", "value1").build();
|
||||
ImmutableMetadata i2 =
|
||||
ImmutableMetadata.builder().addString("key1", "value1").build();
|
||||
|
||||
assertEquals(i1, i2);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue