summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java11
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java88
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java5
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node1
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M8
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gzbin0 -> 150 bytes
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M8
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java33
8 files changed, 117 insertions, 37 deletions
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java
index 91bd716b..7ed35928 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java
@@ -94,9 +94,9 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
this.followRedirects = destInfo.isFollowRedirects();
feedid = destInfo.getLogData();
spool = destInfo.getSpool();
- String dfn = spool + "/" + pubid;
+ String dfn = spool + File.separator + pubid;
String mfn = dfn + ".M";
- datafile = new File(spool + "/" + pubid);
+ datafile = new File(spool + File.separator + pubid);
metafile = new File(mfn);
boolean monly = destInfo.isMetaDataOnly();
date = Long.parseLong(pubid.substring(0, pubid.indexOf('.')));
@@ -242,7 +242,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
httpURLConnection.setRequestProperty(DECOMPRESSION_STATUS, "SUCCESS");
OutputStream outputStream = getOutputStream(httpURLConnection);
if (outputStream != null) {
- int bytesRead = 0;
+ int bytesRead;
try (InputStream gzipInputStream = new GZIPInputStream(new FileInputStream(datafile))) {
int bufferLength = buffer.length;
while ((bytesRead = gzipInputStream.read(buffer, 0, bufferLength)) > 0) {
@@ -371,7 +371,8 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
Files.deleteIfExists(file.toPath());
break;
} catch (IOException e) {
- eelfLogger.error("IOException : Failed to delete file :" + file.getName() + " on attempt " + tryCount, e);
+ eelfLogger.error("IOException : Failed to delete file :"
+ + file.getName() + " on attempt " + tryCount, e);
}
tryCount++;
}
@@ -464,7 +465,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
/**
* Get the followRedirects for this delivery task.
*/
- public boolean getFollowRedirects() {
+ boolean getFollowRedirects() {
return (followRedirects);
}
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
index 3d17e3e3..a0f05779 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
@@ -23,43 +23,105 @@ package org.onap.dmaap.datarouter.node;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DeliveryTask.class})
public class DeliveryTaskTest {
@Mock
private DeliveryQueue deliveryQueue;
+ private ExecutorService executorService;
+
+ @Before
+ public void setUp() throws Exception {
+ DestInfo destInfo = getPrivDestInfo();
+ deliveryQueue = mockDelvieryQueue(destInfo);
+
+ URL url = PowerMockito.mock(URL.class);
+ HttpURLConnection urlConnection = PowerMockito.mock(HttpURLConnection.class);
+ OutputStream outputStream = PowerMockito.mock(OutputStream.class);
+
+ PowerMockito.whenNew(URL.class).withParameterTypes(String.class).withArguments(Mockito.anyString())
+ .thenReturn(url);
+ PowerMockito.when(urlConnection.getOutputStream()).thenReturn(outputStream);
+ PowerMockito.when(url.openConnection()).thenReturn(urlConnection);
+ PowerMockito.when(urlConnection.getHeaderField(0)).thenReturn("PUT");
+ PowerMockito.when(urlConnection.getResponseCode()).thenReturn(200);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+
@Test
public void Validate_Delivery_Task_Equals() {
- DestInfo destInfo = getDestInfo();
- deliveryQueue = mockDelvieryQueue(destInfo);
DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
Assert.assertEquals(task, task2);
Assert.assertEquals(task.hashCode(), task2.hashCode());
Assert.assertEquals(task.toString(), task2.toString());
+ Assert.assertEquals(task.getPublishId(), task2.getPublishId());
+ Assert.assertEquals(task.getSubId(), task2.getSubId());
+ Assert.assertEquals(task.getFeedId(), task2.getFeedId());
+ Assert.assertEquals(task.getLength(), task2.getLength());
+ Assert.assertEquals(task.isCleaned(), task2.isCleaned());
+ Assert.assertEquals(task.getDate(), task2.getDate());
+ Assert.assertEquals(task.getURL(), task2.getURL());
+ Assert.assertEquals(task.getCType(), task2.getCType());
+ Assert.assertEquals(task.getMethod(), task2.getMethod());
+ Assert.assertEquals(task.getFileId(), task2.getFileId());
+ Assert.assertEquals(task.getAttempts(), task2.getAttempts());
+ Assert.assertEquals(task.getFollowRedirects(), task2.getFollowRedirects());
+
Assert.assertEquals(0, task.compareTo(task2));
}
@Test
- public void Validate_Delivery_Tasks_Not_Equal() {
- DestInfo destInfo = getDestInfo();
- deliveryQueue = mockDelvieryQueue(destInfo);
+ public void Validate_Delivery_Tasks_Success_For_Standard_File() throws InterruptedException {
DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
- DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
- Assert.assertNotEquals(task, task2);
- Assert.assertNotEquals(0, task.compareTo(task2));
+ executorService = Executors.newSingleThreadExecutor();
+ executorService.execute(task);
+
+ executorService.shutdown();
+ executorService.awaitTermination(2, TimeUnit.SECONDS);
+ }
+
+ @Test
+ public void Validate_Delivery_Tasks_Success_For_Compressed_File() throws InterruptedException {
+
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node.gz");
+ executorService = Executors.newSingleThreadExecutor();
+ executorService.execute(task);
+
+ executorService.shutdown();
+ executorService.awaitTermination(2, TimeUnit.SECONDS);
}
- private DestInfo getDestInfo() {
+ private DestInfo getPrivDestInfo() {
return new DestInfoBuilder().setName("n:" + "dmaap-dr-node")
- .setSpool(System.getProperty("user.dir") + "/src/test/resources")
- .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
- .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
- .setPrivilegedSubscriber(false).setFollowRedirects(false).setDecompress(false).createDestInfo();
+ .setSpool(System.getProperty("user.dir") + "/src/test/resources/delivery_files")
+ .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
+ .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
+ .setPrivilegedSubscriber(true).setFollowRedirects(false).setDecompress(true).createDestInfo();
}
private DeliveryQueue mockDelvieryQueue(DestInfo destInfo) {
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
index c890ed50..da690206 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
@@ -31,6 +31,7 @@ import java.util.Timer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -56,8 +57,8 @@ public class LogManagerTest {
logManager = new LogManager(config);
}
- @After
- public void tearDown() throws IOException {
+ @AfterClass
+ public static void tearDown() throws IOException {
File spoolDir = new File(System.getProperty("user.dir") + "/src/test/resources/.spool");
FileUtils.deleteDirectory(spoolDir);
}
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node
new file mode 100644
index 00000000..1677aafe
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node
@@ -0,0 +1 @@
+Hello World!!!!!! \ No newline at end of file
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M
new file mode 100644
index 00000000..b317b671
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M
@@ -0,0 +1,8 @@
+PUT A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-InvocationID ea407097-2de5-452e-9f21-569e6d867deb
+X-TransactionID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-ONAP-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-DMAAP-DR-META {"productName":"RnNode","vendorName":"Ericsson","lastEpochMicrosec":"1561550151179","sourceName":"","startEpochMicrosec":"1561550151179","timeZoneOffset":"UTC+00:00","location":"ftps://onap:pano@10.209.63.42:2036/A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz","compression":"gzip","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10"}
+Content-Type application/octet-stream
+X-DMAAP-DR-RECEIVED 2019-06-26T11:56:38.216Z;from=10.42.54.206;by=10.42.70.78 \ No newline at end of file
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz
new file mode 100644
index 00000000..d38bae1f
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz
Binary files differ
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M
new file mode 100644
index 00000000..b317b671
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M
@@ -0,0 +1,8 @@
+PUT A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-InvocationID ea407097-2de5-452e-9f21-569e6d867deb
+X-TransactionID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-ONAP-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-DMAAP-DR-META {"productName":"RnNode","vendorName":"Ericsson","lastEpochMicrosec":"1561550151179","sourceName":"","startEpochMicrosec":"1561550151179","timeZoneOffset":"UTC+00:00","location":"ftps://onap:pano@10.209.63.42:2036/A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz","compression":"gzip","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10"}
+Content-Type application/octet-stream
+X-DMAAP-DR-RECEIVED 2019-06-26T11:56:38.216Z;from=10.42.54.206;by=10.42.70.78 \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
index 79d83899..8bbf231a 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
@@ -29,9 +29,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
-import com.att.eelf.configuration.EELFManager;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
@@ -42,7 +40,6 @@ import java.util.concurrent.TimeUnit;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
@@ -59,7 +56,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet;
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
import org.powermock.api.mockito.PowerMockito;
@@ -84,11 +80,7 @@ public class SynchronizerTaskTest {
@Mock
private CloseableHttpResponse response;
- @Mock
- private ByteArrayOutputStream byteArrayOutputStream;
-
private SynchronizerTask synchronizerTask;
-
private ExecutorService executorService;
private static EntityManagerFactory emf;
@@ -125,7 +117,7 @@ public class SynchronizerTaskTest {
synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
doReturn(2).when(synchronizerTask).lookupState();
- executorService = Executors.newSingleThreadExecutor();
+ executorService = Executors.newCachedThreadPool();
executorService.execute(synchronizerTask);
}
@@ -136,7 +128,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_readRemoteLoglist_Called_And_Valid_BitSet_Returned_Success() throws Exception {
+ public void Given_Synch_Task_readRemoteLoglist_Called_And_Valid_BitSet_Returned_Success()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
@@ -146,7 +139,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Resonse_Code_Failure() throws Exception {
+ public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Resonse_Code_Failure()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
@@ -154,7 +148,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Content_Type_Failure() throws Exception {
+ public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Content_Type_Failure()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
@@ -163,7 +158,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Valid_BitSet_Returned_Success() throws Exception {
+ public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Valid_BitSet_Returned_Success()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
@@ -172,7 +168,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Content_Type_Failure() throws Exception {
+ public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Content_Type_Failure()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
@@ -181,7 +178,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Resonse_Code_Failure() throws Exception {
+ public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Resonse_Code_Failure()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
@@ -189,7 +187,8 @@ public class SynchronizerTaskTest {
}
@Test
- public void Given_Synch_Task_Is_Started_And_LogFileLoader_Is_Idle_Then_Standby_Pod_Synch_Is_Successful() throws Exception {
+ public void Given_Synch_Task_Is_Started_And_LogFileLoader_Is_Idle_Then_Standby_Pod_Synch_Is_Successful()
+ throws IOException, IllegalAccessException {
mockHttpClientForGetRequest();
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "application/vnd.dmaap-dr.provfeed-full; version=1.0"));
@@ -197,7 +196,7 @@ public class SynchronizerTaskTest {
}
- private void mockHttpClientForGetRequest() throws Exception {
+ private void mockHttpClientForGetRequest() throws IllegalAccessException, IOException {
FieldUtils.writeField(synchronizerTask, "httpclient", httpClient, true);
Mockito.when(httpClient.execute(anyObject())).thenReturn(response);
Mockito.when(response.getEntity()).thenReturn(httpEntity);