func TestCreateTable(t *testing.T) { testTableName := "test1_" + getTimestampString() t.Log("testTableName=" + testTableName) ac := gohbase.NewAdminClient(*host) crt := hrpc.NewCreateTable(context.Background(), []byte(testTableName), cFamilies) if err := ac.CreateTable(crt); err != nil { t.Errorf("CreateTable returned an error: %v", err) } // check in hbase:meta if there's a region for the table c := gohbase.NewClient(*host) metaKey := testTableName + ",," keyFilter := filter.NewPrefixFilter([]byte(metaKey)) scan, err := hrpc.NewScanStr(context.Background(), metaTableName, hrpc.Filters(keyFilter)) if err != nil { t.Fatalf("Failed to create Scan request: %s", err) } rsp, err := c.Scan(scan) if err != nil { t.Errorf("Scan returned an error: %v", err) } if len(rsp) != 1 { t.Errorf("Meta returned %s rows for prefix '%s' , want 1", len(rsp), metaKey) } }
func TestEnableTable(t *testing.T) { testTableName := "test1_" + getTimestampString() t.Log("testTableName=" + testTableName) ac := gohbase.NewAdminClient(*host) crt := hrpc.NewCreateTable(context.Background(), []byte(testTableName), cFamilies) if err := ac.CreateTable(crt); err != nil { t.Errorf("CreateTable returned an error: %v", err) } // disable dit := hrpc.NewDisableTable(context.Background(), []byte(testTableName)) err := ac.DisableTable(dit) if err != nil { t.Errorf("DisableTable returned an error: %v", err) } et := hrpc.NewEnableTable(context.Background(), []byte(testTableName)) err = ac.EnableTable(et) if err != nil { t.Errorf("EnableTable returned an error: %v", err) } delt := hrpc.NewDeleteTable(context.Background(), []byte(testTableName)) err = ac.DeleteTable(delt) if err == nil || !strings.Contains(err.Error(), "TableNotDisabledException") { t.Errorf("DeleteTable should error with TableNotDisabledException, got %s", err) } }
// CreateTable creates the given table with the given families func CreateTable(client gohbase.AdminClient, table string, cFamilies []string) error { // If the table exists, delete it DeleteTable(client, table) // Don't check the error, since one will be returned if the table doesn't // exist cf := make(map[string]map[string]string, len(cFamilies)) for _, f := range cFamilies { cf[f] = nil } ct := hrpc.NewCreateTable(context.Background(), []byte(table), cf) if err := client.CreateTable(ct); err != nil { return err } return nil }