24
Jenkinsfile
vendored
24
Jenkinsfile
vendored
@@ -67,6 +67,30 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage("test: native-hints") {
|
||||
when {
|
||||
beforeAgent(true)
|
||||
anyOf {
|
||||
branch(pattern: "main|(\\d\\.\\d\\.x)", comparator: "REGEXP")
|
||||
not { triggeredBy 'UpstreamCause' }
|
||||
}
|
||||
}
|
||||
agent {
|
||||
label 'data'
|
||||
}
|
||||
options { timeout(time: 30, unit: 'MINUTES') }
|
||||
environment {
|
||||
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
docker.image("harbor-repo.vmware.com/dockerhub-proxy-cache/springci/spring-data-with-redis-6.2:${p['java.main.tag']}").inside('-v $HOME:/tmp/jenkins-home') {
|
||||
sh 'PROFILE=runtimehints LONG_TESTS=false ci/test.sh'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Release to artifactory') {
|
||||
when {
|
||||
beforeAgent(true)
|
||||
|
||||
33
pom.xml
33
pom.xml
@@ -234,6 +234,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
@@ -317,5 +323,32 @@
|
||||
<!-- placeholder for no profile -->
|
||||
<id>none</id>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>runtimehints</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>properties</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<configuration>
|
||||
<groups>RuntimeHintsTests</groups>
|
||||
<argLine>-javaagent:${org.springframework:spring-core-test:jar}</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.redis.aot;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
@@ -48,6 +49,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.data.redis.repository.query.RedisQueryCreator;
|
||||
import org.springframework.data.redis.repository.support.RedisRepositoryFactoryBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} for Redis operations and repository support.
|
||||
@@ -55,7 +57,21 @@ import org.springframework.lang.Nullable;
|
||||
* @author Christoph Strobl
|
||||
* @since 3.0
|
||||
*/
|
||||
class RedisRuntimeHints implements RuntimeHintsRegistrar {
|
||||
public class RedisRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
/**
|
||||
* Get a {@link RuntimeHints} instance containing the ones for Redis.
|
||||
*
|
||||
* @param config callback to provide additional custom hints.
|
||||
* @return new instance of {@link RuntimeHints}.
|
||||
*/
|
||||
public static RuntimeHints redisHints(Consumer<RuntimeHints> config) {
|
||||
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
new RedisRuntimeHints().registerHints(hints, null);
|
||||
config.accept(hints);
|
||||
return hints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
@@ -65,49 +81,62 @@ class RedisRuntimeHints implements RuntimeHintsRegistrar {
|
||||
hint -> hint.onReachableType(TypeReference.of(RedisCacheManager.class)));
|
||||
|
||||
// REFLECTION
|
||||
hints.reflection().registerTypes(Arrays.asList(TypeReference.of(RedisConnection.class),
|
||||
TypeReference.of(StringRedisConnection.class), TypeReference.of(DefaultedRedisConnection.class),
|
||||
TypeReference.of(DefaultedRedisClusterConnection.class), TypeReference.of(RedisKeyCommands.class),
|
||||
TypeReference.of(RedisStringCommands.class), TypeReference.of(RedisListCommands.class),
|
||||
TypeReference.of(RedisSetCommands.class), TypeReference.of(RedisZSetCommands.class),
|
||||
TypeReference.of(RedisHashCommands.class), TypeReference.of(RedisTxCommands.class),
|
||||
TypeReference.of(RedisPubSubCommands.class), TypeReference.of(RedisConnectionCommands.class),
|
||||
TypeReference.of(RedisServerCommands.class), TypeReference.of(RedisStreamCommands.class),
|
||||
TypeReference.of(RedisScriptingCommands.class), TypeReference.of(RedisGeoCommands.class),
|
||||
TypeReference.of(RedisHyperLogLogCommands.class), TypeReference.of(RedisClusterCommands.class),
|
||||
TypeReference.of(ReactiveRedisConnection.class), TypeReference.of(ReactiveKeyCommands.class),
|
||||
TypeReference.of(ReactiveStringCommands.class), TypeReference.of(ReactiveListCommands.class),
|
||||
TypeReference.of(ReactiveSetCommands.class), TypeReference.of(ReactiveZSetCommands.class),
|
||||
TypeReference.of(ReactiveHashCommands.class), TypeReference.of(ReactivePubSubCommands.class),
|
||||
TypeReference.of(ReactiveServerCommands.class), TypeReference.of(ReactiveStreamCommands.class),
|
||||
TypeReference.of(ReactiveScriptingCommands.class), TypeReference.of(ReactiveGeoCommands.class),
|
||||
TypeReference.of(ReactiveHyperLogLogCommands.class), TypeReference.of(ReactiveClusterKeyCommands.class),
|
||||
TypeReference.of(ReactiveClusterStringCommands.class), TypeReference.of(ReactiveClusterListCommands.class),
|
||||
TypeReference.of(ReactiveClusterSetCommands.class), TypeReference.of(ReactiveClusterZSetCommands.class),
|
||||
TypeReference.of(ReactiveClusterHashCommands.class), TypeReference.of(ReactiveClusterServerCommands.class),
|
||||
TypeReference.of(ReactiveClusterStreamCommands.class), TypeReference.of(ReactiveClusterScriptingCommands.class),
|
||||
TypeReference.of(ReactiveClusterGeoCommands.class), TypeReference.of(ReactiveClusterHyperLogLogCommands.class),
|
||||
TypeReference.of(ReactiveRedisOperations.class), TypeReference.of(ReactiveRedisTemplate.class),
|
||||
TypeReference.of(RedisOperations.class), TypeReference.of(RedisTemplate.class),
|
||||
TypeReference.of(StringRedisTemplate.class), TypeReference.of(KeyspaceConfiguration.class),
|
||||
TypeReference.of(MappingConfiguration.class), TypeReference.of(MappingRedisConverter.class),
|
||||
TypeReference.of(RedisConverter.class), TypeReference.of(RedisCustomConversions.class),
|
||||
TypeReference.of(ReferenceResolver.class), TypeReference.of(ReferenceResolverImpl.class),
|
||||
TypeReference.of(IndexConfiguration.class), TypeReference.of(ConfigurableIndexDefinitionProvider.class),
|
||||
TypeReference.of(RedisMappingContext.class), TypeReference.of(RedisRepositoryFactoryBean.class),
|
||||
TypeReference.of(RedisQueryCreator.class), TypeReference.of(MessageListener.class),
|
||||
TypeReference.of(RedisMessageListenerContainer.class),
|
||||
hints.reflection().registerTypes(
|
||||
Arrays.asList(TypeReference.of(RedisConnection.class), TypeReference.of(StringRedisConnection.class),
|
||||
TypeReference.of(DefaultedRedisConnection.class), TypeReference.of(DefaultedRedisClusterConnection.class),
|
||||
TypeReference.of(RedisKeyCommands.class), TypeReference.of(RedisStringCommands.class),
|
||||
TypeReference.of(RedisListCommands.class), TypeReference.of(RedisSetCommands.class),
|
||||
TypeReference.of(RedisZSetCommands.class), TypeReference.of(RedisHashCommands.class),
|
||||
TypeReference.of(RedisTxCommands.class), TypeReference.of(RedisPubSubCommands.class),
|
||||
TypeReference.of(RedisConnectionCommands.class), TypeReference.of(RedisServerCommands.class),
|
||||
TypeReference.of(RedisStreamCommands.class), TypeReference.of(RedisScriptingCommands.class),
|
||||
TypeReference.of(RedisGeoCommands.class), TypeReference.of(RedisHyperLogLogCommands.class),
|
||||
TypeReference.of(RedisClusterCommands.class), TypeReference.of(ReactiveRedisConnection.class),
|
||||
TypeReference.of(ReactiveKeyCommands.class), TypeReference.of(ReactiveStringCommands.class),
|
||||
TypeReference.of(ReactiveListCommands.class), TypeReference.of(ReactiveSetCommands.class),
|
||||
TypeReference.of(ReactiveZSetCommands.class), TypeReference.of(ReactiveHashCommands.class),
|
||||
TypeReference.of(ReactivePubSubCommands.class), TypeReference.of(ReactiveServerCommands.class),
|
||||
TypeReference.of(ReactiveStreamCommands.class), TypeReference.of(ReactiveScriptingCommands.class),
|
||||
TypeReference.of(ReactiveGeoCommands.class), TypeReference.of(ReactiveHyperLogLogCommands.class),
|
||||
TypeReference.of(ReactiveClusterKeyCommands.class), TypeReference.of(ReactiveClusterStringCommands.class),
|
||||
TypeReference.of(ReactiveClusterListCommands.class), TypeReference.of(ReactiveClusterSetCommands.class),
|
||||
TypeReference.of(ReactiveClusterZSetCommands.class), TypeReference.of(ReactiveClusterHashCommands.class),
|
||||
TypeReference.of(ReactiveClusterServerCommands.class),
|
||||
TypeReference.of(ReactiveClusterStreamCommands.class),
|
||||
TypeReference.of(ReactiveClusterScriptingCommands.class),
|
||||
TypeReference.of(ReactiveClusterGeoCommands.class),
|
||||
TypeReference.of(ReactiveClusterHyperLogLogCommands.class), TypeReference.of(ReactiveRedisOperations.class),
|
||||
TypeReference.of(ReactiveRedisTemplate.class), TypeReference.of(RedisOperations.class),
|
||||
TypeReference.of(RedisTemplate.class), TypeReference.of(StringRedisTemplate.class),
|
||||
TypeReference.of(KeyspaceConfiguration.class), TypeReference.of(MappingConfiguration.class),
|
||||
TypeReference.of(MappingRedisConverter.class), TypeReference.of(RedisConverter.class),
|
||||
TypeReference.of(RedisCustomConversions.class), TypeReference.of(ReferenceResolver.class),
|
||||
TypeReference.of(ReferenceResolverImpl.class), TypeReference.of(IndexConfiguration.class),
|
||||
TypeReference.of(ConfigurableIndexDefinitionProvider.class), TypeReference.of(RedisMappingContext.class),
|
||||
TypeReference.of(RedisRepositoryFactoryBean.class), TypeReference.of(RedisQueryCreator.class),
|
||||
TypeReference.of(MessageListener.class), TypeReference.of(RedisMessageListenerContainer.class),
|
||||
|
||||
TypeReference.of(RedisKeyValueAdapter.class), TypeReference.of(RedisKeyValueTemplate.class),
|
||||
TypeReference
|
||||
.of("org.springframework.data.redis.core.BoundOperationsProxyFactory$DefaultBoundKeyOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultGeoOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultHashOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultKeyOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultListOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultSetOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultStreamOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultValueOperations"),
|
||||
TypeReference.of("org.springframework.data.redis.core.DefaultZSetOperations"),
|
||||
|
||||
// Key-Value
|
||||
TypeReference.of(KeySpace.class), TypeReference.of(AbstractKeyValueAdapter.class),
|
||||
TypeReference.of(KeyValueAdapter.class), TypeReference.of(KeyValueOperations.class),
|
||||
TypeReference.of(KeyValueTemplate.class), TypeReference.of(KeyValueMappingContext.class),
|
||||
TypeReference.of(KeyValueRepository.class), TypeReference.of(KeyValueRepositoryFactoryBean.class),
|
||||
TypeReference.of(QueryCreatorType.class), TypeReference.of(KeyValuePartTreeQuery.class)),
|
||||
TypeReference.of(RedisKeyValueAdapter.class), TypeReference.of(RedisKeyValueTemplate.class),
|
||||
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
// Key-Value
|
||||
TypeReference.of(KeySpace.class), TypeReference.of(AbstractKeyValueAdapter.class),
|
||||
TypeReference.of(KeyValueAdapter.class), TypeReference.of(KeyValueOperations.class),
|
||||
TypeReference.of(KeyValueTemplate.class), TypeReference.of(KeyValueMappingContext.class),
|
||||
TypeReference.of(KeyValueRepository.class), TypeReference.of(KeyValueRepositoryFactoryBean.class),
|
||||
TypeReference.of(QueryCreatorType.class), TypeReference.of(KeyValuePartTreeQuery.class)),
|
||||
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
|
||||
// PROXIES
|
||||
hints.proxies().registerJdkProxy(TypeReference.of(RedisConnection.class));
|
||||
@@ -117,24 +146,31 @@ class RedisRuntimeHints implements RuntimeHintsRegistrar {
|
||||
TypeReference.of(DecoratedRedisConnection.class));
|
||||
|
||||
// keys are bound by a proxy
|
||||
boundOperationsProxy(BoundGeoOperations.class, hints);
|
||||
boundOperationsProxy(BoundHashOperations.class, hints);
|
||||
boundOperationsProxy(BoundKeyOperations.class, hints);
|
||||
boundOperationsProxy(BoundListOperations.class, hints);
|
||||
boundOperationsProxy(BoundSetOperations.class, hints);
|
||||
boundOperationsProxy(BoundStreamOperations.class, hints);
|
||||
boundOperationsProxy(BoundValueOperations.class, hints);
|
||||
boundOperationsProxy(BoundZSetOperations.class, hints);
|
||||
boundOperationsProxy(
|
||||
TypeReference.of("org.springframework.data.redis.core.BoundOperationsProxyFactory$DefaultBoundKeyOperations"),
|
||||
hints);
|
||||
boundOperationsProxy(BoundGeoOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundHashOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundKeyOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundListOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundSetOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundStreamOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundValueOperations.class, classLoader, hints);
|
||||
boundOperationsProxy(BoundZSetOperations.class, classLoader, hints);
|
||||
}
|
||||
|
||||
private void boundOperationsProxy(Class<?> type, RuntimeHints hints) {
|
||||
boundOperationsProxy(TypeReference.of(type), hints);
|
||||
static void boundOperationsProxy(Class<?> type, ClassLoader classLoader, RuntimeHints hints) {
|
||||
boundOperationsProxy(TypeReference.of(type), classLoader, hints);
|
||||
}
|
||||
|
||||
private void boundOperationsProxy(TypeReference typeReference, RuntimeHints hints) {
|
||||
static void boundOperationsProxy(TypeReference typeReference, ClassLoader classLoader, RuntimeHints hints) {
|
||||
|
||||
String boundTargetClass = typeReference.getPackageName() + "." + typeReference.getSimpleName().replace("Bound", "");
|
||||
if (ClassUtils.isPresent(boundTargetClass, classLoader)) {
|
||||
hints.reflection().registerType(TypeReference.of(boundTargetClass), hint -> hint
|
||||
.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
}
|
||||
|
||||
hints.reflection().registerType(typeReference, hint -> hint
|
||||
.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
|
||||
hints.proxies().registerJdkProxy(typeReference, //
|
||||
TypeReference.of("org.springframework.aop.SpringProxy"), //
|
||||
TypeReference.of("org.springframework.aop.framework.Advised"), //
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.scope.ScopedObject;
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.test.agent.EnabledIfRuntimeHintsAgent;
|
||||
import org.springframework.aot.test.agent.RuntimeHintsInvocations;
|
||||
import org.springframework.aot.test.agent.RuntimeHintsRecorder;
|
||||
import org.springframework.data.redis.aot.RedisRuntimeHints;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@EnabledIfRuntimeHintsAgent
|
||||
class BoundOperationsProxyFactoryRuntimeHintTests {
|
||||
|
||||
@Test // GH-2395
|
||||
void boundOpsRuntimeHints() {
|
||||
|
||||
LettuceConnectionFactory connectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
RedisTemplate template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
template.afterPropertiesSet();
|
||||
|
||||
BoundOperationsProxyFactory factory = new BoundOperationsProxyFactory();
|
||||
BoundListOperations listOp = factory.createProxy(BoundListOperations.class, "key", DataType.LIST, template,
|
||||
RedisOperations::opsForList);
|
||||
|
||||
RuntimeHintsInvocations invocations = RuntimeHintsRecorder.record(() -> {
|
||||
listOp.trim(0, 10);
|
||||
});
|
||||
|
||||
RuntimeHints hints = RedisRuntimeHints.redisHints(it -> {
|
||||
// hints that should come from another module
|
||||
it.reflection().registerType(ScopedObject.class,
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
||||
});
|
||||
|
||||
invocations.assertThat().match(hints);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user