Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #160 from logzio/dependencies-version-bump
Browse files Browse the repository at this point in the history
dependencies version bump
  • Loading branch information
tamir-michaeli committed Jul 27, 2021
2 parents 7a99e8c + 7423414 commit a4d15e3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.idea
*.iml
target
target/*
17 changes: 10 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.logz</groupId>
<artifactId>logzio-msgraph</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -75,7 +78,7 @@
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>5.8.1</version>
<version>5.11.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
Expand All @@ -96,7 +99,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10.3</version>
<version>2.9.10.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -126,7 +129,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.9</version>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -141,7 +144,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -152,7 +155,7 @@
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.1.6</version>
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
1 change: 0 additions & 1 deletion src/test/java/ConfigurationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.Assert;
import org.junit.Test;
import org.yaml.snakeyaml.error.YAMLException;

import java.io.File;
import java.io.FileNotFoundException;

Expand Down
50 changes: 26 additions & 24 deletions src/test/java/FetchSendTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
import org.junit.*;
import org.mockserver.client.MockServerClient;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.RequestDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.naming.AuthenticationException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static java.lang.Thread.sleep;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
Expand All @@ -33,11 +33,9 @@
public class FetchSendTests {

private static final Logger logger = LoggerFactory.getLogger(FetchSendTests.class.getName());

private static MockServerClient mockServerClient = null;
private static ClientAndServer mockServer;
private static LogzioJavaSenderParams senderParams = new LogzioJavaSenderParams();

private int retries = 0;
private static Path tempDir;

Expand Down Expand Up @@ -90,17 +88,14 @@ public void clean() throws IOException {
} catch (FileNotFoundException e) {

}

}

@AfterClass
public static void close() {
mockServer.stop();
}

private RequestDataResult getSampleResult() {
File signinsFile = new File(getClass().getClassLoader().getResource("sampleSignins.json").getFile());

try {
String content = FileUtils.readFileToString(signinsFile, "utf-8");
JSONTokener tokener = new JSONTokener(content);
Expand All @@ -117,53 +112,48 @@ public void FetchSendTest() throws InterruptedException, JSONException {
int initialRequestsLength = mockServerClient.retrieveRecordedRequests(request().withMethod("POST")).length;
ArrayList<JsonArrayRequest> requests = new ArrayList<>();
requests.add(this::getSampleResult);

FetchSendManager manager = new FetchSendManager(requests, senderParams, 10);
manager.start();
manager.pullAndSendData();
Thread.sleep(2000);
HttpRequest[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
RequestDefinition[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
Assert.assertEquals(initialRequestsLength + 1, recordedRequests.length);
JSONObject jsonObject = new JSONObject(recordedRequests[initialRequestsLength].getBodyAsString());
Assert.assertEquals("aaaaa-bbbb-cccc-dddd-123456789", jsonObject.getString("id"));
Assert.assertEquals("John Smith", jsonObject.getString("userDisplayName"));
Assert.assertEquals("john.s@gmail.com", jsonObject.getString("userPrincipalName"));
Map<String,String> paramsMap=mapFromJSONObject(new JSONObject(recordedRequests[initialRequestsLength].toString()).getJSONObject("body"));
Assert.assertEquals("aaaaa-bbbb-cccc-dddd-123456789", paramsMap.get("id"));
Assert.assertEquals("John Smith", paramsMap.get("userDisplayName"));
Assert.assertEquals("john.s@gmail.com", paramsMap.get("userPrincipalName"));
manager.shutdown();
}

@Test
public void awaitAndRetryTest() throws InterruptedException, JSONException {
int initialRequestsLength = mockServerClient.retrieveRecordedRequests(request().withMethod("POST")).length;

ArrayList<JsonArrayRequest> requests = new ArrayList<>();
requests.add(this::getResultAfter2Retries);
FetchSendManager manager = new FetchSendManager(requests, senderParams, 10);
manager.start();
manager.pullAndSendData();
Thread.sleep(2000);
HttpRequest[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
RequestDefinition[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
Assert.assertEquals(initialRequestsLength + 1, recordedRequests.length);
JSONObject jsonObject = new JSONObject(recordedRequests[initialRequestsLength].getBodyAsString());
Assert.assertEquals(1, jsonObject.getInt("key"));
Map<String,String> paramsMap=mapFromJSONObject(new JSONObject(recordedRequests[initialRequestsLength].toString()).getJSONObject("body"));
Assert.assertEquals(1, Integer.parseInt(paramsMap.get("key")));
manager.shutdown();

}


@Test
public void alwaysFalseRetryTest() throws InterruptedException {
int initialRequestsLength = mockServerClient.retrieveRecordedRequests(request().withMethod("POST")).length;

ArrayList<JsonArrayRequest> requests = new ArrayList<>();
requests.add(this::getAlwaysFalseStatus);
FetchSendManager manager = new FetchSendManager(requests, senderParams, 10);
manager.start();
manager.pullAndSendData();
Thread.sleep(2000);
HttpRequest[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
RequestDefinition[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
Assert.assertEquals(initialRequestsLength, recordedRequests.length);
manager.shutdown();

}

private RequestDataResult getResultAfter2Retries() {
Expand All @@ -173,6 +163,7 @@ private RequestDataResult getResultAfter2Retries() {
result.setSucceed(false);
return result;
}

try {
JSONArray dataResult = new JSONArray("[{\"key\":1}]");
return new RequestDataResult(dataResult);
Expand Down Expand Up @@ -204,20 +195,31 @@ public void interruptMidSendTest() {
for (int i = 0; i < 100; i++) {
requests.add(this::getSampleResult);
}

FetchSendManager manager = new FetchSendManager(requests, senderParams, 10);
manager.start();

Thread storageThread = new Thread(manager::pullAndSendData);
storageThread.start();
try {
sleep(1000);
storageThread.interrupt();
sleep(3000);
HttpRequest[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
RequestDefinition[] recordedRequests = mockServerClient.retrieveRecordedRequests(request().withMethod("POST"));
Assert.assertEquals(initialRequestsCount + 100, recordedRequests.length);
} catch (InterruptedException e) {
Assert.fail(e.getMessage());
}
}

private Map<String,String> mapFromJSONObject(JSONObject json){
String[] paramString= json.getString("string").replaceAll("[{}\\\u0000\"]","")
.split("\\r?\\n")[0].split(",");
Map<String,String> paramsMap= new HashMap<>();
for(String string: paramString){
String[] params=string.split(":",2);
paramsMap.put(params[0],params[1]);
}

return paramsMap;
}
}

0 comments on commit a4d15e3

Please sign in to comment.