From 04868c54c8139fcf6163541540879c6243ec06fb Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 19 Mar 2021 18:18:10 +0000 Subject: Fix write failure on PDP statistics Due to the precision of time stamps being saved to the nearest second, a millisecond precision timestamp was being compared to a second precision timestamp, causing the write to fail. This change fixes that. A unit test is also added to test for this on the provider. In addition, a USE-MARIADB flag is being introduced, which allows unit tests to be run against a locally installed MariaDB instance so that the unit tests can be verified against MariaDB locally rather than H2, the default in Gerrit. Issue-ID: POLICY-3146 Change-Id: I878f160956e89506743dc074679ee81ac1c48216 Signed-off-by: liamfallon (cherry picked from commit d6db5582b6705c11abbf8b507aa423aa00bcd7ae) --- .../models/pdp/persistence/provider/PdpProviderTest.java | 10 +++++++--- .../pdp/persistence/provider/PdpStatisticsProviderTest.java | 10 +++++++--- models-pdp/src/test/resources/META-INF/persistence.xml | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'models-pdp') diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java index aadaf3500..f6fe90d49 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java @@ -98,9 +98,13 @@ public class PdpProviderTest { jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); - // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); + if (System.getProperty("USE-MARIADB") != null) { + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + } else { + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); + } daoParameters.setJdbcProperties(jdbcProperties); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java index a418f81cf..724bb3c56 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java @@ -74,9 +74,13 @@ public class PdpStatisticsProviderTest { jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); - // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); + if (System.getProperty("USE-MARIADB") != null) { + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + } else { + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); + jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); + } daoParameters.setJdbcProperties(jdbcProperties); diff --git a/models-pdp/src/test/resources/META-INF/persistence.xml b/models-pdp/src/test/resources/META-INF/persistence.xml index 878998422..65380642a 100644 --- a/models-pdp/src/test/resources/META-INF/persistence.xml +++ b/models-pdp/src/test/resources/META-INF/persistence.xml @@ -1,7 +1,7 @@