From 7d3fb8e0a193c1471fcde17ddbe855b5ac1ebd70 Mon Sep 17 00:00:00 2001 From: Guobiao Mo Date: Thu, 20 Jun 2019 15:30:44 -0700 Subject: No data is lost when program is killed When the program is killed by unix 'kill' or crtl+c, program should exits gracefully after all data is saved to DBs. Issue-ID: DCAEGEN2-1633 Change-Id: Ic134440be507faa44d04434eeaea1035ce7d63f0 Signed-off-by: Guobiao Mo --- .../java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java | 5 +++++ .../test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java | 3 +++ .../java/org/onap/datalake/feeder/service/MongodbServiceTest.java | 5 ++++- .../test/java/org/onap/datalake/feeder/service/TopicServiceTest.java | 3 +-- 4 files changed, 13 insertions(+), 3 deletions(-) (limited to 'components/datalake-handler/feeder/src/test') diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java index 0efde44c..9765329c 100755 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/CouchbaseServiceTest.java @@ -37,8 +37,11 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; import org.onap.datalake.feeder.domain.Topic; +import static org.mockito.Mockito.when; + import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; @RunWith(MockitoJUnitRunner.class) public class CouchbaseServiceTest { @@ -141,6 +144,8 @@ public class CouchbaseServiceTest { public void testCleanupBucket() { CouchbaseService couchbaseService = new CouchbaseService(); couchbaseService.bucket = bucket; + ApplicationConfiguration appConfig = new ApplicationConfiguration(); + couchbaseService.config = appConfig; couchbaseService.cleanUp(); } diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java index 81c37185..e0a1ce5f 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,6 +59,8 @@ public class DmaapServiceTest { // when(config.getDmaapKafkaExclude()).thenReturn(new String[] { "AAI-EVENT" }); when(config.getDmaapZookeeperHostPort()).thenReturn(DMAPP_ZOOKEEPER_HOST_PORT); assertNotEquals(list, dmaapService.getTopics()); + + when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock()); dmaapService.cleanUp(); } diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java index 016381be..ef28f1f6 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java @@ -33,10 +33,13 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; import org.onap.datalake.feeder.domain.Topic; +import static org.mockito.Mockito.when; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.locks.ReentrantReadWriteLock; @RunWith(MockitoJUnitRunner.class) public class MongodbServiceTest { @@ -62,7 +65,7 @@ public class MongodbServiceTest { @Test public void cleanUp() { - + when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock()); mongodbService.cleanUp(); } diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java index 774cd229..757cdd7e 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java @@ -83,7 +83,7 @@ public class TopicServiceTest { } - @Test(expected = IOException.class) + @Test public void testGetEffectiveTopic() throws IOException { String name = "a"; Topic topic = new Topic(name); @@ -96,7 +96,6 @@ public class TopicServiceTest { when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(topic)); when(topicRepository.findById(name)).thenReturn(Optional.of(topic)); when(topicRepository.findById(null)).thenReturn(Optional.empty()); - doThrow(IOException.class).when(elasticsearchService).ensureTableExist(name); assertEquals(topicService.getEffectiveTopic(name), topicService.getEffectiveTopic(name, false)); -- cgit 1.2.3-korg