fix: providing a separate session for each file (#34210)
closes: #34095 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
cef0231bf0
commit
bd499755a2
2 changed files with 32 additions and 3 deletions
|
@ -17,7 +17,9 @@
|
|||
|
||||
package org.keycloak.it.cli.dist;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -30,6 +32,9 @@ import org.keycloak.it.junit5.extension.RawDistOnly;
|
|||
import org.keycloak.it.utils.KeycloakDistribution;
|
||||
import org.keycloak.it.utils.RawKeycloakDistribution;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import io.quarkus.deployment.util.FileUtil;
|
||||
import io.quarkus.test.junit.main.Launch;
|
||||
import io.quarkus.test.junit.main.LaunchResult;
|
||||
|
@ -46,6 +51,21 @@ public class ImportAtStartupDistTest {
|
|||
cliResult.assertMessage("Realm 'quickstart-realm' imported");
|
||||
}
|
||||
|
||||
@Test
|
||||
@BeforeStartDistribution(CreateRealmConfigurationFile.class)
|
||||
void testMultipleImport(KeycloakDistribution dist) throws IOException {
|
||||
RawKeycloakDistribution rawDist = dist.unwrap(RawKeycloakDistribution.class);
|
||||
Path dir = rawDist.getDistPath().resolve("data").resolve("import");
|
||||
|
||||
// add another realm
|
||||
Files.write(dir.resolve("realm2.json"), Files.readAllLines(dir.resolve("realm.json")).stream()
|
||||
.map(s -> s.replace("quickstart-realm", "other-realm")).toList());
|
||||
|
||||
CLIResult cliResult = dist.run("start-dev", "--import-realm");
|
||||
cliResult.assertMessage("Realm 'quickstart-realm' imported");
|
||||
cliResult.assertMessage("Realm 'other-realm' imported");
|
||||
}
|
||||
|
||||
@Test
|
||||
@BeforeStartDistribution(CreateRealmConfigurationFileAndDir.class)
|
||||
@Launch({"start-dev", "--import-realm", "--log-level=org.keycloak.exportimport.ExportImportManager:debug"})
|
||||
|
|
|
@ -170,8 +170,17 @@ public class ExportImportManager {
|
|||
}
|
||||
|
||||
return filesToImport.stream().map(file -> () -> {
|
||||
// we need a new session to pickup the static system property
|
||||
// file setting - it is picked up by the provider only at create time
|
||||
// this will eventually need to be consolidated with the master existance check
|
||||
// to prevent double parsing
|
||||
KeycloakSession newSession = session.getKeycloakSessionFactory().create();
|
||||
try {
|
||||
ExportImportConfig.setFile(file);
|
||||
return session.getProvider(ImportProvider.class, providerId);
|
||||
return newSession.getProvider(ImportProvider.class, providerId);
|
||||
} finally {
|
||||
newSession.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
return Stream.empty();
|
||||
|
|
Loading…
Reference in a new issue