1313import  com .maxmind .db .Networks ;
1414import  com .maxmind .db .Reader ;
1515
16+ import  org .apache .lucene .util .Constants ;
1617import  org .elasticsearch .common .network .NetworkAddress ;
1718import  org .elasticsearch .common .settings .Settings ;
1819import  org .elasticsearch .common .util .set .Sets ;
20+ import  org .elasticsearch .core .IOUtils ;
1921import  org .elasticsearch .core .SuppressForbidden ;
2022import  org .elasticsearch .core .TimeValue ;
2123import  org .elasticsearch .test .ESTestCase ;
@@ -48,17 +50,22 @@ public class IpinfoIpDataLookupsTests extends ESTestCase {
4850    private  ThreadPool  threadPool ;
4951    private  ResourceWatcherService  resourceWatcherService ;
5052
53+     // a temporary directory that mmdb files can be copied to and read from 
54+     private  Path  tmpDir ;
55+ 
5156    @ Before 
5257    public  void  setup () {
5358        threadPool  = new  TestThreadPool (ConfigDatabases .class .getSimpleName ());
5459        Settings  settings  = Settings .builder ().put ("resource.reload.interval.high" , TimeValue .timeValueMillis (100 )).build ();
5560        resourceWatcherService  = new  ResourceWatcherService (settings , threadPool );
61+         tmpDir  = createTempDir ();
5662    }
5763
5864    @ After 
59-     public  void  cleanup () {
65+     public  void  cleanup () throws   IOException   {
6066        resourceWatcherService .close ();
6167        threadPool .shutdownNow ();
68+         IOUtils .rm (tmpDir );
6269    }
6370
6471    public  void  testDatabasePropertyInvariants () {
@@ -82,7 +89,8 @@ public void testParseAsn() {
8289    }
8390
8491    public  void  testAsn () throws  IOException  {
85-         Path  configDir  = createTempDir ();
92+         assumeFalse ("https://github.com/elastic/elasticsearch/issues/114266" , Constants .WINDOWS );
93+         Path  configDir  = tmpDir ;
8694        copyDatabase ("ipinfo/ip_asn_sample.mmdb" , configDir .resolve ("ip_asn_sample.mmdb" ));
8795        copyDatabase ("ipinfo/asn_sample.mmdb" , configDir .resolve ("asn_sample.mmdb" ));
8896
@@ -91,8 +99,7 @@ public void testAsn() throws IOException {
9199        configDatabases .initialize (resourceWatcherService );
92100
93101        // this is the 'free' ASN database (sample) 
94-         {
95-             DatabaseReaderLazyLoader  loader  = configDatabases .getDatabase ("ip_asn_sample.mmdb" );
102+         try  (DatabaseReaderLazyLoader  loader  = configDatabases .getDatabase ("ip_asn_sample.mmdb" )) {
96103            IpDataLookup  lookup  = new  IpinfoIpDataLookups .Asn (Set .of (Database .Property .values ()));
97104            Map <String , Object > data  = lookup .getData (loader , "5.182.109.0" );
98105            assertThat (
@@ -110,8 +117,7 @@ public void testAsn() throws IOException {
110117        }
111118
112119        // this is the non-free or 'standard' ASN database (sample) 
113-         {
114-             DatabaseReaderLazyLoader  loader  = configDatabases .getDatabase ("asn_sample.mmdb" );
120+         try  (DatabaseReaderLazyLoader  loader  = configDatabases .getDatabase ("asn_sample.mmdb" )) {
115121            IpDataLookup  lookup  = new  IpinfoIpDataLookups .Asn (Set .of (Database .Property .values ()));
116122            Map <String , Object > data  = lookup .getData (loader , "23.53.116.0" );
117123            assertThat (
@@ -132,7 +138,8 @@ public void testAsn() throws IOException {
132138    }
133139
134140    public  void  testAsnInvariants () {
135-         Path  configDir  = createTempDir ();
141+         assumeFalse ("https://github.com/elastic/elasticsearch/issues/114266" , Constants .WINDOWS );
142+         Path  configDir  = tmpDir ;
136143        copyDatabase ("ipinfo/ip_asn_sample.mmdb" , configDir .resolve ("ip_asn_sample.mmdb" ));
137144        copyDatabase ("ipinfo/asn_sample.mmdb" , configDir .resolve ("asn_sample.mmdb" ));
138145
@@ -168,16 +175,16 @@ public void testAsnInvariants() {
168175    }
169176
170177    public  void  testCountry () throws  IOException  {
171-         Path  configDir  = createTempDir ();
178+         assumeFalse ("https://github.com/elastic/elasticsearch/issues/114266" , Constants .WINDOWS );
179+         Path  configDir  = tmpDir ;
172180        copyDatabase ("ipinfo/ip_country_sample.mmdb" , configDir .resolve ("ip_country_sample.mmdb" ));
173181
174182        GeoIpCache  cache  = new  GeoIpCache (1000 ); // real cache to test purging of entries upon a reload 
175183        ConfigDatabases  configDatabases  = new  ConfigDatabases (configDir , cache );
176184        configDatabases .initialize (resourceWatcherService );
177185
178186        // this is the 'free' Country database (sample) 
179-         {
180-             DatabaseReaderLazyLoader  loader  = configDatabases .getDatabase ("ip_country_sample.mmdb" );
187+         try  (DatabaseReaderLazyLoader  loader  = configDatabases .getDatabase ("ip_country_sample.mmdb" )) {
181188            IpDataLookup  lookup  = new  IpinfoIpDataLookups .Country (Set .of (Database .Property .values ()));
182189            Map <String , Object > data  = lookup .getData (loader , "4.221.143.168" );
183190            assertThat (
0 commit comments