Files
seaweedfs/test/testutil/maven_test.go
T
Chris LuandClaude Opus 5.5 9b94f00325 test: mount pinned Iceberg jars into the Spark catalog tests (#12757)
* testutil: fetch pinned Maven Central jars with a mirror fallback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: mount pinned Iceberg jars into the Spark catalog containers

Each test started a new Spark container that resolved the Iceberg runtime
and AWS bundle through Ivy from Maven Central, so a run downloaded them six
times and a single refused request left Spark retrying until the package
timed out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci: cache the Iceberg jars for the Spark catalog tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* testutil: test the verified jar download

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: bound Maven jar downloads by one deadline shared across retries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: give each Maven mirror attempt its own timeout within the download budget

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 19:35:54 -08:00

93 lines
2.6 KiB
Go

package testutil
import (
"context"
"crypto/sha256"
"encoding/hex"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"
)
func TestDownloadVerified(t *testing.T) {
body := []byte("jar contents")
sum := sha256.Sum256(body)
want := hex.EncodeToString(sum[:])
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/stall.jar" {
<-r.Context().Done()
return
}
if r.URL.Path != "/a.jar" {
http.NotFound(w, r)
return
}
w.Write(body)
}))
defer srv.Close()
dir := t.TempDir()
path := filepath.Join(dir, "a.jar")
ctx := context.Background()
stallCtx, cancel := context.WithTimeout(ctx, 200*time.Millisecond)
defer cancel()
if err := downloadVerified(stallCtx, srv.URL+"/stall.jar", path, want); err == nil {
t.Fatal("a stalled download should fail at the deadline")
}
if err := downloadVerified(ctx, srv.URL+"/missing.jar", path, want); err == nil {
t.Fatal("a 404 should fail")
}
if err := downloadVerified(ctx, srv.URL+"/a.jar", path, "00"); err == nil {
t.Fatal("a checksum mismatch should fail")
}
if entries, _ := os.ReadDir(dir); len(entries) != 0 {
t.Fatalf("failed downloads left %d files behind", len(entries))
}
if err := downloadVerified(ctx, srv.URL+"/a.jar", path, want); err != nil {
t.Fatalf("download: %v", err)
}
if got := fileSHA256(path); got != want {
t.Fatalf("sha256 %s, want %s", got, want)
}
}
func TestMavenJarFallsBackPastStalledMirror(t *testing.T) {
body := []byte("jar contents")
sum := sha256.Sum256(body)
want := hex.EncodeToString(sum[:])
stalled := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
<-r.Context().Done()
}))
defer stalled.Close()
healthy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/org/example/demo/1.0/demo-1.0.jar" {
http.NotFound(w, r)
return
}
w.Write(body)
}))
defer healthy.Close()
cache := t.TempDir()
t.Setenv("XDG_CACHE_HOME", cache)
t.Setenv("HOME", cache)
t.Setenv("LocalAppData", cache)
oldMirrors, oldBudget, oldAttempt := mavenCentralMirrors, mavenDownloadBudget, mavenAttemptTimeout
mavenCentralMirrors = []string{stalled.URL, healthy.URL}
mavenDownloadBudget, mavenAttemptTimeout = 10*time.Second, 200*time.Millisecond
defer func() {
mavenCentralMirrors, mavenDownloadBudget, mavenAttemptTimeout = oldMirrors, oldBudget, oldAttempt
}()
path := MavenJar(t, "org.example", "demo", "1.0", want)
if got := fileSHA256(path); got != want {
t.Fatalf("sha256 %s, want %s", got, want)
}
}