-
Notifications
You must be signed in to change notification settings - Fork 10
Fix concurrent group access to prevent NullPointerException #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature-group-concurrency-update
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.http.client.methods.CloseableHttpResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.http.client.methods.HttpGet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.http.impl.client.CloseableHttpClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.hamcrest.Matchers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Assertions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.keycloak.admin.client.Keycloak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -76,6 +77,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.UUID; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.CopyOnWriteArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.stream.IntStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.hamcrest.MatcherAssert.assertThat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.hamcrest.Matchers.anEmptyMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -90,6 +94,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.fail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @author <a href="mailto:[email protected]">Marko Strukelj</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -109,6 +114,49 @@ public class GroupTest extends AbstractGroupTest { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @InjectHttpClient | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CloseableHttpClient httpClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void createMultiDeleteMultiReadMulti() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // create multiple groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<String> groupUuuids = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Variable name has typo: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IntStream.range(0, 100).forEach(groupIndex -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupRepresentation group = new GroupRepresentation(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.setName("Test Group " + groupIndex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try (Response response = managedRealm.admin().groups().add(group)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean created = response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (created) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final String groupUuid = ApiUtil.getCreatedId(response); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| groupUuuids.add(groupUuid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fail("Failed to create group: " + response.getStatusInfo().getReasonPhrase()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AtomicBoolean deletedAll = new AtomicBoolean(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Exception> caughtExceptions = new CopyOnWriteArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // read groups in a separate thread | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new Thread(() -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (!deletedAll.get()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // just loading briefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| managedRealm.admin().groups().groups(null, 0, Integer.MAX_VALUE, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| caughtExceptions.add(e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).start(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+139
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Thread is started but not joined, creating a race condition where the test might complete before the reader thread finishes executing
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // delete groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| groupUuuids.forEach(groupUuid -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| managedRealm.admin().groups().group(groupUuid).remove(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deletedAll.set(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(caughtExceptions, Matchers.empty()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // KEYCLOAK-2716 Can't delete client if its role is assigned to a group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testClientRemoveWithClientRoleGroupMapping() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This pattern differs from other methods like
getSubGroupsStream()which callgetDelegateForUpdate()when encountering null models. Consider consistency with the existing error handling pattern.