Skip to content
Open
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
79 changes: 79 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# E2E Tests for analytics-java
# Copy this file to: analytics-java/.github/workflows/e2e-tests.yml
#
# This workflow:
# 1. Checks out the SDK and sdk-e2e-tests repos
# 2. Builds the SDK and e2e-cli
# 3. Runs the e2e test suite

name: E2E Tests

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch: # Allow manual trigger

jobs:
e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout SDK
uses: actions/checkout@v4
with:
path: sdk

- name: Checkout sdk-e2e-tests
uses: actions/checkout@v4
with:
repository: segmentio/sdk-e2e-tests
token: ${{ secrets.E2E_TESTS_TOKEN }}
path: sdk-e2e-tests

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Build Java SDK and e2e-cli
working-directory: sdk
run: mvn package -pl e2e-cli -am -DskipTests

- name: Find e2e-cli jar
id: find-jar
working-directory: sdk
run: |
JAR_PATH=$(find e2e-cli/target -name "e2e-cli-*-jar-with-dependencies.jar" | head -1)
echo "jar_path=$JAR_PATH" >> $GITHUB_OUTPUT

- name: Install sdk-e2e-tests dependencies
working-directory: sdk-e2e-tests
run: npm ci

- name: Build sdk-e2e-tests
working-directory: sdk-e2e-tests
run: npm run build

- name: Run E2E tests
working-directory: sdk-e2e-tests
env:
CLI_COMMAND: java -jar ${{ github.workspace }}/sdk/${{ steps.find-jar.outputs.jar_path }}
E2E_TEST_SUITES: basic,retry
# E2E_TEST_SKIP: exponential-backoff # skip specific test files if needed
run: npm test

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-test-results
path: sdk-e2e-tests/test-results/
if-no-files-found: ignore
54 changes: 54 additions & 0 deletions e2e-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# analytics-java e2e-cli

E2E test CLI for the [analytics-java](https://github.com/segmentio/analytics-java) SDK. Accepts a JSON input describing events and SDK configuration, sends them through the real SDK, and outputs results as JSON.

Built with Kotlin (JVM) and packaged as a fat jar via Maven.

## Setup

```bash
mvn package -pl e2e-cli -am
```

## Usage

```bash
java -jar e2e-cli/target/e2e-cli-*-jar-with-dependencies.jar --input '{"writeKey":"...", ...}'
```

## Input Format

```jsonc
{
"writeKey": "your-write-key", // required
"apiHost": "https://...", // optional — SDK default if omitted
"sequences": [ // required — event sequences to send
{
"delayMs": 0,
"events": [
{ "type": "track", "event": "Test", "userId": "user-1" }
]
}
],
"config": { // optional
"flushAt": 250,
"flushInterval": 10000,
"maxRetries": 3,
"timeout": 15
}
}
```

Note: Java is a server-side SDK — there is no CDN settings fetch, so `cdnHost` does not apply.

## Output Format

```json
{ "success": true, "sentBatches": 1 }
```

On failure:

```json
{ "success": false, "error": "description", "sentBatches": 0 }
```
7 changes: 7 additions & 0 deletions e2e-cli/e2e-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": "java",
"test_suites": "basic",
"auto_settings": false,
"patch": null,
"env": {}
}
91 changes: 91 additions & 0 deletions e2e-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>analytics-parent</artifactId>
<groupId>com.segment.analytics.java</groupId>
<version>3.5.5-SNAPSHOT</version>
</parent>

<groupId>com.segment.analytics.java</groupId>
<artifactId>e2e-cli</artifactId>
<version>3.5.5-SNAPSHOT</version>
<name>Analytics Java E2E CLI</name>

<description>E2E testing CLI for Segment Analytics for Java.</description>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.segment.analytics.java</groupId>
<artifactId>analytics</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-json</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>

<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-serialization</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>cli.MainKt</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
41 changes: 41 additions & 0 deletions e2e-cli/run-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
#
# Run E2E tests for analytics-java
#
# Prerequisites: Java 11+, Maven, Node.js 18+
#
# Usage:
# ./run-e2e.sh [extra args passed to run-tests.sh]
#
# Override sdk-e2e-tests location:
# E2E_TESTS_DIR=../my-e2e-tests ./run-e2e.sh
#

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SDK_ROOT="$SCRIPT_DIR/.."
E2E_DIR="${E2E_TESTS_DIR:-$SDK_ROOT/../sdk-e2e-tests}"

echo "=== Building analytics-java e2e-cli ==="

# Build SDK and e2e-cli
cd "$SDK_ROOT"
mvn package -pl e2e-cli -am -DskipTests

# Find the built jar
CLI_JAR=$(find "$SDK_ROOT/e2e-cli/target" -name "e2e-cli-*-jar-with-dependencies.jar" | head -1)
if [[ -z "$CLI_JAR" ]]; then
echo "Error: Could not find e2e-cli jar"
exit 1
fi
echo "Found jar: $CLI_JAR"

echo ""

# Run tests
cd "$E2E_DIR"
./scripts/run-tests.sh \
--sdk-dir "$SCRIPT_DIR" \
--cli "java -jar $CLI_JAR" \
"$@"
Loading
Loading