2022-09-11 07:09:10 +02:00
|
|
|
// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2023-05-12 15:10:04 +02:00
|
|
|
"path/filepath"
|
2022-09-11 07:09:10 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-05-12 15:10:04 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/internal/util"
|
2022-09-11 07:09:10 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInitEmptyPath(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"kind\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInitNoJson(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("\"path\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestInitNotExists(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/job-archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
version, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-05-04 18:54:34 +02:00
|
|
|
if fsa.path != "testdata/archive" {
|
2022-09-11 07:09:10 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
2023-03-27 14:41:00 +02:00
|
|
|
if version != 1 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2022-09-11 07:09:10 +02:00
|
|
|
if len(fsa.clusters) != 1 || fsa.clusters[0] != "emmy" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadJobMetaInternal(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:54:34 +02:00
|
|
|
job, err := loadJobMeta("testdata/archive/emmy/1404/397/1609300556/meta.json")
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if job.JobID != 1404397 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
if int(job.NumNodes) != len(job.Resources) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
if job.StartTime != 1609300556 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadJobMeta(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
jobIn := schema.Job{BaseJob: schema.JobDefaults}
|
|
|
|
jobIn.StartTime = time.Unix(1608923076, 0)
|
|
|
|
jobIn.JobID = 1403244
|
|
|
|
jobIn.Cluster = "emmy"
|
|
|
|
|
|
|
|
job, err := fsa.LoadJobMeta(&jobIn)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if job.JobID != 1403244 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
if int(job.NumNodes) != len(job.Resources) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
if job.StartTime != 1608923076 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadJobData(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-12 15:10:04 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"path\": \"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
jobIn := schema.Job{BaseJob: schema.JobDefaults}
|
|
|
|
jobIn.StartTime = time.Unix(1608923076, 0)
|
|
|
|
jobIn.JobID = 1403244
|
|
|
|
jobIn.Cluster = "emmy"
|
|
|
|
|
|
|
|
data, err := fsa.LoadJobData(&jobIn)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-12 15:10:04 +02:00
|
|
|
for _, scopes := range data {
|
|
|
|
// fmt.Printf("Metric name: %s\n", name)
|
2022-09-11 07:09:10 +02:00
|
|
|
|
|
|
|
if _, exists := scopes[schema.MetricScopeNode]; !exists {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 15:10:04 +02:00
|
|
|
func BenchmarkLoadJobData(b *testing.B) {
|
|
|
|
|
|
|
|
tmpdir := b.TempDir()
|
|
|
|
jobarchive := filepath.Join(tmpdir, "job-archive")
|
|
|
|
util.CopyDir("./testdata/archive/", jobarchive)
|
|
|
|
archiveCfg := fmt.Sprintf("{\"path\": \"%s\"}", jobarchive)
|
|
|
|
|
|
|
|
var fsa FsArchive
|
|
|
|
fsa.Init(json.RawMessage(archiveCfg))
|
|
|
|
|
|
|
|
jobIn := schema.Job{BaseJob: schema.JobDefaults}
|
|
|
|
jobIn.StartTime = time.Unix(1608923076, 0)
|
|
|
|
jobIn.JobID = 1403244
|
|
|
|
jobIn.Cluster = "emmy"
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
fsa.LoadJobData(&jobIn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkLoadJobDataCompressed(b *testing.B) {
|
|
|
|
|
|
|
|
tmpdir := b.TempDir()
|
|
|
|
jobarchive := filepath.Join(tmpdir, "job-archive")
|
|
|
|
util.CopyDir("./testdata/archive/", jobarchive)
|
|
|
|
archiveCfg := fmt.Sprintf("{\"path\": \"%s\"}", jobarchive)
|
|
|
|
|
|
|
|
var fsa FsArchive
|
|
|
|
fsa.Init(json.RawMessage(archiveCfg))
|
|
|
|
|
|
|
|
jobIn := schema.Job{BaseJob: schema.JobDefaults}
|
|
|
|
jobIn.StartTime = time.Unix(1608923076, 0)
|
|
|
|
jobIn.JobID = 1403244
|
|
|
|
jobIn.Cluster = "emmy"
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
fsa.LoadJobData(&jobIn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-11 07:09:10 +02:00
|
|
|
func TestLoadCluster(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := fsa.LoadClusterCfg("emmy")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-03-22 07:05:41 +01:00
|
|
|
if cfg.SubClusters[0].CoresPerSocket != 4 {
|
2022-09-11 07:09:10 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIter(t *testing.T) {
|
|
|
|
var fsa FsArchive
|
2023-05-04 18:54:34 +02:00
|
|
|
_, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}"))
|
2022-09-11 07:09:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-03-31 15:28:35 +02:00
|
|
|
for job := range fsa.Iter(false) {
|
|
|
|
fmt.Printf("Job %d\n", job.Meta.JobID)
|
2022-09-11 07:09:10 +02:00
|
|
|
|
2023-03-31 15:28:35 +02:00
|
|
|
if job.Meta.Cluster != "emmy" {
|
2022-09-11 07:09:10 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|