From 256e613635b10d7090f3372e1eaac8d6646b22a9 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 1 Jul 2021 19:21:08 +0600 Subject: [PATCH] Modify MEMORY USAGE tests (#2573) * Modify MEMORY USAGE tests According to Redis developers, MEMORY USAGE response should not be tested with exact values. * add note * edit comment --- .../tests/commands/ControlCommandsTest.java | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java index 8218178437..f6280b14cb 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.List; @@ -201,15 +202,41 @@ public void memoryDoctorBinary() { @Test public void memoryUsageString() { - jedis.set("foo", "ba"); - Long usage = jedis.memoryUsage("foo"); - assertEquals(49 + 3, (long) usage); + // Note: It has been recommended not to base MEMORY USAGE test on exact value, as the response + // may subject to be 'tuned' especially targeting a major Redis release. - jedis.lpush("loo", "ba", "da", "sha"); - usage = jedis.memoryUsage("loo", 2); - assertEquals(141 + 3, (long) usage); + jedis.set("foo", "bar"); + long usage = jedis.memoryUsage("foo"); + assertTrue(usage >= 30); + assertTrue(usage <= 80); + + jedis.lpush("foobar", "fo", "ba", "sha"); + usage = jedis.memoryUsage("foobar", 2); + assertTrue(usage >= 110); + assertTrue(usage <= 190); + + assertNull(jedis.memoryUsage("roo", 2)); + } + + @Test + public void memoryUsageBinary() { + // Note: It has been recommended not to base MEMORY USAGE test on exact value, as the response + // may subject to be 'tuned' especially targeting a major Redis release. + + byte[] bfoo = {0x01, 0x02, 0x03, 0x04}; + byte[] bbar = {0x05, 0x06, 0x07, 0x08}; + byte[] bfoobar = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; + + jedis.set(bfoo, bbar); + long usage = jedis.memoryUsage(bfoo); + assertTrue(usage >= 30); + assertTrue(usage <= 80); + + jedis.lpush(bfoobar, new byte[]{0x01, 0x02}, new byte[]{0x05, 0x06}, new byte[]{0x00}); + usage = jedis.memoryUsage(bfoobar, 2); + assertTrue(usage >= 110); + assertTrue(usage <= 190); - usage = jedis.memoryUsage("roo", 2); - assertEquals(null, usage); + assertNull(jedis.memoryUsage("roo", 2)); } }