diff options
author | ramverma <ram.krishna.verma@est.tech> | 2019-01-22 12:39:39 +0000 |
---|---|---|
committer | ramverma <ram.krishna.verma@est.tech> | 2019-01-22 12:39:39 +0000 |
commit | 1936220d00ee644774e58ab33de39cca4a006d2a (patch) | |
tree | 59f9cd0d337a88424813e9eacb37a94720f15acd /plugins/reception-plugins/src/test/java | |
parent | eac48bb3c587999376af202ab421275a27279523 (diff) |
Fix issues in policy-distribution
1) Creating a new thread for watching directory path for new file.
2) Updating distribution statistics from FileSystemReceptionHandler.
Change-Id: Ic539f2cad015f0756407fe910f309a2ea661a764
Issue-ID: POLICY-1437
Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Diffstat (limited to 'plugins/reception-plugins/src/test/java')
-rw-r--r-- | plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java (renamed from plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestFileSystemReceptionHandler.java) | 31 | ||||
-rw-r--r-- | plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java (renamed from plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestFileSystemReceptionHandlerConfigurationParameterGroup.java) | 4 |
2 files changed, 18 insertions, 17 deletions
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestFileSystemReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java index fc2a2b6a..20922a1b 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestFileSystemReceptionHandler.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel. All rights reserved. + * Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.distribution.reception.handling.sdc; +package org.onap.policy.distribution.reception.handling.file; import static org.junit.Assert.fail; @@ -92,16 +93,16 @@ public class TestFileSystemReceptionHandler { @Test public final void testInit() throws IOException { final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); - Mockito.doNothing().when(sypHandler).main(Mockito.isA(String.class)); + Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class)); sypHandler.initializeReception(pssdConfigParameters.getName()); - Mockito.verify(sypHandler, Mockito.times(1)).main(Mockito.isA(String.class)); + Mockito.verify(sypHandler, Mockito.times(1)).initFileWatcher(Mockito.isA(String.class)); } @Test public final void testDestroy() throws IOException { try { final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); - Mockito.doNothing().when(sypHandler).main(Mockito.isA(String.class)); + Mockito.doNothing().when(sypHandler).initFileWatcher(Mockito.isA(String.class)); sypHandler.initializeReception(pssdConfigParameters.getName()); sypHandler.destroy(); } catch (final Exception exp) { @@ -120,11 +121,12 @@ public class TestFileSystemReceptionHandler { public boolean processed = false; } - Processed cond = new Processed(); + final Processed cond = new Processed(); final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler); Mockito.doAnswer(new Answer<Object>() { - public Object answer(InvocationOnMock invocation) { + @Override + public Object answer(final InvocationOnMock invocation) { synchronized (lock) { cond.processed = true; lock.notifyAll(); @@ -133,18 +135,18 @@ public class TestFileSystemReceptionHandler { } }).when(sypHandler).createPolicyInputAndCallHandler(Mockito.isA(String.class)); - Thread th = new Thread(() -> { + final Thread th = new Thread(() -> { try { - sypHandler.main(watchPath); - } catch (IOException ex) { + sypHandler.initFileWatcher(watchPath); + } catch (final IOException ex) { LOGGER.error(ex); } }); th.start(); try { - //wait until internal watch service started or counter reached - AtomicInteger counter = new AtomicInteger(); + // wait until internal watch service started or counter reached + final AtomicInteger counter = new AtomicInteger(); counter.set(0); synchronized (lock) { while (!sypHandler.isRunning() && counter.getAndIncrement() < 10) { @@ -152,8 +154,8 @@ public class TestFileSystemReceptionHandler { } } Files.copy(Paths.get("src/test/resources/hpaPolicyHugePage.csar"), - Paths.get(watchPath + File.separator + "hpaPolicyHugePage.csar")); - //wait until mock method triggered or counter reached + Paths.get(watchPath + File.separator + "hpaPolicyHugePage.csar")); + // wait until mock method triggered or counter reached counter.set(0); synchronized (lock) { while (!cond.processed && counter.getAndIncrement() < 10) { @@ -166,8 +168,7 @@ public class TestFileSystemReceptionHandler { } catch (final InterruptedException ex) { LOGGER.error(ex); } - Mockito.verify(sypHandler, Mockito.times(1)) - .createPolicyInputAndCallHandler(Mockito.isA(String.class)); + Mockito.verify(sypHandler, Mockito.times(1)).createPolicyInputAndCallHandler(Mockito.isA(String.class)); } } diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestFileSystemReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java index 3039560a..92d9443e 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestFileSystemReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel. All rights reserved. + * Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.distribution.reception.handling.sdc; +package org.onap.policy.distribution.reception.handling.file; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -34,7 +35,6 @@ import java.io.IOException; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; - import org.onap.policy.common.parameters.GroupValidationResult; /** |