aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-07-01 14:02:42 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-01 14:02:42 +0000
commit12d85845dbfd7826b2b904faaaf96c0f07bf32a3 (patch)
tree28bbf8216f0d8f3c2e5dd0dcf26c1af782c7086d /controlloop/common
parent4bc80ef77521653cdc56f4bb902ab66129c5bd91 (diff)
parente6bf601e69e40768efbc934c88b17fd9d4062e49 (diff)
Merge "Remove sleep() from junit tests"1.5.0
Diffstat (limited to 'controlloop/common')
-rw-r--r--controlloop/common/feature-controlloop-trans/pom.xml10
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java15
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties8
3 files changed, 21 insertions, 12 deletions
diff --git a/controlloop/common/feature-controlloop-trans/pom.xml b/controlloop/common/feature-controlloop-trans/pom.xml
index a7cc8dd5a..f7bc974aa 100644
--- a/controlloop/common/feature-controlloop-trans/pom.xml
+++ b/controlloop/common/feature-controlloop-trans/pom.xml
@@ -8,9 +8,9 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -153,6 +153,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <version>3.0.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope>
diff --git a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
index 661803315..abc5db8e6 100644
--- a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
+++ b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.drools.apps.controlloop.feature.trans;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -28,6 +29,7 @@ import static org.junit.Assert.assertTrue;
import java.nio.file.Path;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -65,7 +67,7 @@ public class ControlLoopMetricsFeatureTest {
@Test
public void cacheDefaults() {
assertEquals(3, ControlLoopMetrics.manager.getCacheSize());
- assertEquals(10, ControlLoopMetrics.manager.getTransactionTimeout());
+ assertEquals(2, ControlLoopMetrics.manager.getTransactionTimeout());
assertEquals(0, ControlLoopMetrics.manager.getCacheOccupancy());
}
@@ -98,10 +100,10 @@ public class ControlLoopMetricsFeatureTest {
assertNotNull(ControlLoopMetrics.manager.getTransaction(requestId).getNotificationTime());
assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == 1);
- /* let the entries expire */
- Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout() + 1) * 1000L);
+ /* wait for the entries to expire */
+ await().atMost(ControlLoopMetrics.manager.getTransactionTimeout() + 1, TimeUnit.SECONDS)
+ .until(() -> ControlLoopMetrics.manager.getTransaction(requestId) == null);
- assertNull(ControlLoopMetrics.manager.getTransaction(requestId));
this.cacheDefaults();
}
@@ -151,8 +153,9 @@ public class ControlLoopMetricsFeatureTest {
assertFalse(ControlLoopMetrics.manager.getTransactionIds().isEmpty());
assertFalse(ControlLoopMetrics.manager.getTransactions().isEmpty());
- /* let the entries expire */
- Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout() + 1) * 1000L);
+ /* wait for the entries to expire */
+ await().atMost(ControlLoopMetrics.manager.getTransactionTimeout() + 1, TimeUnit.SECONDS)
+ .until(() -> ControlLoopMetrics.manager.getTransactions().isEmpty());
ControlLoopMetrics.manager.refresh();
assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager
diff --git a/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties b/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties
index cc4c0681d..c921e8c27 100644
--- a/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties
+++ b/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties
@@ -2,14 +2,14 @@
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,4 +18,4 @@
# ============LICENSE_END=========================================================
###
controlloop.cache.transactions.size=3
-controllop.cache.transactions.timeout.seconds=10 \ No newline at end of file
+controllop.cache.transactions.timeout.seconds=2