|
21 | 21 | package com.apple.foundationdb.record.provider.common;
|
22 | 22 |
|
23 | 23 | import org.junit.jupiter.api.Test;
|
| 24 | + |
| 25 | +import javax.annotation.Nonnull; |
24 | 26 | import javax.crypto.Cipher;
|
25 | 27 | import java.security.GeneralSecurityException;
|
26 | 28 |
|
|
40 | 42 | public class MappedPoolTest {
|
41 | 43 |
|
42 | 44 | public static String CIPHER = "DES/ECB/PKCS5Padding";
|
43 |
| - public static MappedPool<String, Cipher, GeneralSecurityException> MAPPED_POOL = new MappedPool<>(Cipher::getInstance); |
| 45 | + |
| 46 | + @Nonnull |
| 47 | + private MappedPool<String, Cipher, GeneralSecurityException> getPool() { |
| 48 | + return new MappedPool<>(Cipher::getInstance); |
| 49 | + } |
44 | 50 |
|
45 | 51 | @Test
|
46 | 52 | public void testCipherPool() throws Exception {
|
| 53 | + final var mappedPool = getPool(); |
47 | 54 | Cipher lastCipher = null;
|
48 | 55 | for (int i = 0; i < 100; i++) {
|
49 |
| - Cipher cipher = MAPPED_POOL.poll(CIPHER); |
| 56 | + Cipher cipher = mappedPool.poll(CIPHER); |
50 | 57 | if (lastCipher != null) {
|
51 | 58 | assertSame(cipher, lastCipher);
|
52 | 59 | lastCipher = cipher;
|
53 | 60 | }
|
54 | 61 | assertNotNull(cipher);
|
55 |
| - assertTrue(MAPPED_POOL.offer(CIPHER, cipher)); |
| 62 | + assertTrue(mappedPool.offer(CIPHER, cipher)); |
56 | 63 | }
|
57 |
| - assertEquals(1, MAPPED_POOL.getPoolSize(CIPHER)); |
58 |
| - assertThat(MAPPED_POOL.getKeys(), hasItem(CIPHER)); |
| 64 | + assertEquals(1, mappedPool.getPoolSize(CIPHER)); |
| 65 | + assertThat(mappedPool.getKeys(), hasItem(CIPHER)); |
59 | 66 | }
|
60 | 67 |
|
61 | 68 | @Test
|
62 | 69 | public void testMaxPoolSize() throws Exception {
|
| 70 | + final var mappedPool = getPool(); |
63 | 71 | Cipher[] ciphers = new Cipher[1000];
|
64 | 72 | for (int i = 0; i < 1000; i++) {
|
65 |
| - ciphers[i] = MAPPED_POOL.poll(CIPHER); |
| 73 | + ciphers[i] = mappedPool.poll(CIPHER); |
66 | 74 | }
|
67 | 75 | for (int i = 0; i < MappedPool.DEFAULT_POOL_SIZE; i++) {
|
68 |
| - assertTrue(MAPPED_POOL.offer(CIPHER, ciphers[i])); |
| 76 | + assertTrue(mappedPool.offer(CIPHER, ciphers[i])); |
69 | 77 | }
|
70 | 78 | for (int i = MappedPool.DEFAULT_POOL_SIZE; i < 1000; i++) {
|
71 |
| - assertFalse(MAPPED_POOL.offer(CIPHER, ciphers[i])); |
| 79 | + assertFalse(mappedPool.offer(CIPHER, ciphers[i])); |
72 | 80 | }
|
73 |
| - assertEquals(64, MAPPED_POOL.getPoolSize(CIPHER)); |
| 81 | + assertEquals(64, mappedPool.getPoolSize(CIPHER)); |
74 | 82 | }
|
75 | 83 |
|
76 | 84 | }
|
0 commit comments