func TestDiskReload(t *testing.T) {
	t.Parallel()
	tempDir, cleanup := testutils.GetTestFolder(t)
	defer cleanup()

	app, err := New(types.AppVersion{}, getConfigGetter(tempDir))
	if err != nil {
		t.Fatalf("Could not create an application: %s", err)
	}

	stor, err := disk.New(app.cfg.CacheZones["default"], mock.NewLogger())
	if err != nil {
		t.Fatalf("Could not initialize a storage: %s", err)
	}

	objIDNew := types.NewObjectID("key", "new")
	objIDOld := types.NewObjectID("key", "old")
	testutils.ShouldntFail(t,
		stor.SaveMetadata(&types.ObjectMetadata{ID: objIDNew, ExpiresAt: time.Now().Unix() + 600}),
		stor.SaveMetadata(&types.ObjectMetadata{ID: objIDOld, ExpiresAt: time.Now().Unix() - 600}),
		stor.SavePart(&types.ObjectIndex{ObjID: objIDNew, Part: 0}, strings.NewReader("test1-1")),
		stor.SavePart(&types.ObjectIndex{ObjID: objIDNew, Part: 1}, strings.NewReader("test1-2")),
		stor.SavePart(&types.ObjectIndex{ObjID: objIDOld, Part: 0}, strings.NewReader("test2-1")),
	)

	if err := app.initFromConfig(); err != nil {
		t.Fatalf("Could not init from config: %s", err)
	}
	defer app.ctxCancel()
	time.Sleep(1 * time.Second)

	const expectedObjects = 2
	cacheObjects := app.cacheZones["default"].Algorithm.Stats().Objects()
	if cacheObjects != expectedObjects {
		t.Errorf("Expected object count in cache to be %d but it was %d", expectedObjects, cacheObjects)
	}
}
Beispiel #2
0
// This file is generated with go generate. Any changes to it will be lost after
// subsequent generates.
// If you want to edit it go to types.go.template

package storage

import (
	"github.com/ironsmile/nedomi/config"
	"github.com/ironsmile/nedomi/types"

	"github.com/ironsmile/nedomi/storage/disk"
)

type newStorageFunc func(cfg config.CacheZoneSection, ca types.CacheAlgorithm,
	log types.Logger) types.Storage

var storageTypes = map[string]newStorageFunc{

	"disk": func(cfg config.CacheZoneSection, ca types.CacheAlgorithm, log types.Logger) types.Storage {
		return disk.New(cfg, ca, log)
	},
}