diff --git a/model/api/src/main/java/org/keycloak/models/Config.java b/model/api/src/main/java/org/keycloak/models/Config.java index 6f57ad3d0c..17ff238285 100644 --- a/model/api/src/main/java/org/keycloak/models/Config.java +++ b/model/api/src/main/java/org/keycloak/models/Config.java @@ -13,7 +13,8 @@ public class Config { public static final String MODEL_PROVIDER_KEY = "keycloak.model"; - public static final String AUDIT_KEY = "keycloak.audit"; + public static final String AUDIT_PROVIDER_KEY = "keycloak.audit"; + public static final String AUDIT_PROVIDER_DEFAULT = "jpa"; public static final String AUDIT_EXPIRATION_SCHEDULE_KEY = "keycloak.audit.expirationSchedule"; public static final String AUDIT_EXPIRATION_SCHEDULE_DEFAULT = String.valueOf(TimeUnit.MINUTES.toMillis(15)); @@ -36,7 +37,7 @@ public class Config { } public static String getAuditProvider() { - return System.getProperty(AUDIT_KEY); + return System.getProperty(AUDIT_PROVIDER_KEY, AUDIT_PROVIDER_DEFAULT); } public static void setAuditProvider(String provider) { diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/Retry.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/Retry.java new file mode 100644 index 0000000000..4e585ad313 --- /dev/null +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/Retry.java @@ -0,0 +1,24 @@ +package org.keycloak.testsuite; + +/** + * @author Stian Thorgersen + */ +public class Retry { + + public static void execute(Runnable runnable, int retry, long interval) throws InterruptedException { + while (true) { + try { + runnable.run(); + return; + } catch (RuntimeException e) { + retry--; + if (retry > 0) { + Thread.sleep(interval); + } else { + throw e; + } + } + } + } + +} diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java index 5300cfa3e9..663eb6af56 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java @@ -22,8 +22,10 @@ package org.keycloak.testsuite.account; import org.junit.After; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -31,6 +33,7 @@ import org.keycloak.audit.Details; import org.keycloak.audit.Event; import org.keycloak.audit.jpa.JpaAuditProviderFactory; import org.keycloak.models.ApplicationModel; +import org.keycloak.models.Config; import org.keycloak.models.PasswordPolicy; import org.keycloak.models.RealmModel; import org.keycloak.models.UserCredentialModel; @@ -40,6 +43,7 @@ import org.keycloak.representations.idm.CredentialRepresentation; import org.keycloak.services.managers.RealmManager; import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.Retry; import org.keycloak.testsuite.pages.AccountLogPage; import org.keycloak.testsuite.pages.AccountPasswordPage; import org.keycloak.testsuite.pages.AccountTotpPage; @@ -145,8 +149,6 @@ public class AccountTest { appRealm.updateCredential(user, cred); } }); - - System.out.println(JpaAuditProviderFactory.class); } @Test @@ -365,17 +367,23 @@ public class AccountTest { Assert.assertTrue(logPage.isCurrent()); - List> actual = logPage.getEvents(); + final int expectedEvents = e.size(); + Retry.execute(new Runnable() { + @Override + public void run() { + Assert.assertEquals(expectedEvents, logPage.getEvents().size()); + } + }, 10, 500); - Assert.assertEquals(e.size(), actual.size()); - - Iterator> itr = actual.iterator(); + Iterator> itr = logPage.getEvents().iterator(); for (Event event : e) { List a = itr.next(); Assert.assertEquals(event.getEvent().replace('_', ' '), a.get(1)); Assert.assertEquals(event.getIpAddress(), a.get(2)); Assert.assertEquals(event.getClientId(), a.get(3)); } + } catch (InterruptedException e) { + e.printStackTrace(); } finally { keycloakRule.configure(new KeycloakSetup() { @Override