KEYCLOAK-1678 fixed TwoNodeClusterTest
This commit is contained in:
parent
fd327bb225
commit
590ad1a7ca
2 changed files with 34 additions and 21 deletions
|
@ -35,25 +35,31 @@ public abstract class AbstractClusterTest extends AbstractKeycloakTest {
|
||||||
controller.start(backendNode.getQualifier());
|
controller.start(backendNode.getQualifier());
|
||||||
assertTrue(controller.isStarted(backendNode.getQualifier()));
|
assertTrue(controller.isStarted(backendNode.getQualifier()));
|
||||||
|
|
||||||
log.info("Initializing admin client for: '" + backendNode.getContextRoot() + "/auth'");
|
backendAdminClients.add(createAdminClientFor(backendNode));
|
||||||
backendAdminClients.add(Keycloak.getInstance(backendNode.getContextRoot() + "/auth",
|
|
||||||
MASTER, ADMIN, ADMIN, Constants.ADMIN_CLI_CLIENT_ID));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Keycloak createAdminClientFor(ContainerInfo backendNode) {
|
||||||
|
log.info("Initializing admin client for " + backendNode.getContextRoot() + "/auth");
|
||||||
|
return Keycloak.getInstance(backendNode.getContextRoot() + "/auth",
|
||||||
|
MASTER, ADMIN, ADMIN, Constants.ADMIN_CLI_CLIENT_ID);
|
||||||
|
}
|
||||||
|
|
||||||
protected ContainerInfo backendInfo(int i) {
|
protected ContainerInfo backendNode(int i) {
|
||||||
return suiteContext.getAuthServerBackendsInfo().get(i);
|
return suiteContext.getAuthServerBackendsInfo().get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startBackendNode(int i) {
|
protected void startBackendNode(int i) {
|
||||||
String container = backendInfo(i).getQualifier();
|
String container = backendNode(i).getQualifier();
|
||||||
if (!controller.isStarted(container)) {
|
if (!controller.isStarted(container)) {
|
||||||
controller.start(container);
|
controller.start(container);
|
||||||
|
backendAdminClients.set(i, createAdminClientFor(backendNode(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopBackendNode(int i) {
|
protected void killBackendNode(int i) {
|
||||||
controller.kill(backendInfo(i).getQualifier());
|
backendAdminClients.get(i).close();
|
||||||
|
controller.kill(backendNode(i).getQualifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ public class TwoNodeClusterTest extends AbstractClusterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRealm() {
|
public void testRealmCRUDWithoutFailover() {
|
||||||
testRealm(TEST, false);
|
testRealm(TEST + "_wofo", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRealmWithFailover() {
|
public void testRealmCRUDWithFailover() {
|
||||||
testRealm(TEST + "_fo", true);
|
testRealm(TEST + "_wfo", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRealm(String realm, boolean containerFailover) {
|
public void testRealm(String realm, boolean containerFailover) {
|
||||||
|
@ -43,9 +43,7 @@ public class TwoNodeClusterTest extends AbstractClusterTest {
|
||||||
testRealm.setEnabled(true);
|
testRealm.setEnabled(true);
|
||||||
|
|
||||||
// CREATE on node1
|
// CREATE on node1
|
||||||
log.info("Creating test realm via node1.");
|
|
||||||
backend1AdminClient().realms().create(testRealm);
|
backend1AdminClient().realms().create(testRealm);
|
||||||
log.info("Test realm created.");
|
|
||||||
|
|
||||||
// check if created on node1
|
// check if created on node1
|
||||||
RealmRepresentation testRealmOnBackend1 = backend1AdminClient().realms().realm(realm).toRepresentation();
|
RealmRepresentation testRealmOnBackend1 = backend1AdminClient().realms().realm(realm).toRepresentation();
|
||||||
|
@ -60,29 +58,31 @@ public class TwoNodeClusterTest extends AbstractClusterTest {
|
||||||
assertEquals(testRealmOnBackend1.getRealm(), testRealmOnBackend2.getRealm());
|
assertEquals(testRealmOnBackend1.getRealm(), testRealmOnBackend2.getRealm());
|
||||||
|
|
||||||
failback();
|
failback();
|
||||||
|
pause(1000);
|
||||||
|
|
||||||
// UPDATE on node2
|
// UPDATE on node2
|
||||||
testRealmOnBackend2.setRealm(realm + "_updated");
|
String realmUpdated = realm + "_updated";
|
||||||
|
testRealmOnBackend2.setRealm(realmUpdated);
|
||||||
backend2AdminClient().realms().realm(realm).update(testRealmOnBackend2);
|
backend2AdminClient().realms().realm(realm).update(testRealmOnBackend2);
|
||||||
if (containerFailover) {
|
if (containerFailover) {
|
||||||
stopBackend2();
|
stopBackend2();
|
||||||
}
|
}
|
||||||
// check if updated on node1
|
// check if updated on node1
|
||||||
testRealmOnBackend1 = backend1AdminClient().realms().realm(realm).toRepresentation();
|
testRealmOnBackend1 = backend1AdminClient().realms().realm(realmUpdated).toRepresentation();
|
||||||
assertEquals(testRealmOnBackend1.getId(), testRealmOnBackend2.getId());
|
assertEquals(testRealmOnBackend1.getId(), testRealmOnBackend2.getId());
|
||||||
assertEquals(testRealmOnBackend1.getRealm(), testRealmOnBackend2.getRealm());
|
assertEquals(testRealmOnBackend1.getRealm(), testRealmOnBackend2.getRealm());
|
||||||
|
|
||||||
failback();
|
failback();
|
||||||
|
|
||||||
// DELETE on node1
|
// DELETE on node1
|
||||||
backend1AdminClient().realms().realm(realm).remove();
|
backend1AdminClient().realms().realm(realmUpdated).remove();
|
||||||
if (containerFailover) {
|
if (containerFailover) {
|
||||||
stopBackend1();
|
stopBackend1();
|
||||||
}
|
}
|
||||||
// check if deleted on node2
|
// check if deleted on node2
|
||||||
boolean testRealmOnBackend2Exists = false;
|
boolean testRealmOnBackend2Exists = false;
|
||||||
for (RealmRepresentation realmOnBackend2 : backend2AdminClient().realms().findAll()) {
|
for (RealmRepresentation realmOnBackend2 : backend2AdminClient().realms().findAll()) {
|
||||||
if (realm.equals(realmOnBackend2.getRealm())
|
if (realmUpdated.equals(realmOnBackend2.getRealm())
|
||||||
|| testRealmOnBackend1.getId().equals(realmOnBackend2.getId())) {
|
|| testRealmOnBackend1.getId().equals(realmOnBackend2.getId())) {
|
||||||
testRealmOnBackend2Exists = true;
|
testRealmOnBackend2Exists = true;
|
||||||
break;
|
break;
|
||||||
|
@ -91,12 +91,19 @@ public class TwoNodeClusterTest extends AbstractClusterTest {
|
||||||
assertFalse(testRealmOnBackend2Exists);
|
assertFalse(testRealmOnBackend2Exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void listRealms(int i) {
|
||||||
|
log.info(String.format("Node %s: AccessTokenString: %s", i + 1, backendAdminClients.get(i).tokenManager().getAccessTokenString()));
|
||||||
|
for (RealmRepresentation r : backendAdminClients.get(i).realms().findAll()) {
|
||||||
|
log.info(String.format("Node %s: Realm: %s, Id: %s", i + 1, r.getRealm(), r.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected ContainerInfo backend1Info() {
|
protected ContainerInfo backend1Info() {
|
||||||
return backendInfo(0);
|
return backendNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ContainerInfo backend2Info() {
|
protected ContainerInfo backend2Info() {
|
||||||
return backendInfo(1);
|
return backendNode(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Keycloak backend1AdminClient() {
|
protected Keycloak backend1AdminClient() {
|
||||||
|
@ -121,11 +128,11 @@ public class TwoNodeClusterTest extends AbstractClusterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopBackend1() {
|
protected void stopBackend1() {
|
||||||
stopBackendNode(0);
|
killBackendNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopBackend2() {
|
protected void stopBackend2() {
|
||||||
stopBackendNode(1);
|
killBackendNode(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue