|
| 1 | +# 🚀 FalkorDB Spring Data Integration Test |
| 2 | + |
| 3 | +This directory contains a comprehensive integration test that demonstrates the FalkorDB Spring Data library working with a real FalkorDB instance using a Twitter-like social graph. |
| 4 | + |
| 5 | +## 📋 Prerequisites |
| 6 | + |
| 7 | +1. **FalkorDB Server**: You need FalkorDB running locally on port 6379 |
| 8 | +2. **Java 17+**: Make sure Java 17 or later is installed |
| 9 | +3. **Maven**: Required for building and running the test |
| 10 | + |
| 11 | +## 🏗️ Starting FalkorDB |
| 12 | + |
| 13 | +### Option 1: Using Docker (Recommended) |
| 14 | +```bash |
| 15 | +docker run -p 6379:6379 falkordb/falkordb:latest |
| 16 | +``` |
| 17 | + |
| 18 | +### Option 2: Using Native Installation |
| 19 | +If you have FalkorDB installed natively: |
| 20 | +```bash |
| 21 | +falkordb-server --port 6379 |
| 22 | +``` |
| 23 | + |
| 24 | +### Option 3: Using Redis with FalkorDB Module |
| 25 | +If you have Redis with FalkorDB module: |
| 26 | +```bash |
| 27 | +redis-server --port 6379 --loadmodule /path/to/falkordb.so |
| 28 | +``` |
| 29 | + |
| 30 | +## 🧪 Running the Test |
| 31 | + |
| 32 | +### Quick Run (Automated Script) |
| 33 | +```bash |
| 34 | +./run-falkordb-test.sh |
| 35 | +``` |
| 36 | + |
| 37 | +### Manual Run |
| 38 | +1. **Compile the project:** |
| 39 | + ```bash |
| 40 | + mvn compile -Dcheckstyle.skip=true -Dmaven.javadoc.skip=true |
| 41 | + ``` |
| 42 | + |
| 43 | +2. **Run the integration test:** |
| 44 | + ```bash |
| 45 | + mvn exec:java -Dexec.mainClass="org.springframework.data.falkordb.integration.FalkorDBTwitterIntegrationTest" -Dexec.classpathScope="test" |
| 46 | + ``` |
| 47 | + |
| 48 | +### JUnit Test Runner |
| 49 | +You can also run individual tests using JUnit: |
| 50 | +```bash |
| 51 | +mvn test -Dtest=FalkorDBTwitterIntegrationTest |
| 52 | +``` |
| 53 | + |
| 54 | +## 🌐 What the Test Does |
| 55 | + |
| 56 | +The integration test creates a comprehensive Twitter-like social graph and demonstrates: |
| 57 | + |
| 58 | +### 🎭 Entity Creation |
| 59 | +- **TwitterUser**: Users with profiles, follower counts, verification status |
| 60 | +- **Tweet**: Tweets with text, timestamps, engagement metrics |
| 61 | +- **Hashtag**: Hashtags with usage tracking |
| 62 | + |
| 63 | +### 🔗 Relationship Types |
| 64 | +- `FOLLOWS`: User following relationships |
| 65 | +- `POSTED`: Users posting tweets |
| 66 | +- `LIKED`: Users liking tweets |
| 67 | +- `RETWEETED`: Users retweeting tweets |
| 68 | +- `MENTIONS`: Tweets mentioning users |
| 69 | +- `HAS_HASHTAG`: Tweets containing hashtags |
| 70 | +- `REPLIES_TO`: Tweet reply chains |
| 71 | + |
| 72 | +### 📊 Test Scenarios |
| 73 | + |
| 74 | +1. **Connection & Basic Operations** |
| 75 | + - Connect to FalkorDB instance |
| 76 | + - Create and save entities |
| 77 | + - Retrieve entities by ID |
| 78 | + |
| 79 | +2. **Twitter Network Creation** |
| 80 | + - Create influential users (Elon Musk, Bill Gates, Oprah) |
| 81 | + - Set up realistic profiles with follower counts |
| 82 | + - Create tweets and relationships |
| 83 | + |
| 84 | +3. **Relationship Traversal** |
| 85 | + - Follow relationships between users |
| 86 | + - Find mutual connections |
| 87 | + - Navigate relationship paths |
| 88 | + |
| 89 | +4. **Complex Queries** |
| 90 | + - Analytics queries (user counts, tweet counts) |
| 91 | + - Find most followed users |
| 92 | + - Search verified users |
| 93 | + - Filter by follower thresholds |
| 94 | + |
| 95 | +## 📈 Sample Output |
| 96 | + |
| 97 | +``` |
| 98 | +🚀 Starting FalkorDB Twitter Integration Test |
| 99 | +================================================================================ |
| 100 | +=== Testing FalkorDB Connection and Basic Operations === |
| 101 | +✅ Saved user: TwitterUser{id=1, username='testuser', displayName='Test User', ...} |
| 102 | +✅ Retrieved user: TwitterUser{id=1, username='testuser', displayName='Test User', ...} |
| 103 | +
|
| 104 | +================================================================================ |
| 105 | +=== Testing Twitter Graph Creation and Traversal === |
| 106 | +Created Twitter network with users: |
| 107 | +- TwitterUser{id=2, username='elonmusk', displayName='Elon Musk', followerCount=150000000, verified=true} |
| 108 | +- TwitterUser{id=3, username='billgates', displayName='Bill Gates', followerCount=60000000, verified=true} |
| 109 | +- TwitterUser{id=4, username='oprah', displayName='Oprah Winfrey', followerCount=45000000, verified=true} |
| 110 | +
|
| 111 | +Found 3 verified users: |
| 112 | + - Elon Musk (@elonmusk) - 150000000 followers |
| 113 | + - Bill Gates (@billgates) - 60000000 followers |
| 114 | + - Oprah Winfrey (@oprah) - 45000000 followers |
| 115 | +
|
| 116 | +================================================================================ |
| 117 | +=== Testing Relationship Traversal === |
| 118 | +Alice follows 2 users: |
| 119 | + - Bob Smith |
| 120 | + - Charlie Brown |
| 121 | +Bob has 1 followers: |
| 122 | + - Alice Johnson |
| 123 | +Alice and Charlie both follow 1 users: |
| 124 | + - Bob Smith |
| 125 | +
|
| 126 | +================================================================================ |
| 127 | +🎉 All tests completed successfully! |
| 128 | +FalkorDB Spring Data integration is working correctly. |
| 129 | +``` |
| 130 | + |
| 131 | +## 🔍 Inspecting the Graph |
| 132 | + |
| 133 | +After running the test, you can inspect the created graph using the Redis CLI: |
| 134 | + |
| 135 | +```bash |
| 136 | +redis-cli -p 6379 |
| 137 | +``` |
| 138 | + |
| 139 | +### Useful Queries |
| 140 | + |
| 141 | +```cypher |
| 142 | +# View all nodes |
| 143 | +GRAPH.QUERY TWITTER 'MATCH (n) RETURN n LIMIT 10' |
| 144 | +
|
| 145 | +# View all users |
| 146 | +GRAPH.QUERY TWITTER 'MATCH (u:User) RETURN u.username, u.display_name, u.follower_count' |
| 147 | +
|
| 148 | +# View follow relationships |
| 149 | +GRAPH.QUERY TWITTER 'MATCH (u1:User)-[:FOLLOWS]->(u2:User) RETURN u1.username, u2.username' |
| 150 | +
|
| 151 | +# View tweets with authors |
| 152 | +GRAPH.QUERY TWITTER 'MATCH (u:User)-[:POSTED]->(t:Tweet) RETURN u.username, t.text' |
| 153 | +
|
| 154 | +# Find verified users |
| 155 | +GRAPH.QUERY TWITTER 'MATCH (u:User) WHERE u.verified = true RETURN u.username, u.follower_count ORDER BY u.follower_count DESC' |
| 156 | +
|
| 157 | +# Count nodes by type |
| 158 | +GRAPH.QUERY TWITTER 'MATCH (u:User) RETURN "Users" as type, count(u) as count UNION MATCH (t:Tweet) RETURN "Tweets" as type, count(t) as count' |
| 159 | +
|
| 160 | +# Clear the graph (if needed) |
| 161 | +GRAPH.QUERY TWITTER 'MATCH (n) DETACH DELETE n' |
| 162 | +``` |
| 163 | + |
| 164 | +## 🏗️ Architecture Demonstrated |
| 165 | + |
| 166 | +### Spring Data FalkorDB Components Used |
| 167 | + |
| 168 | +1. **FalkorDBClient**: Direct connection to FalkorDB server |
| 169 | +2. **FalkorDBTemplate**: High-level operations template |
| 170 | +3. **Entity Mapping**: JPA-style annotations for graph entities |
| 171 | +4. **Relationship Mapping**: Automatic relationship traversal |
| 172 | +5. **Repository Pattern**: Spring Data repository interfaces |
| 173 | +6. **Query Methods**: Derived and custom query methods |
| 174 | + |
| 175 | +### Annotations Used |
| 176 | + |
| 177 | +- `@Node`: Mark classes as graph nodes |
| 178 | +- `@Id`: Specify entity identifiers |
| 179 | +- `@GeneratedValue`: Auto-generate IDs |
| 180 | +- `@Property`: Map properties to graph attributes |
| 181 | +- `@Relationship`: Define relationships between entities |
| 182 | + |
| 183 | +## 🎯 Key Features Demonstrated |
| 184 | + |
| 185 | +✅ **Connection Management**: Robust FalkorDB connectivity |
| 186 | +✅ **Entity Persistence**: Save and retrieve complex objects |
| 187 | +✅ **Relationship Handling**: Navigate graph relationships |
| 188 | +✅ **Query Execution**: Custom Cypher query support |
| 189 | +✅ **Collection Support**: Handle lists of related entities |
| 190 | +✅ **Type Safety**: Strongly-typed entity conversion |
| 191 | +✅ **Error Handling**: Graceful failure management |
| 192 | + |
| 193 | +## 🚨 Troubleshooting |
| 194 | + |
| 195 | +### FalkorDB Not Running |
| 196 | +``` |
| 197 | +❌ FalkorDB connection failed: Connection refused |
| 198 | +``` |
| 199 | +**Solution**: Make sure FalkorDB is running on localhost:6379 |
| 200 | + |
| 201 | +### Compilation Errors |
| 202 | +``` |
| 203 | +❌ Compilation failed |
| 204 | +``` |
| 205 | +**Solution**: Ensure Java 17+ is installed and JAVA_HOME is set correctly |
| 206 | + |
| 207 | +### Permission Denied |
| 208 | +``` |
| 209 | +❌ Permission denied: ./run-falkordb-test.sh |
| 210 | +``` |
| 211 | +**Solution**: Make the script executable: `chmod +x run-falkordb-test.sh` |
| 212 | + |
| 213 | +### Memory Issues |
| 214 | +If you encounter OutOfMemoryError, increase Java heap size: |
| 215 | +```bash |
| 216 | +export MAVEN_OPTS="-Xmx2g" |
| 217 | +``` |
| 218 | + |
| 219 | +## 📚 Further Reading |
| 220 | + |
| 221 | +- [FalkorDB Documentation](https://www.falkordb.com/docs/) |
| 222 | +- [Spring Data Documentation](https://spring.io/projects/spring-data) |
| 223 | +- [Graph Database Concepts](https://www.falkordb.com/docs/graph-concepts) |
| 224 | + |
| 225 | +--- |
| 226 | + |
| 227 | +🎉 **Happy Graph Traversing with FalkorDB and Spring Data!** 🎉 |
0 commit comments