Skip to content

Commit

Permalink
Add tests and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Apr 26, 2024
1 parent ecbfd32 commit 9c36afe
Show file tree
Hide file tree
Showing 290 changed files with 1,247 additions and 805 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,8 @@
<configuration>
<directories>
<directory>${project.build.sourceDirectory}</directory>
<directory>${project.build.directory}/generated-sources</directory>
<directory>${project.build.testSourceDirectory}</directory>
<directory>${project.basedir}/src/main/templates</directory>
</directories>
</configuration>
<executions>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,5 @@ private List<RedisCommand<Object, Object, Object>> prepareDefaultFlush(int consu
private <T> ArrayList<T> newDrainTarget() {
return new ArrayList<>(Math.max(0, Math.min(batchSize, queue.size())));
}

}
22 changes: 12 additions & 10 deletions src/main/templates/io/lettuce/core/api/BaseRedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,18 @@ public interface BaseRedisCommands<K, V> {

/**
* @return {@code true} if the connection is open (connected and not closed).
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#isOpen()} method on the connection
* interface. To be removed with Lettuce 7.0.
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#isOpen()} method on the
* connection interface. To be removed with Lettuce 7.0.
*/
@Deprecated
boolean isOpen();

/**
* Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the
* internal state machine gets out of sync with the connection.
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#reset()} method on the connection
* interface. To be removed with Lettuce 7.0.
*
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#reset()} method on the
* connection interface. To be removed with Lettuce 7.0.
*/
@Deprecated
void reset();
Expand All @@ -201,19 +202,20 @@ public interface BaseRedisCommands<K, V> {
* issued. After calling {@link #flushCommands()} commands are sent to the transport and executed by Redis.
*
* @param autoFlush state of autoFlush.
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#setAutoFlushCommands(boolean)} method on the connection
* interface. To be removed with Lettuce 7.0.
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#setAutoFlushCommands(boolean)}
* method on the connection interface. To be removed with Lettuce 7.0.
*
*/
@Deprecated
void setAutoFlushCommands(boolean autoFlush);

/**
* Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to
* achieve batching. No-op if channel is not connected.
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#flushCommands()} method on the connection
* interface. To be removed with Lettuce 7.0.
*
* @deprecated since 6.2. Use the corresponding {@link io.lettuce.core.api.StatefulConnection#flushCommands()} method on the
* connection interface. To be removed with Lettuce 7.0.
*
*/
@Deprecated
void flushCommands();
Expand Down
9 changes: 5 additions & 4 deletions src/main/templates/io/lettuce/core/api/RedisAclCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public interface RedisAclCommands<K, V> {
List<String> aclList();

/**
* When Redis is configured to use an ACL file (with the aclfile configuration option), this command
* will reload the ACLs from the file, replacing all the current ACL rules with the ones defined in the file.
* When Redis is configured to use an ACL file (with the aclfile configuration option), this command will reload the ACLs
* from the file, replacing all the current ACL rules with the ones defined in the file.
*
* @return String simple-string-reply OK or error message.
*/
Expand Down Expand Up @@ -140,8 +140,8 @@ public interface RedisAclCommands<K, V> {
String aclLogReset();

/**
* When Redis is configured to use an ACL file (with the aclfile configuration option),
* this command will save the currently defined ACLs from the server memory to the ACL file.
* When Redis is configured to use an ACL file (with the aclfile configuration option), this command will save the currently
* defined ACLs from the server memory to the ACL file.
*
* @return String simple-string-reply OK or error message.
*/
Expand Down Expand Up @@ -169,4 +169,5 @@ public interface RedisAclCommands<K, V> {
* @return K bulk-string-reply the username of the current connection.
*/
String aclWhoami();

}
11 changes: 6 additions & 5 deletions src/main/templates/io/lettuce/core/api/RedisGeoCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ Long georadius(K key, double longitude, double latitude, double distance, GeoArg
Long georadiusbymember(K key, V member, double distance, GeoArgs.Unit unit, GeoRadiusStoreArgs<K> geoRadiusStoreArgs);

/**
* Retrieve members selected by distance with the center of {@code reference} the search {@code predicate}.
* Use {@link GeoSearch} to create reference and predicate objects.
* Retrieve members selected by distance with the center of {@code reference} the search {@code predicate}. Use
* {@link GeoSearch} to create reference and predicate objects.
*
* @param key the key of the geo set.
* @param reference the reference member or longitude/latitude coordinates.
Expand All @@ -203,8 +203,8 @@ Long georadius(K key, double longitude, double latitude, double distance, GeoArg
Set<V> geosearch(K key, GeoSearch.GeoRef<K> reference, GeoSearch.GeoPredicate predicate);

/**
* Retrieve members selected by distance with the center of {@code reference} the search {@code predicate}.
* Use {@link GeoSearch} to create reference and predicate objects.
* Retrieve members selected by distance with the center of {@code reference} the search {@code predicate}. Use
* {@link GeoSearch} to create reference and predicate objects.
*
* @param key the key of the geo set.
* @param reference the reference member or longitude/latitude coordinates.
Expand All @@ -224,7 +224,8 @@ Long georadius(K key, double longitude, double latitude, double distance, GeoArg
* @param reference the reference member or longitude/latitude coordinates.
* @param predicate the bounding box or radius to search in.
* @param geoArgs args to control the result.
* @param storeDist stores the items in a sorted set populated with their distance from the center of the circle or box, as a floating-point number, in the same unit specified for that shape.
* @param storeDist stores the items in a sorted set populated with their distance from the center of the circle or box, as
* a floating-point number, in the same unit specified for that shape.
* @return Long integer-reply the number of elements in the result.
* @since 6.1
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,5 @@ public interface RedisHashCommands<K, V> {
* associated timeout.
*/
Boolean hpersist(K key, K... fields);

}
25 changes: 17 additions & 8 deletions src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ public interface RedisSortedSetCommands<K, V> {
* Return {@code count} random members from the sorted set stored at {@code key}.
*
* @param key the key.
* @param count the number of members to return. If the provided count argument is positive, return an array of distinct fields.
* @param count the number of members to return. If the provided count argument is positive, return an array of distinct
* fields.
* @return List&lt;ScoredValue&lt;V&gt;&gt; array-reply list of scores and elements.
* @since 6.1
*/
Expand All @@ -507,7 +508,8 @@ public interface RedisSortedSetCommands<K, V> {
* Return {@code count} random members along their value from the sorted set stored at {@code key}.
*
* @param key the key.
* @param count the number of members to return. If the provided count argument is positive, return an array of distinct fields.
* @param count the number of members to return. If the provided count argument is positive, return an array of distinct
* fields.
* @return List&lt;ScoredValue&lt;V&gt;&gt; array-reply list of scores and elements.
* @since 6.1
*/
Expand Down Expand Up @@ -909,7 +911,8 @@ Long zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Stri
Long zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the {@code dstKey} destination key.
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
Expand All @@ -920,7 +923,8 @@ Long zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Stri
Long zrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the {@code dstKey} destination key.
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
Expand All @@ -932,7 +936,8 @@ Long zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Stri
Long zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the {@code dstKey} destination key.
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
Expand Down Expand Up @@ -1409,7 +1414,8 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, S
Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements ordered from high to low in the sorted set stored at {@code srcKey} and stores the result in the {@code dstKey} destination key.
* Get the specified range of elements ordered from high to low in the sorted set stored at {@code srcKey} and stores the
* result in the {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
Expand All @@ -1420,7 +1426,8 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, S
Long zrevrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at {@code srcKey} and stores the result in the {@code dstKey} destination key.
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at {@code srcKey} and stores
* the result in the {@code dstKey} destination key.
*
* @param dstKey the src key.
* @param srcKey the dst key.
Expand All @@ -1432,9 +1439,11 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, S
Long zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey with scores ordered from high to low and stores the result in the {@code dstKey} destination key.
* Get the specified range of elements in the sorted set stored at {@code srcKey with scores ordered from high to low and
* stores the result in the {@code dstKey} destination key.
*
* @param dstKey the src key.
*
* @param srcKey the dst key.
* @param range the score range.
* @param limit the limit to apply.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,5 @@ public interface RedisStreamCommands<K, V> {
* @since 6.1
*/
Long xtrim(K key, XTrimArgs args);

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public static void main(String[] args) {
redis.getStatefulConnection().close();
redisClient.shutdown();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ protected <K, V> StatefulRedisPubSubConnectionImpl<K, V> newStatefulRedisPubSubC
RedisChannelWriter channelWriter, RedisCodec<K, V> codec, Duration timeout) {
return new MyPubSubConnection<>(endpoint, channelWriter, codec, timeout);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class MyPubSubConnection<K, V> extends StatefulRedisPubSubConnectionImpl<K, V> {
* @param codec Codec used to encode/decode keys and values.
* @param timeout Maximum time to wait for a response.
*/
public MyPubSubConnection(PubSubEndpoint<K, V> endpoint, RedisChannelWriter writer, RedisCodec<K, V> codec, Duration timeout) {
public MyPubSubConnection(PubSubEndpoint<K, V> endpoint, RedisChannelWriter writer, RedisCodec<K, V> codec,
Duration timeout) {
super(endpoint, writer, codec, timeout);
}

Expand All @@ -41,4 +42,5 @@ public <T> RedisCommand<K, V, T> dispatch(RedisCommand<K, V, T> command) {

return super.dispatch(command);
}

}
2 changes: 2 additions & 0 deletions src/test/java/io/lettuce/RedisBug.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
@Documented
@Disabled("Redis Bug")
public @interface RedisBug {

String value() default "";

}
66 changes: 32 additions & 34 deletions src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,24 @@ class CompilationUnitFactory {
private CompilationUnit template;

private final CompilationUnit result = new CompilationUnit();

private ClassOrInterfaceDeclaration resultType;

public CompilationUnitFactory(File templateFile, File sources, String targetPackage, String targetName,
Function<String, String> typeDocFunction, Function<MethodDeclaration, Type> methodReturnTypeFunction,
Predicate<MethodDeclaration> methodFilter, Supplier<List<String>> importSupplier,
Consumer<ClassOrInterfaceDeclaration> typeMutator, Function<Comment, Comment> methodCommentMutator) {
Function<String, String> typeDocFunction, Function<MethodDeclaration, Type> methodReturnTypeFunction,
Predicate<MethodDeclaration> methodFilter, Supplier<List<String>> importSupplier,
Consumer<ClassOrInterfaceDeclaration> typeMutator, Function<Comment, Comment> methodCommentMutator) {
this(templateFile, sources, targetPackage, targetName, typeDocFunction, methodReturnTypeFunction, methodDeclaration -> {
}, methodFilter, importSupplier, typeMutator, (m, c) -> methodCommentMutator != null ? methodCommentMutator.apply(c) : c);
}, methodFilter, importSupplier, typeMutator,
(m, c) -> methodCommentMutator != null ? methodCommentMutator.apply(c) : c);

}

public CompilationUnitFactory(File templateFile, File sources, String targetPackage, String targetName,
Function<String, String> typeDocFunction, Function<MethodDeclaration, Type> methodReturnTypeFunction,
Consumer<MethodDeclaration> onMethod, Predicate<MethodDeclaration> methodFilter,
Supplier<List<String>> importSupplier, Consumer<ClassOrInterfaceDeclaration> typeMutator,
BiFunction<MethodDeclaration, Comment, Comment> methodCommentMutator) {
Function<String, String> typeDocFunction, Function<MethodDeclaration, Type> methodReturnTypeFunction,
Consumer<MethodDeclaration> onMethod, Predicate<MethodDeclaration> methodFilter,
Supplier<List<String>> importSupplier, Consumer<ClassOrInterfaceDeclaration> typeMutator,
BiFunction<MethodDeclaration, Comment, Comment> methodCommentMutator) {

this.templateFile = templateFile;
this.sources = sources;
Expand Down Expand Up @@ -139,11 +141,13 @@ public void createInterface() throws Exception {
if (!templateTypeDeclaration.getTypeParameters().isEmpty()) {
resultType.setTypeParameters(new NodeList<>());
for (TypeParameter typeParameter : templateTypeDeclaration.getTypeParameters()) {
resultType.getTypeParameters().add(new TypeParameter(typeParameter.getName().getIdentifier(), typeParameter.getTypeBound()));
resultType.getTypeParameters()
.add(new TypeParameter(typeParameter.getName().getIdentifier(), typeParameter.getTypeBound()));
}
}

resultType.setComment(new JavadocComment(typeDocFunction.apply(templateTypeDeclaration.getComment().get().getContent())));
resultType
.setComment(new JavadocComment(typeDocFunction.apply(templateTypeDeclaration.getComment().get().getContent())));
result.setComment(template.getComment().orElse(null));

result.setImports(new NodeList<>());
Expand Down Expand Up @@ -209,24 +213,19 @@ public static boolean contains(Collection<String> haystack, MethodDeclaration ne
public void removeUnusedImports() {
ClassOrInterfaceDeclaration declaringClass = (ClassOrInterfaceDeclaration) result.getChildNodes().get(1);

List<ImportDeclaration> optimizedImports = result
.getImports()
.stream()
.filter(i -> i.isAsterisk()
|| i.isStatic()
|| declaringClass.findFirst(Type.class, t -> {
String fullType = t.toString();
String importIdentifier = i.getName().getIdentifier();

return fullType.contains(importIdentifier);
}).isPresent()
)
.sorted((o1, o2) -> {
if (o1.getNameAsString().startsWith("java")) return -1;
if (o2.getNameAsString().startsWith("java")) return 1;
List<ImportDeclaration> optimizedImports = result.getImports().stream()
.filter(i -> i.isAsterisk() || i.isStatic() || declaringClass.findFirst(Type.class, t -> {
String fullType = t.toString();
String importIdentifier = i.getName().getIdentifier();

return fullType.contains(importIdentifier);
}).isPresent()).sorted((o1, o2) -> {
if (o1.getNameAsString().startsWith("java"))
return -1;
if (o2.getNameAsString().startsWith("java"))
return 1;
return o1.getNameAsString().compareTo(o2.getNameAsString());
})
.collect(Collectors.toList());
}).collect(Collectors.toList());

result.setImports(NodeList.nodeList(optimizedImports));
}
Expand Down Expand Up @@ -263,16 +262,15 @@ public void visit(MethodDeclaration parsedDeclaration, Object arg) {

private Type getMethodReturnType(MethodDeclaration parsedDeclaration) {

List<Map.Entry<Predicate<MethodDeclaration>, Function<MethodDeclaration, Type>>> entries = new ArrayList<>(methodReturnTypeMutation.entrySet());
List<Map.Entry<Predicate<MethodDeclaration>, Function<MethodDeclaration, Type>>> entries = new ArrayList<>(
methodReturnTypeMutation.entrySet());

Collections.reverse(entries);

return entries
.stream()
.filter(entry -> entry.getKey().test(parsedDeclaration))
.findFirst()
.map(entry -> entry.getValue().apply(parsedDeclaration))
.orElse(null);
return entries.stream().filter(entry -> entry.getKey().test(parsedDeclaration)).findFirst()
.map(entry -> entry.getValue().apply(parsedDeclaration)).orElse(null);
}

}

}
Loading

0 comments on commit 9c36afe

Please sign in to comment.