Exemplo n.º 1
0
func TestMutationsWithMultipleIndexBuilds(t *testing.T) {
	log.Printf("In TestMutationsWithMultipleIndexBuilds()")
	prodfile = filepath.Join(proddir, "test.prod")
	secondaryindex.DropAllSecondaryIndexes(indexManagementAddress)

	log.Printf("Generating JSON docs")
	kvdocs = GenerateJsons(100000, seed, prodfile, bagdir)
	seed++

	log.Printf("Setting initial JSON docs in KV")
	kv.SetKeyValues(kvdocs, "default", "", clusterconfig.KVAddress)

	var index_p = "index_primary"
	var bucketName = "default"
	indexes := []string{"index_company", "index_age", "index_firstname", "index_lastname"}
	fields := []string{"company", "age", "`first-name`", "`last-name`"}

	// Create a primary index
	err := secondaryindex.CreateSecondaryIndex(index_p, bucketName, indexManagementAddress, "", nil, true, nil, true, defaultIndexActiveTimeout, nil)
	FailTestIfError(err, "Error in creating the index", t)

	log.Printf("Creating multiple indexes in deferred mode")
	for i := range indexes {
		e := secondaryindex.CreateSecondaryIndexAsync(indexes[i], bucketName, indexManagementAddress, "", []string{fields[i]}, false, []byte("{\"defer_build\": true}"), true, nil)
		FailTestIfError(e, "Error in creating the index", t)
	}

	log.Printf("Build Indexes and wait for indexes to become active: %v", indexes)
	err = secondaryindex.BuildIndexes(indexes, bucketName, indexManagementAddress, 2000)
	FailTestIfError(err, "Error in deferred index build", t)
}
Exemplo n.º 2
0
func TestDeferredIndexCreate(t *testing.T) {
	log.Printf("In TestDeferredIndexCreate()")

	var indexName = "index_deferred"
	var bucketName = "default"

	err := secondaryindex.CreateSecondaryIndexAsync(indexName, bucketName, indexManagementAddress, "", []string{"company"}, false, []byte("{\"defer_build\": true}"), true, nil)
	FailTestIfError(err, "Error in creating the index", t)

	state, err := secondaryindex.IndexState(indexName, bucketName, indexManagementAddress)
	FailTestIfError(err, "Error in getting index state for index", t)
	log.Printf("Created the index %v in deferred mode. Index state is %v", indexName, state)

	err = secondaryindex.BuildIndex(indexName, bucketName, indexManagementAddress, defaultIndexActiveTimeout)
	FailTestIfError(err, "Error in deferred index build", t)

	docScanResults := datautility.ExpectedScanResponse_string(docs, "company", "G", "M", 1)
	scanResults, err := secondaryindex.Range(indexName, bucketName, indexScanAddress, []interface{}{"G"}, []interface{}{"M"}, 1, true, defaultlimit, c.SessionConsistency, nil)
	FailTestIfError(err, "Error in scan of deferred index", t)
	err = tv.Validate(docScanResults, scanResults)
	FailTestIfError(err, "Error in scan result validation", t)
}