-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test with 8.0-M03-pre * Test with 8.0-M03-pre * Test with 8.0-M03 * Test with 8.0-M04-pre * SearchDefaultDialectTest.testDialectsWithFTExplain Output of ft.explain has changed in Redis 8.0. Existing Jedis client ftExplain() API returns the raw output and does not perform any parsing/mapping, hence updating the test to verify only for received output when used with correct dialect & gets syntax error otherwise. * Update testAggregationBuilderAddScores test to match change in SEARCH module replacing default SCORER from TF-IDF to BM25. * Apply suggestions from code review Co-authored-by: M Sazzadul Hoque <[email protected]> * Address review comments * Update SearchDefaultDialectTest.java * Output of ft.explain has changed in Redis 8.0. Existing Jedis client ftExplain() API returns the raw output and does not perform any parsing/mapping, hence updating the test to verify only for received output when used with correct dialect & gets syntax error otherwise. * minor changes: format, private, unused variable, etc. --------- Co-authored-by: M Sazzadul Hoque <[email protected]>
- Loading branch information
Showing
6 changed files
with
149 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/test/java/redis/clients/jedis/util/RedisConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package redis.clients.jedis.util; | ||
|
||
import io.redis.test.utils.RedisVersion; | ||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.CommandObject; | ||
import redis.clients.jedis.Module; | ||
import redis.clients.jedis.UnifiedJedis; | ||
import redis.clients.jedis.resps.CommandInfo; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static redis.clients.jedis.BuilderFactory.MODULE_LIST; | ||
import static redis.clients.jedis.Protocol.Command.COMMAND; | ||
import static redis.clients.jedis.Protocol.Command.MODULE; | ||
import static redis.clients.jedis.Protocol.Keyword.LIST; | ||
|
||
public class RedisConditions { | ||
|
||
private final RedisVersion version; | ||
private final Map<String, Integer> modules; | ||
private final Map<String, CommandInfo> commands; | ||
|
||
private RedisConditions(RedisVersion version, Map< String, CommandInfo> commands, Map<String, Integer> modules) { | ||
this.version = version; | ||
this.commands = commands; | ||
this.modules = modules; | ||
} | ||
|
||
public static RedisConditions of(UnifiedJedis jedis) { | ||
RedisVersion version = RedisVersionUtil.getRedisVersion(jedis); | ||
|
||
CommandObject<Map<String, CommandInfo>> commandInfoCmd | ||
= new CommandObject<>(new CommandArguments(COMMAND), CommandInfo.COMMAND_INFO_RESPONSE); | ||
Map<String, CommandInfo> commands = jedis.executeCommand(commandInfoCmd); | ||
|
||
CommandObject<List<Module>> moduleListCmd | ||
= new CommandObject<>(new CommandArguments(MODULE).add(LIST), MODULE_LIST); | ||
|
||
Map<String, Integer> modules = jedis.executeCommand(moduleListCmd) | ||
.stream() | ||
.collect(Collectors.toMap((m) -> m.getName().toUpperCase(), Module::getVersion)); | ||
|
||
return new RedisConditions(version, commands, modules); | ||
} | ||
|
||
public RedisVersion getVersion() { | ||
return version; | ||
} | ||
|
||
/** | ||
* @param command | ||
* @return {@code true} if the command is present. | ||
*/ | ||
public boolean hasCommand(String command) { | ||
return commands.containsKey(command.toUpperCase()); | ||
} | ||
|
||
/** | ||
* @param module | ||
* @return {@code true} if the module is present. | ||
*/ | ||
public boolean hasModule(String module) { | ||
return modules.containsKey(module.toUpperCase()); | ||
} | ||
|
||
/** | ||
* @param module | ||
* @param version | ||
* @return {@code true} if the module is present. | ||
*/ | ||
public boolean moduleVersionIsGreatherThan(String module, int version) { | ||
Integer moduleVersion = modules.get(module.toUpperCase()); | ||
return moduleVersion != null && moduleVersion > version; | ||
} | ||
} |