Compare commits
7 Commits
tantivy
...
8331ed032b
Author | SHA1 | Date | |
---|---|---|---|
8331ed032b | |||
|
4bb24b38dd | ||
|
f3da14b957 | ||
|
5ea34b4445 | ||
|
d9a3b711d1 | ||
|
d931770e90 | ||
|
a87ec4dbb5 |
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "herodb"
|
name = "herodb"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = ["Pin Fang <fpfangpin@hotmail.com>"]
|
authors = ["ThreeFold Tech NV"]
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.59"
|
anyhow = "1.0.59"
|
||||||
|
@@ -47,13 +47,13 @@ You can start HeroDB with different backends and encryption options:
|
|||||||
#### `redb` with Encryption
|
#### `redb` with Encryption
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./target/release/herodb --dir /tmp/herodb_encrypted --port 6379 --encrypt --key mysecretkey
|
./target/release/herodb --dir /tmp/herodb_encrypted --port 6379 --encrypt --encryption_key mysecretkey
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `sled` with Encryption
|
#### `sled` with Encryption
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./target/release/herodb --dir /tmp/herodb_sled_encrypted --port 6379 --sled --encrypt --key mysecretkey
|
./target/release/herodb --dir /tmp/herodb_sled_encrypted --port 6379 --sled --encrypt --encryption_key mysecretkey
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage with Redis Clients
|
## Usage with Redis Clients
|
||||||
|
143
run.sh
Executable file
143
run.sh
Executable file
@@ -0,0 +1,143 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
|
|
||||||
|
# Test script for HeroDB - Redis-compatible database with redb backend
|
||||||
|
# This script starts the server and runs comprehensive tests
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
DB_DIR="/tmp/test_db"
|
||||||
|
PORT=6381
|
||||||
|
SERVER_PID=""
|
||||||
|
|
||||||
|
# Function to print colored output
|
||||||
|
print_status() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to cleanup on exit
|
||||||
|
cleanup() {
|
||||||
|
if [ ! -z "$SERVER_PID" ]; then
|
||||||
|
print_status "Stopping HeroDB server (PID: $SERVER_PID)..."
|
||||||
|
kill $SERVER_PID 2>/dev/null || true
|
||||||
|
wait $SERVER_PID 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up test database
|
||||||
|
if [ -d "$DB_DIR" ]; then
|
||||||
|
print_status "Cleaning up test database directory..."
|
||||||
|
rm -rf "$DB_DIR"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set trap to cleanup on script exit
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# Function to wait for server to start
|
||||||
|
wait_for_server() {
|
||||||
|
local max_attempts=30
|
||||||
|
local attempt=1
|
||||||
|
|
||||||
|
print_status "Waiting for server to start on port $PORT..."
|
||||||
|
|
||||||
|
while [ $attempt -le $max_attempts ]; do
|
||||||
|
if nc -z localhost $PORT 2>/dev/null; then
|
||||||
|
print_success "Server is ready!"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "."
|
||||||
|
sleep 1
|
||||||
|
attempt=$((attempt + 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
print_error "Server failed to start within $max_attempts seconds"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to send Redis command and get response
|
||||||
|
redis_cmd() {
|
||||||
|
local cmd="$1"
|
||||||
|
local expected="$2"
|
||||||
|
|
||||||
|
print_status "Testing: $cmd"
|
||||||
|
|
||||||
|
local result=$(echo "$cmd" | redis-cli -p $PORT --raw 2>/dev/null || echo "ERROR")
|
||||||
|
|
||||||
|
if [ "$expected" != "" ] && [ "$result" != "$expected" ]; then
|
||||||
|
print_error "Expected: '$expected', Got: '$result'"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
print_success "✓ $cmd -> $result"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main execution
|
||||||
|
main() {
|
||||||
|
print_status "Starting HeroDB"
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
print_status "Building HeroDB..."
|
||||||
|
if ! cargo build -p herodb --release; then
|
||||||
|
print_error "Failed to build HeroDB"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create test database directory
|
||||||
|
mkdir -p "$DB_DIR"
|
||||||
|
|
||||||
|
# Start the server
|
||||||
|
print_status "Starting HeroDB server..."
|
||||||
|
${SCRIPT_DIR}/target/release/herodb --dir "$DB_DIR" --port $PORT &
|
||||||
|
SERVER_PID=$!
|
||||||
|
|
||||||
|
# Wait for server to start
|
||||||
|
if ! wait_for_server; then
|
||||||
|
print_error "Failed to start server"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check dependencies
|
||||||
|
check_dependencies() {
|
||||||
|
if ! command -v cargo &> /dev/null; then
|
||||||
|
print_error "cargo is required but not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v nc &> /dev/null; then
|
||||||
|
print_warning "netcat (nc) not found - some tests may not work properly"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v redis-cli &> /dev/null; then
|
||||||
|
print_warning "redis-cli not found - using netcat fallback"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run dependency check and main function
|
||||||
|
check_dependencies
|
||||||
|
main "$@"
|
||||||
|
tail -f /dev/null
|
@@ -1,4 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
echo "🧪 Running HeroDB Redis Compatibility Tests"
|
echo "🧪 Running HeroDB Redis Compatibility Tests"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
# Test script for HeroDB - Redis-compatible database with redb backend
|
# Test script for HeroDB - Redis-compatible database with redb backend
|
||||||
# This script starts the server and runs comprehensive tests
|
# This script starts the server and runs comprehensive tests
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Colors for output
|
# Colors for output
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
|
@@ -501,11 +501,11 @@ async fn test_07_age_stateless_suite() {
|
|||||||
let mut s = connect(port).await;
|
let mut s = connect(port).await;
|
||||||
|
|
||||||
// GENENC -> [recipient, identity]
|
// GENENC -> [recipient, identity]
|
||||||
let gen = send_cmd(&mut s, &["AGE", "GENENC"]).await;
|
let genenc = send_cmd(&mut s, &["AGE", "GENENC"]).await;
|
||||||
assert!(
|
assert!(
|
||||||
gen.starts_with("*2\r\n$"),
|
genenc.starts_with("*2\r\n$"),
|
||||||
"AGE GENENC should return array [recipient, identity], got:\n{}",
|
"AGE GENENC should return array [recipient, identity], got:\n{}",
|
||||||
gen
|
genenc
|
||||||
);
|
);
|
||||||
|
|
||||||
// Parse simple RESP array of two bulk strings to extract keys
|
// Parse simple RESP array of two bulk strings to extract keys
|
||||||
@@ -520,7 +520,7 @@ async fn test_07_age_stateless_suite() {
|
|||||||
let ident = lines.next().unwrap_or("").to_string();
|
let ident = lines.next().unwrap_or("").to_string();
|
||||||
(recip, ident)
|
(recip, ident)
|
||||||
}
|
}
|
||||||
let (recipient, identity) = parse_two_bulk_array(&gen);
|
let (recipient, identity) = parse_two_bulk_array(&genenc);
|
||||||
assert!(
|
assert!(
|
||||||
recipient.starts_with("age1") && identity.starts_with("AGE-SECRET-KEY-1"),
|
recipient.starts_with("age1") && identity.starts_with("AGE-SECRET-KEY-1"),
|
||||||
"Unexpected AGE key formats.\nrecipient: {}\nidentity: {}",
|
"Unexpected AGE key formats.\nrecipient: {}\nidentity: {}",
|
||||||
|
Reference in New Issue
Block a user