engine refactor

This commit is contained in:
Anatoly Antonov 2026-05-23 00:55:35 +09:00
parent 9e663db9dc
commit 81b8e763bd
37 changed files with 3532 additions and 1639 deletions

View file

@ -2,7 +2,6 @@ package datasets
import (
"os"
"path/filepath"
"testing"
"time"
)
@ -14,8 +13,8 @@ func TestLocalStoreBeginWriteResume(t *testing.T) {
t.Fatalf("NewLocalStore: %v", err)
}
epoch := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
h, err := store.BeginWrite(epoch)
id := DatasetID{Epoch: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)}
h, err := store.BeginWrite(id)
if err != nil {
t.Fatalf("BeginWrite: %v", err)
}
@ -27,7 +26,7 @@ func TestLocalStoreBeginWriteResume(t *testing.T) {
}
// Re-open should see the previous manifest entry.
h2, err := store.BeginWrite(epoch)
h2, err := store.BeginWrite(id)
if err != nil {
t.Fatalf("BeginWrite resume: %v", err)
}
@ -35,48 +34,59 @@ func TestLocalStoreBeginWriteResume(t *testing.T) {
t.Errorf("resumed manifest missing step000-A; units = %v", h2.Manifest().Units())
}
// Commit promotes the temp file and removes the manifest.
if err := h2.Commit(); err != nil {
t.Fatalf("Commit: %v", err)
}
if !store.Exists(epoch) {
if !store.Exists(id) {
t.Errorf("Exists after commit returned false")
}
if _, err := os.Stat(filepath.Join(dir, store.manifestPath(epoch))); !os.IsNotExist(err) {
if _, err := os.Stat(store.manifestPath(id)); !os.IsNotExist(err) {
t.Errorf("manifest should be removed, got err=%v", err)
}
// Listing finds the committed epoch.
epochs, err := store.List()
stored, err := store.List()
if err != nil {
t.Fatalf("List: %v", err)
}
if len(epochs) != 1 || !epochs[0].Equal(epoch) {
t.Errorf("List = %v, want [%v]", epochs, epoch)
if len(stored) != 1 || !stored[0].Epoch.Equal(id.Epoch) {
t.Errorf("List = %v, want one item with epoch %v", stored, id.Epoch)
}
// Remove cleans up.
if err := store.Remove(epoch); err != nil {
if err := store.Remove(id); err != nil {
t.Fatalf("Remove: %v", err)
}
if store.Exists(epoch) {
if store.Exists(id) {
t.Errorf("Exists after remove returned true")
}
}
func TestLocalStoreAbort(t *testing.T) {
func TestLocalStoreSubsetPath(t *testing.T) {
dir := t.TempDir()
store, _ := NewLocalStore(dir, "gfs-test")
epoch := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
h, _ := store.BeginWrite(epoch)
os.WriteFile(h.Path(), []byte("x"), 0o644)
h.Manifest().Mark("step000-A")
if err := h.Abort(); err != nil {
t.Fatalf("Abort: %v", err)
regional := DatasetID{
Epoch: epoch,
Subset: SubsetSpec{
Region: &Region{MinLat: -10, MaxLat: 10, MinLng: 0, MaxLng: 30},
HourRange: &HourRange{MinHour: 0, MaxHour: 72},
},
}
if _, err := os.Stat(h.Path()); !os.IsNotExist(err) {
t.Errorf("temp file should be removed after abort, got %v", err)
global := DatasetID{Epoch: epoch}
if store.Path(global) == store.Path(regional) {
t.Errorf("global and regional should have distinct paths")
}
}
func TestSubsetSpecCoverage(t *testing.T) {
r := Region{MinLat: -10, MaxLat: 10, MinLng: 350, MaxLng: 10} // wraps antimeridian
s := SubsetSpec{Region: &r}
if !s.IncludesLatLng(0, 0) {
t.Errorf("(0,0) should be inside antimeridian region")
}
if !s.IncludesLatLng(0, 359) {
t.Errorf("(0,359) should be inside antimeridian region")
}
if s.IncludesLatLng(0, 180) {
t.Errorf("(0,180) should be outside antimeridian region")
}
}