MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / assertNumSGIndexPartitions

Function assertNumSGIndexPartitions

rest/indextest/index_init_api_test.go:195–219  ·  view source on GitHub ↗

requireNumSGIndexPartitions ensures that the number of partitions for SG indexes is as expected. Some indexes aren't partitioned.

(t testing.TB, database *db.DatabaseContext)

Source from the content-addressed store, hash-verified

193
194// requireNumSGIndexPartitions ensures that the number of partitions for SG indexes is as expected. Some indexes aren't partitioned.
195func assertNumSGIndexPartitions(t testing.TB, database *db.DatabaseContext) {
196 gocbBucket, err := base.AsGocbV2Bucket(database.Bucket)
197 require.NoError(t, err)
198 re := regexp.MustCompile(`sg_(?:allDocs|channels)_x1(?:_p(\d+))?$`)
199 for _, dsName := range []sgbucket.DataStoreName{db.GetSingleDatabaseCollection(t, database).GetCollectionDatastore(), database.MetadataStore} {
200 allIndexes, err := gocbBucket.GetCluster().Bucket(gocbBucket.BucketName()).Scope(dsName.ScopeName()).Collection(dsName.CollectionName()).QueryIndexes().GetAllIndexes(nil)
201 require.NoError(t, err)
202 require.Greaterf(t, len(allIndexes), 0, "expected at least one index for datastore %s", dsName)
203 for _, index := range allIndexes {
204 // only two SG indexes are partitioned currently
205 partitionsFromNameStrs := re.FindStringSubmatch(index.Name)
206 if len(partitionsFromNameStrs) > 1 && partitionsFromNameStrs[1] != "" {
207 expectedPartitionsFromName, err := strconv.ParseInt(partitionsFromNameStrs[1], 10, 64)
208 require.NoError(t, err)
209 require.Greaterf(t, int(expectedPartitionsFromName), 1, "expected at least one partition for %s", index.Name)
210 assert.NotEqualf(t, "", index.Partition, "expected partition clause for %s", index.Name)
211 assert.Equal(t, int(expectedPartitionsFromName), int(db.GetIndexPartitionCount(t, gocbBucket, dsName, index.Name)))
212 } else {
213 assert.Equal(t, "", index.Partition)
214 assert.True(t, strings.HasSuffix(index.Name, "_x1"), "expected no partitions for %+v", index)
215 assert.Equal(t, 1, int(db.GetIndexPartitionCount(t, gocbBucket, dsName, index.Name)))
216 }
217 }
218 }
219}
220
221func TestChangeIndexPartitionsErrors(t *testing.T) {
222 tests := []struct {

Callers 1

Calls 12

AsGocbV2BucketFunction · 0.92
GetIndexPartitionCountFunction · 0.92
GetAllIndexesMethod · 0.80
BucketMethod · 0.80
GetClusterMethod · 0.80
BucketNameMethod · 0.65
CollectionMethod · 0.45
ScopeNameMethod · 0.45
CollectionNameMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected