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('.')));
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) {
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++;
}
/**
* Get the followRedirects for this delivery task.
*/
- public boolean getFollowRedirects() {
+ boolean getFollowRedirects() {
return (followRedirects);
}
}
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) {
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;
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);
}
--- /dev/null
+Hello World!!!!!!
\ No newline at end of file
--- /dev/null
+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
--- /dev/null
+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
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;
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;
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;
@Mock
private CloseableHttpResponse response;
- @Mock
- private ByteArrayOutputStream byteArrayOutputStream;
-
private SynchronizerTask synchronizerTask;
-
private ExecutorService executorService;
private static EntityManagerFactory emf;
synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
doReturn(2).when(synchronizerTask).lookupState();
- executorService = Executors.newSingleThreadExecutor();
+ executorService = Executors.newCachedThreadPool();
executorService.execute(synchronizerTask);
}
}
@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"));
}
@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();
}
@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"));
}
@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"));
}
@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"));
}
@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();
}
@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"));
}
- 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);