File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,21 @@ func (p *PartitionManager) ReadAndUpdateSchema() (err error) {
267
267
return
268
268
}
269
269
270
+ func unmarshalSchema (data []byte ) (* config.Schema , error ) {
271
+ schemaInstance := & config.Schema {}
272
+ err := json .Unmarshal (data , schemaInstance )
273
+ if err != nil {
274
+ return nil , err
275
+ }
276
+ if schemaInstance .TableSchemaInfo .PartitionerInterval == "" {
277
+ return nil , errors .New ("Schema partition interval may not be empty" )
278
+ }
279
+ if schemaInstance .TableSchemaInfo .ChunckerInterval == "" {
280
+ return nil , errors .New ("Schema chunk interval may not be empty" )
281
+ }
282
+ return schemaInstance , nil
283
+ }
284
+
270
285
func (p * PartitionManager ) updatePartitionsFromSchema (schema * config.Schema ) error {
271
286
if schema == nil {
272
287
schemaFilePath := p .GetSchemaFilePath ()
@@ -275,8 +290,7 @@ func (p *PartitionManager) updatePartitionsFromSchema(schema *config.Schema) err
275
290
return errors .Wrapf (innerError , "Failed to read schema at path '%s'." , schemaFilePath )
276
291
}
277
292
278
- schema = & config.Schema {}
279
- innerError = json .Unmarshal (resp .Body (), schema )
293
+ schema , innerError = unmarshalSchema (resp .Body ())
280
294
if innerError != nil {
281
295
return errors .Wrapf (innerError , "Failed to unmarshal schema at path '%s'." , schemaFilePath )
282
296
}
Original file line number Diff line number Diff line change @@ -96,6 +96,20 @@ func TestNewPartitionMngrBadInput(t *testing.T) {
96
96
assert .Error (t , err )
97
97
}
98
98
99
+ func TestUnmarshalSchemaError (t * testing.T ) {
100
+ schemaString := []byte (`{}` )
101
+ _ , err := unmarshalSchema (schemaString )
102
+ assert .Error (t , err )
103
+
104
+ schemaString = []byte (`{"tableSchemaInfo": {}}` )
105
+ _ , err = unmarshalSchema (schemaString )
106
+ assert .Error (t , err )
107
+
108
+ schemaString = []byte (`{"tableSchemaInfo": {"PartitionerInterval": ""}}` )
109
+ _ , err = unmarshalSchema (schemaString )
110
+ assert .Error (t , err )
111
+ }
112
+
99
113
func TestPartsForRange (tst * testing.T ) {
100
114
numPartitions := 5
101
115
manager := getPartitionManager (tst )
You can’t perform that action at this time.
0 commit comments