func TestLookupFloatDiffForms(t *testing.T) { log.Printf("In TestLookupFloatDiffForms()") var indexName = "index_latitude" var bucketName = "default" err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"latitude"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) // Scan 1 log.Printf("Scan 1") docScanResults := datautility.ExpectedScanResponse_float64(docs, "latitude", -13, 70, 1) scanResults, err := secondaryindex.Range(indexName, bucketName, indexScanAddress, []interface{}{-13}, []interface{}{70}, 1, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Scan 2 log.Printf("Scan 2") docScanResults = datautility.ExpectedScanResponse_float64(docs, "latitude", 4.112783, 4.112783, 3) scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{4.112783}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Scan 3 log.Printf("Scan 3") scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{20.563915 / 5}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Scan 4 log.Printf("Scan 4") scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{2.0563915 * 2}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Scan 5 log.Printf("Scan 5") docScanResults = datautility.ExpectedScanResponse_float64(docs, "latitude", 4.112783000, 4.112783000, 3) scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{4.112783000}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Scan 6 log.Printf("Scan 6") docScanResults = datautility.ExpectedScanResponse_float64(docs, "latitude", 4.112783333, 4.112783333, 3) scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{4.112783333}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
func TestFieldsWithSpecialCharacters(t *testing.T) { log.Printf("In TestFieldsWithSpecialCharacters()") var bucketName = "default" var indexName = "index_specialchar" var field = "splfield" docsToCreate := generateDocsWithSpecialCharacters(1000, "users.prod", field) UpdateKVDocs(docsToCreate, docs) var valueToLookup string for _, v := range docsToCreate { json := v.(map[string]interface{}) valueToLookup = json[field].(string) break } kvutility.SetKeyValues(docsToCreate, bucketName, "", clusterconfig.KVAddress) err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{field}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) log.Printf("Looking up for value %v", valueToLookup) docScanResults := datautility.ExpectedScanResponse_string(docs, field, valueToLookup, valueToLookup, 3) scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{valueToLookup}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
func TestCompositeIndex_NumAndString(t *testing.T) { log.Printf("In TestCompositeIndex()") var bucketName = "default" var indexName = "index_composite1" err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"age", "company"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) scanResults, err := secondaryindex.ScanAll(indexName, bucketName, indexScanAddress, defaultlimit, c.SessionConsistency, nil) if len(scanResults) != len(docs) { log.Printf("ScanAll of composite index is wrong. Expected and actual num of results: %d and %d", len(docs), len(scanResults)) e := errors.New("ScanAll of composite index is wrong") FailTestIfError(e, "Error in TestCompositeIndex", t) } scanResults, err = secondaryindex.Range(indexName, bucketName, indexScanAddress, []interface{}{25, "F"}, []interface{}{30, "M"}, 3, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) // todo: validate the results addDocIfNotPresentInKV("User22a44f1c-3f15-4ada-9cf5-6c24a7690a37") docScanResults := make(tc.ScanResponse) docScanResults["User22a44f1c-3f15-4ada-9cf5-6c24a7690a37"] = []interface{}{25.0, "ZIGGLES"} scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{25, "ZIGGLES"}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
func TestBasicArrayDataType_Lookup(t *testing.T) { log.Printf("In TestBasicArrayDataType_Lookup()") var indexName = "index_tags" var bucketName = "default" addDocIfNotPresentInKV("Usere46cea01-38f6-4e7b-92e5-69d64668ae75") time.Sleep(2 * time.Second) err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"tags"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) // Document has array: "reprehenderit", "tempor", "officia", "exercitation", "labore", "sunt", "tempor" arrayValue := []string{"reprehenderit", "tempor", "officia", "exercitation", "labore", "sunt", "tempor"} scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{arrayValue}, true, defaultlimit, c.SessionConsistency, nil) tc.PrintScanResults(scanResults, "scanResults") FailTestIfError(err, "Error in scan", t) if len(scanResults) != 1 { e := errors.New("Lookup should return exactly one result") FailTestIfError(e, "Error in array Lookup: ", t) } for k := range scanResults { if k != "Usere46cea01-38f6-4e7b-92e5-69d64668ae75" { e := errors.New("Lookup returned a wrong key") FailTestIfError(e, "Error in array Lookup: ", t) } } }
func TestLookupJsonObject(t *testing.T) { log.Printf("In TestLookupJsonObject()") var indexName = "index_streetaddress" var bucketName = "default" addDocIfNotPresentInKV("User3bf51f08-0bac-4c03-bcec-5c255cbdde2c") addDocIfNotPresentInKV("Userbb48952f-f8d1-4e04-a0e1-96b9019706fb") time.Sleep(2 * time.Second) err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"address.streetaddress"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) value := map[string]interface{}{ "doornumber": "12B", "floor": 5.0, "buildingname": "Sterling Heights", "streetname": "Hill Street"} docScanResults := datautility.ExpectedLookupResponse_json(docs, "address.streetaddress", value) scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{value}, true, defaultlimit, c.SessionConsistency, nil) tc.PrintScanResults(docScanResults, "docScanResults") tc.PrintScanResults(scanResults, "scanResults") FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
func SkipTestPerfLookupWithoutMutations_1M(t *testing.T) { log.Printf("In TestPerfQueryWithoutMutations_1M()") e := secondaryindex.DropAllSecondaryIndexes(indexManagementAddress) FailTestIfError(e, "Error in DropAllSecondaryIndexes", t) prodfile := "../../../../../prataprc/monster/prods/test.prod" bagdir := "../../../../../prataprc/monster/bags/" log.Printf("Generating JSON docs") count := 1000000 keyValues := GenerateJsons(count, 1, prodfile, bagdir) log.Printf("Setting JSON docs in KV") kv.SetKeyValues(keyValues, "default", "", clusterconfig.KVAddress) var indexName = "index_company" var bucketName = "default" log.Printf("Creating a 2i") err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"company"}, false, nil, true, 1500, nil) FailTestIfError(err, "Error in creating the index", t) start := time.Now() scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{"AQUACINE"}, true, defaultlimit, c.AnyConsistency, nil) elapsed := time.Since(start) log.Printf("Lookup:: Len of scanResults is: %d", len(scanResults)) log.Printf("Lookup of %d user documents took %s\n", count, elapsed) }
func TestUpdateMutations_DataTypeChange(t *testing.T) { log.Printf("In TestUpdateMutations_DataTypeChange()") var bucketName = "default" var indexName = "index_isUserActive" var field = "isActive" docsToCreate := generateDocs(1000, "users.prod") UpdateKVDocs(docsToCreate, docs) seed++ log.Printf("Setting JSON docs in KV") kvutility.SetKeyValues(docsToCreate, "default", "", clusterconfig.KVAddress) time.Sleep(2 * time.Second) err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{field}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) docScanResults := datautility.ExpectedScanAllResponse(docs, field) scanResults, err := secondaryindex.ScanAll(indexName, bucketName, indexScanAddress, defaultlimit, c.SessionConsistency, nil) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Create mutations with delete fields DataTypeChangeMutations_BoolToString(200, field) // Update documents by changing datatype of the indexed field docScanResults = datautility.ExpectedScanAllResponse(docs, field) scanResults, err = secondaryindex.ScanAll(indexName, bucketName, indexScanAddress, defaultlimit, c.SessionConsistency, nil) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) docScanResults = datautility.ExpectedScanResponse_string(docs, field, "true", "true", 3) scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{"true"}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) docScanResults = datautility.ExpectedScanResponse_string(docs, field, "false", "false", 3) scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{"false"}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
// After bucket delete:- // 1) query for old index before loading bucket // 2) query for old index after loading bucket // 3) create new indexes and query // 4) list indexes: should list only new indexes func TestBucketDefaultDelete(t *testing.T) { kvutility.DeleteBucket("default", "", clusterconfig.Username, clusterconfig.Password, kvaddress) time.Sleep(30 * time.Second) // Sleep after bucket create or delete kvutility.CreateBucket("default", "none", "", clusterconfig.Username, clusterconfig.Password, kvaddress, "256", "11212") time.Sleep(30 * time.Second) // Sleep after bucket create or delete tc.ClearMap(docs) tc.ClearMap(mut_docs) docs = datautility.LoadJSONFromCompressedFile(dataFilePath, "docid") mut_docs = datautility.LoadJSONFromCompressedFile(mutationFilePath, "docid") log.Printf("Populating the default bucket") kvutility.SetKeyValues(docs, "default", "", clusterconfig.KVAddress) time.Sleep(2 * time.Second) var indexName = "index_isActive" var bucketName = "default" scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{"BIOSPAN"}, true, defaultlimit, c.SessionConsistency, nil) if err == nil { log.Printf("Scan did not fail as expected. Got scanresults: %v\n", scanResults) e := errors.New("Scan did not fail as expected after bucket delete") FailTestIfError(e, "Error in TestBucketDefaultDelete", t) } else { log.Printf("Scan failed as expected with error: %v", err) } log.Printf("Populating the default bucket after it was deleted") kvutility.SetKeyValues(docs, "default", "", clusterconfig.KVAddress) err = secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"company"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) docScanResults := datautility.ExpectedScanResponse_string(docs, "company", "BIOSPAN", "BIOSPAN", 3) scanResults, err = secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{"BIOSPAN"}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // todo: list the index and confirm there is only index created }
func TestBasicLookup(t *testing.T) { log.Printf("In TestBasicLookup()") var indexName = "index_company" var bucketName = "default" err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"company"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) docScanResults := datautility.ExpectedScanResponse_string(docs, "company", "BIOSPAN", "BIOSPAN", 3) scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{"BIOSPAN"}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
func TestBasicNullDataType(t *testing.T) { log.Printf("In TestBasicNullDataType()") var indexName = "index_email" var bucketName = "default" err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"email"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) docScanResults := datautility.ExpectedLookupResponse_nil(docs, "email") scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{nil}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) // Scan all should include null : todo }
func TestArrayDataType_LookupWrongOrder(t *testing.T) { log.Printf("In TestArrayDataType_LookupWrongOrder()") var indexName = "index_tags" var bucketName = "default" err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"tags"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) // Document has array: "reprehenderit", "tempor", "officia", "exercitation", "labore", "sunt", "tempor" arrayValue := []string{"reprehenderit", "tempor", "officia", "labore", "sunt", "tempor", "exercitation"} // Re-ordered the array elements scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{arrayValue}, true, defaultlimit, c.SessionConsistency, nil) tc.PrintScanResults(scanResults, "scanResults") FailTestIfError(err, "Error in scan", t) if len(scanResults) != 0 { e := errors.New("Lookup should not return any doc key as array was looked up in wrong order") FailTestIfError(e, "Error in array Lookup", t) } }
func TestLookupObjDifferentOrdering(t *testing.T) { log.Printf("In TestLookupObjDifferentOrdering()") var indexName = "index_streetaddress" var bucketName = "default" err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"address.streetaddress"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) value := map[string]interface{}{ "floor": 5.0, "streetname": "Hill Street", "buildingname": "Sterling Heights", "doornumber": "12B"} docScanResults := datautility.ExpectedLookupResponse_json(docs, "address.streetaddress", value) scanResults, err := secondaryindex.Lookup(indexName, bucketName, indexScanAddress, []interface{}{value}, true, defaultlimit, c.SessionConsistency, nil) tc.PrintScanResults(docScanResults, "docScanResults") tc.PrintScanResults(scanResults, "scanResults") FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }
func TestMultipleIndexCreatesDropsWithMutations(t *testing.T) { log.Printf("In TestThreeIndexCreates()") var i1 = "index_state" var i2 = "index_registered" var i3 = "index_gender" var i4 = "index_longitude" var bucketName = "default" //Testcase Flow // Create i1, create mutations, scan i1 // Create i2, create mutations, scan i2 // Create i3, create mutations, scan i3 // Drop i2, create/delete mutations, scan i1 // Create i4, create mutations, scan i4 e := secondaryindex.CreateSecondaryIndex(i1, bucketName, indexManagementAddress, "", []string{"address.street"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(e, "Error in creating the index", t) //Create docs mutations: Add new docs to KV log.Printf("Create docs mutations") CreateDocs(100) docScanResults := datautility.ExpectedScanResponse_string(docs, "address.street", "F", "X", 2) scanResults, err := secondaryindex.Range(i1, bucketName, indexScanAddress, []interface{}{"F"}, []interface{}{"X"}, 2, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) err = secondaryindex.CreateSecondaryIndex(i2, bucketName, indexManagementAddress, "", []string{"registered"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) //Create docs mutations: Add new docs to KV log.Printf("Create docs mutations") CreateDocs(100) docScanResults = datautility.ExpectedScanResponse_string(docs, "registered", "2014-01", "2014-09", 1) scanResults, err = secondaryindex.Range(i2, bucketName, indexScanAddress, []interface{}{"2014-01"}, []interface{}{"2014-09"}, 1, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) err = secondaryindex.CreateSecondaryIndex(i3, bucketName, indexManagementAddress, "", []string{"gender"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) //Create docs mutations: Add new docs to KV log.Printf("Create docs mutations") CreateDocs(100) docScanResults = datautility.ExpectedScanResponse_string(docs, "gender", "male", "male", 3) scanResults, err = secondaryindex.Lookup(i3, bucketName, indexScanAddress, []interface{}{"male"}, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) err = secondaryindex.DropSecondaryIndex(i2, bucketName, indexManagementAddress) FailTestIfError(err, "Error dropping index", t) //Create docs mutations: Add new docs to KV log.Printf("Create docs mutations") CreateDocs(100) //Delete docs mutations: Delete docs from KV log.Printf("Delete docs mutations") DeleteDocs(150) docScanResults = datautility.ExpectedScanResponse_string(docs, "address.street", "F", "X", 2) scanResults, err = secondaryindex.Range(i1, bucketName, indexScanAddress, []interface{}{"F"}, []interface{}{"X"}, 2, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) err = secondaryindex.CreateSecondaryIndex(i4, bucketName, indexManagementAddress, "", []string{"longitude"}, false, nil, true, defaultIndexActiveTimeout, nil) FailTestIfError(err, "Error in creating the index", t) //Create docs mutations: Add new docs to KV log.Printf("Create docs mutations") CreateDocs(100) docScanResults = datautility.ExpectedScanResponse_float64(docs, "longitude", -50, 200, 3) scanResults, err = secondaryindex.Range(i4, bucketName, indexScanAddress, []interface{}{-50}, []interface{}{200}, 3, true, defaultlimit, c.SessionConsistency, nil) FailTestIfError(err, "Error in scan", t) err = tv.Validate(docScanResults, scanResults) FailTestIfError(err, "Error in scan result validation", t) }