예제 #1
0
func testKvChangeIndex(bucketname string) (*kvChangeIndex, base.Bucket) {
	cacheBucketSpec := base.BucketSpec{
		Server:     kTestURL,
		BucketName: bucketname}
	index := &kvChangeIndex{}

	changeIndexOptions := &ChangeIndexOptions{
		Spec:   cacheBucketSpec,
		Writer: true,
	}
	err := index.Init(nil, SequenceID{}, nil, &CacheOptions{}, changeIndexOptions)
	if err != nil {
		log.Fatal("Couldn't connect to index bucket")
	}

	base.SeedTestPartitionMap(index.reader.indexReadBucket, 64)

	return index, index.reader.indexReadBucket
}
예제 #2
0
func setupTestDBForChangeIndex(t *testing.T) *Database {

	var vbEnabledBucket base.Bucket
	if kTestURL == "walrus:" {
		leakyBucketConfig := base.LeakyBucketConfig{
			TapFeedVbuckets: true,
		}
		vbEnabledBucket = testLeakyBucket(leakyBucketConfig)
	} else {
		vbEnabledBucket = testBucket()
	}

	indexBucketSpec := base.BucketSpec{
		Server:     kTestURL,
		BucketName: "test_indexBucket"}
	indexBucket, err := ConnectToBucket(indexBucketSpec, nil)

	if err != nil {
		log.Fatal("Couldn't connect to index bucket")
	}
	dbcOptions := DatabaseContextOptions{
		IndexOptions: &ChangeIndexOptions{
			Spec:   indexBucketSpec,
			Writer: true,
		},
		SequenceHashOptions: &SequenceHashOptions{
			Bucket: indexBucket,
		},
	}
	context, err := NewDatabaseContext("db", vbEnabledBucket, false, dbcOptions)
	assertNoError(t, err, "Couldn't create context for database 'db'")
	db, err := CreateDatabase(context)
	assertNoError(t, err, "Couldn't create database 'db'")

	base.SeedTestPartitionMap(context.GetIndexBucket(), 64)
	return db
}
예제 #3
0
func initIndexTester(useBucketIndex bool, syncFn string) indexTester {

	it := indexTester{}
	it.syncFn = syncFn

	it._sc = NewServerContext(&ServerConfig{
		Facebook: &FacebookConfig{},
		Persona:  &PersonaConfig{},
	})

	var syncFnPtr *string
	if len(it.syncFn) > 0 {
		syncFnPtr = &it.syncFn
	}

	serverName := "walrus:"
	bucketName := "sg_bucket"

	feedType := "tap"
	if useBucketIndex {
		feedType = "dcp"
	}

	dbConfig := &DbConfig{
		BucketConfig: BucketConfig{
			Server: &serverName,
			Bucket: &bucketName},
		Name:     "db",
		Sync:     syncFnPtr,
		FeedType: feedType,
	}

	if useBucketIndex {
		indexBucketName := "sg_index_bucket"
		channelIndexConfig := &ChannelIndexConfig{
			BucketConfig: BucketConfig{
				Server: &serverName,
				Bucket: &indexBucketName,
			},
			IndexWriter: true,
		}
		dbConfig.ChannelIndex = channelIndexConfig
	}

	dbContext, err := it._sc.AddDatabaseFromConfig(dbConfig)

	if useBucketIndex {
		err := base.SeedTestPartitionMap(dbContext.GetIndexBucket(), 64)
		if err != nil {
			panic(fmt.Sprintf("Error from seed partition map: %v", err))
		}
	}

	if err != nil {
		panic(fmt.Sprintf("Error from AddDatabaseFromConfig: %v", err))
	}

	it._bucket = it._sc.Database("db").Bucket

	if useBucketIndex {
		it._indexBucket = it._sc.Database("db").GetIndexBucket()
	}

	return it
}