kstyrc / embedded-redis

Redis embedded server for Java integration testing
840 stars 368 forks source link

redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream #78

Open evbo opened 7 years ago

evbo commented 7 years ago

It does not seem possible to start and stop the embedded redis database within separate, isolated unit tests that implement redislabs' Spark Redis.

The second unit test below fails with: redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream

import com.holdenkarau.spark.testing.SharedSparkContext
import com.redislabs.provider.redis.{RedisConfig, RedisEndpoint}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfterEach, FlatSpec, Matchers}
import redis.embedded.RedisServer

@RunWith(classOf[JUnitRunner])
class RedisSpec extends FlatSpec with SharedSparkContext with BeforeAndAfterEach with Matchers {

  "first test" should "connect and close redis" in {
    val redisEmbedded = new RedisServer(6379)
    redisEmbedded.start()
    val redisConfig = new RedisConfig(new RedisEndpoint("localhost", 6379))
    redisEmbedded.stop()
  }

  "second test" should "also connect and close redis" in {
    val redisEmbedded = new RedisServer(6379)
    redisEmbedded.start()
    // fails here:
    val redisConfig = new RedisConfig(new RedisEndpoint("localhost", 6379))
    redisEmbedded.stop()
  }
}

This issue is also captured here for similar contexts: https://github.com/kstyrc/embedded-redis/issues/31 http://stackoverflow.com/questions/28737107/redis-clients-jedis-exceptions-jedisconnectionexception-unexpected-end-of-strea