@@ -2064,6 +2064,217 @@ func TestIntegration_AutomatedBackups(t *testing.T) {
20642064 }
20652065}
20662066
2067+ func TestIntegration_CreateTableWithRowKeySchema (t * testing.T ) {
2068+ testEnv , err := NewIntegrationEnv ()
2069+ if err != nil {
2070+ t .Fatalf ("IntegrationEnv: %v" , err )
2071+ }
2072+ defer testEnv .Close ()
2073+
2074+ if ! testEnv .Config ().UseProd {
2075+ t .Skip ("emulator doesn't support Automated Backups" )
2076+ }
2077+
2078+ timeout := 5 * time .Minute
2079+ ctx , cancel := context .WithTimeout (context .Background (), timeout )
2080+ defer cancel ()
2081+
2082+ adminClient , err := testEnv .NewAdminClient ()
2083+ if err != nil {
2084+ t .Fatalf ("NewAdminClient: %v" , err )
2085+ }
2086+ defer adminClient .Close ()
2087+
2088+ myTableName := myTableNameSpace .New ()
2089+ tableConf := TableConf {
2090+ TableID : myTableName ,
2091+ Families : map [string ]GCPolicy {
2092+ "fam1" : MaxVersionsPolicy (1 ),
2093+ "fam2" : MaxVersionsPolicy (2 ),
2094+ },
2095+ }
2096+
2097+ testCases := []struct {
2098+ desc string
2099+ rks StructType
2100+ errorExpected bool
2101+ }{
2102+ {
2103+ desc : "Create fail with conflict family and row key column" ,
2104+ rks : StructType {
2105+ Fields : []StructField {{FieldName : "fam1" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}}},
2106+ Encoding : StructOrderedCodeBytesEncoding {},
2107+ },
2108+ errorExpected : true ,
2109+ },
2110+ {
2111+ desc : "Create fail with missing encoding in struct type" ,
2112+ rks : StructType {
2113+ Fields : []StructField {{FieldName : "myfield" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}}},
2114+ },
2115+ errorExpected : true ,
2116+ },
2117+ {
2118+ desc : "Create fail on DelimitedBytes missing delimiter" ,
2119+ rks : StructType {
2120+ Fields : []StructField {{FieldName : "myfield" , FieldType : StringType {Encoding : StringUtf8BytesEncoding {}}}},
2121+ Encoding : StructDelimitedBytesEncoding {},
2122+ },
2123+ errorExpected : true ,
2124+ },
2125+ {
2126+ desc : "Create with Singleton failed with more than 1 field" ,
2127+ rks : StructType {
2128+ Fields : []StructField {
2129+ {FieldName : "myfield1" , FieldType : StringType {Encoding : StringUtf8BytesEncoding {}}},
2130+ {FieldName : "myfield2" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}},
2131+ },
2132+ Encoding : StructSingletonEncoding {},
2133+ },
2134+ errorExpected : true ,
2135+ },
2136+ {
2137+ desc : "Create with Singleton ok" ,
2138+ rks : StructType {
2139+ Fields : []StructField {
2140+ {FieldName : "myfield1" , FieldType : StringType {Encoding : StringUtf8BytesEncoding {}}},
2141+ },
2142+ Encoding : StructSingletonEncoding {},
2143+ },
2144+ },
2145+ {
2146+ desc : "Create with OrderedCode ok" ,
2147+ rks : StructType {
2148+ Fields : []StructField {
2149+ {FieldName : "myfield1" , FieldType : StringType {Encoding : StringUtf8BytesEncoding {}}},
2150+ {FieldName : "myfield2" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}},
2151+ },
2152+ Encoding : StructOrderedCodeBytesEncoding {},
2153+ },
2154+ },
2155+ {
2156+ desc : "Create with DelimitedBytes ok" ,
2157+ rks : StructType {
2158+ Fields : []StructField {
2159+ {FieldName : "myfield1" , FieldType : StringType {Encoding : StringUtf8BytesEncoding {}}},
2160+ {FieldName : "myfield2" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}},
2161+ },
2162+ Encoding : StructDelimitedBytesEncoding {
2163+ Delimiter : []byte {'#' },
2164+ },
2165+ },
2166+ },
2167+ }
2168+
2169+ for _ , tc := range testCases {
2170+ tableConf .RowKeySchema = & tc .rks
2171+ err := adminClient .CreateTableFromConf (ctx , & tableConf )
2172+
2173+ if tc .errorExpected && err == nil {
2174+ t .Errorf ("Want error from test: '%v', got nil" , tc .desc )
2175+ }
2176+
2177+ if ! tc .errorExpected && err != nil {
2178+ t .Errorf ("Unexpected error: %v" , err )
2179+ }
2180+
2181+ // get the table and see the new schema is updated
2182+ tbl , err := adminClient .getTable (ctx , tableConf .TableID , btapb .Table_SCHEMA_VIEW )
2183+ if ! tc .errorExpected && tbl .RowKeySchema == nil {
2184+ t .Errorf ("Expecting row key schema %v to be updated in table, got: %v" , tc .rks , tbl )
2185+ }
2186+
2187+ if tbl != nil {
2188+ // clean up table
2189+ err = adminClient .DeleteTable (ctx , tableConf .TableID )
2190+ if err != nil {
2191+ t .Fatalf ("Unexpected error trying to clean up table: %v" , err )
2192+ }
2193+ }
2194+ }
2195+ }
2196+
2197+ func TestIntegration_UpdateRowKeySchemaInTable (t * testing.T ) {
2198+ testEnv , err := NewIntegrationEnv ()
2199+ if err != nil {
2200+ t .Fatalf ("IntegrationEnv: %v" , err )
2201+ }
2202+ defer testEnv .Close ()
2203+
2204+ if ! testEnv .Config ().UseProd {
2205+ t .Skip ("emulator doesn't support Automated Backups" )
2206+ }
2207+
2208+ timeout := 5 * time .Minute
2209+ ctx , cancel := context .WithTimeout (context .Background (), timeout )
2210+ defer cancel ()
2211+
2212+ adminClient , err := testEnv .NewAdminClient ()
2213+ if err != nil {
2214+ t .Fatalf ("NewAdminClient: %v" , err )
2215+ }
2216+ defer adminClient .Close ()
2217+
2218+ myTableName := myTableNameSpace .New ()
2219+ tableConf := TableConf {
2220+ TableID : myTableName ,
2221+ Families : map [string ]GCPolicy {
2222+ "fam1" : MaxVersionsPolicy (1 ),
2223+ },
2224+ }
2225+
2226+ if err := adminClient .CreateTableFromConf (ctx , & tableConf ); err != nil {
2227+ t .Fatalf ("Unexpected error trying to create table: %v" , err )
2228+ }
2229+
2230+ testCases := []struct {
2231+ desc string
2232+ rks StructType
2233+ errorExpected bool
2234+ }{
2235+ {desc : "Update fail with conflicting family name" ,
2236+ rks : StructType {
2237+ Fields : []StructField {{FieldName : "fam1" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}}},
2238+ Encoding : StructSingletonEncoding {},
2239+ },
2240+ errorExpected : true ,
2241+ },
2242+ {
2243+ desc : "Update ok" ,
2244+ rks : StructType {
2245+ Fields : []StructField {
2246+ {FieldName : "myfield" , FieldType : Int64Type {Encoding : BigEndianBytesEncoding {}}},
2247+ {FieldName : "myfield2" , FieldType : StringType {Encoding : StringUtf8BytesEncoding {}}}},
2248+ Encoding : StructDelimitedBytesEncoding {
2249+ Delimiter : []byte {'#' },
2250+ },
2251+ },
2252+ },
2253+ }
2254+
2255+ for _ , tc := range testCases {
2256+ err := adminClient .UpdateTableWithRowKeySchema (ctx , tableConf .TableID , tc .rks )
2257+ if tc .errorExpected && err == nil {
2258+ t .Errorf ("Expecting error from test '%v', got nil" , tc .desc )
2259+ }
2260+
2261+ if ! tc .errorExpected && err != nil {
2262+ t .Errorf ("Unexpected error from test '%v': %v" , tc .desc , err )
2263+ }
2264+
2265+ // Get the table to check if the schema is updated
2266+ tbl , err := adminClient .getTable (ctx , tableConf .TableID , btapb .Table_SCHEMA_VIEW )
2267+ if ! tc .errorExpected && tbl .RowKeySchema == nil {
2268+ t .Errorf ("Expecting row key schema %v to be updated in table, got: %v" , tc .rks , tbl )
2269+ }
2270+
2271+ // Clear schema ok
2272+ if err = adminClient .UpdateTableRemoveRowKeySchema (ctx , tableConf .TableID ); err != nil {
2273+ t .Errorf ("Unexpected error trying to clear row key schema: %v" , err )
2274+ }
2275+ }
2276+ }
2277+
20672278func TestIntegration_Admin (t * testing.T ) {
20682279 testEnv , err := NewIntegrationEnv ()
20692280 if err != nil {
0 commit comments