Skip to content

Commit 8555c16

Browse files
Fix testPurgeCacheEntriesForDatabase on Windows (#129648)
Our hypothesis is that the path is not round-tripping on Windows. This fixes the test by always using the canonical string for the path, when inserting and when purging. Fixes #129635
1 parent 1bcd9b4 commit 8555c16

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpCacheTests.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.ingest.geoip.stats.CacheStats;
1818
import org.elasticsearch.test.ESTestCase;
1919

20+
import java.nio.file.Path;
2021
import java.util.concurrent.atomic.AtomicInteger;
2122
import java.util.concurrent.atomic.AtomicLong;
2223
import java.util.function.Function;
@@ -140,23 +141,25 @@ public void testPurgeCacheEntriesForDatabase() {
140141
GeoIpCache cache = new GeoIpCache(100);
141142
ProjectId projectId1 = randomUniqueProjectId();
142143
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");
145148
String ip1 = "127.0.0.1";
146149
String ip2 = "127.0.0.2";
147150

148151
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);
154157
// 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()));
157160
// ...but left the one for projectId2...
158-
assertSame(response, cache.get(projectId2, ip1, databasePath1));
161+
assertSame(response, cache.get(projectId2, ip1, databasePath1.toString()));
159162
// ...and for databasePath2:
160-
assertSame(response, cache.get(projectId1, ip1, databasePath2));
163+
assertSame(response, cache.get(projectId1, ip1, databasePath2.toString()));
161164
}
162165
}

0 commit comments

Comments
 (0)