MCPcopy
hub / github.com/grafana/tempo / TestShardedRoundTrip

Function TestShardedRoundTrip

modules/backendscheduler/work/work_sharded_test.go:15–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestShardedRoundTrip(t *testing.T) {
16 shardedWork := New(Config{})
17
18 // Add multiple jobs to different shards
19 jobs := []*Job{
20 createTestJob("test-job-1", tempopb.JobType_JOB_TYPE_COMPACTION),
21 createTestJob("test-job-2", tempopb.JobType_JOB_TYPE_COMPACTION),
22 createTestJob("test-job-3", tempopb.JobType_JOB_TYPE_RETENTION),
23 }
24
25 for _, job := range jobs {
26 err := shardedWork.AddJob(job)
27 require.NoError(t, err, "failed to add job: %v", err)
28 }
29
30 // Verify jobs were added
31 require.Equal(t, len(jobs), len(shardedWork.ListJobs()), "unexpected number of jobs before marshal")
32
33 // Marshal the sharded work
34 data, err := shardedWork.Marshal()
35 require.NoError(t, err, "failed to marshal sharded work")
36
37 // Unmarshal into a new instance
38 newShardedWork := New(Config{})
39 err = newShardedWork.Unmarshal(data)
40 require.NoError(t, err, "failed to unmarshal sharded work")
41
42 // Verify the lengths match
43 require.Equal(t, len(shardedWork.ListJobs()), len(newShardedWork.ListJobs()), "sharded work lengths do not match")
44
45 // Verify all jobs are present in the new instance
46 originalJobs := shardedWork.ListJobs()
47 newJobs := newShardedWork.ListJobs()
48
49 require.Equal(t, len(originalJobs), len(newJobs), "job counts don't match")
50
51 // Create maps for easier comparison
52 originalJobMap := make(map[string]*Job)
53 for _, job := range originalJobs {
54 originalJobMap[job.ID] = job
55 }
56
57 newJobMap := make(map[string]*Job)
58 for _, job := range newJobs {
59 newJobMap[job.ID] = job
60 }
61
62 // Verify all original jobs exist in the new instance
63 for jobID, originalJob := range originalJobMap {
64 newJob, exists := newJobMap[jobID]
65 require.True(t, exists, "job %s should exist in unmarshaled instance", jobID)
66 require.Equal(t, originalJob.ID, newJob.ID, "job IDs should match")
67 }
68}
69
70func TestAddJob(t *testing.T) {
71 work := New(Config{})

Callers

nothing calls this directly

Calls 7

createTestJobFunction · 0.85
NewFunction · 0.70
AddJobMethod · 0.65
ListJobsMethod · 0.65
MarshalMethod · 0.65
UnmarshalMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected