From d4178a63bc036936e863d2f76f3805d1f5110a27 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 26 Sep 2024 22:18:39 +0600 Subject: [PATCH] Remove Triggers and Functions feature --- .../redis/clients/jedis/CommandObjects.java | 35 -- .../redis/clients/jedis/UnifiedJedis.java | 35 -- .../jedis/commands/RedisModuleCommands.java | 4 +- .../jedis/gears/RedisGearsCommands.java | 27 - .../jedis/gears/RedisGearsProtocol.java | 52 -- .../jedis/gears/TFunctionListParams.java | 50 -- .../jedis/gears/TFunctionLoadParams.java | 36 -- .../jedis/gears/resps/FunctionInfo.java | 99 ---- .../jedis/gears/resps/FunctionStreamInfo.java | 90 --- .../jedis/gears/resps/GearsLibraryInfo.java | 185 ------ .../jedis/gears/resps/StreamTriggerInfo.java | 147 ----- .../jedis/gears/resps/TriggerInfo.java | 164 ------ ...jectsTriggersAndFunctionsCommandsTest.java | 77 --- .../mocked/MockedCommandObjectsTestBase.java | 2 - ...JedisTriggersAndFunctionsCommandsTest.java | 109 ---- .../jedis/modules/gears/GearsTest.java | 536 ------------------ 16 files changed, 1 insertion(+), 1647 deletions(-) delete mode 100644 src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java delete mode 100644 src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java delete mode 100644 src/main/java/redis/clients/jedis/gears/TFunctionListParams.java delete mode 100644 src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java delete mode 100644 src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java delete mode 100644 src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java delete mode 100644 src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java delete mode 100644 src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java delete mode 100644 src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java delete mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java delete mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java delete mode 100644 src/test/java/redis/clients/jedis/modules/gears/GearsTest.java diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 5a66f803a8..687aa04e4e 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -19,9 +19,6 @@ import redis.clients.jedis.bloom.*; import redis.clients.jedis.bloom.RedisBloomProtocol.*; import redis.clients.jedis.commands.ProtocolCommand; -import redis.clients.jedis.gears.*; -import redis.clients.jedis.gears.RedisGearsProtocol.*; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; import redis.clients.jedis.graph.GraphProtocol.*; import redis.clients.jedis.json.*; import redis.clients.jedis.json.JsonProtocol.JsonCommand; @@ -4413,38 +4410,6 @@ public final CommandObject> graphConfigGet(String configName } // RedisGraph commands - // RedisGears commands - @Deprecated - public final CommandObject tFunctionLoad(String libraryCode, TFunctionLoadParams params) { - return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.LOAD) - .addParams(params).add(libraryCode), BuilderFactory.STRING); - } - - @Deprecated - public final CommandObject tFunctionDelete(String libraryName) { - return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.DELETE) - .add(libraryName), BuilderFactory.STRING); - } - - @Deprecated - public final CommandObject> tFunctionList(TFunctionListParams params) { - return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.LIST) - .addParams(params), GearsLibraryInfo.GEARS_LIBRARY_INFO_LIST); - } - - @Deprecated - public final CommandObject tFunctionCall(String library, String function, List keys, List args) { - return new CommandObject<>(commandArguments(GearsCommand.TFCALL).add(library + "." + function) - .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); - } - - @Deprecated - public final CommandObject tFunctionCallAsync(String library, String function, List keys, List args) { - return new CommandObject<>(commandArguments(GearsCommand.TFCALLASYNC).add(library + "." + function) - .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); - } - // RedisGears commands - // Transaction commands public final CommandObject watch(String... keys) { return new CommandObject<>(commandArguments(WATCH).keys((Object[]) keys), BuilderFactory.STRING); diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 50d18351d7..a89f38aa92 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -21,9 +21,6 @@ import redis.clients.jedis.commands.RedisModuleCommands; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.executors.*; -import redis.clients.jedis.gears.TFunctionListParams; -import redis.clients.jedis.gears.TFunctionLoadParams; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; import redis.clients.jedis.graph.GraphCommandObjects; import redis.clients.jedis.graph.ResultSet; import redis.clients.jedis.json.JsonSetParams; @@ -4983,38 +4980,6 @@ public Map graphConfigGet(String configName) { } // RedisGraph commands - // RedisGears commands - @Deprecated - @Override - public String tFunctionLoad(String libraryCode, TFunctionLoadParams params) { - return executeCommand(commandObjects.tFunctionLoad(libraryCode, params)); - } - - @Deprecated - @Override - public String tFunctionDelete(String libraryName) { - return executeCommand(commandObjects.tFunctionDelete(libraryName)); - } - - @Deprecated - @Override - public List tFunctionList(TFunctionListParams params) { - return executeCommand(commandObjects.tFunctionList(params)); - } - - @Deprecated - @Override - public Object tFunctionCall(String library, String function, List keys, List args) { - return executeCommand(commandObjects.tFunctionCall(library, function, keys, args)); - } - - @Deprecated - @Override - public Object tFunctionCallAsync(String library, String function, List keys, List args) { - return executeCommand(commandObjects.tFunctionCallAsync(library, function, keys, args)); - } - // RedisGears commands - /** * @return pipeline object. Use {@link AbstractPipeline} instead of {@link PipelineBase}. */ diff --git a/src/main/java/redis/clients/jedis/commands/RedisModuleCommands.java b/src/main/java/redis/clients/jedis/commands/RedisModuleCommands.java index 5e67838720..c4b785fc70 100644 --- a/src/main/java/redis/clients/jedis/commands/RedisModuleCommands.java +++ b/src/main/java/redis/clients/jedis/commands/RedisModuleCommands.java @@ -1,7 +1,6 @@ package redis.clients.jedis.commands; import redis.clients.jedis.bloom.commands.RedisBloomCommands; -import redis.clients.jedis.gears.RedisGearsCommands; import redis.clients.jedis.graph.RedisGraphCommands; import redis.clients.jedis.json.commands.RedisJsonCommands; import redis.clients.jedis.search.RediSearchCommands; @@ -12,7 +11,6 @@ public interface RedisModuleCommands extends RedisJsonCommands, RedisTimeSeriesCommands, RedisBloomCommands, - RedisGraphCommands, - RedisGearsCommands { + RedisGraphCommands { } diff --git a/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java b/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java deleted file mode 100644 index e196835ab0..0000000000 --- a/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java +++ /dev/null @@ -1,27 +0,0 @@ -package redis.clients.jedis.gears; - -import redis.clients.jedis.gears.resps.GearsLibraryInfo; - -import java.util.List; - -@Deprecated -public interface RedisGearsCommands { - - @Deprecated default String tFunctionLoad(String libraryCode) { - return tFunctionLoad(libraryCode, TFunctionLoadParams.loadParams()); - } - - @Deprecated String tFunctionLoad(String libraryCode, TFunctionLoadParams params); - - @Deprecated default List tFunctionList() { - return tFunctionList(TFunctionListParams.listParams()); - } - - @Deprecated List tFunctionList(TFunctionListParams params); - - @Deprecated String tFunctionDelete(String libraryName); - - @Deprecated Object tFunctionCall(String library, String function, List keys, List args); - - @Deprecated Object tFunctionCallAsync(String library, String function, List keys, List args); -} diff --git a/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java b/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java deleted file mode 100644 index dfb73b04a9..0000000000 --- a/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java +++ /dev/null @@ -1,52 +0,0 @@ -package redis.clients.jedis.gears; - -import redis.clients.jedis.args.Rawable; -import redis.clients.jedis.commands.ProtocolCommand; -import redis.clients.jedis.util.SafeEncoder; - -@Deprecated -public class RedisGearsProtocol { - - @Deprecated - public enum GearsCommand implements ProtocolCommand { - - @Deprecated TFUNCTION, - @Deprecated TFCALL, - @Deprecated TFCALLASYNC; - - private final byte[] raw; - - private GearsCommand() { - this.raw = SafeEncoder.encode(name()); - } - - @Override - public byte[] getRaw() { - return raw; - } - } - - @Deprecated - public enum GearsKeyword implements Rawable { - - CONFIG, - REPLACE, - LOAD, - DELETE, - LIST, - WITHCODE, - LIBRARY, - VERBOSE; - - private final byte[] raw; - - private GearsKeyword() { - this.raw = SafeEncoder.encode(name()); - } - - @Override - public byte[] getRaw() { - return raw; - } - } -} diff --git a/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java b/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java deleted file mode 100644 index e32bb43639..0000000000 --- a/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java +++ /dev/null @@ -1,50 +0,0 @@ -package redis.clients.jedis.gears; - -import redis.clients.jedis.CommandArguments; -import redis.clients.jedis.gears.RedisGearsProtocol.GearsKeyword; -import redis.clients.jedis.params.IParams; - -import java.util.Collections; - -@Deprecated -public class TFunctionListParams implements IParams { - private boolean withCode = false; - private int verbose; - private String libraryName; - - public static TFunctionListParams listParams() { - return new TFunctionListParams(); - } - - @Override - public void addParams(CommandArguments args) { - if (withCode) { - args.add(GearsKeyword.WITHCODE); - } - - if (verbose > 0 && verbose < 4) { - args.add(String.join("", Collections.nCopies(verbose, "v"))); - } else if (verbose != 0) { // verbose == 0 is the default, so we don't need to throw an error - throw new IllegalArgumentException("verbose must be between 1 and 3"); - } - - if (libraryName != null) { - args.add(GearsKeyword.LIBRARY).add(libraryName); - } - } - - public TFunctionListParams withCode() { - this.withCode = true; - return this; - } - - public TFunctionListParams verbose(int verbose) { - this.verbose = verbose; - return this; - } - - public TFunctionListParams library(String libraryName) { - this.libraryName = libraryName; - return this; - } -} diff --git a/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java b/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java deleted file mode 100644 index b8b0363b6e..0000000000 --- a/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java +++ /dev/null @@ -1,36 +0,0 @@ -package redis.clients.jedis.gears; - -import redis.clients.jedis.CommandArguments; -import redis.clients.jedis.gears.RedisGearsProtocol.GearsKeyword; -import redis.clients.jedis.params.IParams; - -@Deprecated -public class TFunctionLoadParams implements IParams { - private boolean replace = false; - private String config; - - public static TFunctionLoadParams loadParams() { - return new TFunctionLoadParams(); - } - - @Override - public void addParams(CommandArguments args) { - if (replace) { - args.add(GearsKeyword.REPLACE); - } - - if (config != null && !config.isEmpty()) { - args.add(GearsKeyword.CONFIG).add(config); - } - } - - public TFunctionLoadParams replace() { - this.replace = true; - return this; - } - - public TFunctionLoadParams config(String config) { - this.config = config; - return this; - } -} diff --git a/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java b/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java deleted file mode 100644 index 24d47b0e4e..0000000000 --- a/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java +++ /dev/null @@ -1,99 +0,0 @@ -package redis.clients.jedis.gears.resps; - -import redis.clients.jedis.Builder; -import redis.clients.jedis.util.KeyValue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static redis.clients.jedis.BuilderFactory.*; - -@Deprecated -public class FunctionInfo { - private final String name; - private final String description; - private final boolean isAsync; - - private final List flags; - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public boolean isAsync() { - return isAsync; - } - - public List getFlags() { - return flags; - } - - public FunctionInfo(String name, String description, boolean isAsync, List flags) { - this.name = name; - this.description = description; - this.isAsync = isAsync; - this.flags = flags; - } - - @Deprecated - public static final Builder> FUNCTION_INFO_LIST = new Builder>() { - @Override - public List build(Object data) { - List dataAsList = (List) data; - if (!dataAsList.isEmpty()) { - boolean isListOfList = dataAsList.get(0).getClass().isAssignableFrom(ArrayList.class); - - if (isListOfList) { - if (((List>)data).get(0).get(0) instanceof KeyValue) { - List> dataAsKeyValues = (List>)data; - return dataAsKeyValues.stream().map(keyValues -> { - String name = null; - String description = null; - List flags = Collections.emptyList(); - boolean isAsync = false; - for (KeyValue kv : keyValues) { - switch (STRING.build(kv.getKey())) { - case "name": - name = STRING.build(kv.getValue()); - break; - case "description": - description = STRING.build(kv.getValue()); - break; - case "raw-arguments": - flags = STRING_LIST.build(kv.getValue()); - break; - case "is_async": - isAsync = BOOLEAN.build(kv.getValue()); - break; - } - } - return new FunctionInfo(name, description, isAsync, flags); - }).collect(Collectors.toList()); - } else { - return dataAsList.stream().map((pairObject) -> (List) pairObject) - .map((pairList) -> new FunctionInfo( // - STRING.build(pairList.get(7)), // name - STRING.build(pairList.get(1)), // description - BOOLEAN.build(pairList.get(5)), // is_async - STRING_LIST.build(pairList.get(3)) // flags - )).collect(Collectors.toList()); - } - } else { - return dataAsList.stream() // - .map(STRING::build) // - .map((name) -> new FunctionInfo(name, null, false, null)) // - .collect(Collectors.toList()); - } - } else { - return Collections.emptyList(); - } - } - }; -} - diff --git a/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java b/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java deleted file mode 100644 index 577a0992fc..0000000000 --- a/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java +++ /dev/null @@ -1,90 +0,0 @@ -package redis.clients.jedis.gears.resps; - -import redis.clients.jedis.Builder; -import redis.clients.jedis.BuilderFactory; - -import java.util.List; -import java.util.stream.Collectors; - -@Deprecated -public class FunctionStreamInfo { - private final String name; - private final String idToReadFrom; - private final String lastError; - private final long lastLag; - private final long lastProcessedTime; - private final long totalLag; - private final long totalProcessedTime; - private final long totalRecordProcessed; - private final List pendingIds; - - public String getName() { - return name; - } - - public String getIdToReadFrom() { - return idToReadFrom; - } - - public String getLastError() { - return lastError; - } - - public long getLastLag() { - return lastLag; - } - - public long getLastProcessedTime() { - return lastProcessedTime; - } - - public long getTotalLag() { - return totalLag; - } - - public long getTotalProcessedTime() { - return totalProcessedTime; - } - - public long getTotalRecordProcessed() { - return totalRecordProcessed; - } - - public List getPendingIds() { - return pendingIds; - } - - public FunctionStreamInfo(String name, String idToReadFrom, String lastError, - long lastProcessedTime, long lastLag, long totalLag, long totalProcessedTime, long totalRecordProcessed, - List pendingIds) { - this.name = name; - this.idToReadFrom = idToReadFrom; - this.lastError = lastError; - this.lastProcessedTime = lastProcessedTime; - this.lastLag = lastLag; - this.totalLag = totalLag; - this.totalProcessedTime = totalProcessedTime; - this.totalRecordProcessed = totalRecordProcessed; - this.pendingIds = pendingIds; - } - - @Deprecated - public static final Builder> STREAM_INFO_LIST = new Builder>() { - @Override - public List build(Object data) { - return ((List) data).stream().map((pairObject) -> (List) pairObject) - .map((pairList) -> new FunctionStreamInfo( - BuilderFactory.STRING.build(pairList.get(9)), // name - BuilderFactory.STRING.build(pairList.get(1)), // id_to_read_from - BuilderFactory.STRING.build(pairList.get(3)), // last_error - BuilderFactory.LONG.build(pairList.get(7)), // last_processed_time - BuilderFactory.LONG.build(pairList.get(5)), // last_lag - BuilderFactory.LONG.build(pairList.get(13)), // total_lag - BuilderFactory.LONG.build(pairList.get(15)), // total_processed_time - BuilderFactory.LONG.build(pairList.get(17)), // total_record_processed - BuilderFactory.STRING_LIST.build(pairList.get(11)) // pending_ids - ))// - .collect(Collectors.toList()); - } - }; -} diff --git a/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java b/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java deleted file mode 100644 index d16a607cd2..0000000000 --- a/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java +++ /dev/null @@ -1,185 +0,0 @@ -package redis.clients.jedis.gears.resps; - -import redis.clients.jedis.Builder; -import redis.clients.jedis.util.KeyValue; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static redis.clients.jedis.BuilderFactory.*; -import static redis.clients.jedis.gears.resps.FunctionInfo.FUNCTION_INFO_LIST; -import static redis.clients.jedis.gears.resps.StreamTriggerInfo.STREAM_TRIGGER_INFO_LIST; -import static redis.clients.jedis.gears.resps.TriggerInfo.KEYSPACE_TRIGGER_INFO_LIST; - -@Deprecated -public class GearsLibraryInfo { - private final String apiVersion; - private final List clusterFunctions; - private final String code; - private final String configuration; - private final String engine; - private final List functions; - private final List keyspaceTriggers; - private final String name; - private final List pendingAsyncCalls; - private final long pendingJobs; - private final List streamTriggers; - private final String user; - - public GearsLibraryInfo(String apiVersion, List clusterFunctions, String code, String configuration, - String engine, List functions, List keyspaceTriggers, String name, - List pendingAsyncCalls, long pendingJobs, List streamTriggers, String user) { - this.apiVersion = apiVersion; - this.clusterFunctions = clusterFunctions; - this.code = code; - this.configuration = configuration; - this.engine = engine; - this.functions = functions; - this.keyspaceTriggers = keyspaceTriggers; - this.name = name; - this.pendingAsyncCalls = pendingAsyncCalls; - this.pendingJobs = pendingJobs; - this.streamTriggers = streamTriggers; - this.user = user; - } - public String getApiVersion() { - return apiVersion; - } - - public List getClusterFunctions() { - return clusterFunctions; - } - - public String getCode() { - return code; - } - - public String getConfiguration() { - return configuration; - } - - public String getEngine() { - return engine; - } - - public List getFunctions() { - return functions; - } - - public List getKeyspaceTriggers() { - return keyspaceTriggers; - } - - public String getName() { - return name; - } - - public List getPendingAsyncCalls() { - return pendingAsyncCalls; - } - - public long getPendingJobs() { - return pendingJobs; - } - - public List getStreamTriggers() { - return streamTriggers; - } - - public String getUser() { - return user; - } - - @Deprecated - public static final Builder GEARS_LIBRARY_INFO = new Builder() { - @Override - public GearsLibraryInfo build(Object data) { - if (data == null) return null; - List list = (List) data; - if (list.isEmpty()) return null; - - String apiVersion = null; - List clusterFunctions = Collections.emptyList(); - String code = null; - String configuration = null; - String engine = null; - List functions = Collections.emptyList(); - List keyspaceTriggers = Collections.emptyList(); - String name = null; - List pendingAsyncCalls = null; - long pendingJobs = 0; - List streamTriggers = Collections.emptyList(); - String user = null; - - if (list.get(0) instanceof KeyValue) { - for (KeyValue kv : (List) list) { - switch (STRING.build(kv.getKey())) { - case "api_version": - apiVersion = STRING.build(kv.getValue()); - break; - case "cluster_functions": - clusterFunctions = STRING_LIST.build(kv.getValue()); - break; - case "configuration": - configuration = STRING.build(kv.getValue()); - break; - case "engine": - engine = STRING.build(kv.getValue()); - break; - case "functions": - functions = FUNCTION_INFO_LIST.build(kv.getValue()); - break; - case "keyspace_triggers": - keyspaceTriggers = KEYSPACE_TRIGGER_INFO_LIST.build(kv.getValue()); - break; - case "name": - name = STRING.build(kv.getValue()); - break; - case "pending_async_calls": - pendingAsyncCalls = STRING_LIST.build(kv.getValue()); - break; - case "pending_jobs": - pendingJobs = LONG.build(kv.getValue()); - break; - case "stream_triggers": - streamTriggers = STREAM_TRIGGER_INFO_LIST.build(kv.getValue()); - break; - case "user": - user = STRING.build(kv.getValue()); - break; - case "code": - code = STRING.build(kv.getValue()); - break; - } - } - } else { - boolean withCode = list.size() > 23; - int offset = withCode ? 2 : 0; - apiVersion = STRING.build(list.get(1)); - clusterFunctions = STRING_LIST.build(list.get(3)); - code = withCode ? STRING.build(list.get(5)) : null; - configuration = STRING.build(list.get(5 + offset)); - engine = STRING.build(list.get(7 + offset)); - functions = FUNCTION_INFO_LIST.build(list.get(9 + offset)); - keyspaceTriggers = KEYSPACE_TRIGGER_INFO_LIST.build(list.get(11 + offset)); - name = STRING.build(list.get(13 + offset)); - pendingAsyncCalls = STRING_LIST.build(list.get(15 + offset)); - pendingJobs = LONG.build(list.get(17 + offset)); - streamTriggers = STREAM_TRIGGER_INFO_LIST.build(list.get(19 + offset)); - user = STRING.build(list.get(21 + offset)); - } - return new GearsLibraryInfo(apiVersion, clusterFunctions, code, configuration, engine, functions, keyspaceTriggers, name, pendingAsyncCalls, pendingJobs, streamTriggers, user); - } - }; - - @Deprecated - public static final Builder> GEARS_LIBRARY_INFO_LIST = new Builder>() { - @Override - public List build(Object data) { - List list = (List) data; - return list.stream().map(o -> GearsLibraryInfo.GEARS_LIBRARY_INFO.build(o)).collect(Collectors.toList()); - } - }; - -} \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java b/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java deleted file mode 100644 index 202d4bba4f..0000000000 --- a/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java +++ /dev/null @@ -1,147 +0,0 @@ -package redis.clients.jedis.gears.resps; - -import redis.clients.jedis.Builder; -import redis.clients.jedis.util.KeyValue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static redis.clients.jedis.BuilderFactory.*; -import static redis.clients.jedis.gears.resps.FunctionStreamInfo.STREAM_INFO_LIST; - -@Deprecated -public class StreamTriggerInfo { - private final String name; - private final String description; - private final String prefix; - private final boolean trim; - private final long window; - private final List streams; - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public String getPrefix() { - return prefix; - } - public boolean isTrim() { - return trim; - } - - public long getWindow() { - return window; - } - - public List getStreams() { - return streams; - } - - public StreamTriggerInfo(String name, String description, String prefix, - long window, boolean trim, List streams) { - this.name = name; - this.description = description; - this.prefix = prefix; - this.window = window; - this.trim = trim; - this.streams = streams; - } - public StreamTriggerInfo(String name) { - this(name, null, null, 0, false, Collections.emptyList()); - } - - public StreamTriggerInfo(String name, String description, String prefix, - long window, boolean trim) { - this(name, description, prefix, window, trim, Collections.emptyList()); - } - - @Deprecated - public static final Builder> STREAM_TRIGGER_INFO_LIST = new Builder>() { - @Override - public List build(Object data) { - List dataAsList = (List) data; - if (!dataAsList.isEmpty()) { - boolean isListOfList = dataAsList.get(0).getClass().isAssignableFrom(ArrayList.class); - if (isListOfList) { - if (((List>)data).get(0).get(0) instanceof KeyValue) { - List> dataAsKeyValues = (List>)data; - return dataAsKeyValues.stream().map(keyValues -> { - String name = null; - String description = null; - String prefix = null; - long window = 0; - boolean trim = false; - List streams = null; - - for (KeyValue kv : keyValues) { - switch (STRING.build(kv.getKey())) { - case "name": - name = STRING.build(kv.getValue()); - break; - case "description": - description = STRING.build(kv.getValue()); - break; - case "prefix": - prefix = STRING.build(kv.getValue()); - break; - case "window": - window = LONG.build(kv.getValue()); - break; - case "trim": - trim = BOOLEAN.build(kv.getValue()); - break; - case "streams": - streams = STREAM_INFO_LIST.build(kv.getValue()); - break; - } - } - return new StreamTriggerInfo(name, description, prefix, window, trim, streams); - }).collect(Collectors.toList()); - } else { - return dataAsList.stream().map((pairObject) -> (List) pairObject).map((pairList) -> { - StreamTriggerInfo result = null; - switch (pairList.size()) { - case 1: - result = new StreamTriggerInfo(STRING.build(pairList.get(0))); - break; - case 10: - result = new StreamTriggerInfo( // - STRING.build(pairList.get(3)), // name - STRING.build(pairList.get(1)), // description - STRING.build(pairList.get(5)), // prefix - LONG.build(pairList.get(9)), // window - BOOLEAN.build(pairList.get(7)) // trim - ); - break; - case 12: - result = new StreamTriggerInfo( // - STRING.build(pairList.get(3)), // name - STRING.build(pairList.get(1)), // description - STRING.build(pairList.get(5)), // prefix - LONG.build(pairList.get(11)), // window - BOOLEAN.build(pairList.get(9)), // trim - STREAM_INFO_LIST.build(pairList.get(7)) // streams - ); - break; - } - return result; - }) // - .collect(Collectors.toList()); - } - } else { - return dataAsList.stream() // - .map(STRING::build).map((name) -> new StreamTriggerInfo(name, null, null, 0, false)) // - .collect(Collectors.toList()); - } - } else { - return Collections.emptyList(); - } - } - }; -} diff --git a/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java b/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java deleted file mode 100644 index 775af5cecd..0000000000 --- a/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java +++ /dev/null @@ -1,164 +0,0 @@ -package redis.clients.jedis.gears.resps; - -import redis.clients.jedis.Builder; -import redis.clients.jedis.util.KeyValue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static redis.clients.jedis.BuilderFactory.LONG; -import static redis.clients.jedis.BuilderFactory.STRING; - -@Deprecated -public class TriggerInfo { - private final String name; - private final String description; - - private final String lastError; - - private final long lastExecutionTime; - - private final long numFailed; - - private final long numFinished; - - private final long numSuccess; - - private final long numTrigger; - - private final long totalExecutionTime; - - - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public String getLastError() { - return lastError; - } - - public long getLastExecutionTime() { - return lastExecutionTime; - } - - public long getNumFailed() { - return numFailed; - } - - public long getNumFinished() { - return numFinished; - } - - public long getNumSuccess() { - return numSuccess; - } - - public long getNumTrigger() { - return numTrigger; - } - - public long getTotalExecutionTime() { - return totalExecutionTime; - } - - public TriggerInfo(String name, String description, String lastError, long numFinished, long numSuccess, - long numFailed, long numTrigger, long lastExecutionTime, long totalExecutionTime) { - this.name = name; - this.description = description; - this.lastError = lastError; - this.numFinished = numFinished; - this.numSuccess = numSuccess; - this.numFailed = numFailed; - this.numTrigger = numTrigger; - this.lastExecutionTime = lastExecutionTime; - this.totalExecutionTime = totalExecutionTime; - } - - @Deprecated - public static final Builder> KEYSPACE_TRIGGER_INFO_LIST = new Builder>() { - @Override - public List build(Object data) { - List dataAsList = (List) data; - if (!dataAsList.isEmpty()) { - boolean isListOfList = dataAsList.get(0).getClass().isAssignableFrom(ArrayList.class); - if (isListOfList) { - if (((List>)data).get(0).get(0) instanceof KeyValue) { - List> dataAsKeyValues = (List>)data; - return dataAsKeyValues.stream().map(keyValues -> { - String name = null; - String description = null; - String lastError = null; - long lastExecutionTime = 0; - long numFailed = 0; - long numFinished = 0; - long numSuccess = 0; - long numTrigger = 0; - long totalExecutionTime = 0; - - for (KeyValue kv : keyValues) { - switch (STRING.build(kv.getKey())) { - case "name": - name = STRING.build(kv.getValue()); - break; - case "description": - description = STRING.build(kv.getValue()); - break; - case "last_error": - lastError = STRING.build(kv.getValue()); - break; - case "last_execution_time": - lastExecutionTime = LONG.build(kv.getValue()); - break; - case "num_failed": - numFailed = LONG.build(kv.getValue()); - break; - case "num_finished": - numFinished = LONG.build(kv.getValue()); - break; - case "num_success": - numSuccess = LONG.build(kv.getValue()); - break; - case "num_trigger": - numTrigger = LONG.build(kv.getValue()); - break; - case "total_execution_time": - totalExecutionTime = LONG.build(kv.getValue()); - break; - } - } - return new TriggerInfo(name, description, lastError, numFinished, numSuccess, numFailed, numTrigger, - lastExecutionTime, totalExecutionTime); - }).collect(Collectors.toList()); - } else { - return dataAsList.stream().map((pairObject) -> (List) pairObject) - .map((pairList) -> new TriggerInfo(STRING.build(pairList.get(7)), // name - STRING.build(pairList.get(1)), // description - STRING.build(pairList.get(3)), // last_error - LONG.build(pairList.get(11)), // num_finished - LONG.build(pairList.get(13)), // num_success - LONG.build(pairList.get(9)), // num_failed - LONG.build(pairList.get(15)), // num_trigger - LONG.build(pairList.get(5)), // last_execution_time - LONG.build(pairList.get(17)) // total_execution_time - ))// - .collect(Collectors.toList()); - } - } else { - return dataAsList.stream() // - .map(STRING::build)// - .map((name) -> new TriggerInfo(name, null, null, 0,0,0,0,0,0)) // - .collect(Collectors.toList()); - } - } else { - return Collections.emptyList(); - } - } - }; -} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java deleted file mode 100644 index ce198f4627..0000000000 --- a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package redis.clients.jedis.commands.commandobjects; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; - -import java.util.ArrayList; -import java.util.List; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; - -import redis.clients.jedis.RedisProtocol; -import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.gears.TFunctionListParams; -import redis.clients.jedis.gears.TFunctionLoadParams; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; - -/** - * Tests related to Triggers and functions commands. - */ -@Ignore -public class CommandObjectsTriggersAndFunctionsCommandsTest extends CommandObjectsModulesTestBase { - - public CommandObjectsTriggersAndFunctionsCommandsTest(RedisProtocol protocol) { - super(protocol); - } - - @After - public void tearDown() throws Exception { - try { - exec(commandObjects.tFunctionDelete("lib")); - } catch (JedisDataException de) { } - } - - @Test - public void testTFunctionLoadAndCall() { - String libraryCode = "#!js api_version=1.0 name=lib\n" + - "redis.registerFunction('hello', ()=>{return 42;})"; - - TFunctionLoadParams params = new TFunctionLoadParams().replace(); - - String load = exec(commandObjects.tFunctionLoad(libraryCode, params)); - assertThat(load, equalTo("OK")); - - Object call = exec(commandObjects.tFunctionCall("lib", "hello", new ArrayList<>(), new ArrayList<>())); - assertThat(call.toString(), equalTo("42")); - - Object callAsync = exec(commandObjects.tFunctionCallAsync("lib", "hello", new ArrayList<>(), new ArrayList<>())); - assertThat(callAsync.toString(), equalTo("42")); - } - - @Test - public void testTFunctionDeleteAndList() { - String libraryCode = "#!js api_version=1.0 name=lib\n" + - "redis.registerFunction('hello', ()=>{return 42;})"; - - String load = exec(commandObjects.tFunctionLoad(libraryCode, new TFunctionLoadParams().replace())); - assertThat(load, equalTo("OK")); - - TFunctionListParams params = new TFunctionListParams().library("lib"); - - List list = exec(commandObjects.tFunctionList(params)); - - assertThat(list, hasSize(1)); - assertThat(list.get(0).getName(), equalTo("lib")); - assertThat(list.get(0).getFunctions(), hasSize(1)); - assertThat(list.get(0).getFunctions().get(0).getName(), equalTo("hello")); - - String delete = exec(commandObjects.tFunctionDelete("lib")); - assertThat(delete, equalTo("OK")); - - list = exec(commandObjects.tFunctionList(params)); - assertThat(list, empty()); - } -} diff --git a/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java b/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java index 8127c417bc..c755caf9e2 100644 --- a/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java +++ b/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java @@ -11,7 +11,6 @@ import redis.clients.jedis.CommandObject; import redis.clients.jedis.GeoCoordinate; import redis.clients.jedis.StreamEntryID; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; import redis.clients.jedis.graph.ResultSet; import redis.clients.jedis.resps.FunctionStats; import redis.clients.jedis.resps.GeoRadiusResponse; @@ -77,7 +76,6 @@ public final static class MyBean { @Mock protected CommandObject> listBooleanCommandObject; @Mock protected CommandObject>> listClassCommandObject; @Mock protected CommandObject> listDoubleCommandObject; - @Mock protected CommandObject> listGearsLibraryInfoCommandObject; @Mock protected CommandObject> listGeoCoordinateCommandObject; @Mock protected CommandObject> listGeoRadiusResponseCommandObject; @Mock protected CommandObject> listJsonArrayCommandObject; diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java deleted file mode 100644 index 62fd7bf7cd..0000000000 --- a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package redis.clients.jedis.mocked.unified; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.sameInstance; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.junit.Ignore; -import org.junit.Test; -import redis.clients.jedis.gears.TFunctionListParams; -import redis.clients.jedis.gears.TFunctionLoadParams; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; - -@Ignore -public class UnifiedJedisTriggersAndFunctionsCommandsTest extends UnifiedJedisMockedTestBase { - - @Test - public void testTFunctionCall() { - String library = "mylib"; - String function = "myfunc"; - List keys = Arrays.asList("key1", "key2"); - List args = Arrays.asList("arg1", "arg2"); - Object expectedResponse = "result"; - - when(commandObjects.tFunctionCall(library, function, keys, args)).thenReturn(objectCommandObject); - when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); - - Object result = jedis.tFunctionCall(library, function, keys, args); - - assertThat(result, sameInstance(expectedResponse)); - - verify(commandExecutor).executeCommand(objectCommandObject); - verify(commandObjects).tFunctionCall(library, function, keys, args); - } - - @Test - public void testTFunctionCallAsync() { - String library = "mylib"; - String function = "myfunc"; - List keys = Arrays.asList("key1", "key2"); - List args = Arrays.asList("arg1", "arg2"); - Object expectedResponse = "result"; - - when(commandObjects.tFunctionCallAsync(library, function, keys, args)).thenReturn(objectCommandObject); - when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); - - Object result = jedis.tFunctionCallAsync(library, function, keys, args); - - assertThat(result, sameInstance(expectedResponse)); - - verify(commandExecutor).executeCommand(objectCommandObject); - verify(commandObjects).tFunctionCallAsync(library, function, keys, args); - } - - @Test - public void testTFunctionDelete() { - String libraryName = "mylib"; - String expectedResponse = "OK"; - - when(commandObjects.tFunctionDelete(libraryName)).thenReturn(stringCommandObject); - when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); - - String result = jedis.tFunctionDelete(libraryName); - - assertThat(result, sameInstance(expectedResponse)); - - verify(commandExecutor).executeCommand(stringCommandObject); - verify(commandObjects).tFunctionDelete(libraryName); - } - - @Test - public void testTFunctionList() { - TFunctionListParams params = new TFunctionListParams(); - List expectedResponse = new ArrayList<>(); - expectedResponse.add(mock(GearsLibraryInfo.class)); - - when(commandObjects.tFunctionList(params)).thenReturn(listGearsLibraryInfoCommandObject); - when(commandExecutor.executeCommand(listGearsLibraryInfoCommandObject)).thenReturn(expectedResponse); - - List result = jedis.tFunctionList(params); - - assertThat(result, sameInstance(expectedResponse)); - - verify(commandExecutor).executeCommand(listGearsLibraryInfoCommandObject); - verify(commandObjects).tFunctionList(params); - } - - @Test - public void testTFunctionLoad() { - String libraryCode = "function code"; - TFunctionLoadParams params = new TFunctionLoadParams(); - String expectedResponse = "OK"; - - when(commandObjects.tFunctionLoad(libraryCode, params)).thenReturn(stringCommandObject); - when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); - - String result = jedis.tFunctionLoad(libraryCode, params); - - assertThat(result, sameInstance(expectedResponse)); - - verify(commandExecutor).executeCommand(stringCommandObject); - verify(commandObjects).tFunctionLoad(libraryCode, params); - } - -} diff --git a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java deleted file mode 100644 index e32e526279..0000000000 --- a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java +++ /dev/null @@ -1,536 +0,0 @@ -package redis.clients.jedis.modules.gears; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.hamcrest.Matchers; -import org.junit.After; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import redis.clients.jedis.RedisProtocol; -import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.gears.TFunctionListParams; -import redis.clients.jedis.gears.TFunctionLoadParams; -import redis.clients.jedis.modules.RedisModuleCommandsTestBase; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -@Ignore -@RunWith(Parameterized.class) -public class GearsTest extends RedisModuleCommandsTestBase { - - private static final String BAD_FUNCTION = "All Your Base Are Belong to Us"; - - private static final String[] LIBRARIES_ARRAY = new String[]{ - "streamTriggers", "withFlags", "pingpong", "keyspaceTriggers", "hashitout", "withConfig"}; - - @BeforeClass - public static void prepare() { - RedisModuleCommandsTestBase.prepare(); - } - - public GearsTest(RedisProtocol protocol) { - super(protocol); - } - - @After - @Override - public void tearDown() throws Exception { - deleteFunctions(); // delete functions before closing connections - super.tearDown(); - } - - protected void deleteFunctions() { - List libraries = client.tFunctionList(); - libraries.stream().map(GearsLibraryInfo::getName).forEach(library -> client.tFunctionDelete(library)); - } - - @Test - public void testFunctionLoad() throws IOException { - client.tFunctionLoad(readLibrary("pingpong.js")); - - List libraries = client.tFunctionList(); - assertEquals(Collections.singletonList("pingpong"), - libraries.stream().map(GearsLibraryInfo::getName).collect(Collectors.toList())); - } - - @Test(expected = JedisDataException.class) - public void testFunctionLoadAlreadyLoadedFails() throws IOException { - client.tFunctionLoad(readLibrary("pingpong.js")); - client.tFunctionLoad(readLibrary("pingpong.js")); - } - - @Test - public void testFunctionLoadWithReplace() throws IOException { - client.tFunctionLoad(readLibrary("pingpong.js")); - client.tFunctionLoad(readLibrary("pingpong.js"), TFunctionLoadParams.loadParams().replace()); - - List libraries = client.tFunctionList(); - assertEquals(Collections.singletonList("pingpong"), - libraries.stream().map(GearsLibraryInfo::getName).collect(Collectors.toList())); - } - - @Test(expected = JedisDataException.class) - public void testBadFunctionLoad() { - client.tFunctionLoad(BAD_FUNCTION); - } - - private static void assertAllLibrariesNoCode(List libraryInfos) { - assertThat(libraryInfos, Matchers.hasSize(LIBRARIES_ARRAY.length)); - - List libraryNames = libraryInfos.stream().map(GearsLibraryInfo::getName).collect(Collectors.toList()); - assertThat(libraryNames, Matchers.containsInAnyOrder(LIBRARIES_ARRAY)); - - libraryInfos.stream().map(GearsLibraryInfo::getCode).forEach(Assert::assertNull); - } - - private static void assertAllLibrariesWithCode(List libraryInfos) { - assertThat(libraryInfos, Matchers.hasSize(LIBRARIES_ARRAY.length)); - - List libraryNames = libraryInfos.stream().map(GearsLibraryInfo::getName).collect(Collectors.toList()); - assertThat(libraryNames, Matchers.containsInAnyOrder(LIBRARIES_ARRAY)); - - libraryInfos.stream().map(GearsLibraryInfo::getCode).forEach(Assert::assertNotNull); - } - - @Test - public void tFunctionListAll() throws IOException { - loadAllLibraries(); - - List libraryInfos = client.tFunctionList(); - assertAllLibrariesNoCode(libraryInfos); - } - - @Test - public void testFunctionListNoCodeVerboseZero() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().verbose(0)); - assertAllLibrariesNoCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListNoCodeVerboseOne() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().verbose(1)); - assertAllLibrariesNoCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "stream".equalsIgnoreCase(trigger.getPrefix()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> func.getFlags().contains("raw-arguments"))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListNoCodeVerboseTwo() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().verbose(2)); - assertAllLibrariesNoCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "stream".equalsIgnoreCase(trigger.getPrefix()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> func.getFlags().contains("raw-arguments"))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListNoCodeVerboseThree() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().verbose(3)); - assertAllLibrariesNoCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "stream".equalsIgnoreCase(trigger.getPrefix()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> func.getFlags().contains("raw-arguments"))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListWithCodeVerboseZero() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().withCode().verbose(0)); - assertAllLibrariesWithCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListWithCodeVerboseOne() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().withCode().verbose(1)); - assertAllLibrariesWithCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "stream".equalsIgnoreCase(trigger.getPrefix()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> func.getFlags().contains("raw-arguments"))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListWithCodeVerboseTwo() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().withCode().verbose(2)); - assertAllLibrariesWithCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "stream".equalsIgnoreCase(trigger.getPrefix()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> func.getFlags().contains("raw-arguments"))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionListWithCodeVerboseThree() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().withCode().verbose(3)); - assertAllLibrariesWithCode(libraryInfos); - - Map>> libraryConditions = initializeTestLibraryConditions(); - - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("streamTriggers").add(lib -> lib.getStreamTriggers().stream().anyMatch(trigger -> "stream".equalsIgnoreCase(trigger.getPrefix()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> "my_set".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withFlags").add(lib -> lib.getFunctions().stream().anyMatch(func -> func.getFlags().contains("raw-arguments"))); - libraryConditions.get("pingpong").add(lib -> lib.getFunctions().stream().anyMatch(func -> "playPingPong".equalsIgnoreCase(func.getName()))); - libraryConditions.get("keyspaceTriggers").add(lib -> lib.getKeyspaceTriggers().stream().anyMatch(trigger -> "consumer".equalsIgnoreCase(trigger.getName()))); - libraryConditions.get("hashitout").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hashy".equalsIgnoreCase(func.getName()))); - libraryConditions.get("withConfig").add(lib -> lib.getFunctions().stream().anyMatch(func -> "hset".equalsIgnoreCase(func.getName()))); - - for (GearsLibraryInfo libraryInfo : libraryInfos) { - List> conditions = libraryConditions.get(libraryInfo.getName()); - if (conditions != null && !conditions.isEmpty()) { - conditions.forEach(c -> c.test(libraryInfo)); - } - } - } - - @Test - public void testFunctionLibraryListNoCodeVerboseZero() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong")); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertNull(libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListNoCodeVerboseOne() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").verbose(1)); - - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertEquals("You PING, we PONG", libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListNoCodeVerboseTwo() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").verbose(2)); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertEquals("You PING, we PONG", libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListNoCodeVerboseThree() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").verbose(3)); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertEquals("You PING, we PONG", libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListWithCodeVerboseZero() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").withCode()); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertNull(libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNotNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListWithCodeVerboseOne() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").withCode().verbose(1)); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertEquals("You PING, we PONG", libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNotNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListWithCodeVerboseTwo() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").withCode().verbose(2)); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertEquals("You PING, we PONG", libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNotNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testFunctionLibraryListWithCodeVerboseThree() throws IOException { - loadAllLibraries(); - List libraryInfos = client.tFunctionList(TFunctionListParams.listParams().library("pingpong").withCode().verbose(3)); - assertEquals(1, libraryInfos.size()); - assertEquals("pingpong", libraryInfos.get(0).getName()); - assertEquals("You PING, we PONG", libraryInfos.get(0).getFunctions().get(0).getDescription()); - assertNotNull(libraryInfos.get(0).getCode()); - } - - @Test - public void testLibraryDelete() throws IOException { - loadAllLibraries(); - assertEquals("OK", client.tFunctionDelete("pingpong")); - List libraryInfos = client.tFunctionList(); - assertEquals(LIBRARIES_ARRAY.length - 1, libraryInfos.size()); - } - - @Test - public void testLibraryCallStringResult() throws IOException { - loadAllLibraries(); - Object result = client.tFunctionCall("pingpong", "playPingPong", Collections.emptyList(), - Collections.emptyList()); - assertEquals(String.class, result.getClass()); - assertEquals("PONG", result); - } - - @Test - public void testLibraryCallSetValueResult() throws IOException { - loadAllLibraries(); - Object result = client.tFunctionCall("withFlags", "my_set", Collections.singletonList("MY_KEY"), - Collections.singletonList("MY_VALUE")); - assertEquals(String.class, result.getClass()); - assertEquals("OK", result); - assertEquals("MY_VALUE", client.get("MY_KEY")); - } - - @Test - public void testLibraryCallHashResult() throws IOException { - loadAllLibraries(); - Map payload = new HashMap<>(); - payload.put("C", "Dennis Ritchie"); - payload.put("Python", "Guido van Rossum"); - payload.put("C++", "Bjarne Stroustrup"); - payload.put("JavaScript", "Brendan Eich"); - payload.put("Java", "James Gosling"); - payload.put("Ruby", "Yukihiro Matsumoto"); - - client.hmset("hash1", payload); - - Object result = client.tFunctionCall("hashitout", "hashy", Collections.singletonList("hash1"), - Collections.emptyList()); - - final Map asMap; - - if (protocol != RedisProtocol.RESP3) { - final List asList = (List) result; - asMap = flatMapToMap(asList); - - } else { - asMap = (Map) result; - } - - payload.forEach((language, author) -> { - assertThat(asMap, Matchers.hasEntry(language, author)); - }); - assertThat(Long.parseLong(asMap.get("__last_updated__")), Matchers.greaterThan(0L)); - } - - @Test - public void testFunctionLoadWithConfig() throws IOException { - loadAllLibraries(); - List argsBefore = Arrays.asList("Dictionary1", "Pollito", "Chicken"); - client.tFunctionCall("withConfig", "hset", Collections.emptyList(), argsBefore); - - String config = "{\"last_modified_field_name\":\"changed_on\"}"; - client.tFunctionLoad(readLibrary("withConfig.js"), TFunctionLoadParams.loadParams().replace().config(config)); - - List argsAfter = Arrays.asList("Dictionary2", "Gallina", "Hen"); - Object result = client.tFunctionCall("withConfig", "hset", Collections.emptyList(), argsAfter); - assertEquals(2L, result); - - Map dict1 = client.hgetAll("Dictionary1"); - Map dict2 = client.hgetAll("Dictionary2"); - - assertTrue(dict1.containsKey("Pollito")); - assertTrue(dict1.containsKey("__last_modified__")); - assertFalse(dict1.containsKey("changed_on")); - - assertTrue(dict2.containsKey("Gallina")); - assertTrue(dict2.containsKey("changed_on")); - assertFalse(dict2.containsKey("__last_modified__")); - } - - @Test - public void testLibraryCallSetValueResultAsync() throws IOException { - loadAllLibraries(); - Object result = client.tFunctionCallAsync("withFlags", "my_set", Collections.singletonList("KEY_TWO"), - Collections.singletonList("KEY_TWO_VALUE")); - assertEquals(String.class, result.getClass()); - assertEquals("OK", result); - assertEquals("KEY_TWO_VALUE", client.get("KEY_TWO")); - } - - private static String readLibrary(String filename) throws IOException { - Path path = Paths.get("src/test/resources/functions/" + filename); - return String.join("\n", Files.readAllLines(path)); - } - - private void loadAllLibraries() throws IOException { - try (Stream walk = Files.walk(Paths.get("src/test/resources/functions/"))) { - List libs = walk - .filter(p -> !Files.isDirectory(p)) // - .map(Path::toString) // - .filter(f -> f.endsWith(".js")) // - .collect(Collectors.toList()); - - libs.forEach(lib -> { - String code; - try { - code = String.join("\n", Files.readAllLines(Paths.get(lib))); - } catch (IOException e) { - throw new RuntimeException(e); - } - client.tFunctionLoad(code, TFunctionLoadParams.loadParams().replace()); - }); - } - } - - private static Map>> initializeTestLibraryConditions() { - Map>> libraryConditions = new HashMap<>(); - libraryConditions.put("streamTriggers", new ArrayList<>()); - libraryConditions.put("withFlags", new ArrayList<>()); - libraryConditions.put("pingpong", new ArrayList<>()); - libraryConditions.put("keyspaceTriggers", new ArrayList<>()); - libraryConditions.put("hashitout", new ArrayList<>()); - libraryConditions.put("withConfig", new ArrayList<>()); - - return libraryConditions; - } - - private static Map flatMapToMap(List list) { - Map map = new HashMap(list.size() / 2); - for (int i = 0; i < list.size(); i += 2) { - map.put(list.get(i), list.get(i + 1)); - } - return map; - } -}