Merge branch '17074-optimize-itemsavailable' into main. Closes #17074
[arvados.git] / sdk / go / arvadostest / manifest.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package arvadostest
6
7 import (
8         "bytes"
9         "fmt"
10         "math/rand"
11 )
12
13 func FakeManifest(dirCount, filesPerDir, blocksPerFile, interleaveChunk int) string {
14         const blksize = 1 << 26
15         mb := bytes.NewBuffer(make([]byte, 0, 40000000))
16         blkid := 0
17         for i := 0; i < dirCount; i++ {
18                 fmt.Fprintf(mb, "./dir%d", i)
19                 for j := 0; j < filesPerDir; j++ {
20                         for k := 0; k < blocksPerFile; k++ {
21                                 blkid++
22                                 fmt.Fprintf(mb, " %032x+%d+A%040x@%08x", blkid, blksize, blkid, blkid)
23                         }
24                 }
25                 for j := 0; j < filesPerDir; j++ {
26                         if interleaveChunk == 0 {
27                                 fmt.Fprintf(mb, " %d:%d:dir%d/file%d", (filesPerDir-j-1)*blocksPerFile*blksize, blocksPerFile*blksize, j, j)
28                                 continue
29                         }
30                         for todo := int64(blocksPerFile) * int64(blksize); todo > 0; todo -= int64(interleaveChunk) {
31                                 size := int64(interleaveChunk)
32                                 if size > todo {
33                                         size = todo
34                                 }
35                                 offset := rand.Int63n(int64(blocksPerFile)*int64(blksize)*int64(filesPerDir) - size)
36                                 fmt.Fprintf(mb, " %d:%d:dir%d/file%d", offset, size, j, j)
37                         }
38                 }
39                 mb.Write([]byte{'\n'})
40         }
41         return mb.String()
42 }