KEYCLOAK-18505 ConfigMigrationTest failures

This commit is contained in:
Martin Bartoš 2021-06-23 14:25:53 +02:00 committed by Pavel Drozd
parent 57c80483bb
commit 8a82130579
4 changed files with 94 additions and 21 deletions

View file

@ -750,4 +750,11 @@ if (outcome == success) && (result == "") of /profile=$clusteredProfile/subsyste
echo
end-if
if (outcome == failed) of /profile=$clusteredProfile/subsystem=infinispan/cache-container=hibernate/local-cache=pending-puts/:read-resource
echo Add pending-puts local cache clustered and expiration time 60000L
/profile=$clusteredProfile/subsystem=infinispan/cache-container=hibernate/local-cache=pending-puts/:add
/profile=$clusteredProfile/subsystem=infinispan/cache-container=hibernate/local-cache=pending-puts/component=expiration/:write-attribute(name=max-idle,value=60000L)
echo
end-if
echo *** End Migration of /profile=$clusteredProfile ***

View file

@ -651,4 +651,11 @@ if (outcome == success) && (result == "") of /profile=$standaloneProfile/subsyst
echo
end-if
if (outcome == failed) of /profile=$standaloneProfile/subsystem=infinispan/cache-container=hibernate/local-cache=pending-puts/:read-resource
echo Add pending-puts local cache standalone and expiration time 60000L
/profile=$standaloneProfile/subsystem=infinispan/cache-container=hibernate/local-cache=pending-puts/:add
/profile=$standaloneProfile/subsystem=infinispan/cache-container=hibernate/local-cache=pending-puts/component=expiration/:write-attribute(name=max-idle,value=60000L)
echo
end-if
echo *** End Migration of /profile=$standaloneProfile ***

View file

@ -26,7 +26,11 @@
</feature>
</feature>
</feature-group>
<feature-group name="ejb3"/>
<feature-group name="ejb3">
<feature spec="subsystem.ejb3">
<param name="default-sfsb-cache" value="distributable"/>
</feature>
</feature-group>
<feature-group name="health"/>
<feature-group name="io"/>
<feature-group name="jaxrs"/>

View file

@ -22,20 +22,24 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/**
* Compare outputs from jboss-cli read-resource operations. This compare the total
@ -62,15 +66,22 @@ public class ConfigMigrationTest {
@Test
public void testDomain() throws IOException {
compareConfigs("master-domain-standalone.txt", "migrated-domain-standalone.txt");
compareConfigs("master-domain-clustered.txt", "migrated-domain-clustered.txt");
final Set<List<String>> ignoredPaths = new HashSet<>();
// KEYCLOAK-18505 Ignore some keys
ignoredPaths.add(getModelNode("root", "result", "[logging]", "result", "console-handler"));
compareConfigs("master-domain-core-service.txt", "migrated-domain-core-service.txt");
compareConfigs("master-domain-extension.txt", "migrated-domain-extension.txt");
compareConfigs("master-domain-standalone.txt", "migrated-domain-standalone.txt", ignoredPaths);
compareConfigs("master-domain-clustered.txt", "migrated-domain-clustered.txt", ignoredPaths);
compareConfigs("master-domain-core-service.txt", "migrated-domain-core-service.txt", ignoredPaths);
compareConfigs("master-domain-extension.txt", "migrated-domain-extension.txt", ignoredPaths);
// compareConfigs("master-domain-interface.txt", "migrated-domain-interface.txt");
}
private void compareConfigs(String masterConfig, String migratedConfig) throws IOException {
compareConfigs(masterConfig, migratedConfig, null);
}
private void compareConfigs(String masterConfig, String migratedConfig, final Set<List<String>> ignoreMigrated) throws IOException {
File masterFile = new File(TARGET_DIR, masterConfig);
Assert.assertTrue(masterFile.exists());
File migratedFile = new File(TARGET_DIR, migratedConfig);
@ -91,14 +102,57 @@ public class ConfigMigrationTest {
if (Boolean.parseBoolean(System.getProperty("get.simple.full.comparison"))) {
assertThat(migrated, is(equalTo(master)));
}
compareConfigsDeeply("root", master, migrated);
compareConfigsDeeply("root", master, migrated, ignoreMigrated);
}
}
}
private void compareConfigsDeeply(String id, ModelNode master, ModelNode migrated) {
private List<String> getModelNode(String... paths) {
return Collections.unmodifiableList(Arrays.asList(paths));
}
/**
* Helper method for ignoring some keys in migrated files
*
* @param ignoredPaths Set of paths, which should be ignored
*/
private boolean shouldIgnoreKey(final Set<List<String>> ignoredPaths) {
if (ignoredPaths == null || ignoredPaths.isEmpty()) return false;
// Create new references for paths in order to ensure the original set will not be modified
Set<List<String>> available = ignoredPaths.stream()
.map(ArrayList::new)
.collect(Collectors.toSet());
for (String navPath : nav) {
Iterator<List<String>> it = available.iterator();
while (it.hasNext()) {
List<String> ignorePath = it.next();
String first = ignorePath.stream().findFirst().orElse(null);
if (navPath.equals(first)) {
ignorePath.remove(first);
if (ignorePath.isEmpty()) {
log.debugf("Ignoring navigation path '%s'", nav.toString());
return true;
}
} else {
it.remove();
}
}
}
return false;
}
private void compareConfigsDeeply(String id, ModelNode master, ModelNode migrated, final Set<List<String>> ignoredPaths) {
nav.add(id);
if (shouldIgnoreKey(ignoredPaths)) {
return;
}
master.protect();
migrated.protect();
@ -114,7 +168,7 @@ public class ConfigMigrationTest {
assertThat(getMessage(), migrated.keys(), is(equalTo(master.keys())));
for (String key : master.keys()) {
compareConfigsDeeply(key, master.get(key), migrated.get(key));
compareConfigsDeeply(key, master.get(key), migrated.get(key), ignoredPaths);
}
break;
case LIST:
@ -144,7 +198,8 @@ public class ConfigMigrationTest {
}
compareConfigsDeeply(navigation,
diffNodeInMaster,
migratedAsList.get(masterAsList.indexOf(diffNodeInMaster)));
migratedAsList.get(masterAsList.indexOf(diffNodeInMaster)),
ignoredPaths);
}
break;
case BOOLEAN: