()
| 70 | } |
| 71 | |
| 72 | @Test |
| 73 | void get() throws Throwable { |
| 74 | // With max time limits these tests take a minute to run. But with no changes to |
| 75 | // the memoizer it's simply testing overkill. Use a RNG to limit these tests |
| 76 | // regularly but occasionally run the longer tests. |
| 77 | int x = new Random().nextInt(50); |
| 78 | // Set minimal defaults |
| 79 | int refreshIters = 200; // ~ 2 seconds |
| 80 | int noRefreshIters = 2_000; // ~ 2 seconds |
| 81 | if (x == 0) { |
| 82 | // 2% chance full length noRefresh |
| 83 | noRefreshIters = 20_000; // ~ 20 seconds |
| 84 | } else if (x == 1) { |
| 85 | // 2% chance full length refresh |
| 86 | refreshIters = 4000; // ~ 40 seconds |
| 87 | } else if (x < 12) { |
| 88 | // 20% chance longer noRerfesh |
| 89 | noRefreshIters = 5_000; // ~ 5 seconds |
| 90 | } else if (x < 22) { |
| 91 | // 20% chance longer rerfesh |
| 92 | refreshIters = 500; // ~ 5 seconds |
| 93 | } |
| 94 | // Do tests with no refresh. |
| 95 | long iterationDurationNanos = TimeUnit.MILLISECONDS.toNanos(1); |
| 96 | long ttlNanos = -1; |
| 97 | for (int r = 0; r < noRefreshIters; r++) { |
| 98 | run(iterationDurationNanos, ttlNanos); |
| 99 | } |
| 100 | // Do tests with refresh after 0.1 ms. |
| 101 | iterationDurationNanos = TimeUnit.MILLISECONDS.toNanos(10); |
| 102 | ttlNanos = iterationDurationNanos / 100; |
| 103 | assertThat("ttlNanos should not be zero", ttlNanos, is(not(0L))); // avoid div/0 later |
| 104 | for (int r = 0; r < refreshIters; r++) { |
| 105 | run(iterationDurationNanos, ttlNanos); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | private void run(final long iterationDurationNanos, final long ttlNanos) throws Throwable { |
| 110 | final Supplier<Long> s = new Supplier<Long>() { |
no test coverage detected