func TestNewScan(t *testing.T) { ctx := context.Background() table := "test" tableb := []byte(table) fam := make(map[string][]string) fam["info"] = []string{"c1"} filter1 := filter.NewFirstKeyOnlyFilter() start := "0" stop := "100" startb := []byte("0") stopb := []byte("100") scan, err := hrpc.NewScan(ctx, tableb) if err != nil || !confirmScanAttributes(scan, ctx, tableb, nil, nil, nil, nil) { t.Errorf("Scan1 didn't set attributes correctly.") } scan, err = hrpc.NewScanRange(ctx, tableb, startb, stopb) if err != nil || !confirmScanAttributes(scan, ctx, tableb, startb, stopb, nil, nil) { t.Errorf("Scan2 didn't set attributes correctly.") } scan, err = hrpc.NewScanStr(ctx, table) if err != nil || !confirmScanAttributes(scan, ctx, tableb, nil, nil, nil, nil) { t.Errorf("Scan3 didn't set attributes correctly.") } scan, err = hrpc.NewScanRangeStr(ctx, table, start, stop) if err != nil || !confirmScanAttributes(scan, ctx, tableb, startb, stopb, nil, nil) { t.Errorf("Scan4 didn't set attributes correctly.") } scan, err = hrpc.NewScanRange(ctx, tableb, startb, stopb, hrpc.Families(fam), hrpc.Filters(filter1)) if err != nil || !confirmScanAttributes(scan, ctx, tableb, startb, stopb, fam, filter1) { t.Errorf("Scan5 didn't set attributes correctly.") } scan, err = hrpc.NewScan(ctx, tableb, hrpc.Filters(filter1), hrpc.Families(fam)) if err != nil || !confirmScanAttributes(scan, ctx, tableb, nil, nil, fam, filter1) { t.Errorf("Scan6 didn't set attributes correctly.") } }
func TestScanTimeRangeVersions(t *testing.T) { key := "TestScanTimeRangeVersions" c := gohbase.NewClient(*host) err := insertKeyValue(c, key+"1", "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 50*1e6))) if err != nil { t.Fatalf("Put failed: %s", err) } err = insertKeyValue(c, key+"1", "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 51*1e6))) if err != nil { t.Fatalf("Put failed: %s", err) } err = insertKeyValue(c, key+"2", "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 51*1e6))) if err != nil { t.Fatalf("Put failed: %s", err) } err = insertKeyValue(c, key+"2", "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 52*1e6))) if err != nil { t.Fatalf("Put failed: %s", err) } var maxVersions uint32 = 2 scan, err := hrpc.NewScanRangeStr(context.Background(), table, "TestScanTimeRangeVersions1", "TestScanTimeRangeVersions3", hrpc.Families(map[string][]string{"cf": nil}), hrpc.TimeRange(time.Unix(0, 50*1e6), time.Unix(0, 53*1e6)), hrpc.MaxVersions(maxVersions)) if err != nil { t.Fatalf("Scan req failed: %s", err) } rsp, err := c.Scan(scan) if err != nil { t.Fatalf("Scan failed: %s", err) } if len(rsp) != 2 { t.Fatalf("Expected rows: %d, Got rows: %d", maxVersions, len(rsp)) } if uint32(len(rsp[0].Cells)) != maxVersions { t.Fatalf("Expected versions: %d, Got versions: %d", maxVersions, len(rsp[0].Cells)) } scan1 := *rsp[0].Cells[0] if string(scan1.Row) != "TestScanTimeRangeVersions1" && *scan1.Timestamp != 51 { t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v", 51, *scan1.Timestamp) } scan2 := *rsp[0].Cells[1] if string(scan2.Row) != "TestScanTimeRangeVersions1" && *scan2.Timestamp != 50 { t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v", 50, *scan2.Timestamp) } if uint32(len(rsp[1].Cells)) != maxVersions { t.Fatalf("Expected versions: %d, Got versions: %d", maxVersions, len(rsp[1].Cells)) } scan3 := *rsp[1].Cells[0] if string(scan3.Row) != "TestScanTimeRangeVersions2" && *scan3.Timestamp != 52 { t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v", 52, *scan3.Timestamp) } scan4 := *rsp[1].Cells[1] if string(scan4.Row) != "TestScanTimeRangeVersions2" && *scan4.Timestamp != 51 { t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v", 51, *scan4.Timestamp) } // scan with no versions set scan, err = hrpc.NewScanRangeStr(context.Background(), table, "TestScanTimeRangeVersions1", "TestScanTimeRangeVersions3", hrpc.Families(map[string][]string{"cf": nil}), hrpc.TimeRange(time.Unix(0, 50*1e6), time.Unix(0, 53*1e6))) if err != nil { t.Fatalf("Scan req failed: %s", err) } rsp, err = c.Scan(scan) if err != nil { t.Fatalf("Scan failed: %s", err) } if len(rsp) != 2 { t.Fatalf("Expected rows: %d, Got rows: %d", 2, len(rsp)) } if len(rsp[0].Cells) != 1 { t.Fatalf("Expected versions: %d, Got versions: %d", 2, len(rsp[0].Cells)) } if len(rsp[1].Cells) != 1 { t.Fatalf("Expected versions: %d, Got versions: %d", 2, len(rsp[0].Cells)) } }