func setUpBucket( ctx context.Context, flags *flagStorage, conn gcs.Conn, name string) (b gcs.Bucket, err error) { // Extract the appropriate bucket. b, err = conn.OpenBucket(ctx, name) if err != nil { err = fmt.Errorf("OpenBucket: %v", err) return } // Enable rate limiting, if requested. b, err = setUpRateLimiting( b, flags.OpRateLimitHz, flags.EgressBandwidthLimitBytesPerSecond) if err != nil { err = fmt.Errorf("setUpRateLimiting: %v", err) return } // Enable cached StatObject results, if appropriate. if flags.StatCacheTTL != 0 { const cacheCapacity = 4096 b = gcscaching.NewFastStatBucket( flags.StatCacheTTL, gcscaching.NewStatCache(cacheCapacity), timeutil.RealClock(), b) } return }
// Configure a bucket based on the supplied flags. // // Special case: if the bucket name is canned.FakeBucketName, set up a fake // bucket as described in that package. func setUpBucket( ctx context.Context, flags *flagStorage, conn gcs.Conn, name string) (b gcs.Bucket, err error) { // Set up the appropriate backing bucket. if name == canned.FakeBucketName { b = canned.MakeFakeBucket(ctx) } else { b, err = conn.OpenBucket(ctx, name) if err != nil { err = fmt.Errorf("OpenBucket: %v", err) return } } // Limit to a requested prefix of the bucket, if any. if flags.OnlyDir != "" { b, err = gcsx.NewPrefixBucket(path.Clean(flags.OnlyDir)+"/", b) if err != nil { err = fmt.Errorf("NewPrefixBucket: %v", err) return } } // Enable rate limiting, if requested. b, err = setUpRateLimiting( b, flags.OpRateLimitHz, flags.EgressBandwidthLimitBytesPerSecond) if err != nil { err = fmt.Errorf("setUpRateLimiting: %v", err) return } // Enable cached StatObject results, if appropriate. if flags.StatCacheTTL != 0 { const cacheCapacity = 4096 b = gcscaching.NewFastStatBucket( flags.StatCacheTTL, gcscaching.NewStatCache(cacheCapacity), timeutil.RealClock(), b) } return }
func (t *IntegrationTest) SetUp(ti *TestInfo) { t.ctx = context.Background() // Set up a fixed, non-zero time. t.clock.SetTime(time.Date(2015, 4, 5, 2, 15, 0, 0, time.Local)) // Set up dependencies. const cacheCapacity = 100 t.cache = gcscaching.NewStatCache(cacheCapacity) t.wrapped = gcsfake.NewFakeBucket(&t.clock, "some_bucket") t.bucket = gcscaching.NewFastStatBucket( ttl, t.cache, &t.clock, t.wrapped) }
func (t *cachingTestCommon) SetUp(ti *TestInfo) { // Wrap the bucket in a stat caching layer for the purposes of the file // system. t.uncachedBucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket") const statCacheCapacity = 1000 statCache := gcscaching.NewStatCache(statCacheCapacity) t.bucket = gcscaching.NewFastStatBucket( ttl, statCache, &t.clock, t.uncachedBucket) // Enable directory type caching. t.serverCfg.DirTypeCacheTTL = ttl // Call through. t.fsTest.SetUp(ti) }
func (t *StatCacheTest) SetUp(ti *TestInfo) { t.cache.wrapped = gcscaching.NewStatCache(capacity) }