From d6db5582b6705c11abbf8b507aa423aa00bcd7ae Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 19 Mar 2021 18:18:10 +0000 Subject: [PATCH] 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 --- .../models/base/PfReferenceTimestampKey.java | 4 +- .../onap/policy/models/base/PfTimestampKey.java | 2 +- .../src/test/resources/META-INF/persistence.xml | 3 +- .../pdp/persistence/provider/PdpProviderTest.java | 10 ++- .../provider/PdpStatisticsProviderTest.java | 10 ++- .../src/test/resources/META-INF/persistence.xml | 3 +- .../impl/PolicyStatisticsPersistenceTest.java | 86 ++++++++++++++++++++++ .../provider/impl/PolicyToscaPersistenceTest.java | 12 ++- .../provider/impl/PolicyTypePersistenceTest.java | 13 +++- .../src/test/resources/META-INF/persistence.xml | 3 +- .../AuthorativeToscaProviderGenericTest.java | 12 ++- .../AuthorativeToscaProviderPolicyTest.java | 10 ++- .../AuthorativeToscaProviderPolicyTypeTest.java | 10 ++- .../simple/provider/SimpleToscaProviderTest.java | 10 ++- .../SimpleToscaServiceTemplateProviderTest.java | 12 ++- .../src/test/resources/META-INF/persistence.xml | 3 +- 16 files changed, 169 insertions(+), 34 deletions(-) create mode 100644 models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyStatisticsPersistenceTest.java diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java index 1a29c8b01..8be1126af 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java @@ -50,7 +50,7 @@ public class PfReferenceTimestampKey extends PfKey { private static final String TIMESTAMP_TOKEN = "timeStamp"; - @Column(name = TIMESTAMP_TOKEN) + @Column(name = TIMESTAMP_TOKEN, precision = 3) @Temporal(TemporalType.TIMESTAMP) @NotNull private Date timeStamp; @@ -214,6 +214,7 @@ public class PfReferenceTimestampKey extends PfKey { * * @return the pfReferenceTimestamp key */ + @Override public PfReferenceTimestampKey getKey() { return this; } @@ -222,6 +223,7 @@ public class PfReferenceTimestampKey extends PfKey { * Get the key as a string. * @return pfReferenceTimestamp key. */ + @Override public String getId() { return getReferenceKey().getId() + ':' + getTimeStamp().getTime(); } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java index 6e2271846..1f5dc654a 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java @@ -51,7 +51,7 @@ public class PfTimestampKey extends PfKeyImpl { @Pattern(regexp = VERSION_REGEXP) private String version; - @Column(name = TIMESTAMP_TOKEN) + @Column(name = TIMESTAMP_TOKEN, precision = 3) @Temporal(TemporalType.TIMESTAMP) @NonNull private Date timeStamp; diff --git a/models-dao/src/test/resources/META-INF/persistence.xml b/models-dao/src/test/resources/META-INF/persistence.xml index 04b2c5b44..3d1f4ff27 100644 --- a/models-dao/src/test/resources/META-INF/persistence.xml +++ b/models-dao/src/test/resources/META-INF/persistence.xml @@ -1,7 +1,7 @@