From 52c356476e296d84bcc7bf9e6bf2ce7499b860d4 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Thu, 12 Nov 2026 19:37:17 +0000 Subject: [PATCH 1/2] Test that the IP Intelligence benchmark asks only for the property it reads The properties move into benchmarkProperties, which the new test calls, with the behaviour unchanged, so the test fails here. --- .../console/PerformanceBenchmark.java | 18 +++++- .../PerformanceBenchmarkPropertiesTest.java | 61 +++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmarkPropertiesTest.java diff --git a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java index e9b5f568..6d2112e8 100644 --- a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java +++ b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java @@ -103,6 +103,8 @@ public class PerformanceBenchmark { private int numberOfThreads = DEFAULT_NUMBER_OF_THREADS; private List> evidence; private String dataFileLocation; + // the properties asked for when not asking for all of them + private List properties; private PrintWriter writer; // a default set of configurations: (profile, allProperties) @@ -147,6 +149,7 @@ protected void runBenchmarks(PerformanceConfiguration[] performanceConfiguration logger.info("Running Performance example"); this.dataFileLocation = getDataFileLocation(dataFilename); + this.properties = benchmarkProperties(dataFileLocation); File evidenceFile = getEvidenceFile(evidenceFilename); this.evidence = Collections.unmodifiableList( @@ -242,11 +245,22 @@ private void setPipelinePerformanceProperties( // Enterprise data files have RegisteredName, so the benchmark runs // with any of them. if (BooleanUtils.isFalse(config.allProperties)) { - builder.setProperty("RegisteredName"); - builder.setProperty("AsnName"); + for (String property : properties) { + builder.setProperty(property); + } } } + /** + * The properties the benchmark asks for when it does not ask for all of + * them. + * @param dataFileLocation the data file the benchmark uses + * @return the properties to ask for + */ + static List benchmarkProperties(String dataFileLocation) { + return Arrays.asList("RegisteredName", "AsnName"); + } + /** * Report per thread and overall lookup performance * @throws Exception to satisfy needs of called APIs diff --git a/examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmarkPropertiesTest.java b/examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmarkPropertiesTest.java new file mode 100644 index 00000000..5490a8c0 --- /dev/null +++ b/examples/ip-intelligence/console/src/test/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmarkPropertiesTest.java @@ -0,0 +1,61 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.ipintelligence.examples.console; + +import fiftyone.ipintelligence.examples.shared.DataFileHelper; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeTrue; + +/** + * Checks that the performance benchmark asks only for the property it reads, + * being RegisteredName where the data file has it and AsnName for the free + * Asn data file, which has no RegisteredName. + */ +public class PerformanceBenchmarkPropertiesTest { + + @Test + public void registeredNameAloneWhenTheDataFileHasIt() throws Exception { + String dataFile = DataFileHelper.findAvailableDataFile( + DataFileHelper.ENTERPRISE_DATA_FILE_REL_PATH, + DataFileHelper.LITE_DATA_FILE_REL_PATH); + assumeTrue("Skipping test, no IP Intelligence data file with the " + + "RegisteredName property found", + dataFile != null); + assertEquals(Collections.singletonList("RegisteredName"), + PerformanceBenchmark.benchmarkProperties(dataFile)); + } + + @Test + public void asnNameAloneWithTheAsnDataFile() throws Exception { + String dataFile = DataFileHelper.findAvailableDataFile( + DataFileHelper.ASN_DATA_FILE_REL_PATH); + assumeTrue("Skipping test, no free Asn IP Intelligence data file found", + dataFile != null); + assertEquals(Collections.singletonList("AsnName"), + PerformanceBenchmark.benchmarkProperties(dataFile)); + } +} From 60302c50d372979ff4ef26aeec1dd1f3ca85c32a Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Thu, 12 Nov 2026 19:37:25 +0000 Subject: [PATCH 2/2] Ask the IP Intelligence benchmark only for the property it reads The benchmark asked for RegisteredName and AsnName, so that it ran with the free Asn data file. With the Enterprise data file each lookup then did the work for both properties. It now opens the data file with the low memory profile and asks for RegisteredName where the file has it, and AsnName otherwise. --- .../console/PerformanceBenchmark.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java index 6d2112e8..d3c03c4e 100644 --- a/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java +++ b/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java @@ -35,8 +35,9 @@ * This example is available in full on [GitHub](https://github.com/51Degrees/51degrees-java/blob/main/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java). * * By default the example uses the free Asn IP Intelligence data file, which it downloads when it - * is missing, and is far smaller than the Lite file. It asks for RegisteredName and AsnName, so - * it runs with any of the data files. To obtain an Enterprise data file, please + * is missing, and is far smaller than the Lite file. It asks only for the property it reads, + * being RegisteredName, or AsnName with the free Asn data file, which has no RegisteredName, + * so it runs with any of the data files. To obtain an Enterprise data file, please * [contact us](https://51degrees.com/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=console-src-main-java-fiftyone-ipintelligence-examples-console-performancebenchmark.java&utm_term=header). * * Required Maven Dependencies: @@ -51,6 +52,7 @@ import fiftyone.ipintelligence.examples.shared.DataFileHelper; import fiftyone.ipintelligence.examples.shared.EvidenceHelper; import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngine; +import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngineBuilder; import fiftyone.ipintelligence.shared.IPIntelligenceData; import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.core.data.IWeightedValue; @@ -240,10 +242,9 @@ private void setPipelinePerformanceProperties( // Requesting properties from a single component // reduces processing time compared with requesting properties from multiple components. // If you don't specify any properties, then all properties are returned, - // here we choose "all properties" by specifying none, or just "RegisteredName" - // and "AsnName". The free Asn data file has AsnName, and the Lite and - // Enterprise data files have RegisteredName, so the benchmark runs - // with any of them. + // here we choose "all properties" by specifying none, or just the + // one property the benchmark reads, which benchmarkProperties + // chooses for the data file. if (BooleanUtils.isFalse(config.allProperties)) { for (String property : properties) { builder.setProperty(property); @@ -253,12 +254,26 @@ private void setPipelinePerformanceProperties( /** * The properties the benchmark asks for when it does not ask for all of - * them. + * them, being only the one it reads. That is RegisteredName where the + * data file has it, as the Lite and Enterprise data files do, and + * AsnName for the free Asn data file, which has no RegisteredName. The + * data file is opened with the low memory profile, which reads little + * of it. * @param dataFileLocation the data file the benchmark uses - * @return the properties to ask for + * @return the one property to ask for + * @throws Exception if the data file cannot be opened */ - static List benchmarkProperties(String dataFileLocation) { - return Arrays.asList("RegisteredName", "AsnName"); + static List benchmarkProperties(String dataFileLocation) + throws Exception { + try (IPIntelligenceOnPremiseEngine engine = + new IPIntelligenceOnPremiseEngineBuilder() + .setPerformanceProfile(LowMemory) + .setAutoUpdate(false) + .build(dataFileLocation, false)) { + return Collections.singletonList( + DataFileHelper.hasProperty(engine, "RegisteredName") ? + "RegisteredName" : "AsnName"); + } } /**