Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<version>5.10.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private List<UUID> doPost(List<Statement> statements, URI endpoint)
responseBody,
new TypeReference<List<UUID>>(){});
} else {
EntityUtils.consumeQuietly(response.getEntity());
throw new StatementClientException(String.format(
"Error, Non-200 Status. Received: %s",
response.getStatusLine().getStatusCode()));
Expand Down Expand Up @@ -119,6 +120,7 @@ private StatementResult doGetStatementResult(URI endpoint)
String responseBody = EntityUtils.toString(response.getEntity());
return Mapper.getMapper().readValue(responseBody, StatementResult.class);
} else {
EntityUtils.consumeQuietly(response.getEntity());
throw new StatementClientException(String.format(
"Error, Non-200 Status. Received: %s",
response.getStatusLine().getStatusCode()));
Expand All @@ -134,6 +136,7 @@ private Statement doGetStatement(URI endpoint)
String responseBody = EntityUtils.toString(response.getEntity());
return Mapper.getMapper().readValue(responseBody, Statement.class);
} else {
EntityUtils.consumeQuietly(response.getEntity());
throw new StatementClientException(String.format(
"Error, Non-200 Status. Received: %s",
response.getStatusLine().getStatusCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.testcontainers.containers.GenericContainer;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.DatabindException;
import com.yetanalytics.xapi.client.filters.StatementFilters;
import com.yetanalytics.xapi.exception.StatementClientException;
import com.yetanalytics.xapi.model.Agent;
import com.yetanalytics.xapi.model.Statement;
import com.yetanalytics.xapi.util.Mapper;
Expand Down Expand Up @@ -216,5 +218,40 @@ public void testDateFilters() throws StreamReadException, DatabindException, IOE
List<Statement> result = client.getStatements(filters);
assertNotNull(result);

}

@Test
@Timeout(value = 30, unit = TimeUnit.SECONDS)
public void testConnectionPoolOnError() throws StreamReadException, DatabindException, IOException {
LRS lrs = new LRS(getMappedHost(), KEY, SECRET);
StatementClient client = new StatementClient(lrs);

Statement statement = new Statement();
statement.setId(UUID.randomUUID());

// Try 1, handled, no issue
try {
client.postStatement(statement);
} catch (StatementClientException e) {
assertTrue(e.getMessage().contains("Error, Non-200 Status. Received: 400"));
}

// Try 2, handled, no issue
try {
client.postStatement(statement);
} catch (StatementClientException e) {
assertTrue(e.getMessage().contains("Error, Non-200 Status. Received: 400"));
}

// Try 3, will await indefinitely if connection pool is not cleaned up properly (timeout will trigger)
// Test will finish successfully if client is handling conns right
try {
client.postStatement(statement);
} catch (StatementClientException e) {
assertTrue(e.getMessage().contains("Error, Non-200 Status. Received: 400"));
}



}
}
Loading