func TestFullScanVector(t *testing.T) { jsonText := "[FULL_SCAN_VECTOR]" fullScanElement := "[777777, \"VUUID\"]," replacement := strings.TrimRight(strings.Repeat(fullScanElement, 1024), ",") jsonText = strings.Replace(jsonText, "FULL_SCAN_VECTOR", replacement, 1) decoder := json.NewDecoder(strings.NewReader(jsonText)) var target interface{} e := decoder.Decode(&target) if e != nil { t.Errorf("Unexpected JSON parsing error %v", e) } var vector timestamp.Vector vector, err := getScanVectorFromJSON(target) if err != nil { t.Errorf("Unexpected error %v", err) } entries := vector.Entries() if len(entries) != 1024 { t.Errorf("Expected entries lenth 1024, actual %d", len(entries)) } for i, entry := range entries { verifyEntry(t, entry, uint32(i), "VUUID", 777777) } }
func vector2ts(vector timestamp.Vector) *qclient.TsConsistency { if vector == nil { return nil } vbnos := make([]uint16, 0, 1024) seqnos := make([]uint64, 0, 1024) vbuuids := make([]uint64, 0, 1024) for _, entry := range vector.Entries() { vbnos = append(vbnos, uint16(entry.Position())) seqnos = append(seqnos, uint64(entry.Value())) vbuuids = append(vbuuids, uint64(guard2Vbuuid(entry.Guard()))) } return qclient.NewTsConsistency(vbnos, seqnos, vbuuids) }
func TestSparseScanVector(t *testing.T) { jsonText := `{ "3": [ 345, "AAUID" ], "5": [ 100001, "BAUID" ], "7": [ 999999, "CAUID" ] }` var target interface{} decoder := json.NewDecoder(strings.NewReader(jsonText)) e := decoder.Decode(&target) if e != nil { t.Errorf("Unexpected error %v", e) } var actual timestamp.Vector // Verify expected return type. actual, err := getScanVectorFromJSON(target) if err != nil { t.Errorf("expected %v, actual %v", nil, err) } // Results may appear in any order in entry array. if len(actual.Entries()) != 3 { t.Errorf("expected length 3, actual %d", len(actual.Entries())) } for _, entry := range actual.Entries() { switch entry.Position() { case 3: verifyEntry(t, entry, 3, "AAUID", 345) case 5: verifyEntry(t, entry, 5, "BAUID", 100001) case 7: verifyEntry(t, entry, 7, "CAUID", 999999) default: t.Errorf("Unexpected position %d", entry.Position()) } } }