github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/bucketmeta_internal_test.go (about)

     1  // Package ais provides core functionality for the AIStore object storage.
     2  /*
     3   * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package ais
     6  
     7  import (
     8  	"fmt"
     9  	"net/http"
    10  	"time"
    11  
    12  	"github.com/NVIDIA/aistore/api/apc"
    13  	"github.com/NVIDIA/aistore/cmn"
    14  	"github.com/NVIDIA/aistore/cmn/cos"
    15  	"github.com/NVIDIA/aistore/cmn/jsp"
    16  	"github.com/NVIDIA/aistore/core/meta"
    17  	. "github.com/onsi/ginkgo/v2"
    18  	. "github.com/onsi/gomega"
    19  )
    20  
    21  var _ = Describe("BMD marshal and unmarshal", func() {
    22  	const (
    23  		mpath    = "/tmp"
    24  		testpath = "/tmp/.ais.test.bmd"
    25  	)
    26  
    27  	var (
    28  		bmd *bucketMD
    29  		cfg *cmn.Config
    30  	)
    31  
    32  	BeforeEach(func() {
    33  		// Set path for proxy (it uses ConfigDir)
    34  		config := cmn.GCO.BeginUpdate()
    35  		config.ConfigDir = mpath
    36  		config.Cksum.Type = cos.ChecksumXXHash
    37  		config.Space = cmn.SpaceConf{
    38  			LowWM: 75, HighWM: 90, OOS: 95,
    39  		}
    40  		config.LRU = cmn.LRUConf{
    41  			DontEvictTime: cos.Duration(time.Second), CapacityUpdTime: cos.Duration(time.Minute), Enabled: true,
    42  		}
    43  		cmn.GCO.CommitUpdate(config)
    44  		cfg = cmn.GCO.Get()
    45  
    46  		bmd = newBucketMD()
    47  		for _, provider := range []string{apc.AIS, apc.AWS} {
    48  			for i := range 10 {
    49  				var hdr http.Header
    50  				if provider != apc.AIS {
    51  					hdr = http.Header{apc.HdrBackendProvider: []string{provider}}
    52  				}
    53  
    54  				var (
    55  					bck   = meta.NewBck(fmt.Sprintf("bucket_%d", i), provider, cmn.NsGlobal)
    56  					props = defaultBckProps(bckPropsArgs{bck: bck, hdr: hdr})
    57  				)
    58  				bmd.add(bck, props)
    59  			}
    60  		}
    61  	})
    62  
    63  	for _, node := range []string{apc.Target, apc.Proxy} {
    64  		makeBMDOwner := func() bmdOwner {
    65  			var bowner bmdOwner
    66  			switch node {
    67  			case apc.Target:
    68  				bowner = newBMDOwnerTgt()
    69  			case apc.Proxy:
    70  				bowner = newBMDOwnerPrx(cfg)
    71  			}
    72  			return bowner
    73  		}
    74  
    75  		Describe(node, func() {
    76  			var bowner bmdOwner
    77  
    78  			BeforeEach(func() {
    79  				bowner = makeBMDOwner()
    80  				bowner.putPersist(bmd, nil)
    81  			})
    82  
    83  			It("should correctly load bmd for "+node, func() {
    84  				bowner.init()
    85  				Expect(bowner.Get()).To(Equal(&bmd.BMD))
    86  			})
    87  
    88  			It("should save and load bmd using jsp methods for "+node, func() {
    89  				bowner.init()
    90  				bmd := bowner.get()
    91  				for _, signature := range []bool{false, true} {
    92  					for _, compress := range []bool{false, true} {
    93  						for _, checksum := range []bool{false, true} {
    94  							opts := jsp.Options{
    95  								Compress:  compress,
    96  								Checksum:  checksum,
    97  								Signature: signature,
    98  							}
    99  							clone := bmd.clone()
   100  							bck := meta.NewBck("abc"+cos.GenTie(), apc.AIS, cmn.NsGlobal)
   101  
   102  							// Add bucket and save.
   103  							clone.add(bck, defaultBckProps(bckPropsArgs{bck: bck}))
   104  							err := jsp.Save(testpath, clone, opts, nil)
   105  							Expect(err).NotTo(HaveOccurred())
   106  
   107  							// Load elsewhere and check.
   108  							loaded := newBucketMD()
   109  							_, err = jsp.Load(testpath, loaded, opts)
   110  							Expect(err).NotTo(HaveOccurred())
   111  							Expect(loaded.UUID).To(BeEquivalentTo(clone.UUID))
   112  							Expect(loaded.Version).To(BeEquivalentTo(clone.Version))
   113  							_, present := loaded.Get(bck)
   114  							Expect(present).To(BeTrue())
   115  						}
   116  					}
   117  				}
   118  			})
   119  		})
   120  	}
   121  })