|
17 | 17 | import org.elasticsearch.ingest.geoip.stats.CacheStats; |
18 | 18 | import org.elasticsearch.test.ESTestCase; |
19 | 19 |
|
| 20 | +import java.nio.file.Path; |
20 | 21 | import java.util.concurrent.atomic.AtomicInteger; |
21 | 22 | import java.util.concurrent.atomic.AtomicLong; |
22 | 23 | import java.util.function.Function; |
@@ -140,23 +141,25 @@ public void testPurgeCacheEntriesForDatabase() { |
140 | 141 | GeoIpCache cache = new GeoIpCache(100); |
141 | 142 | ProjectId projectId1 = randomUniqueProjectId(); |
142 | 143 | ProjectId projectId2 = randomUniqueProjectId(); |
143 | | - String databasePath1 = "path/to/db1"; |
144 | | - String databasePath2 = "path/to/db2"; |
| 144 | + // Turn the path strings into Paths to ensure that we always use the canonical string representation (this string literal does not |
| 145 | + // round-trip when converting to a Path and back again on Windows): |
| 146 | + Path databasePath1 = PathUtils.get("path/to/db1"); |
| 147 | + Path databasePath2 = PathUtils.get("path/to/db2"); |
145 | 148 | String ip1 = "127.0.0.1"; |
146 | 149 | String ip2 = "127.0.0.2"; |
147 | 150 |
|
148 | 151 | AbstractResponse response = mock(AbstractResponse.class); |
149 | | - cache.putIfAbsent(projectId1, ip1, databasePath1, ip -> response); // cache miss |
150 | | - cache.putIfAbsent(projectId1, ip2, databasePath1, ip -> response); // cache miss |
151 | | - cache.putIfAbsent(projectId2, ip1, databasePath1, ip -> response); // cache miss |
152 | | - cache.putIfAbsent(projectId1, ip1, databasePath2, ip -> response); // cache miss |
153 | | - cache.purgeCacheEntriesForDatabase(projectId1, PathUtils.get(databasePath1)); |
| 152 | + cache.putIfAbsent(projectId1, ip1, databasePath1.toString(), ip -> response); // cache miss |
| 153 | + cache.putIfAbsent(projectId1, ip2, databasePath1.toString(), ip -> response); // cache miss |
| 154 | + cache.putIfAbsent(projectId2, ip1, databasePath1.toString(), ip -> response); // cache miss |
| 155 | + cache.putIfAbsent(projectId1, ip1, databasePath2.toString(), ip -> response); // cache miss |
| 156 | + cache.purgeCacheEntriesForDatabase(projectId1, databasePath1); |
154 | 157 | // should have purged entries for projectId1 and databasePath1... |
155 | | - assertNull(cache.get(projectId1, ip1, databasePath1)); |
156 | | - assertNull(cache.get(projectId1, ip2, databasePath1)); |
| 158 | + assertNull(cache.get(projectId1, ip1, databasePath1.toString())); |
| 159 | + assertNull(cache.get(projectId1, ip2, databasePath1.toString())); |
157 | 160 | // ...but left the one for projectId2... |
158 | | - assertSame(response, cache.get(projectId2, ip1, databasePath1)); |
| 161 | + assertSame(response, cache.get(projectId2, ip1, databasePath1.toString())); |
159 | 162 | // ...and for databasePath2: |
160 | | - assertSame(response, cache.get(projectId1, ip1, databasePath2)); |
| 163 | + assertSame(response, cache.get(projectId1, ip1, databasePath2.toString())); |
161 | 164 | } |
162 | 165 | } |
0 commit comments