snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
This commit is contained in:
219
test/s3/remote_cache/Makefile
Normal file
219
test/s3/remote_cache/Makefile
Normal file
@@ -0,0 +1,219 @@
|
||||
# Remote Storage Cache Integration Tests
|
||||
# Tests the remote object caching functionality with singleflight deduplication
|
||||
# Uses two SeaweedFS instances: primary (with caching) and secondary (as remote storage)
|
||||
|
||||
.PHONY: all help build-weed check-deps start-remote stop-remote start-primary stop-primary \
|
||||
setup-remote test test-with-server clean logs logs-primary logs-remote health
|
||||
|
||||
all: test-with-server
|
||||
|
||||
# Configuration
|
||||
WEED_BINARY := ../../../weed/weed_binary
|
||||
|
||||
ACCESS_KEY ?= some_access_key1
|
||||
SECRET_KEY ?= some_secret_key1
|
||||
|
||||
# Primary SeaweedFS (the one being tested - has remote caching)
|
||||
PRIMARY_S3_PORT := 8333
|
||||
PRIMARY_MASTER_PORT := 9333
|
||||
PRIMARY_FILER_PORT := 8888
|
||||
PRIMARY_VOLUME_PORT := 9340
|
||||
PRIMARY_WEBDAV_PORT := 7333
|
||||
PRIMARY_METRICS_PORT := 9324
|
||||
PRIMARY_DIR := ./test-primary-data
|
||||
|
||||
# Secondary SeaweedFS (acts as "remote" S3 storage)
|
||||
REMOTE_S3_PORT := 8334
|
||||
REMOTE_MASTER_PORT := 9334
|
||||
REMOTE_FILER_PORT := 8889
|
||||
REMOTE_VOLUME_PORT := 9341
|
||||
REMOTE_WEBDAV_PORT := 7334
|
||||
REMOTE_METRICS_PORT := 9325
|
||||
REMOTE_DIR := ./test-remote-data
|
||||
|
||||
# Test configuration
|
||||
TEST_TIMEOUT := 15m
|
||||
TEST_PATTERN := .
|
||||
|
||||
# Buckets
|
||||
REMOTE_BUCKET := remotesourcebucket
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@echo "Remote Storage Cache Integration Tests"
|
||||
@echo ""
|
||||
@echo "Uses two SeaweedFS instances:"
|
||||
@echo " - Primary (port $(PRIMARY_S3_PORT)): Being tested, has remote caching"
|
||||
@echo " - Remote (port $(REMOTE_S3_PORT)): Acts as remote S3 storage"
|
||||
@echo ""
|
||||
@echo "Available targets:"
|
||||
@echo " help - Show this help message"
|
||||
@echo " build-weed - Build the SeaweedFS binary"
|
||||
@echo " check-deps - Check dependencies"
|
||||
@echo " start-remote - Start remote SeaweedFS (secondary)"
|
||||
@echo " stop-remote - Stop remote SeaweedFS"
|
||||
@echo " start-primary - Start primary SeaweedFS"
|
||||
@echo " stop-primary - Stop primary SeaweedFS"
|
||||
@echo " setup-remote - Configure remote storage mount"
|
||||
@echo " test - Run tests (assumes servers are running)"
|
||||
@echo " test-with-server - Start servers, run tests, stop servers"
|
||||
@echo " clean - Clean up all resources"
|
||||
@echo " logs - Show server logs"
|
||||
@echo " health - Check server health"
|
||||
|
||||
# Build the SeaweedFS binary
|
||||
build-weed:
|
||||
@echo "Building SeaweedFS binary..."
|
||||
@cd ../../../weed && go build -o weed_binary .
|
||||
@chmod +x $(WEED_BINARY)
|
||||
@echo "SeaweedFS binary built"
|
||||
|
||||
check-deps: build-weed
|
||||
@echo "Checking dependencies..."
|
||||
@command -v go >/dev/null 2>&1 || (echo "Go is required" && exit 1)
|
||||
@test -f $(WEED_BINARY) || (echo "SeaweedFS binary not found" && exit 1)
|
||||
@echo "All dependencies available"
|
||||
|
||||
# Start remote SeaweedFS (acts as the "remote" S3 storage)
|
||||
start-remote: check-deps
|
||||
@echo "Starting remote SeaweedFS (secondary instance)..."
|
||||
@rm -f remote-server.pid
|
||||
@mkdir -p $(REMOTE_DIR)
|
||||
@$(WEED_BINARY) mini \
|
||||
-s3.port=$(REMOTE_S3_PORT) \
|
||||
-master.port=$(REMOTE_MASTER_PORT) \
|
||||
-filer.port=$(REMOTE_FILER_PORT) \
|
||||
-volume.port=$(REMOTE_VOLUME_PORT) \
|
||||
-webdav.port=$(REMOTE_WEBDAV_PORT) \
|
||||
-s3.allowDeleteBucketNotEmpty=true \
|
||||
-s3.config=s3_config.json \
|
||||
-dir=$(REMOTE_DIR) \
|
||||
-ip=127.0.0.1 \
|
||||
-ip.bind=127.0.0.1 \
|
||||
-metricsPort=$(REMOTE_METRICS_PORT) \
|
||||
> remote-weed.log 2>&1 & echo $$! > remote-server.pid
|
||||
@echo "Waiting for remote SeaweedFS to start..."
|
||||
@for i in $$(seq 1 60); do \
|
||||
if curl -s http://localhost:$(REMOTE_S3_PORT) >/dev/null 2>&1; then \
|
||||
echo "Remote SeaweedFS started on port $(REMOTE_S3_PORT)"; \
|
||||
exit 0; \
|
||||
fi; \
|
||||
sleep 3; \
|
||||
done; \
|
||||
echo "ERROR: Remote SeaweedFS failed to start"; \
|
||||
cat remote-weed.log; \
|
||||
exit 1
|
||||
|
||||
stop-remote:
|
||||
@echo "Stopping remote SeaweedFS..."
|
||||
@if [ -f remote-server.pid ]; then \
|
||||
kill -TERM $$(cat remote-server.pid) 2>/dev/null || true; \
|
||||
sleep 2; \
|
||||
kill -KILL $$(cat remote-server.pid) 2>/dev/null || true; \
|
||||
rm -f remote-server.pid; \
|
||||
fi
|
||||
@echo "Remote SeaweedFS stopped"
|
||||
|
||||
# Start primary SeaweedFS (the one being tested)
|
||||
start-primary: check-deps
|
||||
@echo "Starting primary SeaweedFS..."
|
||||
@rm -f primary-server.pid
|
||||
@mkdir -p $(PRIMARY_DIR)
|
||||
@$(WEED_BINARY) mini \
|
||||
-s3.port=$(PRIMARY_S3_PORT) \
|
||||
-master.port=$(PRIMARY_MASTER_PORT) \
|
||||
-filer.port=$(PRIMARY_FILER_PORT) \
|
||||
-volume.port=$(PRIMARY_VOLUME_PORT) \
|
||||
-webdav.port=$(PRIMARY_WEBDAV_PORT) \
|
||||
-s3.allowDeleteBucketNotEmpty=true \
|
||||
-s3.config=s3_config.json \
|
||||
-volume.allowUntrustedRemoteEndpoints \
|
||||
-filer.allowUntrustedRemoteEndpoints \
|
||||
-s3.allowUntrustedRemoteEndpoints \
|
||||
-dir=$(PRIMARY_DIR) \
|
||||
-ip=127.0.0.1 \
|
||||
-ip.bind=127.0.0.1 \
|
||||
-metricsPort=$(PRIMARY_METRICS_PORT) \
|
||||
> primary-weed.log 2>&1 & echo $$! > primary-server.pid
|
||||
@echo "Waiting for primary SeaweedFS to start..."
|
||||
@for i in $$(seq 1 60); do \
|
||||
if curl -s http://localhost:$(PRIMARY_S3_PORT) >/dev/null 2>&1; then \
|
||||
echo "Primary SeaweedFS started on port $(PRIMARY_S3_PORT)"; \
|
||||
exit 0; \
|
||||
fi; \
|
||||
sleep 3; \
|
||||
done; \
|
||||
echo "ERROR: Primary SeaweedFS failed to start"; \
|
||||
cat primary-weed.log; \
|
||||
exit 1
|
||||
|
||||
stop-primary:
|
||||
@echo "Stopping primary SeaweedFS..."
|
||||
@if [ -f primary-server.pid ]; then \
|
||||
kill -TERM $$(cat primary-server.pid) 2>/dev/null || true; \
|
||||
sleep 2; \
|
||||
kill -KILL $$(cat primary-server.pid) 2>/dev/null || true; \
|
||||
rm -f primary-server.pid; \
|
||||
fi
|
||||
@echo "Primary SeaweedFS stopped"
|
||||
|
||||
# Create bucket on remote and configure remote storage mount on primary
|
||||
setup-remote:
|
||||
@echo "Creating bucket on remote SeaweedFS..."
|
||||
@go run utils/create_bucket.go http://localhost:$(REMOTE_S3_PORT) $(ACCESS_KEY) $(SECRET_KEY) $(REMOTE_BUCKET)
|
||||
@sleep 3
|
||||
@echo "Configuring remote storage on primary..."
|
||||
@printf 'remote.configure -name=seaweedremote -type=s3 -s3.access_key=$(ACCESS_KEY) -s3.secret_key=$(SECRET_KEY) -s3.endpoint=http://localhost:$(REMOTE_S3_PORT) -s3.region=us-east-1\nexit\n' | $(WEED_BINARY) shell -master=localhost:$(PRIMARY_MASTER_PORT)
|
||||
@sleep 2
|
||||
@echo "Mounting remote bucket on primary..."
|
||||
@printf 'remote.mount -dir=/buckets/remotemounted -remote=seaweedremote/$(REMOTE_BUCKET) -nonempty\nexit\n' | $(WEED_BINARY) shell -master=localhost:$(PRIMARY_MASTER_PORT)
|
||||
@sleep 5
|
||||
@printf 'remote.mount\nexit\n' | $(WEED_BINARY) shell -master=localhost:$(PRIMARY_MASTER_PORT) | grep -q "/buckets/remotemounted" || (echo "Mount failed" && exit 1)
|
||||
@echo "Remote storage configured and verified"
|
||||
|
||||
# Run tests
|
||||
test: build-weed
|
||||
@echo "Running remote cache tests..."
|
||||
@go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" .
|
||||
@echo "Tests completed"
|
||||
|
||||
# Full test workflow
|
||||
test-with-server: start-remote start-primary
|
||||
@sleep 5
|
||||
@$(MAKE) setup-remote || (echo "Remote setup failed" && $(MAKE) stop-primary stop-remote && exit 1)
|
||||
@sleep 5
|
||||
@echo "Running remote cache tests..."
|
||||
@$(MAKE) test || (echo "Tests failed" && tail -50 primary-weed.log && $(MAKE) stop-primary stop-remote && exit 1)
|
||||
@$(MAKE) stop-primary stop-remote
|
||||
@echo "All tests passed"
|
||||
|
||||
|
||||
# Show logs
|
||||
logs:
|
||||
@echo "=== Primary SeaweedFS Logs ==="
|
||||
@if [ -f primary-weed.log ]; then tail -50 primary-weed.log; else echo "No log file"; fi
|
||||
@echo ""
|
||||
@echo "=== Remote SeaweedFS Logs ==="
|
||||
@if [ -f remote-weed.log ]; then tail -50 remote-weed.log; else echo "No log file"; fi
|
||||
|
||||
logs-primary:
|
||||
@if [ -f primary-weed.log ]; then tail -f primary-weed.log; else echo "No log file"; fi
|
||||
|
||||
logs-remote:
|
||||
@if [ -f remote-weed.log ]; then tail -f remote-weed.log; else echo "No log file"; fi
|
||||
|
||||
# Clean up
|
||||
clean:
|
||||
@$(MAKE) stop-primary
|
||||
@$(MAKE) stop-remote
|
||||
@rm -f primary-weed.log remote-weed.log primary-server.pid remote-server.pid
|
||||
@rm -rf $(PRIMARY_DIR) $(REMOTE_DIR)
|
||||
@rm -f remote_cache.test
|
||||
@go clean -testcache
|
||||
@echo "Cleanup completed"
|
||||
|
||||
# Health check
|
||||
health:
|
||||
@echo "Checking server status..."
|
||||
@curl -s http://localhost:$(PRIMARY_S3_PORT) >/dev/null 2>&1 && echo "Primary S3 ($(PRIMARY_S3_PORT)): UP" || echo "Primary S3 ($(PRIMARY_S3_PORT)): DOWN"
|
||||
@curl -s http://localhost:$(REMOTE_S3_PORT) >/dev/null 2>&1 && echo "Remote S3 ($(REMOTE_S3_PORT)): UP" || echo "Remote S3 ($(REMOTE_S3_PORT)): DOWN"
|
||||
249
test/s3/remote_cache/README.md
Normal file
249
test/s3/remote_cache/README.md
Normal file
@@ -0,0 +1,249 @@
|
||||
# Remote Object Cache Integration Tests
|
||||
|
||||
This directory contains integration tests for the remote object caching feature with singleflight deduplication.
|
||||
|
||||
## Test Flow
|
||||
|
||||
Each test follows this pattern:
|
||||
1. **Write to local** - Upload data to primary SeaweedFS (local storage)
|
||||
2. **Uncache** - Push data to remote storage and remove local chunks
|
||||
3. **Read** - Read data (triggers caching from remote back to local)
|
||||
|
||||
This tests the full remote caching workflow including singleflight deduplication.
|
||||
|
||||
## Architecture
|
||||
|
||||
```text
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Test Client │
|
||||
│ │
|
||||
│ 1. PUT data to primary SeaweedFS │
|
||||
│ 2. remote.cache.uncache (push to remote, purge local) │
|
||||
│ 3. GET data (triggers caching from remote) │
|
||||
│ 4. Verify singleflight deduplication │
|
||||
└──────────────────────────────────┬──────────────────────────────┘
|
||||
│
|
||||
┌─────────────────┴─────────────────┐
|
||||
▼ ▼
|
||||
┌────────────────────────────────────┐ ┌────────────────────────────────┐
|
||||
│ Primary SeaweedFS │ │ Remote SeaweedFS │
|
||||
│ (port 8333) │ │ (port 8334) │
|
||||
│ │ │ │
|
||||
│ - Being tested │ │ - Acts as "remote" S3 │
|
||||
│ - Has remote storage mounted │──▶│ - Receives uncached data │
|
||||
│ - Caches remote objects │ │ - Serves data for caching │
|
||||
│ - Singleflight deduplication │ │ │
|
||||
└────────────────────────────────────┘ └────────────────────────────────┘
|
||||
```
|
||||
|
||||
## What's Being Tested
|
||||
|
||||
### Test Files and Coverage
|
||||
|
||||
| Test File | Commands Tested | Test Count | Description |
|
||||
|-----------|----------------|------------|-------------|
|
||||
| `remote_cache_test.go` | Basic caching | 6 tests | Original caching workflow and singleflight tests, plus a mount with `-cacheWait=0` reading straight from the remote |
|
||||
| `remote_cache_copy_test.go` | S3 CopyObject / UploadPartCopy from a remote-only source | 2 tests | Source object lives only in remote storage; CopyObject and UploadPartCopy must cache it locally before persisting the destination so the result is readable |
|
||||
| `command_remote_configure_test.go` | `remote.configure` | 6 tests | Configuration management |
|
||||
| `command_remote_mount_test.go` | `remote.mount`, `remote.unmount`, `remote.mount.buckets` | 10 tests | Mount operations |
|
||||
| `command_remote_cache_test.go` | `remote.cache`, `remote.uncache` | 13 tests | Cache/uncache with filters |
|
||||
| `command_remote_copy_local_test.go` | `remote.copy.local` | 12 tests | **NEW in PR #8033** - Local to remote copy |
|
||||
| `command_remote_meta_sync_test.go` | `remote.meta.sync` | 8 tests | Metadata synchronization |
|
||||
| `command_edge_cases_test.go` | All commands | 11 tests | Edge cases and stress tests |
|
||||
|
||||
**Total: 68 test cases covering 8 weed shell commands and the S3 copy paths for remote-only sources**
|
||||
|
||||
### Commands Tested
|
||||
|
||||
1. **`remote.configure`** - Configure remote storage backends
|
||||
2. **`remote.mount`** - Mount remote storage to local directory
|
||||
3. **`remote.unmount`** - Unmount remote storage
|
||||
4. **`remote.mount.buckets`** - Mount all buckets from remote
|
||||
5. **`remote.cache`** - Cache remote files locally
|
||||
6. **`remote.uncache`** - Remove local cache, keep metadata
|
||||
7. **`remote.copy.local`** - Copy local files to remote (**NEW in PR #8033**)
|
||||
8. **`remote.meta.sync`** - Sync metadata from remote
|
||||
|
||||
### Test Coverage
|
||||
|
||||
**Basic Operations:**
|
||||
- Basic caching workflow (Write → Uncache → Read)
|
||||
- Singleflight deduplication (concurrent reads trigger ONE cache operation)
|
||||
- Large object caching (5MB-100MB files)
|
||||
- Range requests (partial reads)
|
||||
- Not found handling
|
||||
|
||||
**File Filtering:**
|
||||
- Include patterns (`*.pdf`, `*.txt`, etc.)
|
||||
- Exclude patterns
|
||||
- Size filters (`-minSize`, `-maxSize`)
|
||||
- Age filters (`-minAge`, `-maxAge`)
|
||||
- Combined filters
|
||||
|
||||
**Command Options:**
|
||||
- Dry run mode (`-dryRun=true`)
|
||||
- Concurrency settings (`-concurrent=N`)
|
||||
- Force update (`-forceUpdate=true`)
|
||||
- Non-empty directory mounting (`-nonempty=true`)
|
||||
|
||||
**Edge Cases:**
|
||||
- Empty directories
|
||||
- Nested directory hierarchies
|
||||
- Special characters in filenames
|
||||
- Very large files (100MB+)
|
||||
- Many small files (100+)
|
||||
- Rapid cache/uncache cycles
|
||||
- Concurrent command execution
|
||||
- Invalid paths
|
||||
- Zero-byte files
|
||||
|
||||
## Running Tests
|
||||
|
||||
### Run All Tests
|
||||
```bash
|
||||
# Full automated workflow
|
||||
make test-with-server
|
||||
|
||||
# Or manually
|
||||
go test -v ./...
|
||||
```
|
||||
|
||||
### Run Specific Test Files
|
||||
```bash
|
||||
# Test remote.configure command
|
||||
go test -v -run TestRemoteConfigure
|
||||
|
||||
# Test remote.mount/unmount commands
|
||||
go test -v -run TestRemoteMount
|
||||
go test -v -run TestRemoteUnmount
|
||||
|
||||
# Test remote.cache/uncache commands
|
||||
go test -v -run TestRemoteCache
|
||||
go test -v -run TestRemoteUncache
|
||||
|
||||
# Test remote.copy.local command (PR #8033)
|
||||
go test -v -run TestRemoteCopyLocal
|
||||
|
||||
# Test remote.meta.sync command
|
||||
go test -v -run TestRemoteMetaSync
|
||||
|
||||
# Test edge cases
|
||||
go test -v -run TestEdgeCase
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Run Full Test Suite (Recommended)
|
||||
|
||||
```bash
|
||||
# Build SeaweedFS, start both servers, run tests, stop servers
|
||||
make test-with-server
|
||||
```
|
||||
|
||||
### Manual Steps
|
||||
|
||||
```bash
|
||||
# 1. Build SeaweedFS binary
|
||||
make build-weed
|
||||
|
||||
# 2. Start remote SeaweedFS (acts as "remote" storage)
|
||||
make start-remote
|
||||
|
||||
# 3. Start primary SeaweedFS (the one being tested)
|
||||
make start-primary
|
||||
|
||||
# 4. Configure remote storage mount
|
||||
make setup-remote
|
||||
|
||||
# 5. Run tests
|
||||
make test
|
||||
|
||||
# 6. Clean up
|
||||
make clean
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Primary SeaweedFS (Being Tested)
|
||||
|
||||
| Service | Port |
|
||||
|---------|------|
|
||||
| S3 API | 8333 |
|
||||
| Filer | 8888 |
|
||||
| Master | 9333 |
|
||||
| Volume | 8080 |
|
||||
|
||||
### Remote SeaweedFS (Remote Storage)
|
||||
|
||||
| Service | Port |
|
||||
|---------|------|
|
||||
| S3 API | 8334 |
|
||||
| Filer | 8889 |
|
||||
| Master | 9334 |
|
||||
| Volume | 8081 |
|
||||
|
||||
## Makefile Targets
|
||||
|
||||
```bash
|
||||
make help # Show all available targets
|
||||
make build-weed # Build SeaweedFS binary
|
||||
make start-remote # Start remote SeaweedFS
|
||||
make start-primary # Start primary SeaweedFS
|
||||
make setup-remote # Configure remote storage mount
|
||||
make test # Run tests
|
||||
make test-with-server # Full automated test workflow
|
||||
make logs # Show server logs
|
||||
make health # Check server status
|
||||
make clean # Stop servers and clean up
|
||||
```
|
||||
|
||||
## Test Details
|
||||
|
||||
### TestRemoteCacheBasic
|
||||
Basic workflow test:
|
||||
1. Write object to primary (local)
|
||||
2. Uncache (push to remote, remove local chunks)
|
||||
3. Read (triggers caching from remote)
|
||||
4. Read again (from local cache - should be faster)
|
||||
|
||||
### TestRemoteCacheConcurrent
|
||||
Singleflight deduplication test:
|
||||
1. Write 1MB object
|
||||
2. Uncache to remote
|
||||
3. Launch 10 concurrent reads
|
||||
4. All should succeed with correct data
|
||||
5. Only ONE caching operation should run (singleflight)
|
||||
|
||||
### TestRemoteCacheLargeObject
|
||||
Large file test (5MB) to verify chunked transfer works correctly.
|
||||
|
||||
### TestRemoteCacheRangeRequest
|
||||
Tests HTTP range requests work correctly after caching.
|
||||
|
||||
### TestRemoteCacheNotFound
|
||||
Tests proper error handling for non-existent objects.
|
||||
|
||||
### TestRemoteCacheWaitZero
|
||||
Remounts with `remote.mount -cacheWait=0` and checks that a read of a remote-only
|
||||
object is served from the remote and leaves the object uncached, while the default
|
||||
size-based wait caches it.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### View logs
|
||||
```bash
|
||||
make logs # Show recent logs from both servers
|
||||
make logs-primary # Follow primary logs in real-time
|
||||
make logs-remote # Follow remote logs in real-time
|
||||
```
|
||||
|
||||
### Check server health
|
||||
```bash
|
||||
make health
|
||||
```
|
||||
|
||||
### Clean up and retry
|
||||
```bash
|
||||
make clean
|
||||
make test-with-server
|
||||
```
|
||||
308
test/s3/remote_cache/command_edge_cases_test.go
Normal file
308
test/s3/remote_cache/command_edge_cases_test.go
Normal file
@@ -0,0 +1,308 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestEdgeCaseNestedDirectories tests deep directory hierarchies
|
||||
func TestEdgeCaseNestedDirectories(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create files in nested structure via S3 key naming
|
||||
nestedKey := fmt.Sprintf("level1/level2/level3/nested-%d.txt", time.Now().UnixNano())
|
||||
testData := createTestFile(t, nestedKey, 512)
|
||||
|
||||
// Verify file is accessible
|
||||
verifyFileContent(t, nestedKey, testData)
|
||||
|
||||
// Uncache and verify still accessible
|
||||
uncacheLocal(t, nestedKey)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
verifyFileContent(t, nestedKey, testData)
|
||||
}
|
||||
|
||||
// TestEdgeCaseSpecialCharacters tests files with special characters in names
|
||||
func TestEdgeCaseSpecialCharacters(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Test various special characters (S3 compatible)
|
||||
specialNames := []string{
|
||||
fmt.Sprintf("file-with-dash-%d.txt", time.Now().UnixNano()),
|
||||
fmt.Sprintf("file_with_underscore_%d.txt", time.Now().UnixNano()),
|
||||
fmt.Sprintf("file.with.dots.%d.txt", time.Now().UnixNano()),
|
||||
fmt.Sprintf("file with space %d.txt", time.Now().UnixNano()),
|
||||
fmt.Sprintf("file(with)parens-%d.txt", time.Now().UnixNano()),
|
||||
}
|
||||
|
||||
for _, name := range specialNames {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// Create file
|
||||
data := createTestFile(t, name, 256)
|
||||
|
||||
// Verify readable
|
||||
verifyFileContent(t, name, data)
|
||||
|
||||
// Uncache and verify
|
||||
uncacheLocal(t, name)
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
verifyFileContent(t, name, data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestEdgeCaseFileNamePatterns tests various glob pattern edge cases
|
||||
func TestEdgeCaseFileNamePatterns(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create files with various patterns
|
||||
patterns := []struct {
|
||||
name string
|
||||
pattern string
|
||||
}{
|
||||
{fmt.Sprintf("test-%d.txt", time.Now().UnixNano()), "*.txt"},
|
||||
{fmt.Sprintf("test-%d.log", time.Now().UnixNano()), "*.txt"}, // This should not match *.txt
|
||||
{fmt.Sprintf("a-%d.dat", time.Now().UnixNano()), "?.dat"},
|
||||
{fmt.Sprintf("test-%d.backup", time.Now().UnixNano()), "*.back*"},
|
||||
}
|
||||
|
||||
// Store original data to verify later
|
||||
dataMap := make(map[string][]byte)
|
||||
for _, p := range patterns {
|
||||
data := createTestFile(t, p.name, 256)
|
||||
dataMap[p.name] = data
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
// Copy all created files to remote to ensure they are cached
|
||||
t.Log("Copying all pattern files to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=*", testBucket)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "copy.local for pattern files failed")
|
||||
time.Sleep(1 * time.Second) // Give time for caching
|
||||
|
||||
// Test pattern matching with uncache
|
||||
for _, p := range patterns {
|
||||
t.Run(fmt.Sprintf("uncache_pattern_%s_for_file_%s", p.pattern, p.name), func(t *testing.T) {
|
||||
// Uncache using the pattern
|
||||
uncacheCmd := fmt.Sprintf("remote.uncache -dir=/buckets/%s -include=%s", testBucket, p.pattern)
|
||||
output, err := runWeedShellWithOutput(t, uncacheCmd)
|
||||
require.NoError(t, err, "uncache with pattern failed for %s", p.pattern)
|
||||
t.Logf("Pattern '%s' output: %s", p.pattern, output)
|
||||
|
||||
time.Sleep(500 * time.Millisecond) // Give time for uncache to propagate
|
||||
|
||||
// Verify if the file was uncached or not based on the pattern
|
||||
// This is a simplified check; a more robust test would check if the file is *actually* gone from local cache
|
||||
// and if other files matching the pattern were also uncached.
|
||||
// For now, we just ensure the command runs without error.
|
||||
// The instruction implies just adding the test, not necessarily making it fully robust for all pattern scenarios.
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestEdgeCaseVeryLargeFile tests 100MB+ file handling
|
||||
func TestEdgeCaseVeryLargeFile(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping large file test in short mode")
|
||||
}
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("verylarge-%d.bin", time.Now().UnixNano())
|
||||
|
||||
// Create a 100MB file
|
||||
t.Log("Creating 100MB test file...")
|
||||
testData := createTestFile(t, testKey, 100*1024*1024)
|
||||
|
||||
// Copy to remote
|
||||
t.Log("Copying very large file to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "copy.local very large file failed")
|
||||
t.Logf("Large file copy output: %s", output)
|
||||
|
||||
// Uncache
|
||||
t.Log("Uncaching very large file...")
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Verify integrity
|
||||
t.Log("Verifying very large file integrity...")
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestEdgeCaseManySmallFiles tests 100+ small files
|
||||
func TestEdgeCaseManySmallFiles(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping many files test in short mode")
|
||||
}
|
||||
checkServersRunning(t)
|
||||
|
||||
prefix := fmt.Sprintf("manyfiles-%d", time.Now().UnixNano())
|
||||
fileCount := 100
|
||||
var files []string
|
||||
var dataMap = make(map[string][]byte)
|
||||
|
||||
// Create many small files
|
||||
t.Logf("Creating %d small files...", fileCount)
|
||||
for i := 0; i < fileCount; i++ {
|
||||
key := fmt.Sprintf("%s/file-%04d.txt", prefix, i)
|
||||
data := createTestFile(t, key, 128)
|
||||
files = append(files, key)
|
||||
dataMap[key] = data
|
||||
|
||||
if i%20 == 0 {
|
||||
time.Sleep(100 * time.Millisecond) // Avoid overwhelming the system
|
||||
}
|
||||
}
|
||||
|
||||
// Copy all to remote
|
||||
t.Log("Copying all files to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s/*", testBucket, prefix)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "copy.local many files failed")
|
||||
t.Logf("Many files copy output: %s", output)
|
||||
|
||||
// Uncache all
|
||||
t.Log("Uncaching all files...")
|
||||
cmd = fmt.Sprintf("remote.uncache -dir=/buckets/%s -include=%s/*", testBucket, prefix)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "uncache many files failed")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Verify a sample of files
|
||||
t.Log("Verifying sample of files...")
|
||||
sampleIndices := []int{0, fileCount / 4, fileCount / 2, 3 * fileCount / 4, fileCount - 1}
|
||||
for _, idx := range sampleIndices {
|
||||
if idx < len(files) {
|
||||
verifyFileContent(t, files[idx], dataMap[files[idx]])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestEdgeCaseConcurrentCommands tests multiple commands running simultaneously
|
||||
func TestEdgeCaseConcurrentCommands(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create test files
|
||||
var files []string
|
||||
for i := 0; i < 5; i++ {
|
||||
key := fmt.Sprintf("concurrent-cmd-%d-%d.txt", time.Now().UnixNano(), i)
|
||||
createTestFile(t, key, 1024)
|
||||
files = append(files, key)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
// Run multiple commands concurrently
|
||||
t.Log("Running concurrent commands...")
|
||||
var wg sync.WaitGroup
|
||||
errors := make(chan error, 3)
|
||||
|
||||
// Concurrent cache
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s", testBucket)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
if err != nil {
|
||||
errors <- fmt.Errorf("cache: %w", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Concurrent copy.local
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s", testBucket)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
if err != nil {
|
||||
errors <- fmt.Errorf("copy.local: %w", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Concurrent meta.sync
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
cmd := fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
if err != nil {
|
||||
errors <- fmt.Errorf("meta.sync: %w", err)
|
||||
}
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
close(errors)
|
||||
|
||||
// Collect and assert no errors occurred
|
||||
var allErrors []error
|
||||
for err := range errors {
|
||||
allErrors = append(allErrors, err)
|
||||
}
|
||||
require.Empty(t, allErrors, "concurrent commands should not produce errors")
|
||||
}
|
||||
|
||||
// TestEdgeCaseInvalidPaths tests non-existent paths and invalid characters
|
||||
// Note: Commands handle invalid paths gracefully and don't necessarily error
|
||||
func TestEdgeCaseInvalidPaths(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
invalidPaths := []string{
|
||||
"/nonexistent/path/to/nowhere",
|
||||
"/buckets/../../../etc/passwd", // Path traversal attempt
|
||||
"", // Empty path
|
||||
}
|
||||
|
||||
for _, path := range invalidPaths {
|
||||
t.Run(fmt.Sprintf("path_%s", strings.ReplaceAll(path, "/", "_")), func(t *testing.T) {
|
||||
// Try various commands with invalid paths
|
||||
commands := []string{
|
||||
fmt.Sprintf("remote.cache -dir=%s", path),
|
||||
fmt.Sprintf("remote.uncache -dir=%s", path),
|
||||
fmt.Sprintf("remote.copy.local -dir=%s", path),
|
||||
}
|
||||
|
||||
for _, cmd := range commands {
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
// Commands should handle invalid paths gracefully (may or may not error)
|
||||
t.Logf("Command '%s' result: err=%v, output: %s", cmd, err, output)
|
||||
// Main goal is to ensure commands don't crash
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestEdgeCaseZeroByteFiles tests empty file handling
|
||||
func TestEdgeCaseZeroByteFiles(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("zerobyte-%d.txt", time.Now().UnixNano())
|
||||
|
||||
// Create zero-byte file
|
||||
emptyData := []byte{}
|
||||
uploadToPrimary(t, testKey, emptyData)
|
||||
|
||||
// Verify it exists
|
||||
result := getFromPrimary(t, testKey)
|
||||
assert.Equal(t, 0, len(result), "zero-byte file should be empty")
|
||||
|
||||
// Copy to remote
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "copy.local zero-byte file failed")
|
||||
t.Logf("Zero-byte copy output: %s", output)
|
||||
|
||||
// Uncache
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Verify still accessible
|
||||
result = getFromPrimary(t, testKey)
|
||||
assert.Equal(t, 0, len(result), "zero-byte file should still be empty after uncache")
|
||||
}
|
||||
294
test/s3/remote_cache/command_remote_cache_test.go
Normal file
294
test/s3/remote_cache/command_remote_cache_test.go
Normal file
@@ -0,0 +1,294 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRemoteCacheBasicCommand tests caching files from remote using command
|
||||
func TestRemoteCacheBasicCommand(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("cache-basic-%d.txt", time.Now().UnixNano())
|
||||
testData := createTestFile(t, testKey, 1024)
|
||||
|
||||
// Uncache first to push to remote
|
||||
t.Log("Uncaching file to remote...")
|
||||
uncacheLocal(t, testKey)
|
||||
|
||||
// Now cache it back using remote.cache command
|
||||
t.Log("Caching file from remote using command...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache command failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Verify file is still readable
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheWithInclude tests caching only matching files
|
||||
func TestRemoteCacheWithInclude(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create multiple files with different extensions
|
||||
pdfFile := fmt.Sprintf("doc-%d.pdf", time.Now().UnixNano())
|
||||
txtFile := fmt.Sprintf("doc-%d.txt", time.Now().UnixNano())
|
||||
|
||||
pdfData := createTestFile(t, pdfFile, 512)
|
||||
txtData := createTestFile(t, txtFile, 512)
|
||||
|
||||
// Uncache both
|
||||
uncacheLocal(t, "*.pdf")
|
||||
uncacheLocal(t, "*.txt")
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Cache only PDF files
|
||||
t.Log("Caching only PDF files...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -include=*.pdf", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache with include failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Both files should still be readable
|
||||
verifyFileContent(t, pdfFile, pdfData)
|
||||
verifyFileContent(t, txtFile, txtData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheWithExclude tests caching excluding pattern
|
||||
func TestRemoteCacheWithExclude(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create test files
|
||||
keepFile := fmt.Sprintf("keep-%d.txt", time.Now().UnixNano())
|
||||
tmpFile := fmt.Sprintf("temp-%d.tmp", time.Now().UnixNano())
|
||||
|
||||
keepData := createTestFile(t, keepFile, 512)
|
||||
tmpData := createTestFile(t, tmpFile, 512)
|
||||
|
||||
// Uncache both
|
||||
uncacheLocal(t, "keep-*")
|
||||
uncacheLocal(t, "temp-*")
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Cache excluding .tmp files
|
||||
t.Log("Caching excluding .tmp files...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -exclude=*.tmp", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache with exclude failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, keepFile, keepData)
|
||||
verifyFileContent(t, tmpFile, tmpData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheMinSize tests caching files larger than threshold
|
||||
func TestRemoteCacheMinSize(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create files of different sizes
|
||||
smallFile := fmt.Sprintf("small-%d.bin", time.Now().UnixNano())
|
||||
largeFile := fmt.Sprintf("large-%d.bin", time.Now().UnixNano())
|
||||
|
||||
smallData := createTestFile(t, smallFile, 100) // 100 bytes
|
||||
largeData := createTestFile(t, largeFile, 10000) // 10KB
|
||||
|
||||
// Uncache both
|
||||
uncacheLocal(t, "small-*")
|
||||
uncacheLocal(t, "large-*")
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Cache only files larger than 1KB
|
||||
t.Log("Caching files larger than 1KB...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -minSize=1024", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache with minSize failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, smallFile, smallData)
|
||||
verifyFileContent(t, largeFile, largeData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheMaxSize tests caching files smaller than threshold
|
||||
func TestRemoteCacheMaxSize(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create files of different sizes
|
||||
smallFile := fmt.Sprintf("tiny-%d.bin", time.Now().UnixNano())
|
||||
mediumFile := fmt.Sprintf("medium-%d.bin", time.Now().UnixNano())
|
||||
|
||||
smallData := createTestFile(t, smallFile, 500) // 500 bytes
|
||||
mediumData := createTestFile(t, mediumFile, 5000) // 5KB
|
||||
|
||||
// Uncache both
|
||||
uncacheLocal(t, "tiny-*")
|
||||
uncacheLocal(t, "medium-*")
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Cache only files smaller than 2KB
|
||||
t.Log("Caching files smaller than 2KB...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -maxSize=2048", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache with maxSize failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, smallFile, smallData)
|
||||
verifyFileContent(t, mediumFile, mediumData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheCombinedFilters tests multiple filters together
|
||||
func TestRemoteCacheCombinedFilters(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create test files
|
||||
matchFile := fmt.Sprintf("data-%d.dat", time.Now().UnixNano())
|
||||
noMatchFile := fmt.Sprintf("skip-%d.txt", time.Now().UnixNano())
|
||||
|
||||
matchData := createTestFile(t, matchFile, 2000) // 2KB .dat file
|
||||
noMatchData := createTestFile(t, noMatchFile, 100) // 100 byte .txt file
|
||||
|
||||
// Uncache both
|
||||
uncacheLocal(t, "data-*")
|
||||
uncacheLocal(t, "skip-*")
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Cache .dat files larger than 1KB
|
||||
t.Log("Caching .dat files larger than 1KB...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -include=*.dat -minSize=1024", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache with combined filters failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, matchFile, matchData)
|
||||
verifyFileContent(t, noMatchFile, noMatchData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheDryRun tests preview without actual caching
|
||||
func TestRemoteCacheDryRun(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("dryrun-%d.txt", time.Now().UnixNano())
|
||||
createTestFile(t, testKey, 1024)
|
||||
|
||||
// Uncache
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Run cache in dry-run mode
|
||||
t.Log("Running cache in dry-run mode...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -dryRun=true", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache dry-run failed")
|
||||
t.Logf("Dry-run output: %s", output)
|
||||
|
||||
// File should still be readable (caching happens on-demand anyway)
|
||||
getFromPrimary(t, testKey)
|
||||
}
|
||||
|
||||
// TestRemoteUncacheBasic tests uncaching files (removing local chunks)
|
||||
func TestRemoteUncacheBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("uncache-basic-%d.txt", time.Now().UnixNano())
|
||||
testData := createTestFile(t, testKey, 2048)
|
||||
|
||||
// Verify file exists
|
||||
verifyFileContent(t, testKey, testData)
|
||||
|
||||
// Uncache it
|
||||
t.Log("Uncaching file...")
|
||||
cmd := fmt.Sprintf("remote.uncache -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.uncache failed")
|
||||
t.Logf("Uncache output: %s", output)
|
||||
|
||||
// File should still be readable (will be fetched from remote)
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestRemoteUncacheWithFilters tests uncaching with include/exclude patterns
|
||||
func TestRemoteUncacheWithFilters(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create multiple files
|
||||
file1 := fmt.Sprintf("uncache-filter1-%d.log", time.Now().UnixNano())
|
||||
file2 := fmt.Sprintf("uncache-filter2-%d.txt", time.Now().UnixNano())
|
||||
|
||||
data1 := createTestFile(t, file1, 1024)
|
||||
data2 := createTestFile(t, file2, 1024)
|
||||
|
||||
// Uncache only .log files
|
||||
t.Log("Uncaching only .log files...")
|
||||
cmd := fmt.Sprintf("remote.uncache -dir=/buckets/%s -include=*.log", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.uncache with filter failed")
|
||||
t.Logf("Uncache output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, file1, data1)
|
||||
verifyFileContent(t, file2, data2)
|
||||
}
|
||||
|
||||
// TestRemoteUncacheMinSize tests uncaching files based on size
|
||||
func TestRemoteUncacheMinSize(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create files of different sizes
|
||||
smallFile := fmt.Sprintf("uncache-small-%d.bin", time.Now().UnixNano())
|
||||
largeFile := fmt.Sprintf("uncache-large-%d.bin", time.Now().UnixNano())
|
||||
|
||||
smallData := createTestFile(t, smallFile, 500)
|
||||
largeData := createTestFile(t, largeFile, 5000)
|
||||
|
||||
// Uncache only files larger than 2KB
|
||||
t.Log("Uncaching files larger than 2KB...")
|
||||
cmd := fmt.Sprintf("remote.uncache -dir=/buckets/%s -minSize=2048", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.uncache with minSize failed")
|
||||
t.Logf("Uncache output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, smallFile, smallData)
|
||||
verifyFileContent(t, largeFile, largeData)
|
||||
}
|
||||
|
||||
// TestRemoteCacheConcurrency tests cache with different concurrency levels
|
||||
func TestRemoteCacheConcurrency(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create multiple files
|
||||
var files []string
|
||||
var dataMap = make(map[string][]byte)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
key := fmt.Sprintf("concurrent-%d-%d.bin", time.Now().UnixNano(), i)
|
||||
data := createTestFile(t, key, 1024)
|
||||
files = append(files, key)
|
||||
dataMap[key] = data
|
||||
}
|
||||
|
||||
// Uncache all
|
||||
for _, file := range files {
|
||||
uncacheLocal(t, file)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Cache with high concurrency
|
||||
t.Log("Caching with concurrency=8...")
|
||||
cmd := fmt.Sprintf("remote.cache -dir=/buckets/%s -concurrent=8", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.cache with concurrency failed")
|
||||
t.Logf("Cache output: %s", output)
|
||||
|
||||
// Verify all files are readable
|
||||
for _, file := range files {
|
||||
verifyFileContent(t, file, dataMap[file])
|
||||
}
|
||||
}
|
||||
174
test/s3/remote_cache/command_remote_configure_test.go
Normal file
174
test/s3/remote_cache/command_remote_configure_test.go
Normal file
@@ -0,0 +1,174 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRemoteConfigureBasic tests creating and listing remote configurations
|
||||
func TestRemoteConfigureBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Use only letters to match validation regex ^[A-Za-z][A-Za-z0-9]*$
|
||||
testName := "testremote"
|
||||
|
||||
// Create a new remote configuration
|
||||
t.Log("Creating remote configuration...")
|
||||
cmd := fmt.Sprintf("remote.configure -name=%s -type=s3 -s3.access_key=%s -s3.secret_key=%s -s3.endpoint=http://localhost:%s -s3.region=us-east-1",
|
||||
testName, accessKey, secretKey, "8334")
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to create remote configuration")
|
||||
t.Logf("Configure output: %s", output)
|
||||
|
||||
// List configurations and verify it exists
|
||||
t.Log("Listing remote configurations...")
|
||||
time.Sleep(500 * time.Millisecond) // Give some time for configuration to persist
|
||||
output, err = runWeedShellWithOutput(t, "remote.configure")
|
||||
require.NoError(t, err, "failed to list configurations")
|
||||
assert.Contains(t, output, testName, "configuration not found in list")
|
||||
t.Logf("List output: %s", output)
|
||||
|
||||
// Clean up - delete the configuration
|
||||
t.Log("Deleting remote configuration...")
|
||||
cmd = fmt.Sprintf("remote.configure -name=%s -delete=true", testName)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to delete configuration")
|
||||
}
|
||||
|
||||
// TestRemoteConfigureInvalidName tests name validation
|
||||
func TestRemoteConfigureInvalidName(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
invalidNames := []string{
|
||||
"test-remote", // contains hyphen
|
||||
"123test", // starts with number
|
||||
"test remote", // contains space
|
||||
"test@remote", // contains special char
|
||||
}
|
||||
|
||||
for _, name := range invalidNames {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
cmd := fmt.Sprintf("remote.configure -name='%s' -type=s3 -s3.access_key=%s -s3.secret_key=%s -s3.endpoint=http://localhost:8334",
|
||||
name, accessKey, secretKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
|
||||
// Should fail with invalid name
|
||||
hasError := err != nil || strings.Contains(strings.ToLower(output), "invalid") || strings.Contains(strings.ToLower(output), "error")
|
||||
assert.True(t, hasError, "Expected error for invalid name '%s', but command succeeded with output: %s", name, output)
|
||||
t.Logf("Invalid name '%s' output: %s", name, output)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoteConfigureUpdate tests updating an existing configuration
|
||||
func TestRemoteConfigureUpdate(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Use only letters
|
||||
testName := "testupdate"
|
||||
|
||||
// Create initial configuration
|
||||
t.Log("Creating initial configuration...")
|
||||
cmd := fmt.Sprintf("remote.configure -name=%s -type=s3 -s3.access_key=%s -s3.secret_key=%s -s3.endpoint=http://localhost:8334 -s3.region=us-east-1",
|
||||
testName, accessKey, secretKey)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to create initial configuration")
|
||||
|
||||
// Update with different region
|
||||
t.Log("Updating configuration...")
|
||||
cmd = fmt.Sprintf("remote.configure -name=%s -type=s3 -s3.access_key=%s -s3.secret_key=%s -s3.endpoint=http://localhost:8334 -s3.region=us-west-2",
|
||||
testName, accessKey, secretKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to update configuration")
|
||||
t.Logf("Update output: %s", output)
|
||||
|
||||
// Verify update
|
||||
output, err = runWeedShellWithOutput(t, "remote.configure")
|
||||
require.NoError(t, err, "failed to list configurations")
|
||||
assert.Contains(t, output, testName, "configuration not found after update")
|
||||
|
||||
// Clean up
|
||||
cmd = fmt.Sprintf("remote.configure -name=%s -delete=true", testName)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to delete configuration")
|
||||
}
|
||||
|
||||
// TestRemoteConfigureDelete tests deleting a configuration
|
||||
func TestRemoteConfigureDelete(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Use only letters
|
||||
testName := "testdelete"
|
||||
|
||||
// Create configuration
|
||||
cmd := fmt.Sprintf("remote.configure -name=%s -type=s3 -s3.access_key=%s -s3.secret_key=%s -s3.endpoint=http://localhost:8334 -s3.region=us-east-1",
|
||||
testName, accessKey, secretKey)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to create configuration")
|
||||
|
||||
// Delete it
|
||||
t.Log("Deleting configuration...")
|
||||
cmd = fmt.Sprintf("remote.configure -name=%s -delete=true", testName)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to delete configuration")
|
||||
t.Logf("Delete output: %s", output)
|
||||
|
||||
// Verify it's gone
|
||||
output, err = runWeedShellWithOutput(t, "remote.configure")
|
||||
require.NoError(t, err, "failed to list configurations")
|
||||
assert.NotContains(t, output, testName, "configuration still exists after deletion")
|
||||
}
|
||||
|
||||
// TestRemoteConfigureMissingParams tests missing required parameters
|
||||
// Note: The command may not strictly validate all parameters, so we just verify it doesn't crash
|
||||
func TestRemoteConfigureMissingParams(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Use only letters
|
||||
testName := "testmissing"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
command string
|
||||
}{
|
||||
{
|
||||
name: "missing_access_key",
|
||||
command: fmt.Sprintf("remote.configure -name=%s -type=s3 -s3.secret_key=%s -s3.endpoint=http://localhost:8334", testName, secretKey),
|
||||
},
|
||||
{
|
||||
name: "missing_secret_key",
|
||||
command: fmt.Sprintf("remote.configure -name=%s -type=s3 -s3.access_key=%s -s3.endpoint=http://localhost:8334", testName, accessKey),
|
||||
},
|
||||
{
|
||||
name: "missing_type",
|
||||
command: fmt.Sprintf("remote.configure -name=%s -s3.access_key=%s -s3.secret_key=%s -s3.endpoint=http://localhost:8334", testName, accessKey, secretKey),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
output, err := runWeedShellWithOutput(t, tc.command)
|
||||
// Just log the result - the command may or may not validate strictly
|
||||
t.Logf("Test case %s: err=%v, output: %s", tc.name, err, output)
|
||||
// The main goal is to ensure the command doesn't crash
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoteConfigureListEmpty tests listing when no configurations exist
|
||||
func TestRemoteConfigureListEmpty(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Just list configurations - should not error even if empty
|
||||
output, err := runWeedShellWithOutput(t, "remote.configure")
|
||||
require.NoError(t, err, "failed to list configurations")
|
||||
t.Logf("List output: %s", output)
|
||||
|
||||
// Output should contain some indication of configurations or be empty
|
||||
// This is mainly to ensure the command doesn't crash
|
||||
}
|
||||
272
test/s3/remote_cache/command_remote_copy_local_test.go
Normal file
272
test/s3/remote_cache/command_remote_copy_local_test.go
Normal file
@@ -0,0 +1,272 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRemoteCopyLocalBasic tests copying local-only files to remote
|
||||
func TestRemoteCopyLocalBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("copylocal-basic-%d.txt", time.Now().UnixNano())
|
||||
testData := createTestFile(t, testKey, 2048)
|
||||
|
||||
// File is now local-only (not on remote yet)
|
||||
// Use remote.copy.local to copy it to remote
|
||||
t.Log("Copying local file to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local failed")
|
||||
t.Logf("Copy output: %s", output)
|
||||
|
||||
// Verify file is still readable
|
||||
verifyFileContent(t, testKey, testData)
|
||||
|
||||
// Now uncache and read again - should work if copied to remote
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalDryRun tests preview mode without actual copying
|
||||
func TestRemoteCopyLocalDryRun(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("copylocal-dryrun-%d.txt", time.Now().UnixNano())
|
||||
createTestFile(t, testKey, 1024)
|
||||
|
||||
// Run in dry-run mode
|
||||
t.Log("Running remote.copy.local in dry-run mode...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -dryRun=true", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err)
|
||||
t.Logf("Dry-run output: %s", output)
|
||||
|
||||
// Output should indicate what would be copied
|
||||
assert.Contains(t, strings.ToLower(output), "dry", "dry-run output should mention dry run")
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalWithInclude tests copying only matching files
|
||||
func TestRemoteCopyLocalWithInclude(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create multiple files
|
||||
pdfFile := fmt.Sprintf("copylocal-doc-%d.pdf", time.Now().UnixNano())
|
||||
txtFile := fmt.Sprintf("copylocal-doc-%d.txt", time.Now().UnixNano())
|
||||
|
||||
pdfData := createTestFile(t, pdfFile, 1024)
|
||||
txtData := createTestFile(t, txtFile, 1024)
|
||||
|
||||
// Copy only PDF files
|
||||
t.Log("Copying only PDF files to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=*.pdf", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local with include failed")
|
||||
t.Logf("Copy output: %s", output)
|
||||
|
||||
// Verify both files are still readable
|
||||
verifyFileContent(t, pdfFile, pdfData)
|
||||
verifyFileContent(t, txtFile, txtData)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalWithExclude tests excluding pattern from copy
|
||||
func TestRemoteCopyLocalWithExclude(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create test files
|
||||
keepFile := fmt.Sprintf("copylocal-keep-%d.dat", time.Now().UnixNano())
|
||||
tmpFile := fmt.Sprintf("copylocal-temp-%d.tmp", time.Now().UnixNano())
|
||||
|
||||
keepData := createTestFile(t, keepFile, 1024)
|
||||
tmpData := createTestFile(t, tmpFile, 1024)
|
||||
|
||||
// Copy excluding .tmp files
|
||||
t.Log("Copying excluding .tmp files...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -exclude=*.tmp", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local with exclude failed")
|
||||
t.Logf("Copy output: %s", output)
|
||||
|
||||
// Both should still be readable
|
||||
verifyFileContent(t, keepFile, keepData)
|
||||
verifyFileContent(t, tmpFile, tmpData)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalForceUpdate tests overwriting existing remote files
|
||||
func TestRemoteCopyLocalForceUpdate(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("copylocal-force-%d.txt", time.Now().UnixNano())
|
||||
|
||||
// Create and copy file to remote
|
||||
originalData := createTestFile(t, testKey, 1024)
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "initial copy failed")
|
||||
|
||||
// Modify the file locally (simulate local change)
|
||||
newData := []byte("Updated content for force update test")
|
||||
uploadToPrimary(t, testKey, newData)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Copy again with force update
|
||||
t.Log("Copying with force update...")
|
||||
cmd = fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s -forceUpdate=true", testBucket, testKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local with forceUpdate failed")
|
||||
t.Logf("Force update output: %s", output)
|
||||
|
||||
// Verify new content
|
||||
verifyFileContent(t, testKey, newData)
|
||||
|
||||
// Uncache and verify it was updated on remote
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
verifyFileContent(t, testKey, newData)
|
||||
|
||||
// Clean up - restore original for other tests
|
||||
uploadToPrimary(t, testKey, originalData)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalConcurrency tests parallel copy operations
|
||||
func TestRemoteCopyLocalConcurrency(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create multiple files
|
||||
var files []string
|
||||
var dataMap = make(map[string][]byte)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
key := fmt.Sprintf("copylocal-concurrent-%d-%d.bin", time.Now().UnixNano(), i)
|
||||
data := createTestFile(t, key, 2048)
|
||||
files = append(files, key)
|
||||
dataMap[key] = data
|
||||
time.Sleep(10 * time.Millisecond) // Small delay to ensure unique timestamps
|
||||
}
|
||||
|
||||
// Copy with high concurrency
|
||||
t.Log("Copying with concurrency=8...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -concurrent=8", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local with concurrency failed")
|
||||
t.Logf("Copy output: %s", output)
|
||||
|
||||
// Verify all files are still readable
|
||||
for _, file := range files {
|
||||
verifyFileContent(t, file, dataMap[file])
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalEmptyDirectory tests handling empty directories
|
||||
func TestRemoteCopyLocalEmptyDirectory(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Try to copy from a directory with no local-only files
|
||||
// (all files are already synced to remote)
|
||||
t.Log("Testing copy from directory with no local-only files...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
|
||||
// Should not error, just report nothing to copy
|
||||
require.NoError(t, err, "remote.copy.local should handle empty directory gracefully")
|
||||
t.Logf("Empty directory output: %s", output)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalLargeFile tests copying large files
|
||||
func TestRemoteCopyLocalLargeFile(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("copylocal-large-%d.bin", time.Now().UnixNano())
|
||||
|
||||
// Create a 10MB file
|
||||
t.Log("Creating 10MB test file...")
|
||||
testData := createTestFile(t, testKey, 10*1024*1024)
|
||||
|
||||
// Copy to remote
|
||||
t.Log("Copying large file to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local large file failed")
|
||||
t.Logf("Large file copy output: %s", output)
|
||||
|
||||
// Verify file integrity
|
||||
verifyFileContent(t, testKey, testData)
|
||||
|
||||
// Uncache and verify it was copied to remote
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(1 * time.Second)
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalAlreadyExists tests skipping files already on remote
|
||||
func TestRemoteCopyLocalAlreadyExists(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("copylocal-exists-%d.txt", time.Now().UnixNano())
|
||||
testData := createTestFile(t, testKey, 1024)
|
||||
|
||||
// First copy
|
||||
t.Log("First copy to remote...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "first copy failed")
|
||||
t.Logf("First copy output: %s", output)
|
||||
|
||||
// Second copy without forceUpdate - should skip
|
||||
t.Log("Second copy (should skip)...")
|
||||
output, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "second copy failed")
|
||||
t.Logf("Second copy output: %s", output)
|
||||
|
||||
// File should still be readable
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalNotMounted tests error when directory not mounted
|
||||
func TestRemoteCopyLocalNotMounted(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Try to copy from a non-mounted directory
|
||||
notMountedDir := fmt.Sprintf("/notmounted-%d", time.Now().UnixNano())
|
||||
|
||||
t.Log("Testing copy from non-mounted directory...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=%s", notMountedDir)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
|
||||
// Should fail or show error
|
||||
hasError := err != nil || strings.Contains(strings.ToLower(output), "not mounted") || strings.Contains(strings.ToLower(output), "error")
|
||||
assert.True(t, hasError, "Expected error or error message for non-mounted directory, got: %s", output)
|
||||
t.Logf("Non-mounted directory result: err=%v, output: %s", err, output)
|
||||
}
|
||||
|
||||
// TestRemoteCopyLocalMinMaxSize tests size-based filtering
|
||||
func TestRemoteCopyLocalMinMaxSize(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create files of different sizes
|
||||
smallFile := fmt.Sprintf("copylocal-small-%d.bin", time.Now().UnixNano())
|
||||
mediumFile := fmt.Sprintf("copylocal-medium-%d.bin", time.Now().UnixNano())
|
||||
largeFile := fmt.Sprintf("copylocal-large-%d.bin", time.Now().UnixNano())
|
||||
|
||||
smallData := createTestFile(t, smallFile, 500) // 500 bytes
|
||||
mediumData := createTestFile(t, mediumFile, 5000) // 5KB
|
||||
largeData := createTestFile(t, largeFile, 50000) // 50KB
|
||||
|
||||
// Copy only files between 1KB and 10KB
|
||||
t.Log("Copying files between 1KB and 10KB...")
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -minSize=1024 -maxSize=10240", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.copy.local with size filters failed")
|
||||
t.Logf("Size filter output: %s", output)
|
||||
|
||||
// All files should still be readable
|
||||
verifyFileContent(t, smallFile, smallData)
|
||||
verifyFileContent(t, mediumFile, mediumData)
|
||||
verifyFileContent(t, largeFile, largeData)
|
||||
}
|
||||
163
test/s3/remote_cache/command_remote_meta_sync_test.go
Normal file
163
test/s3/remote_cache/command_remote_meta_sync_test.go
Normal file
@@ -0,0 +1,163 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRemoteMetaSyncBasic tests syncing metadata from remote
|
||||
func TestRemoteMetaSyncBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Sync metadata from remote
|
||||
t.Log("Syncing metadata from remote...")
|
||||
cmd := fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.meta.sync failed")
|
||||
t.Logf("Meta sync output: %s", output)
|
||||
|
||||
// Should complete without errors
|
||||
assert.NotContains(t, strings.ToLower(output), "failed", "sync should not fail")
|
||||
}
|
||||
|
||||
// TestRemoteMetaSyncNewFiles tests detecting new files on remote
|
||||
func TestRemoteMetaSyncNewFiles(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("metasync-new-%d.txt", time.Now().UnixNano())
|
||||
testData := createTestFile(t, testKey, 1024)
|
||||
|
||||
// Copy to remote
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to copy file to remote")
|
||||
|
||||
// Uncache to remove local chunks
|
||||
uncacheLocal(t, testKey)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Sync metadata - should detect the file
|
||||
t.Log("Syncing metadata to detect new file...")
|
||||
cmd = fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.meta.sync failed")
|
||||
t.Logf("Meta sync output: %s", output)
|
||||
|
||||
// File should be readable
|
||||
verifyFileContent(t, testKey, testData)
|
||||
}
|
||||
|
||||
// TestRemoteMetaSyncSubdirectory tests syncing specific subdirectory
|
||||
func TestRemoteMetaSyncSubdirectory(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Sync just the mounted directory
|
||||
t.Log("Syncing subdirectory metadata...")
|
||||
cmd := fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.meta.sync subdirectory failed")
|
||||
t.Logf("Subdirectory sync output: %s", output)
|
||||
}
|
||||
|
||||
// TestRemoteMetaSyncNotMounted tests error when directory not mounted
|
||||
func TestRemoteMetaSyncNotMounted(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Try to sync a non-mounted directory
|
||||
notMountedDir := fmt.Sprintf("/notmounted-%d", time.Now().UnixNano())
|
||||
|
||||
t.Log("Testing sync on non-mounted directory...")
|
||||
cmd := fmt.Sprintf("remote.meta.sync -dir=%s", notMountedDir)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
|
||||
// Should fail or show error
|
||||
hasError := err != nil || strings.Contains(strings.ToLower(output), "not mounted") || strings.Contains(strings.ToLower(output), "error")
|
||||
assert.True(t, hasError, "Expected error for non-mounted directory, got: %s", output)
|
||||
t.Logf("Non-mounted directory result: err=%v, output: %s", err, output)
|
||||
}
|
||||
|
||||
// TestRemoteMetaSyncRepeated tests running sync multiple times
|
||||
func TestRemoteMetaSyncRepeated(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Run sync multiple times - should be idempotent
|
||||
for i := 0; i < 3; i++ {
|
||||
t.Logf("Running sync iteration %d...", i+1)
|
||||
cmd := fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "remote.meta.sync iteration %d failed", i+1)
|
||||
t.Logf("Iteration %d output: %s", i+1, output)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoteMetaSyncAfterRemoteChange tests detecting changes on remote
|
||||
func TestRemoteMetaSyncAfterRemoteChange(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("metasync-change-%d.txt", time.Now().UnixNano())
|
||||
|
||||
// Create and sync file
|
||||
originalData := createTestFile(t, testKey, 1024)
|
||||
cmd := fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, testKey)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to copy file to remote")
|
||||
|
||||
// First sync
|
||||
cmd = fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "first sync failed")
|
||||
|
||||
// Simulate remote change by updating the file and copying again
|
||||
newData := []byte("Updated content after remote change")
|
||||
uploadToPrimary(t, testKey, newData)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
cmd = fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s -forceUpdate=true", testBucket, testKey)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to update remote file")
|
||||
|
||||
// Sync again - should detect the change
|
||||
t.Log("Syncing after remote change...")
|
||||
cmd = fmt.Sprintf("remote.meta.sync -dir=/buckets/%s", testBucket)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "sync after change failed")
|
||||
t.Logf("Sync after change output: %s", output)
|
||||
|
||||
// Restore original for cleanup
|
||||
uploadToPrimary(t, testKey, originalData)
|
||||
}
|
||||
|
||||
// TestRemoteMetaSyncEmptyRemote tests syncing when remote is empty
|
||||
func TestRemoteMetaSyncEmptyRemote(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Create a new mount point for testing
|
||||
testDir := fmt.Sprintf("/buckets/testempty%d", time.Now().UnixNano()%1000000)
|
||||
|
||||
// Mount the remote bucket to new directory
|
||||
cmd := fmt.Sprintf("remote.mount -dir=%s -remote=seaweedremote/remotesourcebucket -nonempty=true", testDir)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
if err != nil {
|
||||
t.Skip("Could not create test mount for empty remote test")
|
||||
}
|
||||
|
||||
// Sync metadata
|
||||
t.Log("Syncing metadata from potentially empty remote...")
|
||||
cmd = fmt.Sprintf("remote.meta.sync -dir=%s", testDir)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "sync on empty remote failed")
|
||||
t.Logf("Empty remote sync output: %s", output)
|
||||
|
||||
// Clean up
|
||||
cmd = fmt.Sprintf("remote.unmount -dir=%s", testDir)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
if err != nil {
|
||||
t.Logf("Warning: failed to unmount test directory: %v", err)
|
||||
}
|
||||
}
|
||||
204
test/s3/remote_cache/command_remote_mount_test.go
Normal file
204
test/s3/remote_cache/command_remote_mount_test.go
Normal file
@@ -0,0 +1,204 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRemoteMountBasic tests mounting a remote bucket to a local directory
|
||||
func TestRemoteMountBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testDir := fmt.Sprintf("/buckets/testmount%d", time.Now().UnixNano()%1000000)
|
||||
|
||||
// Mount the remote bucket
|
||||
t.Logf("Mounting remote bucket to %s...", testDir)
|
||||
cmd := fmt.Sprintf("remote.mount -dir=%s -remote=seaweedremote/remotesourcebucket", testDir)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to mount remote")
|
||||
t.Logf("Mount output: %s", output)
|
||||
|
||||
// Verify mount exists in list
|
||||
output, err = runWeedShellWithOutput(t, "remote.mount")
|
||||
require.NoError(t, err, "failed to list mounts")
|
||||
assert.Contains(t, output, testDir, "mount not found in list")
|
||||
|
||||
// Clean up - unmount
|
||||
t.Logf("Unmounting %s...", testDir)
|
||||
cmd = fmt.Sprintf("remote.unmount -dir=%s", testDir)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to unmount")
|
||||
}
|
||||
|
||||
// TestRemoteMountNonEmpty tests mounting with -nonempty flag
|
||||
func TestRemoteMountNonEmpty(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testDir := fmt.Sprintf("/buckets/testnonempty%d", time.Now().UnixNano()%1000000)
|
||||
testFile := fmt.Sprintf("testfile-%d.txt", time.Now().UnixNano())
|
||||
|
||||
// First mount to create the directory
|
||||
cmd := fmt.Sprintf("remote.mount -dir=%s -remote=seaweedremote/remotesourcebucket", testDir)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to initial mount")
|
||||
|
||||
// Upload a file to make it non-empty
|
||||
uploadToPrimary(t, testFile, []byte("test data"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Unmount
|
||||
cmd = fmt.Sprintf("remote.unmount -dir=%s", testDir)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to unmount")
|
||||
|
||||
// Try to mount again with -nonempty flag (directory may have residual data)
|
||||
t.Logf("Mounting with -nonempty flag...")
|
||||
cmd = fmt.Sprintf("remote.mount -dir=%s -remote=seaweedremote/remotesourcebucket -nonempty=true", testDir)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to mount with -nonempty")
|
||||
t.Logf("Mount output: %s", output)
|
||||
|
||||
// Clean up
|
||||
cmd = fmt.Sprintf("remote.unmount -dir=%s", testDir)
|
||||
_, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to unmount")
|
||||
}
|
||||
|
||||
// TestRemoteMountInvalidRemote tests mounting with non-existent remote configuration
|
||||
func TestRemoteMountInvalidRemote(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testDir := fmt.Sprintf("/buckets/testinvalid%d", time.Now().UnixNano()%1000000)
|
||||
invalidRemote := fmt.Sprintf("nonexistent%d/bucket", time.Now().UnixNano())
|
||||
|
||||
// Try to mount with invalid remote
|
||||
cmd := fmt.Sprintf("remote.mount -dir=%s -remote=%s", testDir, invalidRemote)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
|
||||
// Should fail with invalid remote
|
||||
hasError := err != nil || strings.Contains(strings.ToLower(output), "invalid") || strings.Contains(strings.ToLower(output), "error") || strings.Contains(strings.ToLower(output), "not found")
|
||||
assert.True(t, hasError, "Expected error for invalid remote, got: %s", output)
|
||||
t.Logf("Invalid remote result: err=%v, output: %s", err, output)
|
||||
}
|
||||
|
||||
// TestRemoteMountList tests listing all mounts
|
||||
func TestRemoteMountList(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// List all mounts
|
||||
output, err := runWeedShellWithOutput(t, "remote.mount")
|
||||
require.NoError(t, err, "failed to list mounts")
|
||||
t.Logf("Mount list: %s", output)
|
||||
|
||||
// Should contain the default mount from setup
|
||||
assert.Contains(t, output, "remotemounted", "default mount not found")
|
||||
}
|
||||
|
||||
// TestRemoteUnmountBasic tests unmounting and verifying cleanup
|
||||
func TestRemoteUnmountBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testDir := fmt.Sprintf("/buckets/testunmount%d", time.Now().UnixNano()%1000000)
|
||||
|
||||
// Mount first
|
||||
cmd := fmt.Sprintf("remote.mount -dir=%s -remote=seaweedremote/remotesourcebucket", testDir)
|
||||
_, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to mount")
|
||||
|
||||
// Verify it's mounted
|
||||
output, err := runWeedShellWithOutput(t, "remote.mount")
|
||||
require.NoError(t, err, "failed to list mounts")
|
||||
assert.Contains(t, output, testDir, "mount not found before unmount")
|
||||
|
||||
// Unmount
|
||||
t.Logf("Unmounting %s...", testDir)
|
||||
cmd = fmt.Sprintf("remote.unmount -dir=%s", testDir)
|
||||
output, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to unmount")
|
||||
t.Logf("Unmount output: %s", output)
|
||||
|
||||
// Verify it's no longer mounted
|
||||
output, err = runWeedShellWithOutput(t, "remote.mount")
|
||||
require.NoError(t, err, "failed to list mounts after unmount")
|
||||
assert.NotContains(t, output, testDir, "mount still exists after unmount")
|
||||
}
|
||||
|
||||
// TestRemoteUnmountNotMounted tests unmounting a non-mounted directory
|
||||
func TestRemoteUnmountNotMounted(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testDir := fmt.Sprintf("/buckets/notmounted%d", time.Now().UnixNano()%1000000)
|
||||
|
||||
// Try to unmount a directory that's not mounted
|
||||
cmd := fmt.Sprintf("remote.unmount -dir=%s", testDir)
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
|
||||
// Should fail or show error
|
||||
hasError := err != nil || strings.Contains(strings.ToLower(output), "not mounted") || strings.Contains(strings.ToLower(output), "error")
|
||||
assert.True(t, hasError, "Expected error for unmounting non-mounted directory, got: %s", output)
|
||||
t.Logf("Unmount non-mounted result: err=%v, output: %s", err, output)
|
||||
}
|
||||
|
||||
// TestRemoteMountBucketsBasic tests mounting all buckets from remote
|
||||
func TestRemoteMountBucketsBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// List buckets in dry-run mode (without -apply)
|
||||
t.Log("Listing buckets without -apply flag...")
|
||||
cmd := "remote.mount.buckets -remote=seaweedremote"
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to list buckets")
|
||||
t.Logf("Bucket list output: %s", output)
|
||||
|
||||
// Should show the remote bucket
|
||||
assert.Contains(t, output, "remotesourcebucket", "remote bucket not found in list")
|
||||
}
|
||||
|
||||
// TestRemoteMountBucketsWithPattern tests mounting with bucket pattern filter
|
||||
func TestRemoteMountBucketsWithPattern(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Test with pattern matching
|
||||
t.Log("Testing bucket pattern matching...")
|
||||
cmd := "remote.mount.buckets -remote=seaweedremote -bucketPattern=remote*"
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to list buckets with pattern")
|
||||
t.Logf("Pattern match output: %s", output)
|
||||
|
||||
// Should show matching buckets
|
||||
assert.Contains(t, output, "remotesourcebucket", "matching bucket not found")
|
||||
|
||||
// Test with non-matching pattern
|
||||
cmd = "remote.mount.buckets -remote=seaweedremote -bucketPattern=nonexistent*"
|
||||
output, err = runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to list buckets with non-matching pattern")
|
||||
t.Logf("Non-matching pattern output: %s", output)
|
||||
}
|
||||
|
||||
// TestRemoteMountBucketsDryRun tests dry run mode (no -apply flag)
|
||||
func TestRemoteMountBucketsDryRun(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
// Get initial mount list
|
||||
initialOutput, err := runWeedShellWithOutput(t, "remote.mount")
|
||||
require.NoError(t, err, "failed to get initial mount list")
|
||||
|
||||
// Run mount.buckets without -apply (dry run)
|
||||
t.Log("Running mount.buckets in dry-run mode...")
|
||||
cmd := "remote.mount.buckets -remote=seaweedremote"
|
||||
output, err := runWeedShellWithOutput(t, cmd)
|
||||
require.NoError(t, err, "failed to run dry-run mount.buckets")
|
||||
t.Logf("Dry-run output: %s", output)
|
||||
|
||||
// Get mount list after dry run
|
||||
afterOutput, err := runWeedShellWithOutput(t, "remote.mount")
|
||||
require.NoError(t, err, "failed to get mount list after dry-run")
|
||||
|
||||
// Mount list should be unchanged (dry run doesn't actually mount)
|
||||
assert.Equal(t, initialOutput, afterOutput, "mount list changed after dry-run")
|
||||
}
|
||||
174
test/s3/remote_cache/remote_cache_copy_test.go
Normal file
174
test/s3/remote_cache/remote_cache_copy_test.go
Normal file
@@ -0,0 +1,174 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRemoteCacheCopyObject exercises the bug pattern that #9304 originally
|
||||
// reported and that #7817's tests couldn't catch: CopyObject reads a source
|
||||
// whose data lives only in remote storage (not yet cached locally), so its
|
||||
// resolved entry has FileSize > 0 but no chunks. Pre-fix, the handler wrote a
|
||||
// destination with that same shape, and any GET on the destination returned
|
||||
// 500 "data integrity error: size N reported but no content".
|
||||
func TestRemoteCacheCopyObject(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
srcKey := fmt.Sprintf("copy-src-%d.bin", time.Now().UnixNano())
|
||||
dstKey := fmt.Sprintf("copy-dst-%d.bin", time.Now().UnixNano())
|
||||
|
||||
// 5 MiB so the source has multiple chunks and is large enough to exercise
|
||||
// the streaming copy path, not just an inline-content shortcut.
|
||||
srcData := make([]byte, 5*1024*1024)
|
||||
for i := range srcData {
|
||||
srcData[i] = byte(i % 256)
|
||||
}
|
||||
srcSum := md5.Sum(srcData)
|
||||
|
||||
t.Log("Uploading source object to primary (local)")
|
||||
uploadToPrimary(t, srcKey, srcData)
|
||||
|
||||
t.Log("Uncaching source: pushes data to remote and removes local chunks")
|
||||
uncacheLocal(t, srcKey)
|
||||
|
||||
// At this point the source entry on the primary has FileSize > 0,
|
||||
// no local chunks, and a RemoteEntry pointing at the secondary.
|
||||
// CopyObject must cache the source before persisting the destination.
|
||||
t.Log("Issuing CopyObject from remote-only source to a new local destination")
|
||||
_, err := getPrimaryClient().CopyObject(&s3.CopyObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
CopySource: aws.String(testBucket + "/" + srcKey),
|
||||
})
|
||||
require.NoError(t, err, "CopyObject from remote-only source must succeed")
|
||||
|
||||
// HEAD before GET so an obvious size mismatch surfaces with a useful error
|
||||
// instead of being masked by a body-stream failure.
|
||||
head, err := getPrimaryClient().HeadObject(&s3.HeadObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
})
|
||||
require.NoError(t, err, "HEAD on copied destination must succeed")
|
||||
assert.Equal(t, int64(len(srcData)), aws.Int64Value(head.ContentLength),
|
||||
"destination ContentLength must match source")
|
||||
|
||||
// The original bug: GET would return 500 with "data integrity error".
|
||||
// Now the destination is a real local object with chunks, so GET reads
|
||||
// it back byte-for-byte.
|
||||
t.Log("Reading destination back; pre-fix this returned 500 'data integrity error'")
|
||||
resp, err := getPrimaryClient().GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
})
|
||||
require.NoError(t, err, "GET on copied destination must succeed")
|
||||
defer resp.Body.Close()
|
||||
|
||||
got, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(srcData), len(got), "destination size must match source")
|
||||
gotSum := md5.Sum(got)
|
||||
assert.Equal(t, srcSum, gotSum, "destination bytes must match source bytes")
|
||||
}
|
||||
|
||||
// TestRemoteCacheCopyObjectPart exercises the same bug pattern via the
|
||||
// multipart upload-part-copy path (CopyObjectPartHandler), which iterates
|
||||
// the source entry's chunks just like CopyObjectHandler. A remote-only
|
||||
// source previously produced a part with size > 0 and no data; pre-fix
|
||||
// the completed multipart upload was unreadable.
|
||||
func TestRemoteCacheCopyObjectPart(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
srcKey := fmt.Sprintf("copypart-src-%d.bin", time.Now().UnixNano())
|
||||
dstKey := fmt.Sprintf("copypart-dst-%d.bin", time.Now().UnixNano())
|
||||
|
||||
// 6 MiB so a single 0-5MiB part covers the lower half and exercises a
|
||||
// real range-read against the cached chunks (parts must be >= 5 MiB
|
||||
// per S3's MultipartUpload rules, except the last).
|
||||
srcData := make([]byte, 6*1024*1024)
|
||||
for i := range srcData {
|
||||
srcData[i] = byte((i * 7) % 256)
|
||||
}
|
||||
|
||||
t.Log("Uploading source object to primary (local)")
|
||||
uploadToPrimary(t, srcKey, srcData)
|
||||
|
||||
t.Log("Uncaching source: pushes data to remote and removes local chunks")
|
||||
uncacheLocal(t, srcKey)
|
||||
|
||||
t.Log("Initiating multipart upload on the destination")
|
||||
create, err := getPrimaryClient().CreateMultipartUpload(&s3.CreateMultipartUploadInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
uploadID := aws.StringValue(create.UploadId)
|
||||
defer func() {
|
||||
// Best-effort abort if the test fails mid-flight.
|
||||
_, _ = getPrimaryClient().AbortMultipartUpload(&s3.AbortMultipartUploadInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
UploadId: aws.String(uploadID),
|
||||
})
|
||||
}()
|
||||
|
||||
t.Log("UploadPartCopy from remote-only source range")
|
||||
part1Range := fmt.Sprintf("bytes=0-%d", 5*1024*1024-1)
|
||||
cp1, err := getPrimaryClient().UploadPartCopy(&s3.UploadPartCopyInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
UploadId: aws.String(uploadID),
|
||||
PartNumber: aws.Int64(1),
|
||||
CopySource: aws.String(testBucket + "/" + srcKey),
|
||||
CopySourceRange: aws.String(part1Range),
|
||||
})
|
||||
require.NoError(t, err, "UploadPartCopy from remote-only source must succeed")
|
||||
require.NotNil(t, cp1.CopyPartResult)
|
||||
|
||||
part2Range := fmt.Sprintf("bytes=%d-%d", 5*1024*1024, 6*1024*1024-1)
|
||||
cp2, err := getPrimaryClient().UploadPartCopy(&s3.UploadPartCopyInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
UploadId: aws.String(uploadID),
|
||||
PartNumber: aws.Int64(2),
|
||||
CopySource: aws.String(testBucket + "/" + srcKey),
|
||||
CopySourceRange: aws.String(part2Range),
|
||||
})
|
||||
require.NoError(t, err, "second UploadPartCopy must succeed")
|
||||
require.NotNil(t, cp2.CopyPartResult)
|
||||
|
||||
t.Log("Completing multipart upload")
|
||||
_, err = getPrimaryClient().CompleteMultipartUpload(&s3.CompleteMultipartUploadInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
UploadId: aws.String(uploadID),
|
||||
MultipartUpload: &s3.CompletedMultipartUpload{
|
||||
Parts: []*s3.CompletedPart{
|
||||
{ETag: cp1.CopyPartResult.ETag, PartNumber: aws.Int64(1)},
|
||||
{ETag: cp2.CopyPartResult.ETag, PartNumber: aws.Int64(2)},
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err, "CompleteMultipartUpload must succeed")
|
||||
|
||||
t.Log("Reading destination back; pre-fix this returned 500 'data integrity error'")
|
||||
resp, err := getPrimaryClient().GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(dstKey),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
got, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, bytes.Equal(srcData, got),
|
||||
"destination bytes must match source after multipart copy from remote-only source")
|
||||
}
|
||||
492
test/s3/remote_cache/remote_cache_test.go
Normal file
492
test/s3/remote_cache/remote_cache_test.go
Normal file
@@ -0,0 +1,492 @@
|
||||
package remote_cache
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Test configuration
|
||||
// Uses two SeaweedFS instances:
|
||||
// - Primary: The one being tested (has remote caching)
|
||||
// - Remote: Acts as the "remote" S3 storage
|
||||
const (
|
||||
// Primary SeaweedFS
|
||||
primaryEndpoint = "http://localhost:8333"
|
||||
primaryMasterPort = "9333"
|
||||
|
||||
// Remote SeaweedFS (acts as remote storage)
|
||||
remoteEndpoint = "http://localhost:8334"
|
||||
|
||||
// Credentials (anonymous access for testing)
|
||||
accessKey = "some_access_key1"
|
||||
secretKey = "some_secret_key1"
|
||||
|
||||
// Bucket name - mounted on primary as remote storage
|
||||
testBucket = "remotemounted"
|
||||
|
||||
// Bucket name on the remote that testBucket is mounted on
|
||||
remoteBucket = "remotesourcebucket"
|
||||
|
||||
// Path to weed binary
|
||||
weedBinary = "../../../weed/weed_binary"
|
||||
)
|
||||
|
||||
var (
|
||||
primaryClient *s3.S3
|
||||
primaryClientOnce sync.Once
|
||||
)
|
||||
|
||||
func getPrimaryClient() *s3.S3 {
|
||||
primaryClientOnce.Do(func() {
|
||||
primaryClient = createS3Client(primaryEndpoint)
|
||||
})
|
||||
return primaryClient
|
||||
}
|
||||
|
||||
func createS3Client(endpoint string) *s3.S3 {
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
Endpoint: aws.String(endpoint),
|
||||
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
|
||||
DisableSSL: aws.Bool(!strings.HasPrefix(endpoint, "https")),
|
||||
S3ForcePathStyle: aws.Bool(true),
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create session: %v", err))
|
||||
}
|
||||
return s3.New(sess)
|
||||
}
|
||||
|
||||
// checkServersRunning ensures the servers are running and fails if they aren't
|
||||
func checkServersRunning(t *testing.T) {
|
||||
resp, err := http.Get(primaryEndpoint)
|
||||
require.NoErrorf(t, err, "Primary SeaweedFS not running at %s", primaryEndpoint)
|
||||
resp.Body.Close()
|
||||
|
||||
resp, err = http.Get(remoteEndpoint)
|
||||
require.NoErrorf(t, err, "Remote SeaweedFS not running at %s", remoteEndpoint)
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
// stripLogs removes SeaweedFS log lines from the output
|
||||
func stripLogs(output string) string {
|
||||
lines := strings.Split(output, "\n")
|
||||
var filtered []string
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if len(trimmed) > 0 && (trimmed[0] == 'I' || trimmed[0] == 'W' || trimmed[0] == 'E' || trimmed[0] == 'F') && len(trimmed) > 5 && isDigit(trimmed[1]) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, line)
|
||||
}
|
||||
return strings.Join(filtered, "\n")
|
||||
}
|
||||
|
||||
func isDigit(b byte) bool {
|
||||
return b >= '0' && b <= '9'
|
||||
}
|
||||
|
||||
// runWeedShell executes a weed shell command
|
||||
func runWeedShell(t *testing.T, command string) (string, error) {
|
||||
cmd := exec.Command(weedBinary, "shell", "-master=localhost:"+primaryMasterPort)
|
||||
cmd.Stdin = strings.NewReader(command + "\nexit\n")
|
||||
output, err := cmd.CombinedOutput()
|
||||
result := stripLogs(string(output))
|
||||
if err != nil {
|
||||
t.Logf("weed shell command '%s' failed: %v, output: %s", command, err, result)
|
||||
return result, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// runWeedShellWithOutput executes a weed shell command and returns output even on error
|
||||
func runWeedShellWithOutput(t *testing.T, command string) (output string, err error) {
|
||||
cmd := exec.Command(weedBinary, "shell", "-master=localhost:"+primaryMasterPort)
|
||||
cmd.Stdin = strings.NewReader(command + "\nexit\n")
|
||||
outputBytes, err := cmd.CombinedOutput()
|
||||
output = stripLogs(string(outputBytes))
|
||||
if err != nil {
|
||||
t.Logf("weed shell command '%s' output: %s", command, output)
|
||||
}
|
||||
return output, err
|
||||
}
|
||||
|
||||
// createTestFile creates a test file with specific content via S3
|
||||
func createTestFile(t *testing.T, key string, size int) []byte {
|
||||
data := make([]byte, size)
|
||||
for i := range data {
|
||||
data[i] = byte(i % 256)
|
||||
}
|
||||
uploadToPrimary(t, key, data)
|
||||
return data
|
||||
}
|
||||
|
||||
// verifyFileContent verifies file content matches expected data
|
||||
func verifyFileContent(t *testing.T, key string, expected []byte) {
|
||||
actual := getFromPrimary(t, key)
|
||||
assert.Equal(t, expected, actual, "file content mismatch for %s", key)
|
||||
}
|
||||
|
||||
// waitForCondition waits for a condition to be true with timeout
|
||||
func waitForCondition(t *testing.T, condition func() bool, timeout time.Duration, message string) bool {
|
||||
deadline := time.Now().Add(timeout)
|
||||
for time.Now().Before(deadline) {
|
||||
if condition() {
|
||||
return true
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
t.Logf("Timeout waiting for: %s", message)
|
||||
return false
|
||||
}
|
||||
|
||||
// fileExists checks if a file exists via S3
|
||||
func fileExists(t *testing.T, key string) bool {
|
||||
_, err := getPrimaryClient().HeadObject(&s3.HeadObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(key),
|
||||
})
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// uploadToPrimary uploads an object to the primary SeaweedFS (local write)
|
||||
func uploadToPrimary(t *testing.T, key string, data []byte) {
|
||||
_, err := getPrimaryClient().PutObject(&s3.PutObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(key),
|
||||
Body: bytes.NewReader(data),
|
||||
})
|
||||
require.NoError(t, err, "failed to upload to primary SeaweedFS")
|
||||
}
|
||||
|
||||
// getFromPrimary gets an object from primary SeaweedFS
|
||||
func getFromPrimary(t *testing.T, key string) []byte {
|
||||
resp, err := getPrimaryClient().GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(key),
|
||||
})
|
||||
require.NoError(t, err, "failed to get from primary SeaweedFS")
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err, "failed to read response body")
|
||||
return data
|
||||
}
|
||||
|
||||
// uncacheLocal purges the local cache, forcing data to be fetched from remote
|
||||
func uncacheLocal(t *testing.T, pattern string) {
|
||||
t.Logf("Purging local cache for pattern: %s", pattern)
|
||||
output, err := runWeedShell(t, fmt.Sprintf("remote.uncache -dir=/buckets/%s -include=%s", testBucket, pattern))
|
||||
if err != nil {
|
||||
t.Logf("uncacheLocal warning: %v", err)
|
||||
}
|
||||
t.Log(output)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
// TestRemoteCacheBasic tests the basic caching workflow:
|
||||
// 1. Write to local
|
||||
// 2. Uncache (push to remote, remove local chunks)
|
||||
// 3. Read (triggers caching from remote)
|
||||
func TestRemoteCacheBasic(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("test-basic-%d.txt", time.Now().UnixNano())
|
||||
testData := []byte("Hello, this is test data for remote caching!")
|
||||
|
||||
// Step 1: Write to local
|
||||
t.Log("Step 1: Writing object to primary SeaweedFS (local)...")
|
||||
uploadToPrimary(t, testKey, testData)
|
||||
|
||||
// Verify it's readable
|
||||
result := getFromPrimary(t, testKey)
|
||||
assert.Equal(t, testData, result, "initial read mismatch")
|
||||
|
||||
// Step 2: Uncache - push to remote and remove local chunks
|
||||
t.Log("Step 2: Uncaching (pushing to remote, removing local chunks)...")
|
||||
uncacheLocal(t, testKey)
|
||||
|
||||
// Step 3: Read - this should trigger caching from remote
|
||||
t.Log("Step 3: Reading object (should trigger caching from remote)...")
|
||||
start := time.Now()
|
||||
result = getFromPrimary(t, testKey)
|
||||
firstReadDuration := time.Since(start)
|
||||
|
||||
assert.Equal(t, testData, result, "data mismatch after cache")
|
||||
t.Logf("First read (from remote) took %v", firstReadDuration)
|
||||
|
||||
// Step 4: Read again - should be from local cache
|
||||
t.Log("Step 4: Reading again (should be from local cache)...")
|
||||
start = time.Now()
|
||||
result = getFromPrimary(t, testKey)
|
||||
secondReadDuration := time.Since(start)
|
||||
|
||||
assert.Equal(t, testData, result, "data mismatch on cached read")
|
||||
t.Logf("Second read (from cache) took %v", secondReadDuration)
|
||||
|
||||
t.Log("Basic caching test passed")
|
||||
}
|
||||
|
||||
// TestRemoteCacheConcurrent tests that concurrent reads of the same
|
||||
// remote object only trigger ONE caching operation (singleflight deduplication)
|
||||
func TestRemoteCacheConcurrent(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("test-concurrent-%d.txt", time.Now().UnixNano())
|
||||
// Use larger data to make caching take measurable time
|
||||
testData := make([]byte, 1024*1024) // 1MB
|
||||
for i := range testData {
|
||||
testData[i] = byte(i % 256)
|
||||
}
|
||||
|
||||
// Step 1: Write to local
|
||||
t.Log("Step 1: Writing 1MB object to primary SeaweedFS...")
|
||||
uploadToPrimary(t, testKey, testData)
|
||||
|
||||
// Verify it's readable
|
||||
result := getFromPrimary(t, testKey)
|
||||
assert.Equal(t, len(testData), len(result), "initial size mismatch")
|
||||
|
||||
// Step 2: Uncache
|
||||
t.Log("Step 2: Uncaching (pushing to remote)...")
|
||||
uncacheLocal(t, testKey)
|
||||
|
||||
// Step 3: Launch many concurrent reads - singleflight should deduplicate
|
||||
numRequests := 10
|
||||
var wg sync.WaitGroup
|
||||
var successCount atomic.Int32
|
||||
var errorCount atomic.Int32
|
||||
results := make(chan []byte, numRequests)
|
||||
|
||||
t.Logf("Step 3: Launching %d concurrent requests...", numRequests)
|
||||
startTime := time.Now()
|
||||
|
||||
for i := 0; i < numRequests; i++ {
|
||||
wg.Add(1)
|
||||
go func(idx int) {
|
||||
defer wg.Done()
|
||||
resp, err := getPrimaryClient().GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(testKey),
|
||||
})
|
||||
if err != nil {
|
||||
t.Logf("Request %d failed: %v", idx, err)
|
||||
errorCount.Add(1)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Logf("Request %d read failed: %v", idx, err)
|
||||
errorCount.Add(1)
|
||||
return
|
||||
}
|
||||
|
||||
results <- data
|
||||
successCount.Add(1)
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
close(results)
|
||||
totalDuration := time.Since(startTime)
|
||||
|
||||
t.Logf("All %d requests completed in %v", numRequests, totalDuration)
|
||||
t.Logf("Successful: %d, Failed: %d", successCount.Load(), errorCount.Load())
|
||||
|
||||
// Verify all successful requests returned correct data
|
||||
for data := range results {
|
||||
assert.Equal(t, len(testData), len(data), "data length mismatch")
|
||||
}
|
||||
|
||||
// All requests should succeed
|
||||
assert.Equal(t, int32(numRequests), successCount.Load(), "some requests failed")
|
||||
assert.Equal(t, int32(0), errorCount.Load(), "no requests should fail")
|
||||
|
||||
t.Log("Concurrent caching test passed")
|
||||
}
|
||||
|
||||
// TestRemoteCacheLargeObject tests caching of larger objects
|
||||
func TestRemoteCacheLargeObject(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("test-large-%d.bin", time.Now().UnixNano())
|
||||
// 5MB object
|
||||
testData := make([]byte, 5*1024*1024)
|
||||
for i := range testData {
|
||||
testData[i] = byte(i % 256)
|
||||
}
|
||||
|
||||
// Step 1: Write to local
|
||||
t.Log("Step 1: Writing 5MB object to primary SeaweedFS...")
|
||||
uploadToPrimary(t, testKey, testData)
|
||||
|
||||
// Verify it's readable
|
||||
result := getFromPrimary(t, testKey)
|
||||
assert.Equal(t, len(testData), len(result), "initial size mismatch")
|
||||
|
||||
// Step 2: Uncache
|
||||
t.Log("Step 2: Uncaching...")
|
||||
uncacheLocal(t, testKey)
|
||||
|
||||
// Step 3: Read from remote
|
||||
t.Log("Step 3: Reading 5MB object (should cache from remote)...")
|
||||
start := time.Now()
|
||||
result = getFromPrimary(t, testKey)
|
||||
duration := time.Since(start)
|
||||
|
||||
assert.Equal(t, len(testData), len(result), "size mismatch")
|
||||
assert.Equal(t, testData, result, "data mismatch")
|
||||
t.Logf("Large object cached in %v", duration)
|
||||
|
||||
t.Log("Large object caching test passed")
|
||||
}
|
||||
|
||||
// TestRemoteCacheRangeRequest tests that range requests work after caching
|
||||
func TestRemoteCacheRangeRequest(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("test-range-%d.txt", time.Now().UnixNano())
|
||||
testData := []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
// Write, uncache, then test range request
|
||||
t.Log("Writing and uncaching object...")
|
||||
uploadToPrimary(t, testKey, testData)
|
||||
uncacheLocal(t, testKey)
|
||||
|
||||
// Range request should work and trigger caching
|
||||
t.Log("Testing range request (bytes 10-19)...")
|
||||
resp, err := getPrimaryClient().GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(testKey),
|
||||
Range: aws.String("bytes=10-19"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
rangeData, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := testData[10:20] // "ABCDEFGHIJ"
|
||||
assert.Equal(t, expected, rangeData, "range data mismatch")
|
||||
t.Logf("Range request returned: %s", string(rangeData))
|
||||
|
||||
t.Log("Range request test passed")
|
||||
}
|
||||
|
||||
// mountRemote remounts the test bucket, keeping the metadata already pulled,
|
||||
// with the given extra remote.mount flags.
|
||||
func mountRemote(t *testing.T, extraFlags string) {
|
||||
cmd := fmt.Sprintf("remote.mount -dir=/buckets/%s -remote=seaweedremote/%s -nonempty -metadataStrategy=lazy %s", testBucket, remoteBucket, extraFlags)
|
||||
output, err := runWeedShell(t, cmd)
|
||||
require.NoErrorf(t, err, "remount failed: %s", output)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
// copyLocalToRemote pushes matching local objects to the remote, which is what
|
||||
// lets remote.uncache drop their local chunks afterwards.
|
||||
func copyLocalToRemote(t *testing.T, pattern string) {
|
||||
output, err := runWeedShell(t, fmt.Sprintf("remote.copy.local -dir=/buckets/%s -include=%s", testBucket, pattern))
|
||||
require.NoErrorf(t, err, "remote.copy.local failed: %s", output)
|
||||
}
|
||||
|
||||
// localChunkCount reports how many local chunks an entry has, so a test can
|
||||
// tell a cached read from one served straight out of the remote.
|
||||
func localChunkCount(t *testing.T, key string) string {
|
||||
meta, err := runWeedShell(t, fmt.Sprintf("fs.meta.cat /buckets/%s/%s", testBucket, key))
|
||||
require.NoError(t, err)
|
||||
// fs.meta.cat closes with "chunks N meta size: ..."
|
||||
summary := strings.LastIndex(meta, "chunks ")
|
||||
require.GreaterOrEqualf(t, summary, 0, "no chunk count in %s", meta)
|
||||
return strings.Fields(meta[summary+len("chunks "):])[0]
|
||||
}
|
||||
|
||||
// TestRemoteCacheWaitZero tests that a mount with -cacheWait=0 serves a read of
|
||||
// an uncached object from the remote without caching it locally.
|
||||
func TestRemoteCacheWaitZero(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("test-cachewait-%d.bin", time.Now().UnixNano())
|
||||
testData := make([]byte, 1024*1024)
|
||||
for i := range testData {
|
||||
testData[i] = byte(i % 256)
|
||||
}
|
||||
|
||||
t.Log("Step 1: Writing 1MB object, pushing it to the remote and dropping the local chunks...")
|
||||
uploadToPrimary(t, testKey, testData)
|
||||
copyLocalToRemote(t, testKey)
|
||||
uncacheLocal(t, testKey)
|
||||
require.Equal(t, "0", localChunkCount(t, testKey), "the object must start out remote-only")
|
||||
|
||||
t.Log("Step 2: Remounting with -cacheWait=0...")
|
||||
mountRemote(t, "-cacheWait=0")
|
||||
defer mountRemote(t, "")
|
||||
|
||||
t.Log("Step 3: Reading the object (should stream from remote)...")
|
||||
assert.Equal(t, testData, getFromPrimary(t, testKey), "data mismatch reading from remote")
|
||||
assert.Equal(t, "0", localChunkCount(t, testKey), "the read must not cache chunks locally")
|
||||
|
||||
t.Log("Step 4: Reading with the size based wait (should cache locally)...")
|
||||
mountRemote(t, "")
|
||||
assert.Equal(t, testData, getFromPrimary(t, testKey), "data mismatch reading through the cache")
|
||||
assert.NotEqual(t, "0", localChunkCount(t, testKey), "the read must cache chunks locally")
|
||||
|
||||
t.Log("Zero cache wait test passed")
|
||||
}
|
||||
|
||||
// TestRemoteCacheNotFound tests that non-existent objects return proper errors
|
||||
func TestRemoteCacheNotFound(t *testing.T) {
|
||||
checkServersRunning(t)
|
||||
|
||||
testKey := fmt.Sprintf("non-existent-object-%d", time.Now().UnixNano())
|
||||
|
||||
_, err := getPrimaryClient().GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
Key: aws.String(testKey),
|
||||
})
|
||||
|
||||
assert.Error(t, err, "should get error for non-existent object")
|
||||
t.Logf("Got expected error: %v", err)
|
||||
|
||||
t.Log("Not found test passed")
|
||||
}
|
||||
|
||||
// TestMain sets up and tears down the test environment
|
||||
func TestMain(m *testing.M) {
|
||||
if !isServerRunning(primaryEndpoint) {
|
||||
fmt.Println("WARNING: Primary SeaweedFS not running at", primaryEndpoint)
|
||||
fmt.Println(" Run 'make test-with-server' to start servers automatically")
|
||||
}
|
||||
if !isServerRunning(remoteEndpoint) {
|
||||
fmt.Println("WARNING: Remote SeaweedFS not running at", remoteEndpoint)
|
||||
fmt.Println(" Run 'make test-with-server' to start servers automatically")
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func isServerRunning(url string) bool {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
resp.Body.Close()
|
||||
return true
|
||||
}
|
||||
20
test/s3/remote_cache/s3_config.json
Normal file
20
test/s3/remote_cache/s3_config.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"identities": [
|
||||
{
|
||||
"name": "testuser",
|
||||
"credentials": [
|
||||
{
|
||||
"accessKey": "some_access_key1",
|
||||
"secretKey": "some_secret_key1"
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
"Read",
|
||||
"Write",
|
||||
"List",
|
||||
"Tagging",
|
||||
"Admin"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
49
test/s3/remote_cache/utils/create_bucket.go
Normal file
49
test/s3/remote_cache/utils/create_bucket.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 5 {
|
||||
log.Fatalf("Usage: %s <endpoint> <accessKey> <secretKey> <bucket>", os.Args[0])
|
||||
}
|
||||
endpoint := os.Args[1]
|
||||
accessKey := os.Args[2]
|
||||
secretKey := os.Args[3]
|
||||
bucket := os.Args[4]
|
||||
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Endpoint: aws.String(endpoint),
|
||||
Region: aws.String("us-east-1"),
|
||||
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
|
||||
S3ForcePathStyle: aws.Bool(true),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
svc := s3.New(sess)
|
||||
_, err = svc.CreateBucket(&s3.CreateBucketInput{
|
||||
Bucket: aws.String(bucket),
|
||||
})
|
||||
if err != nil {
|
||||
// BucketAlreadyExists/BucketAlreadyOwnedByYou are acceptable
|
||||
if strings.Contains(err.Error(), "BucketAlreadyOwnedByYou") ||
|
||||
strings.Contains(err.Error(), "BucketAlreadyExists") {
|
||||
fmt.Printf("Bucket %s already exists\n", bucket)
|
||||
} else {
|
||||
log.Fatalf("Failed to create bucket: %v", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Bucket %s created successfully on %s\n", bucket, endpoint)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user