Skip to content

Commit

Permalink
Merge pull request #17 from DataINCITE/flynnc3-temp
Browse files Browse the repository at this point in the history
add edge case support for response and heartbeat interaction
  • Loading branch information
flynnc3 authored Apr 19, 2023
2 parents 3dca5e9 + 98d77f3 commit d33b8da
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package test.stream.external.connected.connections;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.core.core.Core;
import org.framework.router.Response;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestAmberDataConnection {

static {
// disable loggers
LogManager.getRootLogger().setLevel(Level.OFF);
}

private static String apikey;

@BeforeClass
public static void init() throws FileNotFoundException {
Scanner s = new Scanner(new File("src/test/resources/"
+ "test/stream/external/connected/connections/"
+ "test_amberdata_config.txt"));
apikey = s.nextLine();
s.close();
}

//@Test
public void TestAuthorization() {
Core core = new Core();

// successful authorization
assertEquals(200, core.send("SRC", "INIT", "amber_data," + apikey).code());

// failed authorization
assertEquals(422, core.send("SRC", "INIT", "amber_data, does_not_exist").code());
}

//@Test
public void TestRequest() {
Core core = new Core();

Response initResponse = core.send("SRC", "INIT", "amber_data," + apikey);

assertEquals(200, initResponse.code());

String key = initResponse.data().split(",")[1].trim();

Response valid = core.send("SRC", "RQST", String.format("%s, %s", key, "lending-latest"));
assertEquals(200, valid.code());

// invalid request
Response invalid = core.send("SRC", "RQST", String.format("%s, %s", key, "does_not_exist"));
assertEquals(428, invalid.code());
}

@Test
public void TestAaveProtocolDated() throws IOException {
// HashMap<String, String> params = new HashMap<String, String>();
// params.put("start_date", "2022-09-01");
// params.put("end_date", "2022-09-05");
// System.out.println(AmberDataRequestHandler.requestAaveProtocolDated("2022-09-01", "2022-09-05", "UAK7ed69235426c360be22bfc2bde1809b6")[1]);
//System.out.println(AmberDataRequestHandler.requestLendingLatest(apikey, "")[1]);
//System.out.println(AmberDataRequestHandler.request("aave-protocol-dated", apikey, params)[1]);

// OkHttpClient client = new OkHttpClient();
//
// Request request = new Request.Builder()
// .url("https://web3api.io/api/v2/defi/lending/aavev2/protocol?startDate=2022-09-01T01:00:00&endDate=2022-09-05T01:00:00")
// .get()
// .addHeader("accept", "application/json")
// .addHeader("x-api-key", "UAK7ed69235426c360be22bfc2bde1809b6")
// .build();
//
// okhttp3.Response response = client.newCall(request).execute();
// System.out.println(response.body().string().substring(0, 1000));
}
}
12 changes: 10 additions & 2 deletions R-Code-Samples/DataEnginePrimaryFunctions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
else if (grepl("<<<response>>>", temp, fixed=TRUE))
{
temp <- readLines(socket, 1)
while(grepl("<<<heartbeat>>>", temp, fixed=TRUE)) {
temp <- readLines(socket, 1)
}
response <- fromJSON(temp)
break
}
Expand All @@ -122,8 +125,13 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
print(paste("Processed", counter, "lines for", protocol))
# add data point line to data frame
temp.df <- as.data.frame(fromJSON(temp))
df <- rbind.fill(df, temp.df)
tryCatch(expr={
temp.df <- as.data.frame(fromJSON(temp))
df <- rbind.fill(df, temp.df)
},
error=function(e){
message("Heartbeat execption caught and not parsed.")
})
}
output <- list("response"=response, "df"=df)
Expand Down
12 changes: 10 additions & 2 deletions R-Code-Samples/ExampleUserClusteringStarter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
else if (grepl("<<<response>>>", temp, fixed=TRUE))
{
temp <- readLines(socket, 1)
while(grepl("<<<heartbeat>>>", temp, fixed=TRUE)) {
temp <- readLines(socket, 1)
}
response <- fromJSON(temp)
break
}
Expand All @@ -140,8 +143,13 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
print(paste("Processed", counter, "lines for", protocol))
# add data point line to data frame
temp.df <- as.data.frame(fromJSON(temp))
df <- rbind.fill(df, temp.df)
tryCatch(expr={
temp.df <- as.data.frame(fromJSON(temp))
df <- rbind.fill(df, temp.df)
},
error=function(e){
message("Heartbeat execption caught and not parsed.")
})
}
output <- list("response"=response, "df"=df)
Expand Down
12 changes: 10 additions & 2 deletions R-Code-Samples/GetTransactions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
else if (grepl("<<<response>>>", temp, fixed=TRUE))
{
temp <- readLines(socket, 1)
while(grepl("<<<heartbeat>>>", temp, fixed=TRUE)) {
temp <- readLines(socket, 1)
}
response <- fromJSON(temp)
break
}
Expand All @@ -124,8 +127,13 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
print(paste("Processed", counter, "lines for", protocol))
# add data point line to data frame
temp.df <- as.data.frame(fromJSON(temp))
df <- rbind.fill(df, temp.df)
tryCatch(expr={
temp.df <- as.data.frame(fromJSON(temp))
df <- rbind.fill(df, temp.df)
},
error=function(e){
message("Heartbeat execption caught and not parsed.")
})
}
output <- list("response"=response, "df"=df)
Expand Down

0 comments on commit d33b8da

Please sign in to comment.