This article is still about the embedded dependencies needed for integration tests. Yes, as the title said, embedded redis. Show
We use ozimov embedded redis which is the development of kstyrc embedded redis. Let’s begin by adding ozimov embedded redis dependency. <dependency> Followed by adding the embedded server property to application.properties (src/test/resources) spring.redis.host=localhost Now, let’s say we have an API to get student data from redis. Here is a sample code of it: //StudentController.java At he StudentIntegrationTest.java, we need to autowire RedisTemplate to write the data into redis and ObjectMapper just to convert object to String. And then we create RedisServer object ... Then we initialize the redisServer under setUp method @Before And don’t forget to stop what we have started. :D @After On Windows OS, when you run the integration test, you might get the following error: Caused by: java.lang.RuntimeException: Can't start redis server. Check logs for details. And if you’re diligent enough to debug on The Windows version of Redis allocates a memory mapped heap for sharing with the forked process used for persistence operations. In order to share this memory, Windows allocates from the system paging file a portion equal to the size of the Redis heap To fix that, you can add setting max memory on redisServer initialization redisServer = RedisServer.builder().port(6370).setting("maxmemory 128M").build(); Finally, we can start the test method. First, we initialize the student object which we will store in redis. @Test convert the student object into String to store it to redis. try { Last we call the API and assert the result. this.mockMvc That’s it. Quite simple, right? :D java.lang.RuntimeException: Cant start redis server. Check logs for detailsQuestions : java.lang.RuntimeException: Cant start redis server. Check logs for details2022-09-28T05:07:45+00:00 2022-09-28T05:07:45+00:00 810 I am using Redis server of Windows version anycodings_windows 3.2.x (MSOpenTech Redis 3.2 Release Notes). anycodings_windows I am developing Spring Boot + Spring Data anycodings_windows Redis example and I am contineously getting anycodings_windows the below error.
In this case I always need to restart my anycodings_windows machine. Is there any solution? I dont have anycodings_windows admin rights on my machine, so machine anycodings_windows reboot is the only option. Total Answers 2 28 Answers 1 : of java.lang.RuntimeException: Cant start redis server. Check logs for detailsStop any Redis services operating anycodings_windows currently outside the IDE or change the anycodings_windows embedded Redis port to a different port 0 2022-09-28T05:07:45+00:00 2022-09-28T05:07:45+00:00Answer Link mRahman 3 Answers 2 : of java.lang.RuntimeException: Cant start redis server. Check logs for detailsFor me change of port didn't work out. anycodings_windows so I opened task manager and then under anycodings_windows details tab killed anycodings_windows redis-server-0.7.2.exe process and it anycodings_windows worked. 0 2022-09-28T05:07:45+00:00 2022-09-28T05:07:45+00:00Answer Link jidam |