Skip to content

Commit 4765d6d

Browse files
author
Kit Plummer
authored
Kp/claude to java (#9)
* rust and java tests for e2e and convergence testing * add: integration comparo between rust and java * add: handling complex details - convergence on array of elements * fix: bump to preview 2 * fix: remove any and all element order metadata - and optimize the stable key id
1 parent b2477eb commit 4765d6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6427
-27
lines changed

.github/workflows/java-ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ jobs:
4646

4747
build-and-test:
4848
runs-on: ubuntu-latest
49+
env:
50+
DITTO_APP_ID: ${{ secrets.DITTO_APP_ID }}
51+
DITTO_PLAYGROUND_TOKEN: ${{ secrets.DITTO_PLAYGROUND_TOKEN }}
4952
steps:
5053
- uses: actions/checkout@v4
5154

55+
- name: Install system dependencies
56+
run: |
57+
sudo apt-get update
58+
sudo apt-get install -y libffi-dev libffi8
59+
5260
- name: Set up JDK ${{ env.JAVA_VERSION }}
5361
uses: actions/setup-java@v4
5462
with:
@@ -79,7 +87,7 @@ jobs:
7987

8088
- name: Run tests
8189
working-directory: ./java
82-
run: ./gradlew :library:test :example:test
90+
run: ./gradlew :library:test :example:test --info
8391

8492
- name: Generate test report
8593
working-directory: ./java
@@ -106,9 +114,17 @@ jobs:
106114
integration-test:
107115
runs-on: ubuntu-latest
108116
needs: build-and-test
117+
env:
118+
DITTO_APP_ID: ${{ secrets.DITTO_APP_ID }}
119+
DITTO_PLAYGROUND_TOKEN: ${{ secrets.DITTO_PLAYGROUND_TOKEN }}
109120
steps:
110121
- uses: actions/checkout@v4
111122

123+
- name: Install system dependencies
124+
run: |
125+
sudo apt-get update
126+
sudo apt-get install -y libffi-dev libffi8
127+
112128
- name: Set up JDK ${{ env.JAVA_VERSION }}
113129
uses: actions/setup-java@v4
114130
with:

.github/workflows/rust-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Rust CI
22

33
on:
44
push:

Makefile

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Ditto CoT Makefile
22
# Builds and cleans all language-specific libraries
33

4-
# Default target
4+
# Default target - show help when no command is given
5+
.DEFAULT_GOAL := help
6+
7+
# Build all languages
58
.PHONY: all
69
all: rust java csharp
710

@@ -74,7 +77,7 @@ test-rust:
7477
test-java:
7578
@echo "Testing Java library and example..."
7679
@if [ -f "java/build.gradle" ] || [ -f "java/build.gradle.kts" ]; then \
77-
cd java && ./gradlew :library:test :example:test --console=rich --rerun-tasks; \
80+
cd java && ./gradlew :library:test :example:test --info --console=rich --rerun-tasks; \
7881
else \
7982
echo "Java build files not found. Skipping tests."; \
8083
fi
@@ -93,6 +96,23 @@ test-csharp:
9396
clean: clean-rust clean-java clean-csharp
9497
@echo "All libraries cleaned."
9598

99+
# Example targets
100+
.PHONY: example-rust
101+
example-rust:
102+
@echo "Running Rust example..."
103+
@cd rust && cargo run --example integration_client
104+
105+
.PHONY: example-java
106+
example-java:
107+
@echo "Running Java example..."
108+
@cd java && ./gradlew :example:runIntegrationClient
109+
110+
# Integration test target
111+
.PHONY: test-integration
112+
test-integration: example-rust example-java
113+
@echo "Running cross-language integration test..."
114+
@cd rust && cargo test --test integration_test
115+
96116
# Help target
97117
.PHONY: help
98118
help:
@@ -107,6 +127,9 @@ help:
107127
@echo " test-rust - Run tests for Rust library"
108128
@echo " test-java - Run tests for Java library"
109129
@echo " test-csharp - Run tests for C# library"
130+
@echo " example-rust - Run Rust example client"
131+
@echo " example-java - Run Java example client"
132+
@echo " test-integration - Run cross-language integration test"
110133
@echo " clean - Clean all libraries"
111134
@echo " clean-rust - Clean Rust library"
112135
@echo " clean-java - Clean Java library"

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,112 @@ cargo test --all-targets
339339
cargo test test_underscore_key_handling
340340
```
341341

342+
### Cross-Language Integration Testing
343+
344+
The repository includes a comprehensive integration test system that validates compatibility between the Rust and Java implementations:
345+
346+
```bash
347+
# Run individual language examples
348+
make example-rust # Outputs JSON from Rust integration client
349+
make example-java # Outputs JSON from Java integration client
350+
351+
# Run cross-language integration test
352+
make test-integration # Builds both examples and runs compatibility test
353+
```
354+
355+
#### Integration Test Overview
356+
357+
The integration test system (`rust/tests/integration_test.rs`) performs the following validations:
358+
359+
1. **Process Spawning**: Launches both Rust binary and Java distribution executables
360+
2. **Same Input Processing**: Both clients process identical CoT XML input
361+
3. **Output Comparison**: Validates that both implementations produce equivalent JSON output
362+
4. **Document Structure Verification**: Compares Ditto document structures for consistency
363+
5. **Roundtrip Validation**: Ensures both can perform XML → Ditto → XML conversions
364+
365+
#### Example Clients
366+
367+
- **Rust**: `rust/examples/integration_client.rs` - Uses the ditto_cot API
368+
- **Java**: `java/example/src/main/java/com/ditto/cot/example/IntegrationClient.java` - Uses the CoTConverter API
369+
370+
Both clients process the same CoT XML event and output structured JSON containing:
371+
```json
372+
{
373+
"lang": "rust|java",
374+
"original_xml": "...",
375+
"ditto_document": {...},
376+
"roundtrip_xml": "...",
377+
"success": true
378+
}
379+
```
380+
381+
### End-to-End (E2E) Testing
382+
383+
The Rust implementation includes comprehensive end-to-end tests that verify full integration with Ditto:
384+
385+
#### Single-Peer E2E Test: `rust/tests/e2e_test.rs`
386+
387+
Basic E2E tests that perform complete workflows including:
388+
389+
1. **Ditto Integration**: Real connection to Ditto with authentication
390+
2. **Document Storage**: Uses DQL to insert CoT documents into collections
391+
3. **Round-trip Verification**: CoT XML → CotEvent → CotDocument → Ditto → Query → XML
392+
4. **Multiple Document Types**: Tests all CotDocument variants (MapItem, Chat, File, Api, Generic)
393+
5. **Schema Validation**: Validates document structure and field mappings
394+
6. **XML Semantic Comparison**: Uses semantic XML equality for robust comparison
395+
396+
#### Multi-Peer E2E Test: `rust/tests/e2e_multi_peer.rs`
397+
398+
Advanced E2E test that simulates real-world distributed scenarios:
399+
400+
**Test Scenario Overview:**
401+
1. **Peer Connection**: Two Rust clients establish peer-to-peer connection
402+
2. **Document Creation**: One peer creates a CoT MapItem document
403+
3. **Sync Verification**: Document automatically syncs to second peer
404+
4. **Offline Simulation**: Both peers go offline independently
405+
5. **Conflict Creation**: Each peer makes conflicting modifications while offline
406+
6. **Reconnection**: Both peers come back online and sync
407+
7. **Conflict Resolution**: Validates last-write-wins merge behavior
408+
409+
**Key Features Tested:**
410+
- **Peer Discovery**: Automatic peer detection and connection establishment
411+
- **Real-time Sync**: Document changes propagate between peers automatically
412+
- **Offline Resilience**: Peers can operate independently when disconnected
413+
- **Conflict Resolution**: CRDT merge semantics handle conflicting changes
414+
- **DQL Integration**: Uses Ditto Query Language for all operations
415+
- **Observers & Subscriptions**: Real-time change notifications between peers
416+
417+
#### Running E2E Tests
418+
419+
```bash
420+
# Set up Ditto environment variables
421+
export DITTO_APP_ID="your-app-id"
422+
export DITTO_PLAYGROUND_TOKEN="your-token"
423+
424+
# Run single-peer E2E tests
425+
cargo test e2e_xml_roundtrip
426+
cargo test e2e_xml_examples_roundtrip
427+
428+
# Run multi-peer E2E test
429+
cargo test e2e_multi_peer_mapitem_sync_test
430+
431+
# Run with specific XML file
432+
E2E_XML_FILE="example.xml" cargo test e2e_xml_examples_roundtrip
433+
```
434+
435+
#### E2E Test Features
436+
437+
- **Real Ditto Connection**: Tests against actual Ditto playground/cloud
438+
- **Multiple XML Examples**: Processes all XML files in `schema/example_xml/`
439+
- **Collection Management**: Automatically handles different collection types based on document type
440+
- **DQL Integration**: Uses Ditto Query Language for document operations
441+
- **Semantic XML Comparison**: Handles XML formatting differences intelligently
442+
- **Peer-to-Peer Sync**: Validates document synchronization between multiple Ditto instances
443+
- **Conflict Resolution**: Tests CRDT merge behavior under realistic conditions
444+
- **Error Handling**: Comprehensive error reporting for debugging
445+
446+
The E2E tests ensure that the library works correctly in production-like environments with real Ditto instances and provides confidence in the complete CoT → Ditto → CoT workflow, including distributed scenarios with multiple peers.
447+
342448
## 🛠️ Build System
343449

344450
### Makefile

0 commit comments

Comments
 (0)