Example #1
0
func (t *SyncerTest) SetUp(ti *TestInfo) {
	var err error
	t.ctx = ti.Ctx

	// Set up dependencies.
	t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket")
	t.syncer = newSyncer(
		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 TempFile around it.
	t.content, err = NewTempFile(
		strings.NewReader(srcObjectContents),
		"",
		&t.clock)

	AssertEq(nil, err)

	// Return errors from the fakes by default.
	t.fullCreator.err = errors.New("Fake error")
	t.appendCreator.err = errors.New("Fake error")
}
Example #2
0
// Create a fake bucket with canned contents as described in the comments for
// FakeBucketName.
func MakeFakeBucket(ctx context.Context) (b gcs.Bucket) {
	b = gcsfake.NewFakeBucket(timeutil.RealClock(), FakeBucketName)

	// Set up contents.
	contents := map[string]string{
		TopLevelFile:    TopLevelFile_Contents,
		TopLevelDir:     TopLevelDir_Contents,
		ImplicitDirFile: ImplicitDirFile_Contents,
	}

	for k, v := range contents {
		_, err := b.CreateObject(
			ctx,
			&gcs.CreateObjectRequest{
				Name:     k,
				Contents: strings.NewReader(v),
			})

		if err != nil {
			log.Panicf("CreateObject: %v", err)
		}
	}

	return
}
Example #3
0
func (t *DirTest) SetUp(ti *TestInfo) {
	t.ctx = ti.Ctx
	t.clock.SetTime(time.Date(2015, 4, 5, 2, 15, 0, 0, time.Local))
	t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket")

	// Create the inode. No implicit dirs by default.
	t.resetInode(false)
}
Example #4
0
func (t *PrefixBucketTest) SetUp(ti *TestInfo) {
	var err error

	t.ctx = ti.Ctx
	t.prefix = "foo_"
	t.wrapped = gcsfake.NewFakeBucket(timeutil.RealClock(), "some_bucket")

	t.bucket, err = gcsx.NewPrefixBucket(t.prefix, t.wrapped)
	AssertEq(nil, err)
}
Example #5
0
func init() {
	makeDeps := func(ctx context.Context) (deps gcstesting.BucketTestDeps) {
		// Set up a fixed, non-zero time.
		clock := &timeutil.SimulatedClock{}
		clock.SetTime(time.Date(2012, 8, 15, 22, 56, 0, 0, time.Local))
		deps.Clock = clock

		// Set up the bucket.
		deps.Bucket = gcsfake.NewFakeBucket(clock, "some_bucket")

		return
	}

	gcstesting.RegisterBucketTests(makeDeps)
}
Example #6
0
func (t *IntegrationTest) SetUp(ti *TestInfo) {
	t.ctx = ti.Ctx
	t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket")

	// Set up a fixed, non-zero time.
	t.clock.SetTime(time.Date(2012, 8, 15, 22, 56, 0, 0, time.Local))

	// Set up the syncer.
	const appendThreshold = 0
	const tmpObjectPrefix = ".gcsfuse_tmp/"

	t.syncer = gcsx.NewSyncer(
		appendThreshold,
		tmpObjectPrefix,
		t.bucket)
}
Example #7
0
func (t *fsTest) SetUp(ti *TestInfo) {
	var err error
	t.ctx = ti.Ctx

	// Set up the clocks.
	t.mtimeClock = timeutil.RealClock()
	t.cacheClock.SetTime(time.Date(2015, 4, 5, 2, 15, 0, 0, time.Local))
	t.serverCfg.CacheClock = &t.cacheClock

	// And the bucket.
	if t.bucket == nil {
		t.bucket = gcsfake.NewFakeBucket(t.mtimeClock, "some_bucket")
	}

	t.serverCfg.Bucket = t.bucket

	// Set up ownership.
	t.serverCfg.Uid, t.serverCfg.Gid, err = perms.MyUserAndGroup()
	AssertEq(nil, err)

	// Set up permissions.
	t.serverCfg.FilePerms = filePerms
	t.serverCfg.DirPerms = dirPerms

	// Set up the append optimization.
	t.serverCfg.AppendThreshold = 0
	t.serverCfg.TmpObjectPrefix = ".gcsfuse_tmp/"

	// Set up a temporary directory for mounting.
	t.Dir, err = ioutil.TempDir("", "fs_test")
	AssertEq(nil, err)

	// Create a file system server.
	server, err := fs.NewServer(&t.serverCfg)
	AssertEq(nil, err)

	// Mount the file system.
	mountCfg := t.mountCfg
	mountCfg.OpContext = t.ctx

	if *fDebug {
		mountCfg.DebugLogger = log.New(os.Stderr, "fuse: ", 0)
	}

	t.mfs, err = fuse.Mount(t.Dir, server, &mountCfg)
	AssertEq(nil, err)
}
Example #8
0
func (t *fsTest) SetUp(ti *TestInfo) {
	var err error
	t.ctx = ti.Ctx

	// Set up the clock.
	t.clock.SetTime(time.Date(2015, 4, 5, 2, 15, 0, 0, time.Local))
	t.serverCfg.Clock = &t.clock

	// And the bucket.
	if t.bucket == nil {
		t.bucket = gcsfake.NewFakeBucket(&t.clock, "some_bucket")
	}

	t.serverCfg.Bucket = t.bucket

	// Set up ownership.
	t.serverCfg.Uid, t.serverCfg.Gid, err = perms.MyUserAndGroup()
	AssertEq(nil, err)

	// Set up permissions.
	t.serverCfg.FilePerms = filePerms
	t.serverCfg.DirPerms = dirPerms

	// Use some temporary space to speed tests.
	t.serverCfg.TempDirLimitNumFiles = 16
	t.serverCfg.TempDirLimitBytes = 1 << 22 // 4 MiB

	// Set up the append optimization.
	t.serverCfg.AppendThreshold = 0
	t.serverCfg.TmpObjectPrefix = ".gcsfuse_tmp/"

	// Set up a temporary directory for mounting.
	t.Dir, err = ioutil.TempDir("", "fs_test")
	AssertEq(nil, err)

	// Create a file system server.
	server, err := fs.NewServer(&t.serverCfg)
	AssertEq(nil, err)

	// Mount the file system.
	mountCfg := t.mountCfg
	mountCfg.OpContext = t.ctx

	t.mfs, err = fuse.Mount(t.Dir, server, &mountCfg)
	AssertEq(nil, err)
}
Example #9
0
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)
}
Example #10
0
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)
}
Example #11
0
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.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,
		[]byte(t.initialContents))

	AssertEq(nil, err)

	// Create the inode.
	t.createInode()
}
Example #12
0
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 newFakeBlobStore(ctx context.Context) (blobStore blob.Store, err error) {
	// Create a bucket.
	bucket := gcsfake.NewFakeBucket(timeutil.RealClock(), "some_bucket")

	// And a cryptoer.
	_, crypter, err := wiring.MakeRegistryAndCrypter(ctx, "password", bucket)
	if err != nil {
		err = fmt.Errorf("MakeRegistryAndCrypter: %v", err)
		return
	}

	// And the blob store.
	blobStore, err = wiring.MakeBlobStore(bucket, crypter, util.NewStringSet())
	if err != nil {
		err = fmt.Errorf("MakeBlobStore: %v", err)
		return
	}

	return
}
Example #14
0
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")
}
Example #15
0
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()
}