Skip to content

Commit fff1d3e

Browse files
mp911dechristophstrobl
authored andcommitted
DATAREDIS-1233 - Introduce and use Junit5 based ParameterizedRedisTest.
1 parent 2511aa1 commit fff1d3e

File tree

190 files changed

+7598
-8100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+7598
-8100
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pipeline {
117117
sh 'make start'
118118

119119
// Execute maven test
120-
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean test -DrunLongTests=true -U -B'
120+
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean test -U -B'
121121

122122
// Capture resulting exit code from maven (pass/fail)
123123
sh 'RESULT=\$?'

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ stop-26382: work/redis/bin/redis-cli
194194
stop: redis-stop sentinel-stop cluster-stop
195195

196196
test:
197+
$(MAKE) start
198+
sleep 1
199+
./mvnw clean test -U -P$(SPRING_PROFILE) || (echo "maven failed $$?"; exit 1)
200+
$(MAKE) stop
201+
$(MAKE) clean
202+
203+
all-tests:
197204
$(MAKE) start
198205
sleep 1
199206
./mvnw clean test -U -DrunLongTests=true -P$(SPRING_PROFILE) || (echo "maven failed $$?"; exit 1)

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ public Flux<NumericResponse<SUnionStoreCommand, Long>> sUnionStore(Publisher<SUn
8787
}
8888

8989
return sUnion(Mono.just(SUnionCommand.keys(command.getKeys()))).next().flatMap(values -> {
90-
Mono<Long> result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new));
90+
91+
Mono<Long> result = values.getOutput().collectList().flatMap(it -> {
92+
93+
ByteBuffer[] members = it.toArray(new ByteBuffer[0]);
94+
return cmd.sadd(command.getKey(), members);
95+
});
96+
9197
return result.map(value -> new NumericResponse<>(command, value));
9298
});
9399
}));
@@ -147,7 +153,13 @@ public Flux<NumericResponse<SInterStoreCommand, Long>> sInterStore(Publisher<SIn
147153
}
148154

149155
return sInter(Mono.just(SInterCommand.keys(command.getKeys()))).next().flatMap(values -> {
150-
Mono<Long> result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new));
156+
157+
Mono<Long> result = values.getOutput().collectList().flatMap(it -> {
158+
159+
ByteBuffer[] members = it.toArray(new ByteBuffer[0]);
160+
return cmd.sadd(command.getKey(), members);
161+
});
162+
151163
return result.map(value -> new NumericResponse<>(command, value));
152164
});
153165
}));
@@ -209,7 +221,13 @@ public Flux<NumericResponse<SDiffStoreCommand, Long>> sDiffStore(Publisher<SDiff
209221
}
210222

211223
return sDiff(Mono.just(SDiffCommand.keys(command.getKeys()))).next().flatMap(values -> {
212-
Mono<Long> result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new));
224+
225+
Mono<Long> result = values.getOutput().collectList().flatMap(it -> {
226+
227+
ByteBuffer[] members = it.toArray(new ByteBuffer[0]);
228+
return cmd.sadd(command.getKey(), members);
229+
});
230+
213231
return result.map(value -> new NumericResponse<>(command, value));
214232
});
215233
}));

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ protected Mono<RedisReactiveCommands<ByteBuffer, ByteBuffer>> getCommands(RedisN
492492

493493
if (StringUtils.hasText(node.getId())) {
494494
return getConnection().cast(StatefulRedisClusterConnection.class)
495-
.map(it -> it.getConnection(node.getId()).reactive());
495+
.flatMap(it -> {
496+
StatefulRedisClusterConnection<ByteBuffer, ByteBuffer> connection = it;
497+
return Mono.fromCompletionStage(connection.getConnectionAsync(node.getId()))
498+
.map(StatefulRedisConnection::reactive);
499+
});
496500
}
497501

498502
return getConnection().flatMap(it -> Mono.fromCompletionStage(it.getConnectionAsync(node.getHost(), node.getPort()))

src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ public <HK, HV> ReactiveStreamOperations<K, HK, HV> opsForStream(
660660
@SuppressWarnings("unchecked")
661661
public <HK, HV> ReactiveStreamOperations<K, HK, HV> opsForStream(
662662
RedisSerializationContext<K, ?> serializationContext) {
663-
return opsForStream(serializationContext, (HashMapper) new ObjectHashMapper());
663+
return opsForStream(serializationContext, (HashMapper) ObjectHashMapper.getSharedInstance());
664664
}
665665

666666
protected <HK, HV> ReactiveStreamOperations<K, HK, HV> opsForStream(

src/main/java/org/springframework/data/redis/core/RedisTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
106106
private final ValueOperations<K, V> valueOps = new DefaultValueOperations<>(this);
107107
private final ListOperations<K, V> listOps = new DefaultListOperations<>(this);
108108
private final SetOperations<K, V> setOps = new DefaultSetOperations<>(this);
109-
private final StreamOperations<K, ?, ?> streamOps = new DefaultStreamOperations<>(this, new ObjectHashMapper());
109+
private final StreamOperations<K, ?, ?> streamOps = new DefaultStreamOperations<>(this,
110+
ObjectHashMapper.getSharedInstance());
110111
private final ZSetOperations<K, V> zSetOps = new DefaultZSetOperations<>(this);
111112
private final GeoOperations<K, V> geoOps = new DefaultGeoOperations<>(this);
112113
private final HyperLogLogOperations<K, V> hllOps = new DefaultHyperLogLogOperations<>(this);

src/main/java/org/springframework/data/redis/core/StreamObjectMapper.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,36 @@
3939
* This utility can use generic a {@link HashMapper} or adapt specifically to {@link ObjectHashMapper}'s requirement to
4040
* convert incoming data into byte arrays. This class can be subclassed to override template methods for specific object
4141
* mapping strategies.
42-
*
42+
*
4343
* @author Mark Paluch
4444
* @since 2.2
4545
* @see ObjectHashMapper
4646
* @see #doGetHashMapper(ConversionService, Class)
4747
*/
4848
class StreamObjectMapper {
4949

50-
private final DefaultConversionService conversionService = new DefaultConversionService();
51-
private final RedisCustomConversions customConversions = new RedisCustomConversions();
50+
private final static RedisCustomConversions customConversions = new RedisCustomConversions();
51+
private final static ConversionService conversionService;
52+
5253
private final HashMapper<Object, Object, Object> mapper;
5354
private final @Nullable HashMapper<Object, Object, Object> objectHashMapper;
5455

56+
static {
57+
DefaultConversionService cs = new DefaultConversionService();
58+
customConversions.registerConvertersIn(cs);
59+
conversionService = cs;
60+
}
61+
5562
/**
5663
* Creates a new {@link StreamObjectMapper}.
57-
*
64+
*
5865
* @param mapper the configured {@link HashMapper}.
5966
*/
6067
@SuppressWarnings({ "unchecked", "rawtypes" })
6168
StreamObjectMapper(HashMapper<?, ?, ?> mapper) {
6269

6370
Assert.notNull(mapper, "HashMapper must not be null");
6471

65-
this.customConversions.registerConvertersIn(conversionService);
6672
this.mapper = (HashMapper) mapper;
6773

6874
if (mapper instanceof ObjectHashMapper) {
@@ -92,7 +98,7 @@ public Object fromHash(Map<Object, Object> hash) {
9298

9399
/**
94100
* Convert the given {@link Record} into a {@link MapRecord}.
95-
*
101+
*
96102
* @param provider provider for {@link HashMapper} to apply mapping for {@link ObjectRecord}.
97103
* @param source the source value.
98104
* @return the converted {@link MapRecord}.
@@ -121,7 +127,7 @@ static <K, V, HK, HV> MapRecord<K, HK, HV> toMapRecord(HashMapperProvider<HK, HV
121127

122128
/**
123129
* Convert the given {@link Record} into an {@link ObjectRecord}.
124-
*
130+
*
125131
* @param provider provider for {@link HashMapper} to apply mapping for {@link ObjectRecord}.
126132
* @param source the source value.
127133
* @param targetType the desired target type.
@@ -135,7 +141,7 @@ static <K, V, HK, HV> ObjectRecord<K, V> toObjectRecord(HashMapperProvider<HK, H
135141
/**
136142
* Map a {@link List} of {@link MapRecord}s to a {@link List} of {@link ObjectRecord}. Optimizes for empty,
137143
* single-element and multi-element list transformation.l
138-
*
144+
*
139145
* @param records the {@link MapRecord} that should be mapped.
140146
* @param hashMapperProvider the provider to obtain the actual {@link HashMapper} from. Must not be {@literal null}.
141147
* @param targetType the requested {@link Class target type}.
@@ -175,7 +181,7 @@ final <V, HK, HV> HashMapper<V, HK, HV> getHashMapper(Class<V> targetType) {
175181

176182
/**
177183
* Returns the actual {@link HashMapper}. Can be overridden by subclasses.
178-
*
184+
*
179185
* @param conversionService the used {@link ConversionService}.
180186
* @param targetType the target type.
181187
* @return obtain the {@link HashMapper} for a certain type.
@@ -200,6 +206,6 @@ boolean isSimpleType(Class<?> targetType) {
200206
* @return used {@link ConversionService}.
201207
*/
202208
ConversionService getConversionService() {
203-
return this.conversionService;
209+
return conversionService;
204210
}
205211
}

src/main/java/org/springframework/data/redis/hash/ObjectHashMapper.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
*/
7272
public class ObjectHashMapper implements HashMapper<Object, byte[], byte[]> {
7373

74+
@Nullable private volatile static ObjectHashMapper sharedInstance;
75+
7476
private final RedisConverter converter;
7577

7678
/**
@@ -120,6 +122,31 @@ public ObjectHashMapper(@Nullable org.springframework.data.convert.CustomConvers
120122
converter = mappingConverter;
121123
}
122124

125+
/**
126+
* Return a shared default {@value ObjectHashMapper} instance, lazily building it once needed.
127+
* <p>
128+
* <b>NOTE:</b> We highly recommend constructing individual {@link ObjectHashMapper} instances for customization
129+
* purposes. This accessor is only meant as a fallback for code paths which need simple type coercion but cannot
130+
* access a longer-lived {@link ObjectHashMapper} instance any other way.
131+
*
132+
* @return the shared {@link ObjectHashMapper} instance (never {@literal null}).
133+
* @since 2.4
134+
*/
135+
public static ObjectHashMapper getSharedInstance() {
136+
137+
ObjectHashMapper cs = sharedInstance;
138+
if (cs == null) {
139+
synchronized (ObjectHashMapper.class) {
140+
cs = sharedInstance;
141+
if (cs == null) {
142+
cs = new ObjectHashMapper();
143+
sharedInstance = cs;
144+
}
145+
}
146+
}
147+
return cs;
148+
}
149+
123150
/*
124151
* (non-Javadoc)
125152
* @see org.springframework.data.redis.hash.HashMapper#toHash(java.lang.Object)

src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ public <NV> StreamMessageListenerContainerOptionsBuilder<K, ObjectRecord<K, NV>>
749749

750750
hashKeySerializer(RedisSerializer.byteArray());
751751
hashValueSerializer(RedisSerializer.byteArray());
752-
return (StreamMessageListenerContainerOptionsBuilder) objectMapper(new ObjectHashMapper());
752+
return (StreamMessageListenerContainerOptionsBuilder) objectMapper(ObjectHashMapper.getSharedInstance());
753753
}
754754

755755
return (StreamMessageListenerContainerOptionsBuilder) this;

src/main/java/org/springframework/data/redis/stream/StreamReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public <NV> StreamReceiverOptionsBuilder<K, ObjectRecord<K, NV>> targetType(Clas
423423

424424
hashKeySerializer(SerializationPair.raw());
425425
hashValueSerializer(SerializationPair.raw());
426-
return (StreamReceiverOptionsBuilder) objectMapper(new ObjectHashMapper());
426+
return (StreamReceiverOptionsBuilder) objectMapper(ObjectHashMapper.getSharedInstance());
427427
}
428428

429429
return (StreamReceiverOptionsBuilder) this;

0 commit comments

Comments
 (0)