Exemple #1
0
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)
}
Exemple #2
0
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)
		}
	}
}
Exemple #3
0
func Validate(expectedResponse, actualResponse tc.ScanResponse) error {
	if len(expectedResponse) != len(actualResponse) {
		errorStr := fmt.Sprintf("Expected scan count %d does not match actual scan count %d", len(expectedResponse), len(actualResponse))
		log.Printf("%v", errorStr)
		e := errors.New(errorStr)
		return e
	}
	eq := reflect.DeepEqual(expectedResponse, actualResponse)
	if eq {
		log.Printf("Expected and Actual scan responses are the same")
	} else {
		log.Printf("Expected and Actual scan responses below are different")
		tc.PrintScanResults(expectedResponse, "expectedResponse")
		tc.PrintScanResults(actualResponse, "actualResponse")
		time.Sleep(5 * time.Second)
		e := errors.New("Expected and Actual scan responses are different")
		return e
	}
	return nil
}
Exemple #4
0
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)
}
Exemple #5
0
func TestRangeJsonObject(t *testing.T) {
	log.Printf("In TestRangeJsonObject()")
	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)

	low := map[string]interface{}{
		"floor":        1.0,
		"streetname":   "AAA",
		"buildingname": "AA",
		"doornumber":   "AAAA"}
	high := map[string]interface{}{
		"floor":        9.0,
		"streetname":   "zzz",
		"buildingname": "zz",
		"doornumber":   "zzzz"}

	value1 := map[string]interface{}{
		"floor":        5.0,
		"streetname":   "Hill Street",
		"buildingname": "Sterling Heights",
		"doornumber":   "12B"}
	value2 := map[string]interface{}{
		"floor":        2.0,
		"streetname":   "Karweg Place",
		"buildingname": "Rosewood Gardens",
		"doornumber":   "514"}
	docScanResults := make(tc.ScanResponse)
	docScanResults["User3bf51f08-0bac-4c03-bcec-5c255cbdde2c"] = []interface{}{value1}
	docScanResults["Userbb48952f-f8d1-4e04-a0e1-96b9019706fb"] = []interface{}{value2}
	scanResults, err := secondaryindex.Range(indexName, bucketName, indexScanAddress, []interface{}{low}, []interface{}{high}, 3, true, defaultlimit, c.SessionConsistency, nil)
	tc.PrintScanResults(scanResults, "scanResults")
	tc.PrintScanResults(docScanResults, "docScanResults")
	FailTestIfError(err, "Error in scan", t)
	err = tv.Validate(docScanResults, scanResults)
	FailTestIfError(err, "Error in scan result validation", t)
}
Exemple #6
0
func SkipTestScanDistinctParameter(t *testing.T) {
	log.Printf("In TestScanDistinctParameter()")
	var indexName = "index_age"
	var bucketName = "default"

	err := secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"age"}, false, nil, true, defaultIndexActiveTimeout, nil)
	FailTestIfError(err, "Error in creating the index", t)

	// var limit int
	// limit = 10
	scanResults, err := secondaryindex.Range(indexName, bucketName, indexScanAddress, []interface{}{35}, []interface{}{40}, 1, true, defaultlimit, c.SessionConsistency, nil)
	tc.PrintScanResults(scanResults, "scanResults")
	FailTestIfError(err, "Error in scan", t)
	// Todo: Verify the results in scanresults
}
Exemple #7
0
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)
	}
}