Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions aws-lambda-java-runtime-interface-client/Dockerfile.rie
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM public.ecr.aws/amazoncorretto/amazoncorretto:11

# Install RIE
RUN yum update -y && \
yum install -y curl && \
curl -Lo /usr/local/bin/aws-lambda-rie \
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \
chmod +x /usr/local/bin/aws-lambda-rie

WORKDIR /function

COPY target/aws-lambda-java-runtime-interface-client-*.jar ./
COPY target/aws-lambda-java-core-*.jar ./
COPY target/aws-lambda-java-serialization-*.jar ./

COPY test-handlers/EchoHandler.class ./

# Run RIE which will launch the Java RIC
ENTRYPOINT ["/usr/local/bin/aws-lambda-rie", "/usr/bin/java", "-cp", "./*", "com.amazonaws.services.lambda.runtime.api.client.AWSLambda"]

# Default handler can be overridden by passing a new one on `docker run`
CMD ["EchoHandler::handleRequest"]
6 changes: 5 additions & 1 deletion aws-lambda-java-runtime-interface-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ publish:
test-publish:
./ric-dev-environment/test-platform-specific-jar-snapshot.sh

.PHONY: test-rie
test-rie:
./scripts/test-rie.sh "EchoHandler::handleRequest"

define HELP_MESSAGE

Usage: $ make [TARGETS]
Expand All @@ -74,5 +78,5 @@ TARGETS
dev Run all development tests after a change.
pr Perform all checks before submitting a Pull Request.
test Run the Unit tests.

test-rie Build and test RIC locally with Lambda Runtime Interface Emulator. (Requires building the project first)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

endef
43 changes: 43 additions & 0 deletions aws-lambda-java-runtime-interface-client/scripts/test-rie.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
SERIALIZATION_ROOT="$(dirname "$PROJECT_ROOT")/aws-lambda-java-serialization"

if ! ls "$PROJECT_ROOT"/target/aws-lambda-java-runtime-interface-client-*.jar >/dev/null 2>&1; then
echo "RIC jar not found. Please build the project first with 'mvn package'."
exit 1
fi

IMAGE_TAG="java-ric-rie-test"

HANDLER="${1:-EchoHandler::handleRequest}"

echo "Starting RIE test setup for Java..."

# Download required dependencies if not present
if ! ls "$PROJECT_ROOT"/target/aws-lambda-java-core-*.jar >/dev/null 2>&1; then
echo "Downloading aws-lambda-java-core..."
(cd "$PROJECT_ROOT" && mvn dependency:copy -Dartifact=com.amazonaws:aws-lambda-java-core:1.3.0 -DoutputDirectory=target)
fi

if ! ls "$PROJECT_ROOT"/target/aws-lambda-java-serialization-*.jar >/dev/null 2>&1; then
echo "Downloading aws-lambda-java-serialization..."
(cd "$PROJECT_ROOT" && mvn dependency:copy -Dartifact=com.amazonaws:aws-lambda-java-serialization:1.1.6 -DoutputDirectory=target)
fi

echo "Compiling EchoHandler..."
javac -source 11 -target 11 -cp "$(ls "$PROJECT_ROOT"/target/aws-lambda-java-runtime-interface-client-*.jar):$(ls "$PROJECT_ROOT"/target/aws-lambda-java-core-*.jar):$(ls "$PROJECT_ROOT"/target/aws-lambda-java-serialization-*.jar)" \
-d "$PROJECT_ROOT/test-handlers/" "$PROJECT_ROOT/test-handlers/EchoHandler.java"

echo "Building test Docker image..."
docker build -t "$IMAGE_TAG" -f "$PROJECT_ROOT/Dockerfile.rie" "$PROJECT_ROOT"

echo "Starting test container on port 9000..."
echo ""
echo "In another terminal, invoke with:"
echo "curl -s -X POST -H 'Content-Type: application/json' \"http://localhost:9000/2015-03-31/functions/function/invocations\" -d '{\"message\":\"test\"}'"
echo ""

exec docker run -it -p 9000:8080 "$IMAGE_TAG" "$HANDLER"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.amazonaws.services.lambda.crac;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class CheckpointExceptionTest {

@Test
void testConstructor() {
CheckpointException exception = new CheckpointException();
assertNotNull(exception);
assertNull(exception.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.amazonaws.services.lambda.crac;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ResourceTest {

@Test
void testResourceInterface() {
Resource resource = new Resource() {
@Override
public void afterRestore(Context<? extends Resource> context) throws Exception {
// Test implementation
}

@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
// Test implementation
}
};

assertNotNull(resource);
assertDoesNotThrow(() -> resource.afterRestore(null));
assertDoesNotThrow(() -> resource.beforeCheckpoint(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.amazonaws.services.lambda.crac;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class RestoreExceptionTest {

@Test
void testConstructor() {
RestoreException exception = new RestoreException();
assertNotNull(exception);
assertNull(exception.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.amazonaws.services.lambda.runtime.api.client;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class LambdaEnvironmentTest {

@Test
void testConstants() {
assertNotNull(LambdaEnvironment.ENV_READER);
assertTrue(LambdaEnvironment.MEMORY_LIMIT >= 128);
assertNotNull(LambdaEnvironment.LAMBDA_LOG_LEVEL);
assertNotNull(LambdaEnvironment.LAMBDA_LOG_FORMAT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.amazonaws.services.lambda.runtime.api.client;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ReservedRuntimeEnvironmentVariablesTest {

@Test
void testConstants() {
assertEquals("_HANDLER", ReservedRuntimeEnvironmentVariables.HANDLER);
assertEquals("AWS_REGION", ReservedRuntimeEnvironmentVariables.AWS_REGION);
assertEquals("AWS_LAMBDA_FUNCTION_NAME", ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_FUNCTION_NAME);
assertEquals("AWS_LAMBDA_RUNTIME_API", ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_RUNTIME_API);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi;

import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.ErrorRequest;
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.XRayErrorCause;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class DtoSerializersTest {

@Test
void testSerializeErrorRequest() {
ErrorRequest errorRequest = new ErrorRequest();
errorRequest.errorMessage = "test error";
errorRequest.errorType = "TestException";

byte[] result = DtoSerializers.serialize(errorRequest);

assertNotNull(result);
assertTrue(result.length > 0);
}

@Test
void testSerializeXRayErrorCause() {
XRayErrorCause xRayErrorCause = new XRayErrorCause();
xRayErrorCause.working_directory = "/test";

byte[] result = DtoSerializers.serialize(xRayErrorCause);

assertNotNull(result);
assertTrue(result.length > 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi;

import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.ErrorRequest;
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.XRayErrorCause;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class LambdaErrorTest {

@Test
void testConstructorWithXRayErrorCause() {
ErrorRequest errorRequest = new ErrorRequest();
XRayErrorCause xRayErrorCause = new XRayErrorCause();
RapidErrorType errorType = RapidErrorType.BadFunctionCode;

LambdaError lambdaError = new LambdaError(errorRequest, xRayErrorCause, errorType);

assertEquals(errorRequest, lambdaError.errorRequest);
assertEquals(xRayErrorCause, lambdaError.xRayErrorCause);
assertEquals(errorType, lambdaError.errorType);
}

@Test
void testConstructorWithoutXRayErrorCause() {
ErrorRequest errorRequest = new ErrorRequest();
RapidErrorType errorType = RapidErrorType.UserException;

LambdaError lambdaError = new LambdaError(errorRequest, errorType);

assertEquals(errorRequest, lambdaError.errorRequest);
assertNull(lambdaError.xRayErrorCause);
assertEquals(errorType, lambdaError.errorType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class LambdaRuntimeClientExceptionTest {

@Test
void testConstructor() {
String message = "Test error";
int responseCode = 500;

LambdaRuntimeClientException exception = new LambdaRuntimeClientException(message, responseCode);

assertEquals("Test error Response code: '500'.", exception.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class RapidErrorTypeTest {

@Test
void testGetRapidError() {
assertEquals("Runtime.BadFunctionCode", RapidErrorType.BadFunctionCode.getRapidError());
assertEquals("Runtime.UserException", RapidErrorType.UserException.getRapidError());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ErrorRequestTest {

@Test
void testDefaultConstructor() {
ErrorRequest request = new ErrorRequest();
assertNotNull(request);
}

@Test
void testParameterizedConstructor() {
String[] stackTrace = {"line1", "line2"};
ErrorRequest request = new ErrorRequest("error", "type", stackTrace);

assertEquals("error", request.errorMessage);
assertEquals("type", request.errorType);
assertArrayEquals(stackTrace, request.stackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class InvocationRequestTest {

@Test
void testGettersAndSetters() {
InvocationRequest request = new InvocationRequest();

request.setId("test-id");
assertEquals("test-id", request.getId());

request.setXrayTraceId("trace-id");
assertEquals("trace-id", request.getXrayTraceId());

request.setInvokedFunctionArn("arn");
assertEquals("arn", request.getInvokedFunctionArn());

request.setDeadlineTimeInMs(12345L);
assertEquals(12345L, request.getDeadlineTimeInMs());

request.setClientContext("context");
assertEquals("context", request.getClientContext());

request.setCognitoIdentity("identity");
assertEquals("identity", request.getCognitoIdentity());

request.setTenantId("tenant");
assertEquals("tenant", request.getTenantId());

byte[] content = "test".getBytes();
request.setContent(content);
assertArrayEquals(content, request.getContent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class StackElementTest {

@Test
void testDefaultConstructor() {
StackElement stackElement = new StackElement();
assertNotNull(stackElement);
assertNull(stackElement.label);
assertNull(stackElement.path);
assertEquals(0, stackElement.line);
}

@Test
void testParameterizedConstructor() {
String label = "testMethod";
String path = "/test/path";
int line = 42;

StackElement stackElement = new StackElement(label, path, line);

assertEquals(label, stackElement.label);
assertEquals(path, stackElement.path);
assertEquals(line, stackElement.line);
}
}
Loading