fppt / jedis-mock Goto Github PK
View Code? Open in Web Editor NEWThis project forked from zxl0714/redis-mock
A simple redis java mock for unit testing
License: Apache License 2.0
This project forked from zxl0714/redis-mock
A simple redis java mock for unit testing
License: Apache License 2.0
I noticed no commits in over a year. Is this library still supported?
The mock helped us a lot with verifying our new Redis code.
If it's possible to add a mock of Redis in cluster mote it'll help a lot- since we use clusters.
Thanks a lot for this amazing mock
please add zrem zadd and zrange operations
Please support redis dbsize method
Hi, Really appreciate what you have done and it really helps me a lot on unit testing.
zrerangebyscore is a basic operation, especially usual for rate limiter.
Could you mind to add this? Thank you very much.
The current implementation of rename, doesn't delete the values from target key.
This will merge the map result in case of HMAP.
The target key should be delete before renaming
Here is an extract from the doc
If newkey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation
Unsupported operation 'eval'
The script operation is not supported
Unsupported operation 'script'
Please add support for this operation (it is missing in 0.1.15)
io.lettuce.core.RedisCommandExecutionException: Unsupported operation 'config'
From the Redis docs:
EXPIRE key seconds
Available since 1.0.0.Time complexity: O(1)
Set a timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.
The timeout will only be cleared by commands that delete or overwrite the contents of the key, including DEL, SET, GETSET and all the *STORE commands. This means that all the operations that conceptually alter the value stored at the key without replacing it with a new one will leave the timeout untouched. For instance, incrementing the value of a key with INCR, pushing a new value into a list with LPUSH, or altering the field value of a hash with HSET are all operations that will leave the timeout untouched.
Nevertheless, my tests are failing...
redis = RedisServer.newRedisServer(); // bind to a random port
redis.start();
jedis = new Jedis(redis.getHost(), redis.getBindPort());
jedis.set(REDIS_KEY, "1");
jedis.expire(REDIS_KEY, REMAINING_TTL);
assertEquals(REMAINING_TTL, jedis.ttl(REDIS_KEY)); // OK
jedis.incr(REDIS_KEY);
assertEquals(REMAINING_TTL, jedis.ttl(REDIS_KEY)); // Got -1
Am I misunderstanding something?
According to https://redis.io/commands/hsetnx HSETNX should return 0 if value to be set already exists (and thus was not set), but jedis-mock incorrectly returns 1 in this case.
There is a merge request that fixes that:
#94
"-1".charAt(0) = '-'
AND
java.lang.Character#isDigit('-') = false
==>
ERROR com.github.fppt.jedismock.operations.RO_exec - ERROR during committing transaction
com.github.fppt.jedismock.exception.WrongValueTypeException: Valid start must be a number or start with '(' or be equal to '-inf'
at com.github.fppt.jedismock.operations.RO_zremrangebyscore.getStartScore(RO_zremrangebyscore.java:79) ~[jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.operations.RO_zremrangebyscore.response(RO_zremrangebyscore.java:36) ~[jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.operations.AbstractRedisOperation.execute(AbstractRedisOperation.java:47) ~[jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.operations.RO_zremrangebyscore.execute(RO_zremrangebyscore.java:18) ~[jedis-mock-0.1.18.jar:?]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655) ~[?:?]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[?:?]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[?:?]
at com.github.fppt.jedismock.operations.RO_exec.execute(RO_exec.java:25) [jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.server.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:36) [jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.server.RedisClient.run(RedisClient.java:54) [jedis-mock-0.1.18.jar:?]
Add support for 'pubsub'.
thanks!
Hi,
Attempting to use this in a Spring JPA integration test. Seems like most commands are not supported by this mock server.
at com.github.fppt.jedismock.commands.RedisOperationExecutor.buildSimpleOperation(RedisOperationExecutor.java:135) ~[jedis-mock-0.1.6.jar:na]
at com.github.fppt.jedismock.commands.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:154) ~[jedis-mock-0.1.6.jar:na]
...
java.lang.UnsupportedOperationException: Unsupported operation 'sinter'
at com.github.fppt.jedismock.commands.RedisOperationExecutor.buildSimpleOperation(RedisOperationExecutor.java:135) ~[jedis-mock-0.1.6.jar:na]
at com.github.fppt.jedismock.commands.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:154) ~[jedis-mock-0.1.6.jar:na]
'watch' command is not supported
Please support redis scan method
And this one please
Version: 0.1.15
Sep 27, 2019 6:23:01 PM com.github.fppt.jedismock.server.RedisOperationExecutor execCommand
SEVERE: Malformed request
java.lang.UnsupportedOperationException: Unsupported operation 'hlen'
at com.github.fppt.jedismock.operations.OperationFactory.buildTxOperation(OperationFactory.java:89)
at com.github.fppt.jedismock.server.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:39)
at com.github.fppt.jedismock.server.RedisClient.run(RedisClient.java:54)
at java.lang.Thread.run(Thread.java:748)
Add support for srem
Unsupported operation 'srem'; nested exception is redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'srem'
Trying to migrate a current embedded-redis
to jedis-mock
and having the error:
redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'select'
Is something that can be added to jedis-mock
?
I can break the mock by using subscribe
It looks like this should be implemented?
class JedisMockTest {
private lateinit var redisServer: RedisServer
private val jedis by lazy { Jedis(redisServer.host, redisServer.bindPort) }
@Before
fun setUp() {
redisServer = RedisServer.newRedisServer()
redisServer.start()
}
@After
fun tearDown() {
redisServer.stop()
}
@Test
fun `test redis ping`() {
val result = jedis.ping("Hello")
assertEquals("Hello", result)
}
@Test
fun `test pub sub`() {
val countDownLatch = CountDownLatch(1)
jedis.subscribe(object : JedisPubSub() {
override fun onMessage(channel: String?, message: String?) {
countDownLatch.countDown()
}
}, "channel")
// jedis.publish("channel", "Message")
// countDownLatch.await()
}
}
The test will hang forever as it never gets a result from the subscribe
call.
I'm using jedis-mock with Redisson. When I call bucket.getAndDelete()
, the lib is throwing the following exception:
15:49:42.811 [Thread-41] ERROR c.g.f.j.c.RedisOperationExecutor - Malformed request
java.lang.UnsupportedOperationException: Unsupported operation 'eval'
at com.github.fppt.jedismock.commands.RedisOperationExecutor.buildSimpleOperation(RedisOperationExecutor.java:148)
at com.github.fppt.jedismock.commands.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:166)
at com.github.fppt.jedismock.RedisClient.run(RedisClient.java:48)
at java.lang.Thread.run(Thread.java:748)
Is eval already supported?
How can I make it work?
The sismember operation is unsupported.
There is no hget method.
When I try building the mock and running the test, one test case sometimes (in about 40% of the attempts) fails:
sscanIterates(com.github.fppt.jedismock.comparisontests.SimpleOperationsTest) Time elapsed: 0.007 sec <<< FAILURE!
org.junit.experimental.theories.internal.ParameterizedAssertionError: sscanIterates("redis.clients.jedis.Jedis@647e447" <from jedis[0]>)
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:631)
at com.github.fppt.jedismock.comparisontests.SimpleOperationsTest.sscanIterates(SimpleOperationsTest.java:640)
When trying to use debugger, I found out that the test measures iterations in sscan, expecting it to take 5 iterations with 10 "page" size to fetch 45 elements.
However, sometimes I've seen in the debugger that higher amount of elements are returned per call (between 11 and 13 instead of 10), and as the sscan then completes in only 4 iterations instead of 5, it ends as assertion failure.
Possibly some race condition with other test case modifying default "page" size?
I am using OpenJDK 12 for the build.
Same problem
redis/jedis#397
The psubscribe operation is unsupported.
Please note that I am not a Redis expert and that all the examples are in Kotlin.
In my application I got simple class to set hash which should expire after a given amount of time.
override fun method(key: String): String {
return connectionPool.resource.use {
it.hsetnx(key, HASH_CONST, UUID.randomUUID().toString())
it.expire(key, EXPIRE_CONST)
return it.hget(key, HASH_CONST)
}
}
I wrote a simple test which calls this method with given ID, then it waits more than the EXPIRE_CONST
and then calls this method once again with same ID.
Result of this method should be different but it's the same.
After analyzing code of this library I saw that expire returns 0 instead of 1. I came to conclusion that the problem is Slice.reserved()
call in ExpiringKeyValueStorage.java:87
. When value is set using hset()
the key2
value should be set to hash key value, not the "Reserved String In Jedis Mock"
.
One solution might be to iterate over hash keys and setting timeout for every one of them.
Hi, "rename" operation is not supported.
Hello,
I get following error: Unsupported operation 'info'
Greetings
Triggered when setting the client name during jedis pool setup. (Works against real redis).
Cannot flush the db with flushAll()
Jedis jedis = jedisPool.getResource();
jedis.flushAll();
jedis.close();
Add support for 'hvals'.
thinks!
Actual:
Unsupported operation 'scard'; nested exception is redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'scard'
Expected:
"scard" operation expected to be work on jedis operation, which is available from redis version: 1.0.0
Hi,
We're attempting to upgrade from v5.3.3.RELEASE of the lettuce redis client to v6.0.1.RELEASE.
When running unit tests with jedis-mock, we have the following exception:
11:03:02.189 [lettuce-nioEventLoop-40-1] DEBUG io.lettuce.core.AbstractRedisClient - Connecting to Redis at localhost:50385, initialization: localhost:50385
java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: Unsupported operation 'hello'
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:943)
at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
at io.lettuce.core.RedisHandshake.lambda$tryHandshakeResp3$1(RedisHandshake.java:105)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
at io.lettuce.core.protocol.AsyncCommand.doCompleteExceptionally(AsyncCommand.java:139)
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120)
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:704)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:639)
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:560)
Per readme, submitting an issue. Thanks!
Unsupported operation 'hscan'
Mocks for hmset/hmget commands would be very valuable for my use case.
Thanks!
Hello,
I get following error
Caused by: redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'hsetnx' at redis.clients.jedis.Protocol.processError(Protocol.java:127) at redis.clients.jedis.Protocol.process(Protocol.java:161) at redis.clients.jedis.Protocol.read(Protocol.java:215) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265) at redis.clients.jedis.BinaryJedis.hsetnx(BinaryJedis.java:870)
Greetings
Caused by: io.lettuce.core.RedisCommandExecutionException: Unsupported operation 'evalsha'
at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:135) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:108) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandWrapper.complete(CommandWrapper.java:59) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:654) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:614) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:565) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.49.Final.jar:4.1.49.Final]
... 1 more
TTL -related parameters of Redis SET - command are not supported in the RO_set
I encountered this when updating my Spring Boot application to Spring Boot version 2.2.4. This application uses Redis Cache, which used separate Redis SET & EXPIRE commands when storing the item to the cache, but now at Spring Boot (& Spring Data) version 2.2.4 the storing is done using SET cmd with TTL parameter included. And now the jedis-mock can't serve so well in the testing of my microservice cache functionalities.
Versions
jedis = 'redis.clients:jedis:3.0.1'
jedisMock = 'com.github.fppt:jedis-mock:0.1.14'
I do
jedis.rpoplpush(queueName, "processing")
I got
Exception in thread "Thread-4" com.github.fppt.jedismock.exception.ParseErrorException
at com.github.fppt.jedismock.server.SliceParser.consumeLong(SliceParser.java:51)
at com.github.fppt.jedismock.server.SliceParser.consumeParameter(SliceParser.java:114)
at com.github.fppt.jedismock.server.SliceParser.consumeParameter(SliceParser.java:127)
at com.github.fppt.jedismock.operations.RO_rpoplpush.response(RO_rpoplpush.java:22)
at com.github.fppt.jedismock.operations.AbstractRedisOperation.execute(AbstractRedisOperation.java:47)
at com.github.fppt.jedismock.server.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:43)
at com.github.fppt.jedismock.server.RedisClient.run(RedisClient.java:54)
at java.lang.Thread.run(Thread.java:748)
java.net.SocketTimeoutException: Read timed out
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
at redis.clients.jedis.util.RedisInputStream.ensureFill(RedisInputStream.java:205)
at redis.clients.jedis.util.RedisInputStream.readByte(RedisInputStream.java:43)
at redis.clients.jedis.Protocol.process(Protocol.java:154)
at redis.clients.jedis.Protocol.read(Protocol.java:219)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:309)
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:255)
at redis.clients.jedis.Connection.getBulkReply(Connection.java:245)
at redis.clients.jedis.Jedis.rpoplpush(Jedis.java:1195)
Hi,
I'm using embedded redis server in a unit test that increments a counter, and then gets the value using the jedis.get(counterName) command.
All works fine, but the debug output from the jedismock is weird:
It correctly shows expected response from the incr() command (the new value of the counter)
but it prepends "$1" prefix tot he value returned fromt he get() command :) - see examples below:
In this case the correct value of the counter is "5":
10:02:23.126 [Thread-1] DEBUG com.github.fppt.jedismock.Response - Received command [incr] sending reply [:5]
10:02:23.127 [Thread-1] DEBUG com.github.fppt.jedismock.Response - Received command [get] sending reply [$15]
In this case the correct value of the counter is "1":
10:02:23.135 [Thread-3] DEBUG com.github.fppt.jedismock.Response - Received command [incr] sending reply [:1]
10:02:23.136 [Thread-3] DEBUG com.github.fppt.jedismock.Response - Received command [get] sending reply [$11]
Thank you!!!
Deleting a hash with more than one field results in a java.util.ConcurrentModificationException
.
This is due to the following piece of code in the class ExpiringKeyValueStorage
:
public void delete(Slice key) {
for (Slice key2 : values().row(key).keySet())
delete(key, key2);
}
public void delete(Slice key1, Slice key2){
Preconditions.checkNotNull(key1);
Preconditions.checkNotNull(key2);
values().remove(key1, key2);
ttls().remove(key1, key2);
}
The iterator of the row's keySet complains because it is view of the values that get removed with values().remove(key1, key2)
.
Add to SET the functionalities of EX PX NX XX, as described in https://redis.io/commands/set for Redis 2.6.12.
Will be awesome to have blpop
and brpop
implemented here
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.