github.com/weaviate/weaviate@v1.24.6/usecases/sharding/config_update_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package sharding
    13  
    14  import (
    15  	"fmt"
    16  	"testing"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  	"github.com/stretchr/testify/require"
    20  )
    21  
    22  func TestConfigUpdates(t *testing.T) {
    23  	t.Run("various immutable and mutable fields", func(t *testing.T) {
    24  		type test struct {
    25  			name          string
    26  			initial       Config
    27  			update        Config
    28  			expectedError error
    29  		}
    30  
    31  		tests := []test{
    32  			{
    33  				name:    "attempting to shard count",
    34  				initial: Config{DesiredCount: 7},
    35  				update:  Config{DesiredCount: 8},
    36  				expectedError: fmt.Errorf(
    37  					"re-sharding not supported yet: shard count is immutable: " +
    38  						"attempted change from \"7\" to \"8\""),
    39  			},
    40  			{
    41  				name:    "attempting to shard count",
    42  				initial: Config{VirtualPerPhysical: 128},
    43  				update:  Config{VirtualPerPhysical: 256},
    44  				expectedError: fmt.Errorf(
    45  					"virtual shards per physical is immutable: " +
    46  						"attempted change from \"128\" to \"256\""),
    47  			},
    48  		}
    49  
    50  		for _, test := range tests {
    51  			t.Run(test.name, func(t *testing.T) {
    52  				err := ValidateConfigUpdate(test.initial, test.update, &fakeNodeCounter{3})
    53  				if test.expectedError == nil {
    54  					assert.Nil(t, err)
    55  				} else {
    56  					require.NotNil(t, err, "update validation must error")
    57  					assert.Equal(t, test.expectedError.Error(), err.Error())
    58  				}
    59  			})
    60  		}
    61  	})
    62  }
    63  
    64  type fakeNodeCounter struct{ count int }
    65  
    66  func (f *fakeNodeCounter) NodeCount() int {
    67  	return f.count
    68  }