Search in sources :

Example 1 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class OlderNessieClientsExtension method populateFields.

private void populateFields(ExtensionContext context, Object instance) {
    Version version = populateNessieVersionAnnotatedFields(context, instance);
    if (version == null) {
        return;
    }
    populateNessieVersionAnnotatedFields(context, instance);
    ServerKey serverKey = new ServerKey(Version.CURRENT, "In-Memory", Collections.emptyMap());
    BooleanSupplier initializeRepository = () -> true;
    populateNessieAnnotatedFields(context, instance, field -> apiInstanceForField(classContext(context), field, version, ctx -> nessieServer(ctx, serverKey, initializeRepository)));
}
Also used : NessieServer.nessieServer(org.projectnessie.tools.compatibility.internal.NessieServer.nessieServer) AbstractNessieApiHolder.apiInstanceForField(org.projectnessie.tools.compatibility.internal.AbstractNessieApiHolder.apiInstanceForField) Util.classContext(org.projectnessie.tools.compatibility.internal.Util.classContext) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) AnnotatedFields.populateNessieAnnotatedFields(org.projectnessie.tools.compatibility.internal.AnnotatedFields.populateNessieAnnotatedFields) Collections(java.util.Collections) BooleanSupplier(java.util.function.BooleanSupplier) Version(org.projectnessie.tools.compatibility.api.Version) Version(org.projectnessie.tools.compatibility.api.Version) BooleanSupplier(java.util.function.BooleanSupplier)

Example 2 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class OlderNessieServersExtension method populateFields.

private void populateFields(ExtensionContext context, Object instance) {
    Version version = populateNessieVersionAnnotatedFields(context, instance);
    if (version == null) {
        return;
    }
    BooleanSupplier initializeRepository = () -> true;
    ServerKey serverKey = new ServerKey(version, "In-Memory", Collections.emptyMap());
    NessieServer nessieServer = nessieServer(classContext(context), serverKey, initializeRepository);
    Function<Field, Object> fieldValue = field -> apiInstanceForField(classContext(context), field, Version.CURRENT, ctx -> nessieServer);
    populateNessieAnnotatedFields(context, instance, fieldValue);
}
Also used : NessieServer.nessieServer(org.projectnessie.tools.compatibility.internal.NessieServer.nessieServer) AbstractNessieApiHolder.apiInstanceForField(org.projectnessie.tools.compatibility.internal.AbstractNessieApiHolder.apiInstanceForField) Util.classContext(org.projectnessie.tools.compatibility.internal.Util.classContext) Field(java.lang.reflect.Field) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) AnnotatedFields.populateNessieAnnotatedFields(org.projectnessie.tools.compatibility.internal.AnnotatedFields.populateNessieAnnotatedFields) Collections(java.util.Collections) Function(java.util.function.Function) BooleanSupplier(java.util.function.BooleanSupplier) Version(org.projectnessie.tools.compatibility.api.Version) AbstractNessieApiHolder.apiInstanceForField(org.projectnessie.tools.compatibility.internal.AbstractNessieApiHolder.apiInstanceForField) Field(java.lang.reflect.Field) Version(org.projectnessie.tools.compatibility.api.Version) BooleanSupplier(java.util.function.BooleanSupplier)

Example 3 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class NessieUpgradesExtension method buildServerKey.

private ServerKey buildServerKey(Version version, ExtensionContext context) {
    Path tempDir = globalForClass(context).getOrCompute("temporary-directory", x -> new TemporaryDirectory(), TemporaryDirectory.class).getPath();
    // Eagerly create the Nessie server instance
    String databaseAdapterName = "RocksDB";
    Map<String, String> configuration = Collections.singletonMap("nessie.store.db.path", tempDir.resolve("persist").toString());
    return new ServerKey(version, databaseAdapterName, configuration);
}
Also used : Path(java.nio.file.Path) NessieServer.nessieServer(org.projectnessie.tools.compatibility.internal.NessieServer.nessieServer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Function(java.util.function.Function) BooleanSupplier(java.util.function.BooleanSupplier) GlobalForClass.globalForClass(org.projectnessie.tools.compatibility.internal.GlobalForClass.globalForClass) AbstractNessieApiHolder.apiInstanceForField(org.projectnessie.tools.compatibility.internal.AbstractNessieApiHolder.apiInstanceForField) Map(java.util.Map) AnnotatedFields.populateNessieAnnotatedFields(org.projectnessie.tools.compatibility.internal.AnnotatedFields.populateNessieAnnotatedFields) Path(java.nio.file.Path) Collections(java.util.Collections) NessieServer.nessieServerExisting(org.projectnessie.tools.compatibility.internal.NessieServer.nessieServerExisting) Version(org.projectnessie.tools.compatibility.api.Version)

Example 4 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class AbstractMultiVersionExtension method populateNessieVersionAnnotatedFields.

Version populateNessieVersionAnnotatedFields(ExtensionContext context, Object instance) {
    Optional<Version> nessieVersion = nessieVersionFromContext(context);
    if (!nessieVersion.isPresent()) {
        return null;
    }
    Version version = nessieVersion.get();
    populateAnnotatedFields(context, instance, NessieVersion.class, f -> version);
    return version;
}
Also used : NessieVersion(org.projectnessie.tools.compatibility.api.NessieVersion) Version.parseVersion(org.projectnessie.tools.compatibility.api.Version.parseVersion) Version(org.projectnessie.tools.compatibility.api.Version)

Example 5 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class AbstractNessieApiHolder method createNessieClient.

/**
 * Used to construct {@link NessieApi} instances, for both current (in-tree) and old Nessie
 * versions.
 *
 * <p>Must use {@link AutoCloseable} instead of {@link NessieApi}, because it loads the class via
 * the given class loader, so instances of {@link NessieApi} for <em>old</em> Nessie versions will
 * return a different class.
 */
protected static AutoCloseable createNessieClient(ClassLoader classLoader, ClientKey clientKey) {
    try {
        Class<?> builderClazz = classLoader.loadClass(clientKey.getBuilderClass());
        Object builderInstance = builderClazz.getMethod("builder").invoke(null);
        Method fromConfigMethod = builderInstance.getClass().getMethod("fromConfig", Function.class);
        Function<String, String> getCfg = k -> {
            String v = clientKey.getConfigs().get(k);
            if (v != null) {
                return v;
            }
            return System.getProperty(k);
        };
        builderInstance = fromConfigMethod.invoke(builderInstance, getCfg);
        Class<?> targetClass = classLoader.loadClass(clientKey.getType().getName());
        Method buildMethod = builderInstance.getClass().getMethod("build", Class.class);
        Object apiInstance = buildMethod.invoke(builderInstance, targetClass);
        LOGGER.info("Created Nessie client for version {} for {}", clientKey.getVersion(), getCfg.apply("nessie.uri"));
        return (AutoCloseable) apiInstance;
    } catch (InvocationTargetException e) {
        throw throwUnchecked(e.getTargetException());
    } catch (Exception e) {
        throw throwUnchecked(e);
    }
}
Also used : NessieAPI(org.projectnessie.tools.compatibility.api.NessieAPI) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) CloseableResource(org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource) NessieApi(org.projectnessie.client.api.NessieApi) HashMap(java.util.HashMap) AnnotationSupport.findRepeatableAnnotations(org.junit.platform.commons.support.AnnotationSupport.findRepeatableAnnotations) Field(java.lang.reflect.Field) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Util.throwUnchecked(org.projectnessie.tools.compatibility.internal.Util.throwUnchecked) Function(java.util.function.Function) InvocationTargetException(java.lang.reflect.InvocationTargetException) Util.extensionStore(org.projectnessie.tools.compatibility.internal.Util.extensionStore) Map(java.util.Map) URI(java.net.URI) Method(java.lang.reflect.Method) NessieApiBuilderProperty(org.projectnessie.tools.compatibility.api.NessieApiBuilderProperty) Version(org.projectnessie.tools.compatibility.api.Version) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Version (org.projectnessie.tools.compatibility.api.Version)9 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)5 Collections (java.util.Collections)3 BooleanSupplier (java.util.function.BooleanSupplier)3 Function (java.util.function.Function)3 AbstractNessieApiHolder.apiInstanceForField (org.projectnessie.tools.compatibility.internal.AbstractNessieApiHolder.apiInstanceForField)3 AnnotatedFields.populateNessieAnnotatedFields (org.projectnessie.tools.compatibility.internal.AnnotatedFields.populateNessieAnnotatedFields)3 NessieServer.nessieServer (org.projectnessie.tools.compatibility.internal.NessieServer.nessieServer)3 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 UniqueId (org.junit.platform.engine.UniqueId)2 NessieVersion (org.projectnessie.tools.compatibility.api.NessieVersion)2 Version.parseVersion (org.projectnessie.tools.compatibility.api.Version.parseVersion)2 Util.classContext (org.projectnessie.tools.compatibility.internal.Util.classContext)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1