Skip to content
forked from fppt/jedis-mock

A simple redis java mock for unit testing

License

Notifications You must be signed in to change notification settings

24kpure/jedis-mock

 
 

Repository files navigation

GitHub release Maven Central Build Status

Jedis-Mock

Redis Mock is a simple in-memory mock of redis for java testing. It allows you to test any behaviour dependent on redis without having to deploy an instance of redis

Quickstart

Add it as a dependency in Maven as:

<dependency>
  <groupId>com.github.24kpure</groupId>
  <artifactId>jedis-mock</artifactId>
  <version>0.0.1</version>
</dependency>

Create a redis server and bind it to jedis:

private static RedisServer server = null;

@Before
public void before() throws IOException {
  server = RedisServer.newRedisServer();  // bind to a random port
  server.start();
}

@Test
public void test() {
  ...
  Jedis jedis = new Jedis(server.getHost(), server.getBindPort());
  ...
}

@After
public void after() {
  server.stop();
  server = null;
}

From here test as needed

Fault tolerance testing

We can make a RedisServer close connection after every several commands. This will cause a connection exception for clients.

RedisServer server = RedisServer.newRedisServer();
ServiceOptions options = new ServiceOptions();
options.setCloseSocketAfterSeveralCommands(3);
server.setOptions(options);
server.start();

Supported Operations

All currently supported operations are listed here

Missing Operations

If you get the following error:

Unsupported operation {}

Please feel free to create an issue requesting the missing operation.

About

A simple redis java mock for unit testing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%