KEYCLOAK-12065 UserSessionInitializerTest is failing
This commit is contained in:
parent
c3f0b342bf
commit
1bdf77f409
3 changed files with 17 additions and 11 deletions
|
@ -21,6 +21,7 @@ import org.junit.After;
|
||||||
import org.keycloak.admin.client.resource.RealmResource;
|
import org.keycloak.admin.client.resource.RealmResource;
|
||||||
import org.keycloak.common.util.reflections.Reflections;
|
import org.keycloak.common.util.reflections.Reflections;
|
||||||
import org.keycloak.events.Details;
|
import org.keycloak.events.Details;
|
||||||
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.representations.IDToken;
|
import org.keycloak.representations.IDToken;
|
||||||
import org.keycloak.representations.idm.ClientRepresentation;
|
import org.keycloak.representations.idm.ClientRepresentation;
|
||||||
import org.keycloak.representations.idm.EventRepresentation;
|
import org.keycloak.representations.idm.EventRepresentation;
|
||||||
|
@ -109,4 +110,9 @@ public abstract class AbstractTestRealmKeycloakTest extends AbstractKeycloakTest
|
||||||
return idToken;
|
return idToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** KEYCLOAK-12065 Inherit Client Connection from parent session **/
|
||||||
|
public static KeycloakSession inheritClientConnection(KeycloakSession parentSession, KeycloakSession currentSession) {
|
||||||
|
currentSession.getContext().setConnection(parentSession.getContext().getConnection());
|
||||||
|
return currentSession;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,8 +88,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
AtomicReference<UserSessionModel[]> origSessionsAtomic = new AtomicReference<>();
|
AtomicReference<UserSessionModel[]> origSessionsAtomic = new AtomicReference<>();
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInit1) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInit1) -> {
|
||||||
KeycloakSession currentSession = SessionInit1;
|
KeycloakSession currentSession = inheritClientConnection(session, SessionInit1);
|
||||||
UserSessionManager sessionManager = new UserSessionManager(currentSession);
|
|
||||||
|
|
||||||
int started = Time.currentTime();
|
int started = Time.currentTime();
|
||||||
startedAtomic.set(started);
|
startedAtomic.set(started);
|
||||||
|
@ -103,7 +102,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInit2) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInit2) -> {
|
||||||
KeycloakSession currentSession = SessionInit2;
|
KeycloakSession currentSession = inheritClientConnection(session, SessionInit2);
|
||||||
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
||||||
|
|
||||||
int started = startedAtomic.get();
|
int started = startedAtomic.get();
|
||||||
|
@ -133,8 +132,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
AtomicReference<UserSessionModel[]> origSessionsAtomic = new AtomicReference<>();
|
AtomicReference<UserSessionModel[]> origSessionsAtomic = new AtomicReference<>();
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInitWithDeleting1) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInitWithDeleting1) -> {
|
||||||
KeycloakSession currentSession = SessionInitWithDeleting1;
|
KeycloakSession currentSession = inheritClientConnection(session, SessionInitWithDeleting1);
|
||||||
UserSessionManager sessionManager = new UserSessionManager(currentSession);
|
|
||||||
|
|
||||||
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
||||||
|
|
||||||
|
@ -149,7 +147,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInitWithDeleting2) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInitWithDeleting2) -> {
|
||||||
KeycloakSession currentSession = SessionInitWithDeleting2;
|
KeycloakSession currentSession = inheritClientConnection(session, SessionInitWithDeleting2);
|
||||||
|
|
||||||
// Load sessions from persister into infinispan/memory
|
// Load sessions from persister into infinispan/memory
|
||||||
UserSessionProviderFactory userSessionFactory = (UserSessionProviderFactory) currentSession.getKeycloakSessionFactory().getProviderFactory(UserSessionProvider.class);
|
UserSessionProviderFactory userSessionFactory = (UserSessionProviderFactory) currentSession.getKeycloakSessionFactory().getProviderFactory(UserSessionProvider.class);
|
||||||
|
@ -157,7 +155,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInitWithDeleting3) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession SessionInitWithDeleting3) -> {
|
||||||
KeycloakSession currentSession = SessionInitWithDeleting3;
|
KeycloakSession currentSession = inheritClientConnection(session, SessionInitWithDeleting3);
|
||||||
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
||||||
|
|
||||||
int started = startedAtomic.get();
|
int started = startedAtomic.get();
|
||||||
|
@ -184,14 +182,14 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
AtomicReference<UserSessionModel[]> origSessionsAtomic = new AtomicReference<>();
|
AtomicReference<UserSessionModel[]> origSessionsAtomic = new AtomicReference<>();
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister1) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister1) -> {
|
||||||
KeycloakSession currentSession = createSessionPersister1;
|
KeycloakSession currentSession = inheritClientConnection(session, createSessionPersister1);
|
||||||
|
|
||||||
UserSessionModel[] origSessions = createSessions(currentSession);
|
UserSessionModel[] origSessions = createSessions(currentSession);
|
||||||
origSessionsAtomic.set(origSessions);
|
origSessionsAtomic.set(origSessions);
|
||||||
});
|
});
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister2) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister2) -> {
|
||||||
KeycloakSession currentSession = createSessionPersister2;
|
KeycloakSession currentSession = inheritClientConnection(session, createSessionPersister2);
|
||||||
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
||||||
UserSessionManager sessionManager = new UserSessionManager(currentSession);
|
UserSessionManager sessionManager = new UserSessionManager(currentSession);
|
||||||
|
|
||||||
|
@ -206,7 +204,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister3) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister3) -> {
|
||||||
KeycloakSession currentSession = createSessionPersister3;
|
KeycloakSession currentSession = inheritClientConnection(session, createSessionPersister3);
|
||||||
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
||||||
|
|
||||||
// Delete cache (persisted sessions are still kept)
|
// Delete cache (persisted sessions are still kept)
|
||||||
|
@ -219,7 +217,7 @@ public class UserSessionInitializerTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister4) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createSessionPersister4) -> {
|
||||||
KeycloakSession currentSession = createSessionPersister4;
|
KeycloakSession currentSession = inheritClientConnection(session, createSessionPersister4);
|
||||||
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
RealmModel realm = currentSession.realms().getRealmByName(realmName);
|
||||||
|
|
||||||
ClientModel testApp = realm.getClientByClientId("test-app");
|
ClientModel testApp = realm.getClientByClientId("test-app");
|
||||||
|
|
|
@ -259,6 +259,7 @@ public class UserSessionProviderTest extends AbstractTestRealmKeycloakTest {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
|
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession kcSession) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession kcSession) -> {
|
||||||
|
inheritClientConnection(session, kcSession);
|
||||||
createSessions(kcSession);
|
createSessions(kcSession);
|
||||||
});
|
});
|
||||||
Map<String, Integer> clientSessionsKept = new HashMap<>();
|
Map<String, Integer> clientSessionsKept = new HashMap<>();
|
||||||
|
@ -300,6 +301,7 @@ public class UserSessionProviderTest extends AbstractTestRealmKeycloakTest {
|
||||||
public void testRemoveUserSessionsByRealm(KeycloakSession session) {
|
public void testRemoveUserSessionsByRealm(KeycloakSession session) {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession kcSession) -> {
|
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession kcSession) -> {
|
||||||
|
inheritClientConnection(session, kcSession);
|
||||||
createSessions(kcSession);
|
createSessions(kcSession);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue