1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| @Test public void test() throws InterruptedException { final List<Long> list = Lists.newArrayListWithCapacity(5000000); Long first_id = 500000000000000001L; for (int i = 0; i < 5000000; i++) { list.add(first_id++); }
final CountDownLatch allDone = new CountDownLatch(2);
new Thread( new Runnable() { @Override public void run() { try { testIncrby(list); } catch (InterruptedException e) { } allDone.countDown(); } } ).start();
new Thread( new Runnable() { @Override public void run() { try { testIncrByAndDel(list); } catch (InterruptedException e) { } allDone.countDown(); } } ).start();
allDone.await(); log.info("finish method test"); }
@Test public void testDelAndTTL() throws InterruptedException { final List<Long> list = Lists.newArrayListWithCapacity(5000000); Long first_id = 500000000000000001L; for (int i = 0; i < 5000000; i++) { list.add(first_id++); }
final CountDownLatch allDone = new CountDownLatch(2);
new Thread( new Runnable() { @Override public void run() { testDelAndTTL(list, "walletMember"); allDone.countDown(); log.info("finish walletMember keys"); } } ).start();
new Thread( new Runnable() { @Override public void run() { testDelAndTTL(list, "walletMember1"); allDone.countDown(); log.info("finish walletMember1 keys"); } } ).start();
allDone.await(); log.info("finish all keys"); }
private void testIncrby(final List<Long> list) throws InterruptedException { long times = 0L; for(;;){ times ++; for (Long key : list) { Optional<Long> value = redisOperator.incrBy("walletMember" + key, 1); if (value.isPresent()) { if (value.get() != 1L) { log.error("there is something wrong in {}: the incrBy method return wrong value, expact : {} , result : {}, key : {}", "testIncrby", 1, value.get(), "walletMember" + key); continue; } } else { log.error("there is something wrong in {}: the incrBy method return wrong value, expact : {} , result : {}, key : {}", "testIncrby", 1, null, "walletMember" + key); } Optional<Boolean> isSuccess = redisOperator.expire("walletMember" + key, 30); if (!isSuccess.isPresent() || !isSuccess.get()) { log.error("there is something wrong in {}: the expire method return wrong value, expact : {} , result : {}, key : {}", "testIncrby", "true", (isSuccess.isPresent() ? isSuccess.get() : null), "walletMember" + key); } } log.info("finish {} method {} times. sleep 35 seconds", "testIncrby", times); Thread.sleep(60*5*1000L); if(times > 1000000) { return ; } } }
private void testIncrByAndDel(final List<Long> list) throws InterruptedException { long times = 0L; for(;;) { times ++; for (Long key : list) { Optional<Long> value = redisOperator.incrBy("walletMember1"+key, 1); if(value.isPresent()) { if(value.get() != 1L) { log.error("there is something wrong in {} method: the incrBy method return wrong value, expact : {} , result : {}, key : {}", "testIncrByAndDel", 1, value.get(), "walletMember1" + key); continue; } } else { log.error("there is something wrong in {} method: the incrBy method return wrong value, expact : {} , result : {}, key : {}", "testIncrByAndDel", 1, null, "walletMember1" + key); } Optional<Boolean> isSuccess= redisOperator.expire("walletMember"+key, 60); if(!isSuccess.isPresent() || !isSuccess.get()) { log.error("there is something wrong in {}: the expire method return wrong value, expact : {} , result : {}, key : {}", "testIncrByAndDel", "true", (isSuccess.isPresent() ? isSuccess.get() : null), "walletMember1" + key); } redisOperator.del("walletMember1"+key); } log.info("finish {} method {} times. sleep 35 seconds", "testIncrByAndDel", times); Thread.sleep(60*5*1000L); if(times > 1000000) { return ; } } }
private void testDelAndTTL(final List<Long> list, String prefix) { for (Long key : list) { Optional<Integer> value = redisOperator.get(prefix + key, Integer.class); if(value.isPresent()) { Long ttl = redisOperator.getFastJsonRedisTemplate().getExpire(prefix + key); log.error("there is something wrong : key : {}, value : {}, ttl : {}", prefix + key, value.get(), ttl); } } }
|