Search in sources :

Example 1 with InfinispanUserSessionProvider

use of org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider in project keycloak by keycloak.

the class OfflineSessionPersistenceTest method testOfflineSessionLoadingAfterCacheRemoval.

@Test
@RequireProvider(UserSessionPersisterProvider.class)
@RequireProvider(value = UserSessionProvider.class, only = InfinispanUserSessionProviderFactory.PROVIDER_ID)
public void testOfflineSessionLoadingAfterCacheRemoval() {
    List<String> offlineSessionIds = createOfflineSessions(realmId, userIds);
    assertOfflineSessionsExist(realmId, offlineSessionIds);
    // Simulate server restart
    reinitializeKeycloakSessionFactory();
    assertOfflineSessionsExist(realmId, offlineSessionIds);
    // remove sessions from the cache
    withRealm(realmId, (session, realm) -> {
        // Delete local user cache (persisted sessions are still kept)
        UserSessionProvider provider = session.getProvider(UserSessionProvider.class);
        // Remove in-memory representation of the offline sessions
        ((InfinispanUserSessionProvider) provider).removeLocalUserSessions(realm.getId(), true);
        return null;
    });
    // assert sessions are lazily loaded from DB
    assertOfflineSessionsExist(realmId, offlineSessionIds);
}
Also used : UserSessionProvider(org.keycloak.models.UserSessionProvider) InfinispanUserSessionProvider(org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider) InfinispanUserSessionProvider(org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider) KeycloakModelTest(org.keycloak.testsuite.model.KeycloakModelTest) Test(org.junit.Test) RequireProvider(org.keycloak.testsuite.model.RequireProvider)

Aggregations

Test (org.junit.Test)1 UserSessionProvider (org.keycloak.models.UserSessionProvider)1 InfinispanUserSessionProvider (org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider)1 KeycloakModelTest (org.keycloak.testsuite.model.KeycloakModelTest)1 RequireProvider (org.keycloak.testsuite.model.RequireProvider)1