func (t *MultiReadProxyTest) SetUp(ti *TestInfo) { t.ctx = ti.Ctx t.leaser = lease.NewFileLeaser("", math.MaxInt32, math.MaxInt64) // Set up default refresher contents and nil errors. t.refresherContents = []string{ "taco", "burrito", "enchilada", } t.refresherErrors = make([]error, len(t.refresherContents)) // Create the proxy. t.resetProxy() }
func (t *IntegrationTest) SetUp(ti *TestInfo) { t.ctx = ti.Ctx t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket") t.leaser = lease.NewFileLeaser( "", fileLeaserLimitNumFiles, fileLeaserLimitBytes) // Set up a fixed, non-zero time. t.clock.SetTime(time.Date(2012, 8, 15, 22, 56, 0, 0, time.Local)) // Set up the object syncer. const appendThreshold = 0 const tmpObjectPrefix = ".gcsfuse_tmp/" t.syncer = gcsproxy.NewObjectSyncer( appendThreshold, tmpObjectPrefix, t.bucket) }
func (t *ObjectSyncerTest) SetUp(ti *TestInfo) { var err error t.ctx = ti.Ctx // Set up dependencies. t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket") t.leaser = lease.NewFileLeaser("", math.MaxInt32, math.MaxInt32) t.syncer = newObjectSyncer( appendThreshold, &t.fullCreator, &t.appendCreator) t.clock.SetTime(time.Date(2015, 4, 5, 2, 15, 0, 0, time.Local)) // Set up a source object. t.srcObject, err = t.bucket.CreateObject( t.ctx, &gcs.CreateObjectRequest{ Name: "foo", Contents: strings.NewReader(srcObjectContents), }) AssertEq(nil, err) // Wrap a mutable.Content around it. t.content = mutable.NewContent( NewReadProxy( t.srcObject, nil, // Initial read lease math.MaxUint64, // Chunk size t.leaser, t.bucket), &t.clock) // Return errors from the fakes by default. t.fullCreator.err = errors.New("Fake error") t.appendCreator.err = errors.New("Fake error") }
func (t *FileTest) SetUp(ti *TestInfo) { t.ctx = ti.Ctx t.clock.SetTime(time.Date(2012, 8, 15, 22, 56, 0, 0, time.Local)) t.leaser = lease.NewFileLeaser("", math.MaxInt32, math.MaxInt64) t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket") // Set up the backing object. var err error t.initialContents = "taco" t.backingObj, err = gcsutil.CreateObject( t.ctx, t.bucket, fileInodeName, t.initialContents) AssertEq(nil, err) // Create the inode. t.in = inode.NewFileInode( fileInodeID, t.backingObj, fuseops.InodeAttributes{ Uid: uid, Gid: gid, Mode: fileMode, }, math.MaxUint64, // GCS chunk size t.bucket, t.leaser, gcsproxy.NewObjectSyncer( 1, // Append threshold ".gcsfuse_tmp/", t.bucket), &t.clock) t.in.Lock() }
// Create a fuse file system server according to the supplied configuration. func NewServer(cfg *ServerConfig) (server fuse.Server, err error) { // Check permissions bits. if cfg.FilePerms&^os.ModePerm != 0 { err = fmt.Errorf("Illegal file perms: %v", cfg.FilePerms) return } if cfg.DirPerms&^os.ModePerm != 0 { err = fmt.Errorf("Illegal dir perms: %v", cfg.FilePerms) return } // Disable chunking if set to zero. gcsChunkSize := cfg.GCSChunkSize if gcsChunkSize == 0 { gcsChunkSize = math.MaxUint64 } // Create the file leaser. leaser := lease.NewFileLeaser( cfg.TempDir, cfg.TempDirLimitNumFiles, cfg.TempDirLimitBytes) // Create the object syncer. // Check TmpObjectPrefix. if cfg.TmpObjectPrefix == "" { err = errors.New("You must set TmpObjectPrefix.") return } objectSyncer := gcsproxy.NewObjectSyncer( cfg.AppendThreshold, cfg.TmpObjectPrefix, cfg.Bucket) // Set up the basic struct. fs := &fileSystem{ clock: cfg.Clock, bucket: cfg.Bucket, leaser: leaser, objectSyncer: objectSyncer, gcsChunkSize: gcsChunkSize, implicitDirs: cfg.ImplicitDirectories, dirTypeCacheTTL: cfg.DirTypeCacheTTL, uid: cfg.Uid, gid: cfg.Gid, fileMode: cfg.FilePerms, dirMode: cfg.DirPerms | os.ModeDir, inodes: make(map[fuseops.InodeID]inode.Inode), nextInodeID: fuseops.RootInodeID + 1, generationBackedInodes: make(map[string]GenerationBackedInode), implicitDirInodes: make(map[string]inode.DirInode), handles: make(map[fuseops.HandleID]interface{}), } // Set up the root inode. root := inode.NewDirInode( fuseops.RootInodeID, "", // name fuseops.InodeAttributes{ Uid: fs.uid, Gid: fs.gid, Mode: fs.dirMode, }, fs.implicitDirs, fs.dirTypeCacheTTL, cfg.Bucket, fs.clock) root.Lock() root.IncrementLookupCount() fs.inodes[fuseops.RootInodeID] = root fs.implicitDirInodes[root.Name()] = root root.Unlock() // Set up invariant checking. fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants) // Periodically garbage collect temporary objects. var gcCtx context.Context gcCtx, fs.stopGarbageCollecting = context.WithCancel(context.Background()) go garbageCollect(gcCtx, cfg.TmpObjectPrefix, fs.bucket) server = fuseutil.NewFileSystemServer(fs) return }
func (t *FileLeaserTest) SetUp(ti *TestInfo) { t.fl = lease.NewFileLeaser("", limitNumFiles, limitBytes) }