|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +solidb & |
| 5 | +SOLIDB_PID=$! |
| 6 | + |
| 7 | +BASE="http://localhost:6745" |
| 8 | + |
| 9 | +# Wait for SoliDB to be ready |
| 10 | +for i in $(seq 1 30); do |
| 11 | + if curl -sf "$BASE/_api/health" > /dev/null 2>&1; then |
| 12 | + break |
| 13 | + fi |
| 14 | + sleep 1 |
| 15 | +done |
| 16 | + |
| 17 | +# Authenticate and get JWT token |
| 18 | +TOKEN=$(curl -sf -X POST "$BASE/auth/login" \ |
| 19 | + -H "Content-Type: application/json" \ |
| 20 | + -d '{"username": "admin", "password": "benchmarkdbpass"}' \ |
| 21 | + | sed -n 's/.*"token":"\([^"]*\)".*/\1/p') |
| 22 | + |
| 23 | +AUTH="Authorization: Bearer $TOKEN" |
| 24 | + |
| 25 | +# Create database |
| 26 | +curl -sf -X POST "$BASE/_api/database" \ |
| 27 | + -H "Content-Type: application/json" \ |
| 28 | + -H "$AUTH" \ |
| 29 | + -d '{"name": "hello_world"}' || true |
| 30 | + |
| 31 | +DB="$BASE/_api/database/hello_world" |
| 32 | + |
| 33 | +# Create collections before inserting documents |
| 34 | +curl -sf -X POST "$DB/collection" \ |
| 35 | + -H "Content-Type: application/json" \ |
| 36 | + -H "$AUTH" \ |
| 37 | + -d '{"name": "fortunes"}' || true |
| 38 | + |
| 39 | +curl -sf -X POST "$DB/collection" \ |
| 40 | + -H "Content-Type: application/json" \ |
| 41 | + -H "$AUTH" \ |
| 42 | + -d '{"name": "worlds"}' || true |
| 43 | + |
| 44 | +# Seeding errors should not kill the database container |
| 45 | +set +e |
| 46 | + |
| 47 | +# Seed fortune collection via batch insert |
| 48 | +curl -sf -X POST "$DB/document/fortunes/_batch" \ |
| 49 | + -H "Content-Type: application/json" \ |
| 50 | + -H "$AUTH" \ |
| 51 | + -H "X-Shard-Direct: true" \ |
| 52 | + -d '[ |
| 53 | + {"id": 1, "message": "fortune: No such file or directory"}, |
| 54 | + {"id": 2, "message": "A computer scientist is someone who fixes things that aren'\''t broken."}, |
| 55 | + {"id": 3, "message": "After enough decimal places, nobody gives a damn."}, |
| 56 | + {"id": 4, "message": "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1"}, |
| 57 | + {"id": 5, "message": "A computer program does what you tell it to do, not what you want it to do."}, |
| 58 | + {"id": 6, "message": "Emacs is a nice operating system, but I prefer UNIX. \u2014 Tom Christaensen"}, |
| 59 | + {"id": 7, "message": "Any program that runs right is obsolete."}, |
| 60 | + {"id": 8, "message": "A list is only as strong as its weakest link. \u2014 Donald Knuth"}, |
| 61 | + {"id": 9, "message": "Feature: A bug with seniority."}, |
| 62 | + {"id": 10, "message": "Computers make very fast, very accurate mistakes."}, |
| 63 | + {"id": 11, "message": "<script>alert(\"This should not be displayed in a browser alert box.\");<\/script>"}, |
| 64 | + {"id": 12, "message": "\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af"} |
| 65 | + ]' |
| 66 | +echo "Fortunes seeded: exit code $?" |
| 67 | + |
| 68 | +# Seed world collection via batch inserts (1000 docs per batch) |
| 69 | +for batch in $(seq 0 9); do |
| 70 | + start=$((batch * 1000 + 1)) |
| 71 | + end=$((batch * 1000 + 1000)) |
| 72 | + docs="[" |
| 73 | + for i in $(seq $start $end); do |
| 74 | + rnd=$(( (RANDOM % 10000) + 1 )) |
| 75 | + if [ $i -gt $start ]; then docs="$docs,"; fi |
| 76 | + docs="$docs{\"id\":$i,\"randomNumber\":$rnd}" |
| 77 | + done |
| 78 | + docs="$docs]" |
| 79 | + curl -sf -X POST "$DB/document/worlds/_batch" \ |
| 80 | + -H "Content-Type: application/json" \ |
| 81 | + -H "$AUTH" \ |
| 82 | + -H "X-Shard-Direct: true" \ |
| 83 | + -d "$docs" |
| 84 | + echo "World batch $batch seeded: exit code $?" |
| 85 | +done |
| 86 | + |
| 87 | +echo "SoliDB seeding complete" |
| 88 | + |
| 89 | +wait $SOLIDB_PID |
0 commit comments