Add files using upload-large-folder tool
Browse files- platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/dataset_corpus.go +107 -0
- platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/dataset_queries.go +92 -0
- platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/datasets.go +56 -0
- platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/durations.go +60 -0
- platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/schema.go +102 -0
- platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/scores.go +71 -0
- platform/dbops/binaries/weaviate-src/test/docker/mockoidc/Dockerfile +10 -0
- platform/dbops/binaries/weaviate-src/test/docker/mockoidc/mockoidc.go +118 -0
- platform/dbops/binaries/weaviate-src/test/docker/mockoidchelper/Dockerfile +9 -0
- platform/dbops/binaries/weaviate-src/test/docker/mockoidchelper/mockoidc_helper.go +221 -0
- platform/dbops/binaries/weaviate-src/test/helper/graphql/graphql_helper.go +167 -0
- platform/dbops/binaries/weaviate-src/test/helper/grpc/grpc_helper.go +83 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/backup_and_restore_journey.go +260 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/backup_journey.go +397 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/backup_journey_tests.go +81 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/cancel_from_restart_journey.go +85 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/cluster_backup_journey.go +138 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/group_by_journey_tests.go +197 -0
- platform/dbops/binaries/weaviate-src/test/helper/journey/single_node_backup_override_journey.go +94 -0
- platform/dbops/binaries/weaviate-src/test/helper/modules/modules_helper.go +192 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/articles/articles.go +127 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/books/books.go +383 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/cities/cities.go +451 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/companies/companies.go +265 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/documents/documents.go +202 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/data.csv +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/images/1.jpg +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/images/2.jpg +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/videos/1.mp4 +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/videos/2.mp4 +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/multimodal.go +245 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multishard/multishard.go +92 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/planets/data/images/earth.jpg +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/planets/data/images/mars.jpg +3 -0
- platform/dbops/binaries/weaviate-src/test/helper/sample-schema/planets/planets.go +280 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-azure/backup_backend_test.go +307 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-azure/backup_journey_test.go +89 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-azure/multi_tenant_backup_test.go +84 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-filesystem/backup_backend_test.go +214 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-filesystem/backup_journey_test.go +81 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-filesystem/multi_tenant_backup_test.go +82 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-gcs/backup_backend_test.go +273 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-gcs/backup_journey_test.go +110 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-gcs/multi_tenant_backup_test.go +117 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-s3/backup_backend_test.go +262 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-s3/backup_journey_test.go +82 -0
- platform/dbops/binaries/weaviate-src/test/modules/backup-s3/multi_tenant_backup_test.go +74 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-anthropic/generative_anthropic_test.go +204 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-anthropic/setup_test.go +54 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-aws/generative_aws_test.go +255 -0
platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/dataset_corpus.go
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package lib
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"bufio"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"math/rand"
|
| 19 |
+
"os"
|
| 20 |
+
"path/filepath"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
type Corpi struct {
|
| 24 |
+
Data []Corpus
|
| 25 |
+
scanner *bufio.Scanner
|
| 26 |
+
r *rand.Rand
|
| 27 |
+
ds Dataset
|
| 28 |
+
multiply int
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
type Corpus map[string]string
|
| 32 |
+
|
| 33 |
+
func ParseCorpi(ds Dataset, multiply int) (*Corpi, error) {
|
| 34 |
+
p := filepath.Join(ds.Path, "corpus.jsonl")
|
| 35 |
+
f, err := os.Open(p)
|
| 36 |
+
if err != nil {
|
| 37 |
+
return nil, fmt.Errorf("open queries file at %s: %w", p, err)
|
| 38 |
+
}
|
| 39 |
+
scanner := bufio.NewScanner(f)
|
| 40 |
+
// we need reproducible random numbers to be able to compare different runs. This only needs to be stable for a
|
| 41 |
+
// given version of the code. If it produces different numbers after a dependency update it doesn't matter.
|
| 42 |
+
r := rand.New(rand.NewSource(9))
|
| 43 |
+
|
| 44 |
+
c := &Corpi{
|
| 45 |
+
Data: []Corpus{},
|
| 46 |
+
scanner: scanner,
|
| 47 |
+
r: r,
|
| 48 |
+
ds: ds,
|
| 49 |
+
multiply: multiply,
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
return c, nil
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
func (c *Corpi) Next(count int) error {
|
| 56 |
+
i := 0
|
| 57 |
+
|
| 58 |
+
c.Data = []Corpus{}
|
| 59 |
+
|
| 60 |
+
for i < count {
|
| 61 |
+
|
| 62 |
+
if !c.scanner.Scan() && c.scanner.Err() != nil {
|
| 63 |
+
return c.scanner.Err()
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
obj := map[string]interface{}{}
|
| 67 |
+
if err := json.Unmarshal(c.scanner.Bytes(), &obj); err != nil {
|
| 68 |
+
return err
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
corp := Corpus{}
|
| 72 |
+
for _, prop := range c.ds.Corpus.IndexedProperties {
|
| 73 |
+
propStr, ok := obj[prop].(string)
|
| 74 |
+
if !ok {
|
| 75 |
+
return fmt.Errorf("indexed property %s is not a string: %T",
|
| 76 |
+
prop, obj[prop])
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
corp[SanitizePropName(prop)] = propStr
|
| 80 |
+
for i := 1; i < c.multiply; i++ {
|
| 81 |
+
newName := fmt.Sprintf("%s_copy_%d", SanitizePropName(prop), i)
|
| 82 |
+
var propString string
|
| 83 |
+
if len(c.Data) > 1 { // get the content of the property from another object, to get more varied results
|
| 84 |
+
otherObjectIndex := c.r.Intn(len(corp))
|
| 85 |
+
propString = c.Data[otherObjectIndex][SanitizePropName(prop)]
|
| 86 |
+
} else {
|
| 87 |
+
propString = propStr
|
| 88 |
+
}
|
| 89 |
+
corp[newName] = propString
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
for _, prop := range c.ds.Corpus.UnindexedProperties {
|
| 94 |
+
propStr, ok := obj[prop].(string)
|
| 95 |
+
if !ok {
|
| 96 |
+
propStr = fmt.Sprintf("%v", obj[prop])
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
corp[SanitizePropName(prop)] = propStr
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
c.Data = append(c.Data, corp)
|
| 103 |
+
i++
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
return nil
|
| 107 |
+
}
|
platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/dataset_queries.go
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package lib
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"bufio"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"os"
|
| 19 |
+
"path/filepath"
|
| 20 |
+
"strconv"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
type Query struct {
|
| 24 |
+
Query string
|
| 25 |
+
MatchingIds []int
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
type Queries []Query
|
| 29 |
+
|
| 30 |
+
func ParseQueries(ds Dataset, limit int) (Queries, error) {
|
| 31 |
+
p := filepath.Join(ds.Path, "queries.jsonl")
|
| 32 |
+
f, err := os.Open(p)
|
| 33 |
+
if err != nil {
|
| 34 |
+
return nil, fmt.Errorf("open queries file at %s: %w", p, err)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
defer f.Close()
|
| 38 |
+
|
| 39 |
+
scanner := bufio.NewScanner(f)
|
| 40 |
+
|
| 41 |
+
q := Queries{}
|
| 42 |
+
obj := map[string]interface{}{}
|
| 43 |
+
for scanner.Scan() {
|
| 44 |
+
if limit > 0 && len(q) >= limit {
|
| 45 |
+
break
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
if err := json.Unmarshal(scanner.Bytes(), &obj); err != nil {
|
| 49 |
+
return nil, err
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
queryStr, ok := obj[ds.Queries.Property].(string)
|
| 53 |
+
if !ok {
|
| 54 |
+
return nil, fmt.Errorf("property %s is not a string: %T",
|
| 55 |
+
ds.Queries.Property, obj[ds.Queries.Property])
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
var matchingIds []int
|
| 59 |
+
if ds.Queries.MatchingResults != "" {
|
| 60 |
+
matchingIdsInterface, ok := obj[ds.Queries.MatchingResults].([]interface{})
|
| 61 |
+
if !ok {
|
| 62 |
+
return nil, fmt.Errorf("property %s is not a []interface{}]: %T",
|
| 63 |
+
ds.Queries.MatchingResults, obj[ds.Queries.MatchingResults])
|
| 64 |
+
}
|
| 65 |
+
matchingIds = make([]int, len(matchingIdsInterface))
|
| 66 |
+
for i, val := range matchingIdsInterface {
|
| 67 |
+
// docIds can be provided as strings or float arrays
|
| 68 |
+
valStr, ok := val.(string)
|
| 69 |
+
if ok {
|
| 70 |
+
valInt, err := strconv.Atoi(valStr)
|
| 71 |
+
if err != nil {
|
| 72 |
+
return nil, err
|
| 73 |
+
}
|
| 74 |
+
matchingIds[i] = valInt
|
| 75 |
+
|
| 76 |
+
} else {
|
| 77 |
+
valFloat, ok := val.(float64)
|
| 78 |
+
if !ok {
|
| 79 |
+
return nil, fmt.Errorf("matching Id %v is not a float: %v", i, matchingIdsInterface)
|
| 80 |
+
}
|
| 81 |
+
matchingIds[i] = int(valFloat)
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
q = append(q, Query{Query: queryStr, MatchingIds: matchingIds})
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return q, nil
|
| 92 |
+
}
|
platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/datasets.go
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package lib
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"os"
|
| 16 |
+
|
| 17 |
+
"gopkg.in/yaml.v3"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
type DatasetCfg struct {
|
| 21 |
+
Datasets []Dataset `yaml:"datasets"`
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
type Dataset struct {
|
| 25 |
+
ID string `yaml:"id"`
|
| 26 |
+
Path string `yaml:"path"`
|
| 27 |
+
Corpus DatasetCorpus `yaml:"corpus"`
|
| 28 |
+
Queries DatasetQueries `yaml:"queries"`
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
type DatasetCorpus struct {
|
| 32 |
+
IndexedProperties []string `yaml:"indexed_properties"`
|
| 33 |
+
UnindexedProperties []string `yaml:"unindexed_properties"`
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
type DatasetQueries struct {
|
| 37 |
+
Property string `yaml:"property"`
|
| 38 |
+
MatchingResults string `yaml:"matching_results"`
|
| 39 |
+
PropertyWithId string `yaml:"property_with_id"`
|
| 40 |
+
PropertiesToMatch []string `yaml:"properties_to_match"`
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
func ParseDatasetConfig(filename string) (DatasetCfg, error) {
|
| 44 |
+
var config DatasetCfg
|
| 45 |
+
yamlFile, err := os.ReadFile(filename)
|
| 46 |
+
if err != nil {
|
| 47 |
+
return config, err
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
err = yaml.Unmarshal(yamlFile, &config)
|
| 51 |
+
if err != nil {
|
| 52 |
+
return config, err
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return config, nil
|
| 56 |
+
}
|
platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/durations.go
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package lib
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"sort"
|
| 17 |
+
"time"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
type LatencyStats struct {
|
| 21 |
+
Min time.Duration
|
| 22 |
+
Max time.Duration
|
| 23 |
+
Mean time.Duration
|
| 24 |
+
P50 time.Duration
|
| 25 |
+
P90 time.Duration
|
| 26 |
+
P99 time.Duration
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
func AnalyzeLatencies(in []time.Duration) LatencyStats {
|
| 30 |
+
out := LatencyStats{}
|
| 31 |
+
sort.Slice(in, func(a, b int) bool { return in[a] < in[b] })
|
| 32 |
+
|
| 33 |
+
out.Min = in[0]
|
| 34 |
+
out.Max = in[len(in)-1]
|
| 35 |
+
|
| 36 |
+
sum := time.Duration(0)
|
| 37 |
+
for _, dur := range in {
|
| 38 |
+
sum += dur
|
| 39 |
+
}
|
| 40 |
+
out.Mean = sum / time.Duration(len(in))
|
| 41 |
+
|
| 42 |
+
out.P50 = in[len(in)/2]
|
| 43 |
+
out.P90 = in[len(in)*9/10]
|
| 44 |
+
out.P99 = in[len(in)*99/100]
|
| 45 |
+
|
| 46 |
+
return out
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
func (l LatencyStats) PrettyPrint() {
|
| 50 |
+
fmt.Printf("\n")
|
| 51 |
+
fmt.Printf("Query Latencies \n")
|
| 52 |
+
fmt.Printf("-------------------- \n")
|
| 53 |
+
fmt.Printf("Min: %12s\n", l.Min)
|
| 54 |
+
fmt.Printf("Mean: %12s\n", l.Mean)
|
| 55 |
+
fmt.Printf("Max: %12s\n", l.Max)
|
| 56 |
+
fmt.Printf("p50: %12s\n", l.P50)
|
| 57 |
+
fmt.Printf("p90: %12s\n", l.P90)
|
| 58 |
+
fmt.Printf("p99: %12s\n", l.P99)
|
| 59 |
+
fmt.Printf("\n")
|
| 60 |
+
}
|
platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/schema.go
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package lib
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"strings"
|
| 16 |
+
|
| 17 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 18 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 19 |
+
"github.com/weaviate/weaviate/usecases/config"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
func SchemaFromDataset(ds Dataset, includeVectorizer bool) *models.Class {
|
| 23 |
+
out := &models.Class{}
|
| 24 |
+
out.Class = ClassNameFromDatasetID(ds.ID)
|
| 25 |
+
if !includeVectorizer {
|
| 26 |
+
out.VectorIndexConfig = map[string]interface{}{
|
| 27 |
+
"skip": true,
|
| 28 |
+
}
|
| 29 |
+
out.Vectorizer = "none"
|
| 30 |
+
}
|
| 31 |
+
out.InvertedIndexConfig = &models.InvertedIndexConfig{
|
| 32 |
+
Stopwords: &models.StopwordConfig{
|
| 33 |
+
Preset: "none",
|
| 34 |
+
},
|
| 35 |
+
UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND,
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
for _, prop := range ds.Corpus.IndexedProperties {
|
| 39 |
+
t := true
|
| 40 |
+
// all indexed props are indexed as text
|
| 41 |
+
prop := &models.Property{
|
| 42 |
+
Name: SanitizePropName(prop),
|
| 43 |
+
DataType: schema.DataTypeText.PropString(),
|
| 44 |
+
Tokenization: models.PropertyTokenizationWord,
|
| 45 |
+
IndexFilterable: &t,
|
| 46 |
+
IndexSearchable: &t,
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
out.Properties = append(out.Properties, prop)
|
| 50 |
+
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
for _, prop := range ds.Corpus.UnindexedProperties {
|
| 54 |
+
// all indexed props are indexed as text
|
| 55 |
+
f := false
|
| 56 |
+
prop := &models.Property{
|
| 57 |
+
Name: SanitizePropName(prop),
|
| 58 |
+
DataType: schema.DataTypeText.PropString(),
|
| 59 |
+
Tokenization: models.PropertyTokenizationField,
|
| 60 |
+
IndexFilterable: &f,
|
| 61 |
+
IndexSearchable: &f,
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
out.Properties = append(out.Properties, prop)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
filterProps := []*models.Property{
|
| 68 |
+
{
|
| 69 |
+
Name: "modulo_10",
|
| 70 |
+
DataType: []string{"int"},
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
Name: "modulo_100",
|
| 74 |
+
DataType: []string{"int"},
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
Name: "modulo_1000",
|
| 78 |
+
DataType: []string{"int"},
|
| 79 |
+
},
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
out.Properties = append(out.Properties, filterProps...)
|
| 83 |
+
|
| 84 |
+
return out
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
func ClassNameFromDatasetID(in string) string {
|
| 88 |
+
if len(in) == 0 {
|
| 89 |
+
panic("zero length dataset name")
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
return strings.ToUpper(string(in[0])) + strings.ToLower(in[1:])
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
func SanitizePropName(in string) string {
|
| 96 |
+
if len(in) >= 2 && in[0] == '_' && in[1] != '_' {
|
| 97 |
+
// single leading underscore is reserved, but we can append another one
|
| 98 |
+
return "_" + in
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
return in
|
| 102 |
+
}
|
platform/dbops/binaries/weaviate-src/test/benchmark_bm25/lib/scores.go
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package lib
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"math"
|
| 17 |
+
"strconv"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
type Scores struct {
|
| 21 |
+
NDCG float64
|
| 22 |
+
hitsAt1 int
|
| 23 |
+
hitsAt5 int
|
| 24 |
+
numQueries int
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
func (n *Scores) AddResult(matchingIds []int, resultIds []interface{}, propNameWithId string) error {
|
| 28 |
+
IDCG := 0.
|
| 29 |
+
for j := 0; j < len(matchingIds); j++ {
|
| 30 |
+
IDCG += 1. / math.Log(float64(j+2.))
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
DCG := 0.
|
| 34 |
+
for rank, resultId := range resultIds {
|
| 35 |
+
id, err := strconv.Atoi(resultId.(map[string]interface{})[propNameWithId].(string))
|
| 36 |
+
for _, matchingId := range matchingIds {
|
| 37 |
+
if err != nil {
|
| 38 |
+
return err
|
| 39 |
+
}
|
| 40 |
+
if id == matchingId {
|
| 41 |
+
if rank == 0 {
|
| 42 |
+
n.hitsAt1 += 1
|
| 43 |
+
}
|
| 44 |
+
if rank < 5 {
|
| 45 |
+
n.hitsAt5 += 1
|
| 46 |
+
}
|
| 47 |
+
DCG += 1 / math.Log(float64(rank+2))
|
| 48 |
+
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
n.NDCG += DCG / IDCG
|
| 53 |
+
n.numQueries += 1
|
| 54 |
+
return nil
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
func (n *Scores) CurrentNDCG() float64 {
|
| 58 |
+
return n.NDCG / float64(n.numQueries)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
func (n *Scores) CurrentPrecisionAt1() float64 {
|
| 62 |
+
return float64(n.hitsAt1) / float64(n.numQueries)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func (n *Scores) CurrentPrecisionAt5() float64 {
|
| 66 |
+
return float64(n.hitsAt5) / float64(n.numQueries) / float64(5)
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
func (n *Scores) PrettyPrint() {
|
| 70 |
+
fmt.Printf("nDCG score: %.04f, hits at 1: %d, hits at 5: %d\n", n.CurrentNDCG(), n.hitsAt1, n.hitsAt5)
|
| 71 |
+
}
|
platform/dbops/binaries/weaviate-src/test/docker/mockoidc/Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM golang:alpine
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
RUN go mod init mockoidc
|
| 6 |
+
RUN go get github.com/weaviate/mockoidc@latest
|
| 7 |
+
COPY mockoidc.go .
|
| 8 |
+
RUN go build -o mockoidc .
|
| 9 |
+
|
| 10 |
+
CMD ["/app/mockoidc"]
|
platform/dbops/binaries/weaviate-src/test/docker/mockoidc/mockoidc.go
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package main
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"crypto"
|
| 16 |
+
"crypto/rand"
|
| 17 |
+
"crypto/rsa"
|
| 18 |
+
"crypto/tls"
|
| 19 |
+
"crypto/x509"
|
| 20 |
+
"encoding/pem"
|
| 21 |
+
"fmt"
|
| 22 |
+
"log"
|
| 23 |
+
"net"
|
| 24 |
+
"os"
|
| 25 |
+
"os/signal"
|
| 26 |
+
"syscall"
|
| 27 |
+
|
| 28 |
+
"github.com/weaviate/mockoidc"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
const (
|
| 32 |
+
authCode = "auth"
|
| 33 |
+
clientSecret = "Secret"
|
| 34 |
+
clientID = "mock-oidc-test"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
// This starts a mock OIDC server listening on 48001.
|
| 38 |
+
// All codes to authenticate are hardcoded and the server returns tokens for two custom users:
|
| 39 |
+
// - admin-user
|
| 40 |
+
// - custom-user
|
| 41 |
+
// afterwards the mockoidc default user is returned
|
| 42 |
+
|
| 43 |
+
func main() {
|
| 44 |
+
getTLSConfig := func() *tls.Config {
|
| 45 |
+
certificate := os.Getenv("MOCK_CERTIFICATE")
|
| 46 |
+
certificateKey := os.Getenv("MOCK_CERTIFICATE_PRIVATE_KEY")
|
| 47 |
+
if certificate != "" && certificateKey != "" {
|
| 48 |
+
log.Println("Creating TLS config self signed certificates")
|
| 49 |
+
// read certificates
|
| 50 |
+
certBlock, _ := pem.Decode([]byte(certificate))
|
| 51 |
+
cert, err := x509.ParseCertificate(certBlock.Bytes)
|
| 52 |
+
if err != nil {
|
| 53 |
+
log.Fatalf("parse certificate: %v", err)
|
| 54 |
+
}
|
| 55 |
+
var privKey crypto.PrivateKey
|
| 56 |
+
keyBlock, _ := pem.Decode([]byte(certificateKey))
|
| 57 |
+
if keyBlock.Type == "RSA PRIVATE KEY" {
|
| 58 |
+
privKey, err = x509.ParsePKCS1PrivateKey(keyBlock.Bytes)
|
| 59 |
+
if err != nil {
|
| 60 |
+
log.Fatalf("parse certificate's private rsa key: %v", err)
|
| 61 |
+
}
|
| 62 |
+
} else {
|
| 63 |
+
privKey, err = x509.ParsePKCS8PrivateKey(keyBlock.Bytes)
|
| 64 |
+
if err != nil {
|
| 65 |
+
log.Fatalf("parse certificate's private key: %v", err)
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
// TLS configuration
|
| 69 |
+
tlsCert := tls.Certificate{
|
| 70 |
+
Certificate: [][]byte{cert.Raw},
|
| 71 |
+
PrivateKey: privKey,
|
| 72 |
+
}
|
| 73 |
+
tlsConfig := &tls.Config{
|
| 74 |
+
Certificates: []tls.Certificate{tlsCert},
|
| 75 |
+
MinVersion: tls.VersionTLS12,
|
| 76 |
+
}
|
| 77 |
+
return tlsConfig
|
| 78 |
+
}
|
| 79 |
+
// Default OIDC server
|
| 80 |
+
return nil
|
| 81 |
+
}
|
| 82 |
+
tlsConfig := getTLSConfig()
|
| 83 |
+
rsaKey, _ := rsa.GenerateKey(rand.Reader, 2048)
|
| 84 |
+
m, _ := mockoidc.NewServer(rsaKey)
|
| 85 |
+
m.ClientSecret = clientSecret
|
| 86 |
+
m.ClientID = clientID
|
| 87 |
+
hostname := os.Getenv("MOCK_HOSTNAME")
|
| 88 |
+
m.Hostname = fmt.Sprintf("%s:48001", hostname)
|
| 89 |
+
addr := "0.0.0.0:48001"
|
| 90 |
+
if hostname != "" {
|
| 91 |
+
addr = fmt.Sprintf("%s:48001", hostname)
|
| 92 |
+
}
|
| 93 |
+
ln, _ := net.Listen("tcp", addr)
|
| 94 |
+
m.Start(ln, tlsConfig)
|
| 95 |
+
defer m.Shutdown()
|
| 96 |
+
|
| 97 |
+
admin := &mockoidc.MockUser{Subject: "admin-user"}
|
| 98 |
+
m.QueueUser(admin)
|
| 99 |
+
m.QueueCode(authCode)
|
| 100 |
+
|
| 101 |
+
custom := &mockoidc.MockUser{Subject: "custom-user", Groups: []string{"custom-group"}}
|
| 102 |
+
m.QueueUser(custom)
|
| 103 |
+
m.QueueCode(authCode)
|
| 104 |
+
|
| 105 |
+
log.Printf("issuer: %v\n", m.Issuer())
|
| 106 |
+
log.Printf("discovery endpoint: %v\n", m.DiscoveryEndpoint())
|
| 107 |
+
// Create a channel to receive OS signals
|
| 108 |
+
sigChan := make(chan os.Signal, 1)
|
| 109 |
+
// Notify the channel of the interrupt signal (Ctrl+C)
|
| 110 |
+
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
| 111 |
+
|
| 112 |
+
// Print a message indicating the program is running
|
| 113 |
+
log.Println("Program is running. Press Ctrl+C to stop.")
|
| 114 |
+
|
| 115 |
+
// Block until a signal is received
|
| 116 |
+
sig := <-sigChan
|
| 117 |
+
log.Printf("Received signal: %v. Shutting down...\n", sig)
|
| 118 |
+
}
|
platform/dbops/binaries/weaviate-src/test/docker/mockoidchelper/Dockerfile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM golang:alpine
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
RUN go mod init mockoidc_helper
|
| 6 |
+
COPY mockoidc_helper.go .
|
| 7 |
+
RUN go build -o mockoidc_helper .
|
| 8 |
+
|
| 9 |
+
CMD ["/app/mockoidc_helper"]
|
platform/dbops/binaries/weaviate-src/test/docker/mockoidchelper/mockoidc_helper.go
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package main
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"bytes"
|
| 16 |
+
"context"
|
| 17 |
+
"crypto/tls"
|
| 18 |
+
"crypto/x509"
|
| 19 |
+
"encoding/json"
|
| 20 |
+
"encoding/pem"
|
| 21 |
+
"fmt"
|
| 22 |
+
"io"
|
| 23 |
+
"log"
|
| 24 |
+
"net/http"
|
| 25 |
+
"net/url"
|
| 26 |
+
"os"
|
| 27 |
+
"os/signal"
|
| 28 |
+
"syscall"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
const (
|
| 32 |
+
authCode = "auth"
|
| 33 |
+
clientSecret = "Secret"
|
| 34 |
+
clientID = "mock-oidc-test"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
type Response struct {
|
| 38 |
+
AccessToken string `json:"accessToken"`
|
| 39 |
+
RefreshToken string `json:"refreshToken"`
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
type tokensHandler struct {
|
| 43 |
+
client *http.Client
|
| 44 |
+
authEndpoint, tokenEndpoint string
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func newTokensHandler() (*tokensHandler, error) {
|
| 48 |
+
getEndpointsAndClient := func() (string, string, *http.Client, error) {
|
| 49 |
+
hostname := os.Getenv("MOCK_HOSTNAME")
|
| 50 |
+
certificate := os.Getenv("MOCK_CERTIFICATE")
|
| 51 |
+
if certificate != "" {
|
| 52 |
+
certBlock, _ := pem.Decode([]byte(certificate))
|
| 53 |
+
cert, err := x509.ParseCertificate(certBlock.Bytes)
|
| 54 |
+
if err != nil {
|
| 55 |
+
return "", "", nil, fmt.Errorf("failed to decode certificate: %w", err)
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
certPool := x509.NewCertPool()
|
| 59 |
+
certPool.AddCert(cert)
|
| 60 |
+
|
| 61 |
+
// Create an HTTP client with self signed certificate
|
| 62 |
+
client := &http.Client{
|
| 63 |
+
Transport: &http.Transport{
|
| 64 |
+
TLSClientConfig: &tls.Config{
|
| 65 |
+
RootCAs: certPool,
|
| 66 |
+
MinVersion: tls.VersionTLS12,
|
| 67 |
+
},
|
| 68 |
+
},
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Adjust endpoints to use https
|
| 72 |
+
authEndpoint := "https://" + hostname + "/oidc/authorize"
|
| 73 |
+
tokenEndpoint := "https://" + hostname + "/oidc/token"
|
| 74 |
+
|
| 75 |
+
return authEndpoint, tokenEndpoint, client, nil
|
| 76 |
+
}
|
| 77 |
+
// Default HTTP client
|
| 78 |
+
client := &http.Client{}
|
| 79 |
+
|
| 80 |
+
authEndpoint := "http://" + hostname + "/oidc/authorize"
|
| 81 |
+
tokenEndpoint := "http://" + hostname + "/oidc/token"
|
| 82 |
+
|
| 83 |
+
return authEndpoint, tokenEndpoint, client, nil
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
authEndpoint, tokenEndpoint, client, err := getEndpointsAndClient()
|
| 87 |
+
if err != nil {
|
| 88 |
+
return nil, err
|
| 89 |
+
}
|
| 90 |
+
return &tokensHandler{authEndpoint: authEndpoint, tokenEndpoint: tokenEndpoint, client: client}, nil
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
func (t *tokensHandler) handler(w http.ResponseWriter, r *http.Request) {
|
| 94 |
+
if r.Method != http.MethodGet {
|
| 95 |
+
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
| 96 |
+
return
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
accessToken, refreshToken, err := getTokensFromMockOIDC(t.client, t.authEndpoint, t.tokenEndpoint)
|
| 100 |
+
if err != nil {
|
| 101 |
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
| 102 |
+
return
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
w.Header().Set("Content-Type", "application/json")
|
| 106 |
+
w.WriteHeader(http.StatusOK)
|
| 107 |
+
|
| 108 |
+
response := Response{AccessToken: accessToken, RefreshToken: refreshToken}
|
| 109 |
+
if err := json.NewEncoder(w).Encode(response); err != nil {
|
| 110 |
+
http.Error(w, fmt.Sprintf("encode response: %v", err), http.StatusInternalServerError)
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
func getTokensFromMockOIDC(client *http.Client, authEndpoint, tokenEndpoint string) (string, string, error) {
|
| 115 |
+
// getting the token is a two-step process:
|
| 116 |
+
// 1) authorizing with the clientSecret, the return contains an auth-code. However, (dont ask me why) the OIDC flow
|
| 117 |
+
// demands a redirect, so we will not get the return. In the mockserver, we can set the auth code to whatever
|
| 118 |
+
// we want, so we simply will use the same code for each call. Note that even though we do not get the return, we
|
| 119 |
+
// still need to make the request to initialize the session
|
| 120 |
+
// 2) call the token endpoint with the auth code. This returns an access and refresh token.
|
| 121 |
+
//
|
| 122 |
+
// The access token can be used to authenticate with weaviate and the refresh token can be used to get a new valid
|
| 123 |
+
// token in case the access token lifetime expires
|
| 124 |
+
|
| 125 |
+
data := url.Values{}
|
| 126 |
+
data.Set("response_type", "code")
|
| 127 |
+
data.Set("code", authCode)
|
| 128 |
+
data.Set("redirect_uri", "google.com") // needs to be present
|
| 129 |
+
data.Set("client_id", clientID)
|
| 130 |
+
data.Set("client_secret", clientSecret)
|
| 131 |
+
data.Set("state", "email")
|
| 132 |
+
data.Set("scope", "openid groups")
|
| 133 |
+
req, err := http.NewRequest("POST", authEndpoint, bytes.NewBufferString(data.Encode()))
|
| 134 |
+
if err != nil {
|
| 135 |
+
return "", "", err
|
| 136 |
+
}
|
| 137 |
+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
| 138 |
+
// not getting a useful return value as we dont provide a valid redirect
|
| 139 |
+
resp, err := client.Do(req)
|
| 140 |
+
if err != nil {
|
| 141 |
+
return "", "", err
|
| 142 |
+
}
|
| 143 |
+
defer resp.Body.Close()
|
| 144 |
+
|
| 145 |
+
data2 := url.Values{}
|
| 146 |
+
data2.Set("grant_type", "authorization_code")
|
| 147 |
+
data2.Set("client_id", clientID)
|
| 148 |
+
data2.Set("client_secret", clientSecret)
|
| 149 |
+
data2.Set("code", authCode)
|
| 150 |
+
data2.Set("scope", "email")
|
| 151 |
+
data2.Set("state", "email")
|
| 152 |
+
req2, err := http.NewRequest("POST", tokenEndpoint, bytes.NewBufferString(data2.Encode()))
|
| 153 |
+
if err != nil {
|
| 154 |
+
return "", "", err
|
| 155 |
+
}
|
| 156 |
+
req2.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
| 157 |
+
resp2, err := client.Do(req2)
|
| 158 |
+
if err != nil {
|
| 159 |
+
return "", "", err
|
| 160 |
+
}
|
| 161 |
+
defer resp2.Body.Close()
|
| 162 |
+
body, _ := io.ReadAll(resp2.Body)
|
| 163 |
+
var tokenResponse map[string]interface{}
|
| 164 |
+
err = json.Unmarshal(body, &tokenResponse)
|
| 165 |
+
if err != nil {
|
| 166 |
+
return "", "", err
|
| 167 |
+
}
|
| 168 |
+
accessToken, ok := tokenResponse["id_token"].(string)
|
| 169 |
+
if !ok {
|
| 170 |
+
return "", "", fmt.Errorf("failed to get access token from: %v", tokenResponse)
|
| 171 |
+
}
|
| 172 |
+
refreshToken, ok := tokenResponse["refresh_token"].(string)
|
| 173 |
+
if !ok {
|
| 174 |
+
return "", "", fmt.Errorf("failed to get refresh token from: %v", tokenResponse)
|
| 175 |
+
}
|
| 176 |
+
return accessToken, refreshToken, nil
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
func main() {
|
| 180 |
+
// Create tokens handler
|
| 181 |
+
tk, err := newTokensHandler()
|
| 182 |
+
if err != nil {
|
| 183 |
+
log.Fatalf("Failed to create tokens handler: %v", err)
|
| 184 |
+
}
|
| 185 |
+
// Create a new ServeMux for routing
|
| 186 |
+
mux := http.NewServeMux()
|
| 187 |
+
mux.HandleFunc("/tokens", tk.handler)
|
| 188 |
+
|
| 189 |
+
// Create the HTTP server
|
| 190 |
+
server := &http.Server{
|
| 191 |
+
Addr: ":8080",
|
| 192 |
+
Handler: mux,
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
go func() {
|
| 196 |
+
// Start the server
|
| 197 |
+
log.Println("Starting server on :8080")
|
| 198 |
+
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
| 199 |
+
log.Fatalf("Server failed to start: %v", err)
|
| 200 |
+
}
|
| 201 |
+
}()
|
| 202 |
+
defer func() {
|
| 203 |
+
// Perform graceful shutdown
|
| 204 |
+
if err := server.Shutdown(context.Background()); err != nil {
|
| 205 |
+
log.Fatalf("Server shutdown failed: %v", err)
|
| 206 |
+
}
|
| 207 |
+
log.Println("Server gracefully stopped")
|
| 208 |
+
}()
|
| 209 |
+
|
| 210 |
+
// Create a channel to receive OS signals
|
| 211 |
+
sigChan := make(chan os.Signal, 1)
|
| 212 |
+
// Notify the channel of the interrupt signal (Ctrl+C)
|
| 213 |
+
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
| 214 |
+
|
| 215 |
+
// Print a message indicating the program is running
|
| 216 |
+
log.Println("Program is running. Press Ctrl+C to stop.")
|
| 217 |
+
|
| 218 |
+
// Block until a signal is received
|
| 219 |
+
sig := <-sigChan
|
| 220 |
+
log.Printf("Received signal: %v. Shutting down...\n", sig)
|
| 221 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/graphql/graphql_helper.go
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package graphqlhelper
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/json"
|
| 16 |
+
"errors"
|
| 17 |
+
"fmt"
|
| 18 |
+
"strings"
|
| 19 |
+
"testing"
|
| 20 |
+
"time"
|
| 21 |
+
|
| 22 |
+
"github.com/go-openapi/runtime"
|
| 23 |
+
"github.com/stretchr/testify/require"
|
| 24 |
+
|
| 25 |
+
"github.com/weaviate/weaviate/client/graphql"
|
| 26 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 27 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
type GraphQLResult struct {
|
| 31 |
+
Result interface{}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// Perform a GraphQL request
|
| 35 |
+
func QueryGraphQL(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, operation string, query string, variables map[string]interface{}) (*models.GraphQLResponse, error) {
|
| 36 |
+
var vars interface{} = variables
|
| 37 |
+
params := graphql.NewGraphqlPostParams().WithBody(&models.GraphQLQuery{OperationName: operation, Query: query, Variables: vars})
|
| 38 |
+
response, err := helper.Client(t).Graphql.GraphqlPost(params, nil)
|
| 39 |
+
if err != nil {
|
| 40 |
+
return nil, err
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
return response.Payload, nil
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// Perform a GraphQL request with timeout
|
| 47 |
+
func QueryGraphQLWithTimeout(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, operation string, query string, variables map[string]interface{}, timeout time.Duration) (*models.GraphQLResponse, error) {
|
| 48 |
+
var vars interface{} = variables
|
| 49 |
+
params := graphql.NewGraphqlPostParamsWithTimeout(timeout).WithBody(&models.GraphQLQuery{OperationName: operation, Query: query, Variables: vars})
|
| 50 |
+
response, err := helper.Client(t).Graphql.GraphqlPost(params, nil)
|
| 51 |
+
if err != nil {
|
| 52 |
+
return nil, err
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return response.Payload, nil
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// Perform a GraphQL request and call fatal on failure
|
| 59 |
+
func QueryGraphQLOrFatal(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, operation string, query string, variables map[string]interface{}) *models.GraphQLResponse {
|
| 60 |
+
t.Helper()
|
| 61 |
+
response, err := QueryGraphQL(t, auth, operation, query, variables)
|
| 62 |
+
return getGraphQLResponseOrFatal(t, response, err)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// Perform a GraphQL request and call fatal on failure with timeout
|
| 66 |
+
func QueryGraphQLOrFatalWithTimeout(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, operation string, query string, variables map[string]interface{}, timeout time.Duration) *models.GraphQLResponse {
|
| 67 |
+
t.Helper()
|
| 68 |
+
response, err := QueryGraphQLWithTimeout(t, auth, operation, query, variables, timeout)
|
| 69 |
+
return getGraphQLResponseOrFatal(t, response, err)
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
func getGraphQLResponseOrFatal(t *testing.T, response *models.GraphQLResponse, err error) *models.GraphQLResponse {
|
| 73 |
+
t.Helper()
|
| 74 |
+
if err != nil {
|
| 75 |
+
var parsedErr *graphql.GraphqlPostUnprocessableEntity
|
| 76 |
+
if !errors.As(err, &parsedErr) {
|
| 77 |
+
t.Fatalf("Expected the query to succeed, but failed due to: %#v, with message: %s", err, err.Error())
|
| 78 |
+
}
|
| 79 |
+
innerErr := parsedErr.Payload.Error[0]
|
| 80 |
+
t.Fatalf("Expected the query to succeed, but failed with unprocessable entity: %v, with message: %s", innerErr, innerErr.Message)
|
| 81 |
+
}
|
| 82 |
+
return response
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Perform a query and assert that it is successful
|
| 86 |
+
func AssertGraphQL(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, query string) *GraphQLResult {
|
| 87 |
+
t.Helper()
|
| 88 |
+
response := QueryGraphQLOrFatal(t, auth, "", query, nil)
|
| 89 |
+
return getGraphQLResult(t, response)
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Perform a query and assert that it is successful with timeout
|
| 93 |
+
func AssertGraphQLWithTimeout(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, timeout time.Duration, query string) *GraphQLResult {
|
| 94 |
+
t.Helper()
|
| 95 |
+
response := QueryGraphQLOrFatalWithTimeout(t, auth, "", query, nil, timeout)
|
| 96 |
+
return getGraphQLResult(t, response)
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
func getGraphQLResult(t *testing.T, response *models.GraphQLResponse) *GraphQLResult {
|
| 100 |
+
t.Helper()
|
| 101 |
+
if len(response.Errors) != 0 {
|
| 102 |
+
j, _ := json.Marshal(response.Errors)
|
| 103 |
+
t.Fatal("GraphQL resolved to an error:", string(j))
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
data := make(map[string]interface{})
|
| 107 |
+
|
| 108 |
+
// get rid of models.JSONData
|
| 109 |
+
for key, value := range response.Data {
|
| 110 |
+
data[key] = value
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
return &GraphQLResult{Result: data}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Perform a query and assert that it has errors
|
| 117 |
+
func ErrorGraphQL(t *testing.T, auth runtime.ClientAuthInfoWriterFunc, query string) []*models.GraphQLError {
|
| 118 |
+
t.Helper()
|
| 119 |
+
response := QueryGraphQLOrFatal(t, auth, "", query, nil)
|
| 120 |
+
|
| 121 |
+
if len(response.Errors) == 0 {
|
| 122 |
+
j, _ := json.Marshal(response.Errors)
|
| 123 |
+
t.Fatal("GraphQL resolved to data:", string(j))
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
return response.Errors
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Drill down in the result
|
| 130 |
+
func (g GraphQLResult) Get(paths ...string) *GraphQLResult {
|
| 131 |
+
current := g.Result
|
| 132 |
+
for _, path := range paths {
|
| 133 |
+
var ok bool
|
| 134 |
+
currentAsMap := (current.(map[string]interface{}))
|
| 135 |
+
current, ok = currentAsMap[path]
|
| 136 |
+
if !ok {
|
| 137 |
+
panic(fmt.Sprintf("Cannot get element %s in %#v; result: %#v", path, paths, g.Result))
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return &GraphQLResult{
|
| 142 |
+
Result: current,
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Cast the result to a slice
|
| 147 |
+
func (g *GraphQLResult) AsSlice() []interface{} {
|
| 148 |
+
return g.Result.([]interface{})
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
func Vec2String(v []float32) (s string) {
|
| 152 |
+
for _, n := range v {
|
| 153 |
+
s = fmt.Sprintf("%s, %f", s, n)
|
| 154 |
+
}
|
| 155 |
+
s = strings.TrimLeft(s, ", ")
|
| 156 |
+
return fmt.Sprintf("[%s]", s)
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
func ParseVec(t *testing.T, iVec []interface{}) []float32 {
|
| 160 |
+
vec := make([]float32, len(iVec))
|
| 161 |
+
for i, val := range iVec {
|
| 162 |
+
parsed, err := val.(json.Number).Float64()
|
| 163 |
+
require.Nil(t, err)
|
| 164 |
+
vec[i] = float32(parsed)
|
| 165 |
+
}
|
| 166 |
+
return vec
|
| 167 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/grpc/grpc_helper.go
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package grpchelper
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
"google.golang.org/grpc/metadata"
|
| 22 |
+
"google.golang.org/protobuf/types/known/structpb"
|
| 23 |
+
|
| 24 |
+
"github.com/stretchr/testify/require"
|
| 25 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 26 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
func Search(t *testing.T, req *pb.SearchRequest) (*pb.SearchReply, error) {
|
| 30 |
+
return helper.ClientGRPC(t).Search(context.Background(), req)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
func SearchWithTimeout(t *testing.T, req *pb.SearchRequest, timeout time.Duration) (*pb.SearchReply, error) {
|
| 34 |
+
ctx := context.Background()
|
| 35 |
+
ctx, cancel := context.WithTimeout(ctx, timeout)
|
| 36 |
+
defer cancel()
|
| 37 |
+
return helper.ClientGRPC(t).Search(ctx, req)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func AssertSearch(t *testing.T, req *pb.SearchRequest) *pb.SearchReply {
|
| 41 |
+
t.Helper()
|
| 42 |
+
resp, err := Search(t, req)
|
| 43 |
+
require.Nil(t, err)
|
| 44 |
+
return resp
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func AssertSearchWithTimeout(t *testing.T, req *pb.SearchRequest, timeout time.Duration) *pb.SearchReply {
|
| 48 |
+
t.Helper()
|
| 49 |
+
resp, err := SearchWithTimeout(t, req, timeout)
|
| 50 |
+
if err != nil {
|
| 51 |
+
t.Errorf("SearchWithTimeout failed: %v", err)
|
| 52 |
+
}
|
| 53 |
+
return resp
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
func BatchGRPCWithTenantAuth(t *testing.T, objects []*models.Object, key string) (*pb.BatchObjectsReply, error) {
|
| 57 |
+
var objectsGRPC []*pb.BatchObject
|
| 58 |
+
|
| 59 |
+
for _, obj := range objects {
|
| 60 |
+
props := &structpb.Struct{Fields: map[string]*structpb.Value{}}
|
| 61 |
+
for name, val := range obj.Properties.(map[string]interface{}) {
|
| 62 |
+
valTyped := val.(*structpb.Value)
|
| 63 |
+
props.Fields[name] = valTyped
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
objectsGRPC = append(objectsGRPC, &pb.BatchObject{
|
| 67 |
+
Tenant: obj.Tenant,
|
| 68 |
+
Collection: obj.Class,
|
| 69 |
+
Uuid: obj.ID.String(),
|
| 70 |
+
Properties: &pb.BatchObject_Properties{NonRefProperties: props},
|
| 71 |
+
// Vector is missing
|
| 72 |
+
},
|
| 73 |
+
)
|
| 74 |
+
}
|
| 75 |
+
req := &pb.BatchObjectsRequest{Objects: objectsGRPC}
|
| 76 |
+
ctx := metadata.AppendToOutgoingContext(context.Background(), "authorization", fmt.Sprintf("Bearer %s", key))
|
| 77 |
+
|
| 78 |
+
return helper.ClientGRPC(t).BatchObjects(ctx, req)
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func ToPtr[T any](val T) *T {
|
| 82 |
+
return &val
|
| 83 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/backup_and_restore_journey.go
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"errors"
|
| 16 |
+
"testing"
|
| 17 |
+
"time"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
|
| 21 |
+
"github.com/weaviate/weaviate/client/backups"
|
| 22 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/books"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
type vectorsConfigType string
|
| 28 |
+
|
| 29 |
+
const (
|
| 30 |
+
vectorsLegacy vectorsConfigType = "legacy"
|
| 31 |
+
vectorsNamed vectorsConfigType = "named"
|
| 32 |
+
vectorsMixed vectorsConfigType = "mixed"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
func backupAndRestoreJourneyTest(t *testing.T, weaviateEndpoint, backend string, vectorsConfigType vectorsConfigType, overrideName, overridePath string) {
|
| 36 |
+
if weaviateEndpoint != "" {
|
| 37 |
+
helper.SetupClient(weaviateEndpoint)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
var booksClass *models.Class
|
| 41 |
+
switch vectorsConfigType {
|
| 42 |
+
case vectorsNamed:
|
| 43 |
+
booksClass = books.ClassNamedContextionaryVectorizer()
|
| 44 |
+
case vectorsMixed:
|
| 45 |
+
booksClass = books.ClassMixedContextionaryVectorizer()
|
| 46 |
+
default:
|
| 47 |
+
booksClass = books.ClassContextionaryVectorizer()
|
| 48 |
+
}
|
| 49 |
+
helper.CreateClass(t, booksClass)
|
| 50 |
+
defer helper.DeleteClass(t, booksClass.Class)
|
| 51 |
+
|
| 52 |
+
verifyThatAllBooksExist := func(t *testing.T) {
|
| 53 |
+
book := helper.AssertGetObject(t, booksClass.Class, books.Dune)
|
| 54 |
+
require.Equal(t, books.Dune, book.ID)
|
| 55 |
+
book = helper.AssertGetObject(t, booksClass.Class, books.ProjectHailMary)
|
| 56 |
+
require.Equal(t, books.ProjectHailMary, book.ID)
|
| 57 |
+
book = helper.AssertGetObject(t, booksClass.Class, books.TheLordOfTheIceGarden)
|
| 58 |
+
require.Equal(t, books.TheLordOfTheIceGarden, book.ID)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
vectorsForDune := func() map[string][]float32 {
|
| 62 |
+
vectors := map[string][]float32{}
|
| 63 |
+
duneBook := helper.AssertGetObject(t, booksClass.Class, books.Dune)
|
| 64 |
+
|
| 65 |
+
if vectorsConfigType == vectorsNamed || vectorsConfigType == vectorsMixed {
|
| 66 |
+
for name := range booksClass.VectorConfig {
|
| 67 |
+
switch vec := duneBook.Vectors[name].(type) {
|
| 68 |
+
case []float32:
|
| 69 |
+
vectors[name] = vec
|
| 70 |
+
case [][]float32:
|
| 71 |
+
// do nothing
|
| 72 |
+
default:
|
| 73 |
+
// do nothing
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
if vectorsConfigType == vectorsLegacy || vectorsConfigType == vectorsMixed {
|
| 78 |
+
vectors["vector"] = duneBook.Vector
|
| 79 |
+
}
|
| 80 |
+
return vectors
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
backupID := "backup-1_named_vectors_" + string(vectorsConfigType)
|
| 84 |
+
t.Run("add data to Books schema", func(t *testing.T) {
|
| 85 |
+
for _, book := range books.Objects() {
|
| 86 |
+
helper.CreateObject(t, book)
|
| 87 |
+
helper.AssertGetObjectEventually(t, book.Class, book.ID)
|
| 88 |
+
}
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
t.Run("verify that Books objects exist", func(t *testing.T) {
|
| 92 |
+
verifyThatAllBooksExist(t)
|
| 93 |
+
})
|
| 94 |
+
initialVectors := vectorsForDune()
|
| 95 |
+
|
| 96 |
+
t.Run("verify invalid compression config", func(t *testing.T) {
|
| 97 |
+
// unknown compression level
|
| 98 |
+
resp, err := helper.CreateBackup(t, &models.BackupConfig{
|
| 99 |
+
CompressionLevel: "some-weird-config",
|
| 100 |
+
}, booksClass.Class, backend, backupID)
|
| 101 |
+
|
| 102 |
+
helper.AssertRequestFail(t, resp, err, func() {
|
| 103 |
+
var customErr *backups.BackupsCreateUnprocessableEntity
|
| 104 |
+
require.True(t, errors.As(err, &customErr), "not backups.BackupsCreateUnprocessableEntity")
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
// out of band cpu %
|
| 108 |
+
resp, err = helper.CreateBackup(t, &models.BackupConfig{
|
| 109 |
+
CPUPercentage: 120,
|
| 110 |
+
}, booksClass.Class, backend, backupID)
|
| 111 |
+
helper.AssertRequestFail(t, resp, err, func() {
|
| 112 |
+
var customErr *backups.BackupsCreateUnprocessableEntity
|
| 113 |
+
require.True(t, errors.As(err, &customErr), "not backups.BackupsCreateUnprocessableEntity")
|
| 114 |
+
})
|
| 115 |
+
|
| 116 |
+
// out of band chunkSize
|
| 117 |
+
resp, err = helper.CreateBackup(t, &models.BackupConfig{
|
| 118 |
+
ChunkSize: 1024,
|
| 119 |
+
}, booksClass.Class, backend, backupID)
|
| 120 |
+
helper.AssertRequestFail(t, resp, err, func() {
|
| 121 |
+
var customErr *backups.BackupsCreateUnprocessableEntity
|
| 122 |
+
require.True(t, errors.As(err, &customErr), "not backups.BackupsCreateUnprocessableEntity")
|
| 123 |
+
})
|
| 124 |
+
})
|
| 125 |
+
|
| 126 |
+
t.Run("start backup process", func(t *testing.T) {
|
| 127 |
+
params := backups.NewBackupsCreateParams().
|
| 128 |
+
WithBackend(backend).
|
| 129 |
+
WithBody(&models.BackupCreateRequest{
|
| 130 |
+
ID: backupID,
|
| 131 |
+
Include: []string{booksClass.Class},
|
| 132 |
+
Config: &models.BackupConfig{
|
| 133 |
+
CPUPercentage: 80,
|
| 134 |
+
ChunkSize: 512,
|
| 135 |
+
CompressionLevel: models.BackupConfigCompressionLevelDefaultCompression,
|
| 136 |
+
Bucket: overrideName,
|
| 137 |
+
Path: overridePath,
|
| 138 |
+
},
|
| 139 |
+
})
|
| 140 |
+
resp, err := helper.Client(t).Backups.BackupsCreate(params, nil)
|
| 141 |
+
|
| 142 |
+
helper.AssertRequestOk(t, resp, err, func() {
|
| 143 |
+
meta := resp.GetPayload()
|
| 144 |
+
require.NotNil(t, meta)
|
| 145 |
+
require.Equal(t, models.BackupCreateStatusResponseStatusSTARTED, *meta.Status)
|
| 146 |
+
})
|
| 147 |
+
})
|
| 148 |
+
|
| 149 |
+
t.Run("verify that backup process is completed", func(t *testing.T) {
|
| 150 |
+
params := backups.NewBackupsCreateStatusParams().
|
| 151 |
+
WithBackend(backend).
|
| 152 |
+
WithID(backupID).
|
| 153 |
+
WithBucket(&overrideName).
|
| 154 |
+
WithPath(&overridePath)
|
| 155 |
+
for {
|
| 156 |
+
resp, err := helper.Client(t).Backups.BackupsCreateStatus(params, nil)
|
| 157 |
+
require.Nil(t, err)
|
| 158 |
+
require.NotNil(t, resp)
|
| 159 |
+
|
| 160 |
+
meta := resp.GetPayload()
|
| 161 |
+
require.NotNil(t, meta)
|
| 162 |
+
|
| 163 |
+
if err != nil {
|
| 164 |
+
t.Logf("failed to get backup status: %+v", err)
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
switch *meta.Status {
|
| 168 |
+
case models.BackupCreateStatusResponseStatusSUCCESS:
|
| 169 |
+
return
|
| 170 |
+
case models.BackupCreateStatusResponseStatusFAILED:
|
| 171 |
+
t.Errorf("failed to create backup, got response: %+v", meta)
|
| 172 |
+
return
|
| 173 |
+
default:
|
| 174 |
+
time.Sleep(1 * time.Second)
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
})
|
| 178 |
+
|
| 179 |
+
t.Run("verify that Books objects still exist", func(t *testing.T) {
|
| 180 |
+
verifyThatAllBooksExist(t)
|
| 181 |
+
})
|
| 182 |
+
|
| 183 |
+
t.Run("remove Books class", func(t *testing.T) {
|
| 184 |
+
helper.DeleteClass(t, booksClass.Class)
|
| 185 |
+
})
|
| 186 |
+
|
| 187 |
+
t.Run("verify that objects don't exist", func(t *testing.T) {
|
| 188 |
+
err := helper.AssertGetObjectFailsEventually(t, booksClass.Class, books.Dune)
|
| 189 |
+
require.NotNil(t, err)
|
| 190 |
+
err = helper.AssertGetObjectFailsEventually(t, booksClass.Class, books.ProjectHailMary)
|
| 191 |
+
require.NotNil(t, err)
|
| 192 |
+
err = helper.AssertGetObjectFailsEventually(t, booksClass.Class, books.TheLordOfTheIceGarden)
|
| 193 |
+
require.NotNil(t, err)
|
| 194 |
+
})
|
| 195 |
+
|
| 196 |
+
// out of band cpu %
|
| 197 |
+
t.Run("invalid restore request", func(t *testing.T) {
|
| 198 |
+
resp, err := helper.RestoreBackup(t, &models.RestoreConfig{
|
| 199 |
+
CPUPercentage: 180,
|
| 200 |
+
Bucket: overrideName,
|
| 201 |
+
Path: overridePath,
|
| 202 |
+
}, booksClass.Class, backend, backupID, map[string]string{}, false)
|
| 203 |
+
helper.AssertRequestFail(t, resp, err, func() {
|
| 204 |
+
var customErr *backups.BackupsRestoreUnprocessableEntity
|
| 205 |
+
require.True(t, errors.As(err, &customErr), "not backups.BackupsRestoreUnprocessableEntity")
|
| 206 |
+
})
|
| 207 |
+
})
|
| 208 |
+
|
| 209 |
+
t.Run("start restore process", func(t *testing.T) {
|
| 210 |
+
params := backups.NewBackupsRestoreParams().
|
| 211 |
+
WithBackend(backend).
|
| 212 |
+
WithID(backupID).
|
| 213 |
+
WithBody(&models.BackupRestoreRequest{
|
| 214 |
+
Include: []string{booksClass.Class},
|
| 215 |
+
Config: &models.RestoreConfig{
|
| 216 |
+
CPUPercentage: 80,
|
| 217 |
+
Bucket: overrideName,
|
| 218 |
+
Path: overridePath,
|
| 219 |
+
},
|
| 220 |
+
})
|
| 221 |
+
resp, err := helper.Client(t).Backups.BackupsRestore(params, nil)
|
| 222 |
+
helper.AssertRequestOk(t, resp, err, func() {
|
| 223 |
+
meta := resp.GetPayload()
|
| 224 |
+
require.NotNil(t, meta)
|
| 225 |
+
require.Equal(t, models.BackupCreateStatusResponseStatusSTARTED, *meta.Status)
|
| 226 |
+
})
|
| 227 |
+
})
|
| 228 |
+
t.Run("verify that restore process is completed", func(t *testing.T) {
|
| 229 |
+
params := backups.NewBackupsRestoreStatusParams().
|
| 230 |
+
WithBackend(backend).
|
| 231 |
+
WithID(backupID).
|
| 232 |
+
WithBucket(&overrideName).
|
| 233 |
+
WithPath(&overridePath)
|
| 234 |
+
for {
|
| 235 |
+
resp, err := helper.Client(t).Backups.BackupsRestoreStatus(params, nil)
|
| 236 |
+
require.Nil(t, err)
|
| 237 |
+
require.NotNil(t, resp)
|
| 238 |
+
meta := resp.GetPayload()
|
| 239 |
+
require.NotNil(t, meta)
|
| 240 |
+
switch *meta.Status {
|
| 241 |
+
case models.BackupRestoreStatusResponseStatusSUCCESS:
|
| 242 |
+
return
|
| 243 |
+
case models.BackupRestoreStatusResponseStatusFAILED:
|
| 244 |
+
t.Errorf("failed to restore backup, got response: %+v", meta)
|
| 245 |
+
return
|
| 246 |
+
default:
|
| 247 |
+
time.Sleep(1 * time.Second)
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
})
|
| 251 |
+
|
| 252 |
+
t.Run("verify that Books objects exist after restore", func(t *testing.T) {
|
| 253 |
+
verifyThatAllBooksExist(t)
|
| 254 |
+
})
|
| 255 |
+
|
| 256 |
+
t.Run("verify that vectors are the same after restore", func(t *testing.T) {
|
| 257 |
+
restoredVectors := vectorsForDune()
|
| 258 |
+
require.Equal(t, initialVectors, restoredVectors)
|
| 259 |
+
})
|
| 260 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/backup_journey.go
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"math/rand"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
|
| 23 |
+
"github.com/weaviate/weaviate/entities/backup"
|
| 24 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 25 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 26 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 27 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
type journeyType int
|
| 31 |
+
|
| 32 |
+
const (
|
| 33 |
+
singleNodeJourney journeyType = iota
|
| 34 |
+
clusterJourney
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
type dataIntegrityCheck int
|
| 38 |
+
|
| 39 |
+
const (
|
| 40 |
+
checkClassPresenceOnly = iota
|
| 41 |
+
checkClassAndDataPresence
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
const (
|
| 45 |
+
singleTenant = ""
|
| 46 |
+
multiTenant = true
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
func backupJourney(t *testing.T, className, backend, basebackupID string,
|
| 50 |
+
journeyType journeyType, dataIntegrityCheck dataIntegrityCheck,
|
| 51 |
+
tenantNames []string, pqEnabled bool, nodeMapping map[string]string,
|
| 52 |
+
override bool, overrideBucket, overridePath string,
|
| 53 |
+
) {
|
| 54 |
+
backupID := basebackupID
|
| 55 |
+
if override {
|
| 56 |
+
backupID = fmt.Sprintf("%s_%s", backupID, overrideBucket)
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
overrideString := ""
|
| 60 |
+
|
| 61 |
+
if override {
|
| 62 |
+
overrideString = fmt.Sprintf(" with override bucket: %s, path: %s", overrideBucket, overridePath)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if journeyType == clusterJourney && backend == "filesystem" {
|
| 66 |
+
t.Run("should fail backup/restore with local filesystem backend"+overrideString, func(t *testing.T) {
|
| 67 |
+
backupResp, err := helper.CreateBackup(t, helper.DefaultBackupConfig(), className, backend, backupID)
|
| 68 |
+
assert.Nil(t, backupResp)
|
| 69 |
+
assert.Error(t, err)
|
| 70 |
+
|
| 71 |
+
restoreResp, err := helper.RestoreBackup(t, helper.DefaultRestoreConfig(), className, backend, backupID, map[string]string{}, false)
|
| 72 |
+
assert.Nil(t, restoreResp)
|
| 73 |
+
assert.Error(t, err)
|
| 74 |
+
})
|
| 75 |
+
return
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
t.Run("create backup"+overrideString, func(t *testing.T) {
|
| 79 |
+
// Ensure cluster is in sync
|
| 80 |
+
if journeyType == clusterJourney {
|
| 81 |
+
time.Sleep(3 * time.Second)
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
cfg := helper.DefaultBackupConfig()
|
| 85 |
+
|
| 86 |
+
if override {
|
| 87 |
+
cfg.Bucket = overrideBucket
|
| 88 |
+
cfg.Path = overridePath
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
assert.EventuallyWithT(t, func(t1 *assert.CollectT) {
|
| 92 |
+
resp, err := helper.CreateBackup(t, cfg, className, backend, backupID)
|
| 93 |
+
helper.AssertRequestOk(t, resp, err, nil)
|
| 94 |
+
assert.Equal(t1, cfg.Bucket, resp.Payload.Bucket)
|
| 95 |
+
if cfg.Bucket != "" {
|
| 96 |
+
assert.Contains(t, resp.Payload.Path, cfg.Bucket)
|
| 97 |
+
}
|
| 98 |
+
if cfg.Path != "" {
|
| 99 |
+
assert.Contains(t, resp.Payload.Path, cfg.Path)
|
| 100 |
+
}
|
| 101 |
+
assert.Equal(t1, backupID, resp.Payload.ID)
|
| 102 |
+
assert.Equal(t1, className, resp.Payload.Classes[0])
|
| 103 |
+
assert.Equal(t1, "", resp.Payload.Error)
|
| 104 |
+
assert.Equal(t1, string(backup.Started), *resp.Payload.Status)
|
| 105 |
+
}, 240*time.Second, 500*time.Millisecond)
|
| 106 |
+
|
| 107 |
+
assert.EventuallyWithT(t, func(t1 *assert.CollectT) {
|
| 108 |
+
resp, err := helper.CreateBackupStatus(t, backend, backupID, overrideBucket, overridePath)
|
| 109 |
+
assert.Nil(t, err, "expected nil, got: %v", err)
|
| 110 |
+
|
| 111 |
+
assert.NotNil(t1, resp)
|
| 112 |
+
assert.NotNil(t1, resp.Payload)
|
| 113 |
+
assert.NotNil(t1, resp.Payload.Status)
|
| 114 |
+
assert.Equal(t1, backupID, resp.Payload.ID)
|
| 115 |
+
assert.Equal(t1, backend, resp.Payload.Backend)
|
| 116 |
+
assert.Contains(t1, resp.Payload.Path, overrideBucket)
|
| 117 |
+
assert.Contains(t1, resp.Payload.Path, overridePath)
|
| 118 |
+
|
| 119 |
+
assert.True(t1, (*resp.Payload.Status == "STARTED") || (*resp.Payload.Status == "SUCCESS"))
|
| 120 |
+
}, 120*time.Second, 1000*time.Millisecond)
|
| 121 |
+
|
| 122 |
+
assert.EventuallyWithT(t, func(t1 *assert.CollectT) {
|
| 123 |
+
statusResp, err := helper.CreateBackupStatus(t, backend, backupID, overrideBucket, overridePath)
|
| 124 |
+
|
| 125 |
+
helper.AssertRequestOk(t, statusResp, err, func() {
|
| 126 |
+
assert.NotNil(t1, statusResp)
|
| 127 |
+
assert.NotNil(t1, statusResp.Payload)
|
| 128 |
+
assert.NotNil(t1, statusResp.Payload.Status)
|
| 129 |
+
assert.Equal(t1, backupID, statusResp.Payload.ID)
|
| 130 |
+
assert.Equal(t1, backend, statusResp.Payload.Backend)
|
| 131 |
+
assert.Contains(t1, statusResp.Payload.Path, overrideBucket)
|
| 132 |
+
assert.Contains(t1, statusResp.Payload.Path, overridePath)
|
| 133 |
+
})
|
| 134 |
+
|
| 135 |
+
assert.Equal(t1, string(backup.Success), *statusResp.Payload.Status,
|
| 136 |
+
statusResp.Payload.Error)
|
| 137 |
+
}, 120*time.Second, 1000*time.Millisecond)
|
| 138 |
+
})
|
| 139 |
+
|
| 140 |
+
t.Run("delete class for restoration"+overrideString, func(t *testing.T) {
|
| 141 |
+
helper.DeleteClass(t, className)
|
| 142 |
+
time.Sleep(time.Second)
|
| 143 |
+
})
|
| 144 |
+
|
| 145 |
+
t.Run("restore backup"+overrideString, func(t *testing.T) {
|
| 146 |
+
cfg := helper.DefaultRestoreConfig()
|
| 147 |
+
|
| 148 |
+
if override {
|
| 149 |
+
cfg.Bucket = overrideBucket
|
| 150 |
+
cfg.Path = overridePath
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
t.Logf("cfg: %+v, className: %s, backend: %s, backupID: %s, nodeMapping: %+v\n", cfg, className, backend, backupID, nodeMapping)
|
| 154 |
+
resp, err := helper.RestoreBackup(t, cfg, className, backend, backupID, nodeMapping, false)
|
| 155 |
+
require.Nil(t, err, "expected nil, got: %v", err)
|
| 156 |
+
assert.Equal(t, backupID, resp.Payload.ID)
|
| 157 |
+
assert.Equal(t, backend, resp.Payload.Backend)
|
| 158 |
+
assert.Contains(t, resp.Payload.Path, overrideBucket)
|
| 159 |
+
assert.Contains(t, resp.Payload.Path, overridePath)
|
| 160 |
+
|
| 161 |
+
// wait for restore success
|
| 162 |
+
ticker := time.NewTicker(90 * time.Second)
|
| 163 |
+
wait:
|
| 164 |
+
for {
|
| 165 |
+
select {
|
| 166 |
+
case <-ticker.C:
|
| 167 |
+
break wait
|
| 168 |
+
default:
|
| 169 |
+
resp, err := helper.RestoreBackupStatus(t, backend, backupID, overrideBucket, overridePath)
|
| 170 |
+
helper.AssertRequestOk(t, resp, err, func() {
|
| 171 |
+
require.NotNil(t, resp)
|
| 172 |
+
require.NotNil(t, resp.Payload)
|
| 173 |
+
require.NotNil(t, resp.Payload.Status)
|
| 174 |
+
assert.Equal(t, backupID, resp.Payload.ID)
|
| 175 |
+
assert.Equal(t, backend, resp.Payload.Backend)
|
| 176 |
+
assert.Contains(t, resp.Payload.Path, overrideBucket)
|
| 177 |
+
assert.Contains(t, resp.Payload.Path, overridePath)
|
| 178 |
+
})
|
| 179 |
+
|
| 180 |
+
if *resp.Payload.Status == string(backup.Success) {
|
| 181 |
+
break wait
|
| 182 |
+
}
|
| 183 |
+
time.Sleep(1 * time.Second)
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
statusResp, err := helper.RestoreBackupStatus(t, backend, backupID, overrideBucket, overridePath)
|
| 188 |
+
helper.AssertRequestOk(t, statusResp, err, func() {
|
| 189 |
+
require.NotNil(t, statusResp)
|
| 190 |
+
require.NotNil(t, statusResp.Payload)
|
| 191 |
+
require.NotNil(t, statusResp.Payload.Status)
|
| 192 |
+
assert.Equal(t, backupID, resp.Payload.ID)
|
| 193 |
+
assert.Equal(t, backend, resp.Payload.Backend)
|
| 194 |
+
assert.Contains(t, resp.Payload.Path, overrideBucket)
|
| 195 |
+
assert.Contains(t, resp.Payload.Path, overridePath)
|
| 196 |
+
})
|
| 197 |
+
|
| 198 |
+
require.Equal(t, string(backup.Success), *statusResp.Payload.Status)
|
| 199 |
+
})
|
| 200 |
+
|
| 201 |
+
// Ensure that on restoring the class it is consistent on the followers
|
| 202 |
+
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
|
| 203 |
+
if tenantNames != nil {
|
| 204 |
+
for _, name := range tenantNames {
|
| 205 |
+
moduleshelper.EnsureClassExists(t, className, name)
|
| 206 |
+
if dataIntegrityCheck == checkClassAndDataPresence {
|
| 207 |
+
count := moduleshelper.GetClassCount(t, className, name)
|
| 208 |
+
assert.Equal(t, int64(500/len(tenantNames)), count)
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
} else {
|
| 212 |
+
moduleshelper.EnsureClassExists(t, className, singleTenant)
|
| 213 |
+
if dataIntegrityCheck == checkClassAndDataPresence {
|
| 214 |
+
count := moduleshelper.GetClassCount(t, className, singleTenant)
|
| 215 |
+
assert.Equal(t, int64(500), count)
|
| 216 |
+
if pqEnabled {
|
| 217 |
+
moduleshelper.EnsureCompressedVectorsRestored(t, className)
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
}, 5*time.Second, 500*time.Microsecond, "class doesn't exists in follower nodes")
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
func backupJourneyWithCancellation(t *testing.T, className, backend, basebackupID string, journeyType journeyType, overrideBucket, overridePath string) {
|
| 225 |
+
backupID := basebackupID
|
| 226 |
+
if overridePath != "" {
|
| 227 |
+
backupID = fmt.Sprintf("%s_%s", backupID, overrideBucket)
|
| 228 |
+
}
|
| 229 |
+
if journeyType == clusterJourney && backend == "filesystem" {
|
| 230 |
+
t.Run("should fail backup/restore with local filesystem backend", func(t *testing.T) {
|
| 231 |
+
backupResp, err := helper.CreateBackup(t, helper.DefaultBackupConfig(), className, backend, backupID)
|
| 232 |
+
assert.Nil(t, backupResp)
|
| 233 |
+
assert.Error(t, err)
|
| 234 |
+
|
| 235 |
+
restoreResp, err := helper.RestoreBackup(t, helper.DefaultRestoreConfig(), className, backend, backupID, map[string]string{}, false)
|
| 236 |
+
assert.Nil(t, restoreResp)
|
| 237 |
+
assert.Error(t, err)
|
| 238 |
+
})
|
| 239 |
+
return
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
t.Run("create and cancel backup", func(t *testing.T) {
|
| 243 |
+
// Ensure cluster is in sync
|
| 244 |
+
if journeyType == clusterJourney {
|
| 245 |
+
time.Sleep(5 * time.Second)
|
| 246 |
+
}
|
| 247 |
+
cfg := helper.DefaultBackupConfig()
|
| 248 |
+
cfg.Bucket = overrideBucket
|
| 249 |
+
cfg.Path = overridePath
|
| 250 |
+
|
| 251 |
+
resp, err := helper.CreateBackup(t, cfg, className, backend, backupID)
|
| 252 |
+
helper.AssertRequestOk(t, resp, err, nil)
|
| 253 |
+
|
| 254 |
+
t.Run("cancel backup", func(t *testing.T) {
|
| 255 |
+
require.Nil(t, helper.CancelBackup(t, backend, backupID))
|
| 256 |
+
})
|
| 257 |
+
|
| 258 |
+
// wait for cancellation
|
| 259 |
+
ticker := time.NewTicker(20 * time.Second)
|
| 260 |
+
wait:
|
| 261 |
+
for {
|
| 262 |
+
select {
|
| 263 |
+
case <-ticker.C:
|
| 264 |
+
break wait
|
| 265 |
+
default:
|
| 266 |
+
statusResp, err := helper.CreateBackupStatus(t, backend, backupID, overrideBucket, overridePath)
|
| 267 |
+
helper.AssertRequestOk(t, statusResp, err, func() {
|
| 268 |
+
require.NotNil(t, statusResp)
|
| 269 |
+
require.NotNil(t, statusResp.Payload)
|
| 270 |
+
require.NotNil(t, statusResp.Payload.Status)
|
| 271 |
+
})
|
| 272 |
+
|
| 273 |
+
if *statusResp.Payload.Status == string(backup.Cancelled) {
|
| 274 |
+
break wait
|
| 275 |
+
}
|
| 276 |
+
time.Sleep(500 * time.Millisecond)
|
| 277 |
+
}
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
statusResp, err := helper.CreateBackupStatus(t, backend, backupID, overrideBucket, overridePath)
|
| 281 |
+
helper.AssertRequestOk(t, statusResp, err, func() {
|
| 282 |
+
require.NotNil(t, statusResp)
|
| 283 |
+
require.NotNil(t, statusResp.Payload)
|
| 284 |
+
require.NotNil(t, statusResp.Payload.Status)
|
| 285 |
+
require.Equal(t, string(backup.Cancelled), *statusResp.Payload.Status)
|
| 286 |
+
})
|
| 287 |
+
})
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
func backupJourneyWithListing(t *testing.T, journeyType journeyType, className, backend, backupID string, overrideBucket, overridePath string) {
|
| 291 |
+
if journeyType == clusterJourney && backend == "filesystem" || overrideBucket != "" {
|
| 292 |
+
return
|
| 293 |
+
}
|
| 294 |
+
if overridePath != "" {
|
| 295 |
+
backupID = fmt.Sprintf("%s_%s", backupID, overrideBucket)
|
| 296 |
+
}
|
| 297 |
+
// Create a backup first
|
| 298 |
+
cfg := helper.DefaultBackupConfig()
|
| 299 |
+
if overrideBucket != "" {
|
| 300 |
+
cfg.Bucket = overrideBucket
|
| 301 |
+
cfg.Path = overridePath
|
| 302 |
+
}
|
| 303 |
+
resp, err := helper.CreateBackup(t, cfg, className, backend, fmt.Sprintf("%s_for_listing", backupID))
|
| 304 |
+
helper.AssertRequestOk(t, resp, err, nil)
|
| 305 |
+
|
| 306 |
+
// Wait for backup to complete
|
| 307 |
+
ticker := time.NewTicker(90 * time.Second)
|
| 308 |
+
wait:
|
| 309 |
+
for {
|
| 310 |
+
select {
|
| 311 |
+
case <-ticker.C:
|
| 312 |
+
break wait
|
| 313 |
+
default:
|
| 314 |
+
resp, err := helper.CreateBackupStatus(t, backend, fmt.Sprintf("%s_for_listing", backupID), overrideBucket, overridePath)
|
| 315 |
+
helper.AssertRequestOk(t, resp, err, nil)
|
| 316 |
+
if *resp.Payload.Status == string(backup.Success) {
|
| 317 |
+
break wait
|
| 318 |
+
}
|
| 319 |
+
time.Sleep(1 * time.Second)
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
// List backups and verify
|
| 324 |
+
listResp, err := helper.ListBackup(t, backend)
|
| 325 |
+
helper.AssertRequestOk(t, listResp, err, func() {
|
| 326 |
+
require.NotNil(t, listResp)
|
| 327 |
+
require.NotNil(t, listResp.Payload)
|
| 328 |
+
// Verify that our backup is in the list
|
| 329 |
+
found := false
|
| 330 |
+
for _, b := range listResp.Payload {
|
| 331 |
+
if b.ID == fmt.Sprintf("%s_for_listing", backupID) {
|
| 332 |
+
found = true
|
| 333 |
+
assert.Equal(t, string(backup.Success), b.Status)
|
| 334 |
+
assert.Contains(t, b.Classes, className)
|
| 335 |
+
break
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
assert.True(t, found, "backup not found in list")
|
| 339 |
+
})
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
func addTestClass(t *testing.T, className string, multiTenant bool) {
|
| 343 |
+
class := &models.Class{
|
| 344 |
+
Class: className,
|
| 345 |
+
ModuleConfig: map[string]interface{}{
|
| 346 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 347 |
+
"vectorizeClassName": true,
|
| 348 |
+
},
|
| 349 |
+
},
|
| 350 |
+
Properties: []*models.Property{
|
| 351 |
+
{
|
| 352 |
+
Name: "contents",
|
| 353 |
+
DataType: schema.DataTypeText.PropString(),
|
| 354 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 355 |
+
},
|
| 356 |
+
},
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
if multiTenant {
|
| 360 |
+
class.MultiTenancyConfig = &models.MultiTenancyConfig{
|
| 361 |
+
Enabled: true,
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
helper.CreateClass(t, class)
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
func addTestObjects(t *testing.T, className string, tenantNames []string) {
|
| 369 |
+
const (
|
| 370 |
+
noteLengthMin = 4
|
| 371 |
+
noteLengthMax = 1024
|
| 372 |
+
|
| 373 |
+
batchSize = 10
|
| 374 |
+
numBatches = 50
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
|
| 378 |
+
multiTenant := len(tenantNames) > 0
|
| 379 |
+
|
| 380 |
+
for i := 0; i < numBatches; i++ {
|
| 381 |
+
batch := make([]*models.Object, batchSize)
|
| 382 |
+
for j := 0; j < batchSize; j++ {
|
| 383 |
+
contentsLength := noteLengthMin + seededRand.Intn(noteLengthMax-noteLengthMin+1)
|
| 384 |
+
contents := helper.GetRandomString(contentsLength)
|
| 385 |
+
|
| 386 |
+
obj := models.Object{
|
| 387 |
+
Class: className,
|
| 388 |
+
Properties: map[string]interface{}{"contents": contents},
|
| 389 |
+
}
|
| 390 |
+
if multiTenant {
|
| 391 |
+
obj.Tenant = tenantNames[i]
|
| 392 |
+
}
|
| 393 |
+
batch[j] = &obj
|
| 394 |
+
}
|
| 395 |
+
helper.CreateObjectsBatch(t, batch)
|
| 396 |
+
}
|
| 397 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/backup_journey_tests.go
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"testing"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
// BackupJourneyTests_SingleNode this method gathers all backup related e2e tests
|
| 19 |
+
func BackupJourneyTests_SingleNode(t *testing.T, weaviateEndpoint, backend, className, backupID string, tenantNames []string, override bool, overrideBucket, overrideLocation string) {
|
| 20 |
+
if len(tenantNames) > 0 {
|
| 21 |
+
t.Run("multi-tenant single node backup", func(t *testing.T) {
|
| 22 |
+
singleNodeBackupJourneyTest(t, weaviateEndpoint, backend, className, backupID, tenantNames, false, override, overrideBucket, overrideLocation)
|
| 23 |
+
})
|
| 24 |
+
t.Run("multi-tenant single node backup with empty class", func(t *testing.T) {
|
| 25 |
+
singleNodeBackupEmptyClassJourneyTest(t, weaviateEndpoint, backend, className, backupID+"_empty", tenantNames, override, overrideBucket, overrideLocation)
|
| 26 |
+
})
|
| 27 |
+
} else {
|
| 28 |
+
// This is a simple test which covers almost the same scenario as singleNodeBackupJourneyTest
|
| 29 |
+
// but is left here to be expanded in the future with a more complex example
|
| 30 |
+
// like adding there a new reference property and trying to run the test with 2 classes which
|
| 31 |
+
// one of those classes is a class with a reference property
|
| 32 |
+
t.Run("backup and restore Books", func(t *testing.T) {
|
| 33 |
+
backupAndRestoreJourneyTest(t, weaviateEndpoint, backend, vectorsLegacy, overrideBucket, overrideLocation)
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
t.Run("backup and restore Books with named vectors", func(t *testing.T) {
|
| 37 |
+
backupAndRestoreJourneyTest(t, weaviateEndpoint, backend, vectorsNamed, overrideBucket, overrideLocation)
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
t.Run("backup and restore Books with mixed vectors", func(t *testing.T) {
|
| 41 |
+
backupAndRestoreJourneyTest(t, weaviateEndpoint, backend, vectorsMixed, overrideBucket, overrideLocation)
|
| 42 |
+
})
|
| 43 |
+
|
| 44 |
+
t.Run("single-tenant single node backup", func(t *testing.T) {
|
| 45 |
+
singleNodeBackupJourneyTest(t, weaviateEndpoint, backend, className, backupID, nil, false, override, overrideBucket, overrideLocation)
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
t.Run("single-tenant single node backup with PQ", func(t *testing.T) {
|
| 49 |
+
singleNodeBackupJourneyTest(t, weaviateEndpoint, backend, className, backupID+"_pq", nil, true, override, overrideBucket, overrideLocation)
|
| 50 |
+
})
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// BackupJourneyTests_Cluster this method gathers all backup related e2e tests to be run on a cluster
|
| 55 |
+
func BackupJourneyTests_Cluster(t *testing.T, backend, className, backupID string,
|
| 56 |
+
tenantNames []string, override bool, overrideBucket, overrideLocation string, weaviateEndpoints ...string,
|
| 57 |
+
) {
|
| 58 |
+
if len(weaviateEndpoints) <= 1 {
|
| 59 |
+
t.Fatal("must provide more than one node for cluster backup test")
|
| 60 |
+
}
|
| 61 |
+
coordinator := weaviateEndpoints[0]
|
| 62 |
+
|
| 63 |
+
if len(tenantNames) > 0 {
|
| 64 |
+
t.Run("multi-tenant cluster backup", func(t *testing.T) {
|
| 65 |
+
clusterBackupJourneyTest(t, backend, className, backupID+"mtcb",
|
| 66 |
+
coordinator, tenantNames, false, override, overrideBucket, overrideLocation, weaviateEndpoints[1:]...)
|
| 67 |
+
})
|
| 68 |
+
t.Run("multi-tenant cluster backup with empty class", func(t *testing.T) {
|
| 69 |
+
clusterBackupEmptyClassJourneyTest(t, backend, className, backupID+"_empty",
|
| 70 |
+
coordinator, tenantNames, override, overrideBucket, overrideLocation, weaviateEndpoints[1:]...)
|
| 71 |
+
})
|
| 72 |
+
} else {
|
| 73 |
+
t.Run("single-tenant cluster backup", func(t *testing.T) {
|
| 74 |
+
clusterBackupJourneyTest(t, backend, className, backupID+"_pq", coordinator, nil, true, override, overrideBucket, overrideLocation, weaviateEndpoints[1:]...)
|
| 75 |
+
})
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
t.Run("node mapping cluster backup", func(t *testing.T) {
|
| 79 |
+
clusterNodeMappingBackupJourneyTest(t, backend, className, backupID+"_with_node_mapping", coordinator, override, overrideBucket, overrideLocation, weaviateEndpoints[1:]...) // FIXME
|
| 80 |
+
})
|
| 81 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/cancel_from_restart_journey.go
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/require"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/backup"
|
| 22 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 23 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func CancelFromRestartJourney(t *testing.T, cluster *docker.DockerCompose, nodeName, backend string) {
|
| 28 |
+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
| 29 |
+
defer cancel()
|
| 30 |
+
|
| 31 |
+
nodeStopTimeout := 10 * time.Second
|
| 32 |
+
className := "CancelClass"
|
| 33 |
+
backupID := fmt.Sprintf("%s-backup-cancel", backend)
|
| 34 |
+
numObjects := 20_000
|
| 35 |
+
batchSize := 200
|
| 36 |
+
|
| 37 |
+
t.Run("create class", func(t *testing.T) {
|
| 38 |
+
helper.CreateClass(t, &models.Class{
|
| 39 |
+
Class: className,
|
| 40 |
+
Properties: []*models.Property{
|
| 41 |
+
{Name: "textProp", DataType: []string{"text"}},
|
| 42 |
+
},
|
| 43 |
+
})
|
| 44 |
+
})
|
| 45 |
+
|
| 46 |
+
t.Run("import data", func(t *testing.T) {
|
| 47 |
+
for i := 0; i < numObjects; i += batchSize {
|
| 48 |
+
batch := make([]*models.Object, batchSize)
|
| 49 |
+
for j := range batch {
|
| 50 |
+
batch[j] = &models.Object{
|
| 51 |
+
Class: className,
|
| 52 |
+
Properties: map[string]interface{}{
|
| 53 |
+
"textProp": fmt.Sprintf("object-%d", i+j),
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
helper.CreateObjectsBatch(t, batch)
|
| 58 |
+
}
|
| 59 |
+
})
|
| 60 |
+
|
| 61 |
+
t.Run("create backup", func(t *testing.T) {
|
| 62 |
+
resp, err := helper.CreateBackup(t, &models.BackupConfig{}, className, backend, backupID)
|
| 63 |
+
require.Nil(t, err)
|
| 64 |
+
require.NotNil(t, resp.Payload)
|
| 65 |
+
require.NotNil(t, resp.Payload.Status)
|
| 66 |
+
require.Equal(t, string(backup.Started), *resp.Payload.Status)
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
t.Run("restart node mid-backup", func(t *testing.T) {
|
| 70 |
+
err := cluster.Stop(ctx, nodeName, &nodeStopTimeout)
|
| 71 |
+
require.Nil(t, err)
|
| 72 |
+
err = cluster.Start(ctx, nodeName)
|
| 73 |
+
require.Nil(t, err)
|
| 74 |
+
helper.SetupClient(cluster.GetWeaviate().URI())
|
| 75 |
+
})
|
| 76 |
+
|
| 77 |
+
t.Run("validate that backup was set to CANCELED on restart", func(t *testing.T) {
|
| 78 |
+
resp, err := helper.CreateBackupStatus(t, backend, backupID, "", "")
|
| 79 |
+
require.Nil(t, err)
|
| 80 |
+
require.NotNil(t, resp)
|
| 81 |
+
require.NotNil(t, resp.Payload)
|
| 82 |
+
require.NotNil(t, resp.Payload.Status)
|
| 83 |
+
require.Equal(t, string(backup.Cancelled), *resp.Payload.Status)
|
| 84 |
+
})
|
| 85 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/cluster_backup_journey.go
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"math/rand"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func clusterBackupJourneyTest(t *testing.T, backend, className,
|
| 24 |
+
backupID, coordinatorEndpoint string, tenantNames []string, pqEnabled bool, override bool, overrideBucket, overrideLocation string,
|
| 25 |
+
nodeEndpoints ...string,
|
| 26 |
+
) {
|
| 27 |
+
uploaderEndpoint := nodeEndpoints[rand.Intn(len(nodeEndpoints))]
|
| 28 |
+
helper.SetupClient(uploaderEndpoint)
|
| 29 |
+
t.Logf("uploader selected -> %s:%s", helper.ServerHost, helper.ServerPort)
|
| 30 |
+
|
| 31 |
+
if len(tenantNames) > 0 {
|
| 32 |
+
// upload data to a node other than the coordinator
|
| 33 |
+
t.Run(fmt.Sprintf("add test data to endpoint: %s", uploaderEndpoint), func(t *testing.T) {
|
| 34 |
+
addTestClass(t, className, multiTenant)
|
| 35 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 36 |
+
for i := range tenantNames {
|
| 37 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 38 |
+
}
|
| 39 |
+
helper.CreateTenants(t, className, tenants)
|
| 40 |
+
addTestObjects(t, className, tenantNames)
|
| 41 |
+
})
|
| 42 |
+
} else {
|
| 43 |
+
// upload data to a node other than the coordinator
|
| 44 |
+
t.Run(fmt.Sprintf("add test data to endpoint: %s", uploaderEndpoint), func(t *testing.T) {
|
| 45 |
+
addTestClass(t, className, !multiTenant)
|
| 46 |
+
addTestObjects(t, className, nil)
|
| 47 |
+
})
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if pqEnabled {
|
| 51 |
+
pq := map[string]interface{}{
|
| 52 |
+
"enabled": true,
|
| 53 |
+
"segments": 1,
|
| 54 |
+
"centroids": 16,
|
| 55 |
+
}
|
| 56 |
+
helper.EnablePQ(t, className, pq)
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
helper.SetupClient(coordinatorEndpoint)
|
| 60 |
+
t.Logf("coordinator selected -> %s:%s", helper.ServerHost, helper.ServerPort)
|
| 61 |
+
|
| 62 |
+
// send backup requests to the chosen coordinator
|
| 63 |
+
t.Run(fmt.Sprintf("with coordinator endpoint: %s", coordinatorEndpoint), func(t *testing.T) {
|
| 64 |
+
backupJourney(t, className, backend, backupID, clusterJourney,
|
| 65 |
+
checkClassAndDataPresence, tenantNames, pqEnabled, map[string]string{}, override, overrideBucket, overrideLocation)
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
t.Run(fmt.Sprintf("cancelling with coordinator endpoint: %s", coordinatorEndpoint), func(t *testing.T) {
|
| 69 |
+
backupJourneyWithCancellation(t, className, backend, fmt.Sprintf("%s_with_cancellation", backupID), clusterJourney, overrideBucket, overrideLocation)
|
| 70 |
+
})
|
| 71 |
+
|
| 72 |
+
t.Run(fmt.Sprintf("listing backups with coordinator endpoint: %s", coordinatorEndpoint), func(t *testing.T) {
|
| 73 |
+
backupJourneyWithListing(t, clusterJourney, className, backend, backupID, overrideBucket, overrideLocation)
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
t.Run("cleanup", func(t *testing.T) {
|
| 77 |
+
helper.DeleteClass(t, className)
|
| 78 |
+
})
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func clusterBackupEmptyClassJourneyTest(t *testing.T, backend, className, backupID,
|
| 82 |
+
coordinatorEndpoint string, tenantNames []string, override bool, overrideBucket, overridePath string, nodeEndpoints ...string,
|
| 83 |
+
) {
|
| 84 |
+
uploaderEndpoint := nodeEndpoints[rand.Intn(len(nodeEndpoints))]
|
| 85 |
+
helper.SetupClient(uploaderEndpoint)
|
| 86 |
+
t.Logf("uploader selected -> %s:%s", helper.ServerHost, helper.ServerPort)
|
| 87 |
+
|
| 88 |
+
if len(tenantNames) > 0 {
|
| 89 |
+
// upload data to a node other than the coordinator
|
| 90 |
+
t.Run(fmt.Sprintf("add test data to endpoint: %s", uploaderEndpoint), func(t *testing.T) {
|
| 91 |
+
addTestClass(t, className, multiTenant)
|
| 92 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 93 |
+
for i := range tenantNames {
|
| 94 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 95 |
+
}
|
| 96 |
+
helper.CreateTenants(t, className, tenants)
|
| 97 |
+
})
|
| 98 |
+
} else {
|
| 99 |
+
// upload data to a node other than the coordinator
|
| 100 |
+
t.Run(fmt.Sprintf("add test data to endpoint: %s", uploaderEndpoint), func(t *testing.T) {
|
| 101 |
+
addTestClass(t, className, !multiTenant)
|
| 102 |
+
})
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
helper.SetupClient(coordinatorEndpoint)
|
| 106 |
+
t.Logf("coordinator selected -> %s:%s", helper.ServerHost, helper.ServerPort)
|
| 107 |
+
|
| 108 |
+
// send backup requests to the chosen coordinator
|
| 109 |
+
t.Run(fmt.Sprintf("with coordinator endpoint: %s", coordinatorEndpoint), func(t *testing.T) {
|
| 110 |
+
backupJourney(t, className, backend, backupID, clusterJourney,
|
| 111 |
+
checkClassPresenceOnly, tenantNames, false, map[string]string{}, false, "", "")
|
| 112 |
+
})
|
| 113 |
+
|
| 114 |
+
t.Run("cleanup", func(t *testing.T) {
|
| 115 |
+
helper.DeleteClass(t, className)
|
| 116 |
+
})
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
func clusterNodeMappingBackupJourneyTest(t *testing.T, backend, className, backupID, coordinatorEndpoint string, override bool, overrideBucket, overridePath string, nodeEndpoints ...string) {
|
| 120 |
+
uploaderEndpoint := nodeEndpoints[rand.Intn(len(nodeEndpoints))]
|
| 121 |
+
helper.SetupClient(uploaderEndpoint)
|
| 122 |
+
|
| 123 |
+
t.Logf("uploader selected -> %s:%s", helper.ServerHost, helper.ServerPort)
|
| 124 |
+
t.Run(fmt.Sprintf("add test data to endpoint: %s", uploaderEndpoint), func(t *testing.T) {
|
| 125 |
+
addTestClass(t, className, !multiTenant)
|
| 126 |
+
})
|
| 127 |
+
|
| 128 |
+
// send backup requests to the chosen coordinator, with nodeMapping.
|
| 129 |
+
// for nodeMapping we simply reverse the node(s) around, where node1 is now node2 and node2 is now node1.
|
| 130 |
+
t.Run(fmt.Sprintf("with coordinator endpoint: %s", coordinatorEndpoint), func(t *testing.T) {
|
| 131 |
+
backupJourney(t, className, backend, backupID, clusterJourney, checkClassPresenceOnly, nil, false,
|
| 132 |
+
map[string]string{"node1": "node2", "node2": "node1"}, override, overrideBucket, overridePath)
|
| 133 |
+
})
|
| 134 |
+
|
| 135 |
+
t.Run("cleanup", func(t *testing.T) {
|
| 136 |
+
helper.DeleteClass(t, className)
|
| 137 |
+
})
|
| 138 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/group_by_journey_tests.go
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"strings"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/documents"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func GroupBySingleAndMultiShardTests(t *testing.T, weaviateEndpoint string) {
|
| 28 |
+
if weaviateEndpoint != "" {
|
| 29 |
+
helper.SetupClient(weaviateEndpoint)
|
| 30 |
+
}
|
| 31 |
+
// helper methods
|
| 32 |
+
getGroup := func(value interface{}) map[string]interface{} {
|
| 33 |
+
group := value.(map[string]interface{})["_additional"].(map[string]interface{})["group"].(map[string]interface{})
|
| 34 |
+
return group
|
| 35 |
+
}
|
| 36 |
+
getGroupHits := func(group map[string]interface{}) (string, []string) {
|
| 37 |
+
result := []string{}
|
| 38 |
+
hits := group["hits"].([]interface{})
|
| 39 |
+
for _, hit := range hits {
|
| 40 |
+
additional := hit.(map[string]interface{})["_additional"].(map[string]interface{})
|
| 41 |
+
result = append(result, additional["id"].(string))
|
| 42 |
+
}
|
| 43 |
+
groupedBy := group["groupedBy"].(map[string]interface{})
|
| 44 |
+
groupedByValue := groupedBy["value"].(string)
|
| 45 |
+
return groupedByValue, result
|
| 46 |
+
}
|
| 47 |
+
getContents := func(t *testing.T, group map[string]interface{}) []string {
|
| 48 |
+
result := []string{}
|
| 49 |
+
hits := group["hits"].([]interface{})
|
| 50 |
+
for _, hit := range hits {
|
| 51 |
+
content, ok := hit.(map[string]interface{})["content"].(string)
|
| 52 |
+
require.True(t, ok, "hits{content} cannot be empty")
|
| 53 |
+
result = append(result, content)
|
| 54 |
+
}
|
| 55 |
+
return result
|
| 56 |
+
}
|
| 57 |
+
// test methods
|
| 58 |
+
create := func(t *testing.T, multishard bool) {
|
| 59 |
+
for _, class := range documents.ClassesContextionaryVectorizer(multishard) {
|
| 60 |
+
helper.CreateClass(t, class)
|
| 61 |
+
}
|
| 62 |
+
for _, obj := range documents.Objects() {
|
| 63 |
+
helper.CreateObject(t, obj)
|
| 64 |
+
helper.AssertGetObjectEventually(t, obj.Class, obj.ID)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// wait for the objects to be indexed
|
| 68 |
+
// TODO: remove this sleep when we have a better way to determine when the objects are indexed
|
| 69 |
+
time.Sleep(3 * time.Second)
|
| 70 |
+
}
|
| 71 |
+
groupBy := func(t *testing.T, groupsCount, objectsPerGroup int) {
|
| 72 |
+
query := `
|
| 73 |
+
{
|
| 74 |
+
Get{
|
| 75 |
+
Passage(
|
| 76 |
+
nearObject:{
|
| 77 |
+
id: "00000000-0000-0000-0000-000000000001"
|
| 78 |
+
}
|
| 79 |
+
groupBy:{
|
| 80 |
+
path:["ofDocument"]
|
| 81 |
+
groups:%v
|
| 82 |
+
objectsPerGroup:%v
|
| 83 |
+
}
|
| 84 |
+
){
|
| 85 |
+
_additional{
|
| 86 |
+
id
|
| 87 |
+
group{
|
| 88 |
+
groupedBy{value}
|
| 89 |
+
count
|
| 90 |
+
maxDistance
|
| 91 |
+
minDistance
|
| 92 |
+
hits {
|
| 93 |
+
content
|
| 94 |
+
_additional{
|
| 95 |
+
id
|
| 96 |
+
distance
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
`
|
| 105 |
+
result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, fmt.Sprintf(query, groupsCount, objectsPerGroup))
|
| 106 |
+
groups := result.Get("Get", "Passage").AsSlice()
|
| 107 |
+
|
| 108 |
+
require.Len(t, groups, groupsCount)
|
| 109 |
+
|
| 110 |
+
expectedResults := map[string][]string{}
|
| 111 |
+
|
| 112 |
+
groupedBy1 := `weaviate://localhost/Document/00000000-0000-0000-0000-000000000011`
|
| 113 |
+
expectedGroup1 := []string{
|
| 114 |
+
documents.PassageIDs[0].String(),
|
| 115 |
+
documents.PassageIDs[5].String(),
|
| 116 |
+
documents.PassageIDs[4].String(),
|
| 117 |
+
documents.PassageIDs[3].String(),
|
| 118 |
+
documents.PassageIDs[2].String(),
|
| 119 |
+
documents.PassageIDs[1].String(),
|
| 120 |
+
}
|
| 121 |
+
expectedResults[groupedBy1] = expectedGroup1
|
| 122 |
+
|
| 123 |
+
groupedBy2 := `weaviate://localhost/Document/00000000-0000-0000-0000-000000000012`
|
| 124 |
+
expectedGroup2 := []string{
|
| 125 |
+
documents.PassageIDs[6].String(),
|
| 126 |
+
documents.PassageIDs[7].String(),
|
| 127 |
+
}
|
| 128 |
+
expectedResults[groupedBy2] = expectedGroup2
|
| 129 |
+
|
| 130 |
+
groupsOrder := []string{groupedBy1, groupedBy2}
|
| 131 |
+
|
| 132 |
+
for i, current := range groups {
|
| 133 |
+
group := getGroup(current)
|
| 134 |
+
groupedBy, ids := getGroupHits(group)
|
| 135 |
+
assert.Equal(t, groupsOrder[i], groupedBy)
|
| 136 |
+
for j := range ids {
|
| 137 |
+
assert.Equal(t, expectedResults[groupedBy][j], ids[j])
|
| 138 |
+
}
|
| 139 |
+
contents := getContents(t, group)
|
| 140 |
+
for _, content := range contents {
|
| 141 |
+
assert.True(t, strings.HasPrefix(content, "Content of Passage"))
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
delete := func(t *testing.T) {
|
| 146 |
+
helper.DeleteClass(t, documents.Passage)
|
| 147 |
+
helper.DeleteClass(t, documents.Document)
|
| 148 |
+
}
|
| 149 |
+
// tests
|
| 150 |
+
tests := []struct {
|
| 151 |
+
name string
|
| 152 |
+
multishard bool
|
| 153 |
+
groups, objectsPerGroup int
|
| 154 |
+
}{
|
| 155 |
+
{
|
| 156 |
+
name: "single shard - 2 groups 10 objects per group",
|
| 157 |
+
multishard: false,
|
| 158 |
+
groups: 2,
|
| 159 |
+
objectsPerGroup: 10,
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
name: "multi shard - 2 groups 10 objects per group",
|
| 163 |
+
multishard: true,
|
| 164 |
+
groups: 2,
|
| 165 |
+
objectsPerGroup: 10,
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
name: "single shard - 1 groups 1 objects per group",
|
| 169 |
+
multishard: false,
|
| 170 |
+
groups: 1,
|
| 171 |
+
objectsPerGroup: 1,
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
name: "multi shard - 1 groups 1 objects per group",
|
| 175 |
+
multishard: true,
|
| 176 |
+
groups: 1,
|
| 177 |
+
objectsPerGroup: 1,
|
| 178 |
+
},
|
| 179 |
+
}
|
| 180 |
+
for _, tt := range tests {
|
| 181 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 182 |
+
t.Run("create", func(t *testing.T) {
|
| 183 |
+
create(t, tt.multishard)
|
| 184 |
+
})
|
| 185 |
+
t.Run("group by", func(t *testing.T) {
|
| 186 |
+
groupBy(t, tt.groups, tt.objectsPerGroup)
|
| 187 |
+
})
|
| 188 |
+
t.Run("delete", func(t *testing.T) {
|
| 189 |
+
delete(t)
|
| 190 |
+
// The delete is not strongly consistent but the create method will use a strongly consistent check to
|
| 191 |
+
// ensure that the class doesn't exists. Introduce the sleep to ensure we don't fail creating the class
|
| 192 |
+
// due to consistency issue on the subsequent run
|
| 193 |
+
time.Sleep(500 * time.Millisecond)
|
| 194 |
+
})
|
| 195 |
+
})
|
| 196 |
+
}
|
| 197 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/journey/single_node_backup_override_journey.go
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package journey
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"testing"
|
| 16 |
+
|
| 17 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 18 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
func singleNodeBackupJourneyTest(t *testing.T,
|
| 22 |
+
weaviateEndpoint, backend, className, backupID string,
|
| 23 |
+
tenantNames []string, pqEnabled bool, overrideActive bool, overrideBucket, overridePath string,
|
| 24 |
+
) {
|
| 25 |
+
if weaviateEndpoint != "" {
|
| 26 |
+
helper.SetupClient(weaviateEndpoint)
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
if len(tenantNames) > 0 {
|
| 30 |
+
t.Run("add test data", func(t *testing.T) {
|
| 31 |
+
addTestClass(t, className, multiTenant)
|
| 32 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 33 |
+
for i := range tenantNames {
|
| 34 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 35 |
+
}
|
| 36 |
+
helper.CreateTenants(t, className, tenants)
|
| 37 |
+
addTestObjects(t, className, tenantNames)
|
| 38 |
+
})
|
| 39 |
+
} else {
|
| 40 |
+
t.Run("add test data", func(t *testing.T) {
|
| 41 |
+
addTestClass(t, className, !multiTenant)
|
| 42 |
+
addTestObjects(t, className, nil)
|
| 43 |
+
})
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
if pqEnabled {
|
| 47 |
+
pq := map[string]interface{}{
|
| 48 |
+
"enabled": true,
|
| 49 |
+
"segments": 1,
|
| 50 |
+
"centroids": 16,
|
| 51 |
+
}
|
| 52 |
+
helper.EnablePQ(t, className, pq)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
t.Run("single node backup", func(t *testing.T) {
|
| 56 |
+
backupJourney(t, className, backend, backupID, singleNodeJourney,
|
| 57 |
+
checkClassAndDataPresence, tenantNames, pqEnabled, map[string]string{}, overrideActive, overrideBucket, overridePath)
|
| 58 |
+
})
|
| 59 |
+
|
| 60 |
+
t.Run("cleanup", func(t *testing.T) {
|
| 61 |
+
helper.DeleteClass(t, className)
|
| 62 |
+
})
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func singleNodeBackupEmptyClassJourneyTest(t *testing.T,
|
| 66 |
+
weaviateEndpoint, backend, className, backupID string,
|
| 67 |
+
tenantNames []string, overrideActive bool, overrideBucket, overridePath string,
|
| 68 |
+
) {
|
| 69 |
+
if weaviateEndpoint != "" {
|
| 70 |
+
helper.SetupClient(weaviateEndpoint)
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if len(tenantNames) <= 0 {
|
| 74 |
+
t.Skip("test is only relevant with tenancy enabled")
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
t.Run("add test class and tenant", func(t *testing.T) {
|
| 78 |
+
addTestClass(t, className, multiTenant)
|
| 79 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 80 |
+
for i := range tenantNames {
|
| 81 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 82 |
+
}
|
| 83 |
+
helper.CreateTenants(t, className, tenants)
|
| 84 |
+
})
|
| 85 |
+
|
| 86 |
+
t.Run("single node backup", func(t *testing.T) {
|
| 87 |
+
backupJourney(t, className, backend, backupID,
|
| 88 |
+
singleNodeJourney, checkClassPresenceOnly, tenantNames, false, map[string]string{}, overrideActive, overrideBucket, overridePath)
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
t.Run("cleanup", func(t *testing.T) {
|
| 92 |
+
helper.DeleteClass(t, className)
|
| 93 |
+
})
|
| 94 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/modules/modules_helper.go
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package moduleshelper
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"errors"
|
| 18 |
+
"fmt"
|
| 19 |
+
"os"
|
| 20 |
+
"path/filepath"
|
| 21 |
+
"testing"
|
| 22 |
+
"time"
|
| 23 |
+
|
| 24 |
+
"cloud.google.com/go/storage"
|
| 25 |
+
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
| 26 |
+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
|
| 27 |
+
"github.com/stretchr/testify/assert"
|
| 28 |
+
"github.com/stretchr/testify/require"
|
| 29 |
+
"google.golang.org/api/iterator"
|
| 30 |
+
"google.golang.org/api/option"
|
| 31 |
+
|
| 32 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 33 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
func EnsureClassExists(t *testing.T, className string, tenant string) {
|
| 37 |
+
query := fmt.Sprintf("{Aggregate{%s", className)
|
| 38 |
+
if tenant != "" {
|
| 39 |
+
query += fmt.Sprintf("(tenant:%q)", tenant)
|
| 40 |
+
}
|
| 41 |
+
query += " { meta { count}}}}"
|
| 42 |
+
resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 43 |
+
|
| 44 |
+
class := resp.Get("Aggregate", className).Result.([]interface{})
|
| 45 |
+
require.Len(t, class, 1)
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
func EnsureCompressedVectorsRestored(t *testing.T, className string) {
|
| 49 |
+
query := fmt.Sprintf("{Get{%s(limit:1){_additional{vector}}}}", className)
|
| 50 |
+
resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 51 |
+
|
| 52 |
+
class := resp.Get("Get", className).Result.([]interface{})
|
| 53 |
+
require.Len(t, class, 1)
|
| 54 |
+
vecResp := class[0].(map[string]interface{})["_additional"].(map[string]interface{})["vector"].([]interface{})
|
| 55 |
+
|
| 56 |
+
searchVec := graphqlhelper.Vec2String(graphqlhelper.ParseVec(t, vecResp))
|
| 57 |
+
|
| 58 |
+
limit := 10
|
| 59 |
+
query = fmt.Sprintf(
|
| 60 |
+
"{Get{%s(nearVector:{vector:%s} limit:%d){_additional{vector}}}}",
|
| 61 |
+
className, searchVec, limit)
|
| 62 |
+
resp = graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 63 |
+
class = resp.Get("Get", className).Result.([]interface{})
|
| 64 |
+
require.Len(t, class, limit)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
func GetClassCount(t *testing.T, className string, tenant string) int64 {
|
| 68 |
+
query := fmt.Sprintf("{Aggregate{%s", className)
|
| 69 |
+
if tenant != "" {
|
| 70 |
+
query += fmt.Sprintf("(tenant:%q)", tenant)
|
| 71 |
+
}
|
| 72 |
+
query += " { meta { count}}}}"
|
| 73 |
+
resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 74 |
+
|
| 75 |
+
class := resp.Get("Aggregate", className).Result.([]interface{})
|
| 76 |
+
require.Len(t, class, 1)
|
| 77 |
+
|
| 78 |
+
meta := class[0].(map[string]interface{})["meta"].(map[string]interface{})
|
| 79 |
+
|
| 80 |
+
countPayload := meta["count"].(json.Number)
|
| 81 |
+
|
| 82 |
+
count, err := countPayload.Int64()
|
| 83 |
+
require.Nil(t, err)
|
| 84 |
+
|
| 85 |
+
return count
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
func CreateTestFiles(t *testing.T, dirPath string) []string {
|
| 89 |
+
count := 5
|
| 90 |
+
filePaths := make([]string, count)
|
| 91 |
+
var fileName string
|
| 92 |
+
|
| 93 |
+
for i := 0; i < count; i += 1 {
|
| 94 |
+
fileName = fmt.Sprintf("file_%d.db", i)
|
| 95 |
+
filePaths[i] = filepath.Join(dirPath, fileName)
|
| 96 |
+
file, err := os.Create(filePaths[i])
|
| 97 |
+
if err != nil {
|
| 98 |
+
t.Fatalf("failed to create test file '%s': %s", fileName, err)
|
| 99 |
+
}
|
| 100 |
+
fmt.Fprintf(file, "This is content of db file named %s", fileName)
|
| 101 |
+
file.Close()
|
| 102 |
+
t.Logf("Created test file: %s\n", filePaths[i])
|
| 103 |
+
}
|
| 104 |
+
return filePaths
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
func CreateGCSBucket(ctx context.Context, t *testing.T, projectID, bucketName string) {
|
| 108 |
+
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
|
| 109 |
+
opts := []option.ClientOption{option.WithoutAuthentication()}
|
| 110 |
+
if emulatorHost := os.Getenv("STORAGE_EMULATOR_HOST"); emulatorHost != "" {
|
| 111 |
+
opts = append(opts, option.WithEndpoint(emulatorHost))
|
| 112 |
+
}
|
| 113 |
+
client, err := storage.NewClient(ctx, opts...)
|
| 114 |
+
assert.Nil(t, err)
|
| 115 |
+
defer client.Close()
|
| 116 |
+
|
| 117 |
+
assert.Nil(t, client.Bucket(bucketName).Create(ctx, projectID, nil))
|
| 118 |
+
}, 10*time.Second, 500*time.Millisecond)
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
func DeleteGCSBucket(ctx context.Context, t *testing.T, bucketName string) {
|
| 122 |
+
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
|
| 123 |
+
opts := []option.ClientOption{option.WithoutAuthentication()}
|
| 124 |
+
if emulatorHost := os.Getenv("STORAGE_EMULATOR_HOST"); emulatorHost != "" {
|
| 125 |
+
opts = append(opts, option.WithEndpoint(emulatorHost))
|
| 126 |
+
}
|
| 127 |
+
client, err := storage.NewClient(ctx, opts...)
|
| 128 |
+
assert.Nil(t, err)
|
| 129 |
+
defer client.Close()
|
| 130 |
+
|
| 131 |
+
bucket := client.Bucket(bucketName)
|
| 132 |
+
// we do iterate over objects because GCP doesn't allow deleting non-empty buckets
|
| 133 |
+
it := bucket.Objects(ctx, nil)
|
| 134 |
+
for {
|
| 135 |
+
objAttrs, err := it.Next()
|
| 136 |
+
if errors.Is(err, iterator.Done) {
|
| 137 |
+
break
|
| 138 |
+
}
|
| 139 |
+
assert.Nil(t, err)
|
| 140 |
+
|
| 141 |
+
obj := bucket.Object(objAttrs.Name)
|
| 142 |
+
err = obj.Delete(ctx)
|
| 143 |
+
assert.Nil(t, err)
|
| 144 |
+
}
|
| 145 |
+
assert.Nil(t, bucket.Delete(ctx))
|
| 146 |
+
}, 5*time.Second, 500*time.Millisecond)
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
func CreateAzureContainer(ctx context.Context, t *testing.T, endpoint, containerName string) {
|
| 150 |
+
t.Log("Creating azure container", containerName)
|
| 151 |
+
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
|
| 152 |
+
// First try to create a client to check if Azurite is ready
|
| 153 |
+
connectionString := "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://%s/devstoreaccount1;"
|
| 154 |
+
client, err := azblob.NewClientFromConnectionString(fmt.Sprintf(connectionString, endpoint), nil)
|
| 155 |
+
assert.NoError(collect, err, "Failed to create Azure client")
|
| 156 |
+
|
| 157 |
+
// Try to list containers to verify connection
|
| 158 |
+
pager := client.NewListContainersPager(nil)
|
| 159 |
+
_, err = pager.NextPage(ctx)
|
| 160 |
+
assert.NoError(collect, err, "Failed to list containers (Azurite might not be ready)")
|
| 161 |
+
|
| 162 |
+
// Now try to create the container
|
| 163 |
+
_, err = client.CreateContainer(ctx, containerName, nil)
|
| 164 |
+
if err != nil {
|
| 165 |
+
var respErr *azcore.ResponseError
|
| 166 |
+
if errors.As(err, &respErr) && respErr.ErrorCode == "ContainerAlreadyExists" {
|
| 167 |
+
// Container already exists, we're good
|
| 168 |
+
return
|
| 169 |
+
}
|
| 170 |
+
assert.NoError(collect, err, "Failed to create container %s", containerName)
|
| 171 |
+
}
|
| 172 |
+
}, 10*time.Second, 1*time.Second)
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
func DeleteAzureContainer(ctx context.Context, t *testing.T, endpoint, containerName string) {
|
| 176 |
+
t.Log("Deleting azure container", containerName)
|
| 177 |
+
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
|
| 178 |
+
connectionString := "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://%s/devstoreaccount1;"
|
| 179 |
+
client, err := azblob.NewClientFromConnectionString(fmt.Sprintf(connectionString, endpoint), nil)
|
| 180 |
+
assert.NoError(collect, err, "Failed to create Azure client")
|
| 181 |
+
|
| 182 |
+
_, err = client.DeleteContainer(ctx, containerName, nil)
|
| 183 |
+
if err != nil {
|
| 184 |
+
var respErr *azcore.ResponseError
|
| 185 |
+
if errors.As(err, &respErr) && respErr.ErrorCode == "ContainerNotFound" {
|
| 186 |
+
// Container doesn't exist, which is fine for deletion
|
| 187 |
+
return
|
| 188 |
+
}
|
| 189 |
+
assert.NoError(collect, err, "Failed to delete container %s", containerName)
|
| 190 |
+
}
|
| 191 |
+
}, 10*time.Second, 1*time.Second)
|
| 192 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/articles/articles.go
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package articles
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"github.com/go-openapi/strfmt"
|
| 16 |
+
"github.com/google/uuid"
|
| 17 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 18 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
func ArticlesClass() *models.Class {
|
| 22 |
+
return &models.Class{
|
| 23 |
+
Class: "Article",
|
| 24 |
+
Properties: []*models.Property{
|
| 25 |
+
{
|
| 26 |
+
Name: "title",
|
| 27 |
+
DataType: schema.DataTypeText.PropString(),
|
| 28 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
Name: "hasParagraphs",
|
| 32 |
+
DataType: []string{"Paragraph"},
|
| 33 |
+
},
|
| 34 |
+
},
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
func ParagraphsClass() *models.Class {
|
| 39 |
+
return &models.Class{
|
| 40 |
+
Class: "Paragraph",
|
| 41 |
+
Properties: []*models.Property{
|
| 42 |
+
{
|
| 43 |
+
Name: "contents",
|
| 44 |
+
DataType: schema.DataTypeText.PropString(),
|
| 45 |
+
},
|
| 46 |
+
},
|
| 47 |
+
Vectorizer: "none",
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
type Article models.Object
|
| 52 |
+
|
| 53 |
+
func (a *Article) WithID(id strfmt.UUID) *Article {
|
| 54 |
+
a.ID = id
|
| 55 |
+
return a
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
func (a *Article) WithReferences(refs ...*models.SingleRef) *Article {
|
| 59 |
+
props := a.Properties.(map[string]interface{})
|
| 60 |
+
props["hasParagraphs"] = models.MultipleRef(refs)
|
| 61 |
+
return a
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
func (a *Article) WithTitle(title string) *Article {
|
| 65 |
+
props := a.Properties.(map[string]interface{})
|
| 66 |
+
props["title"] = title
|
| 67 |
+
return a
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
func (a *Article) WithTenant(tk string) *Article {
|
| 71 |
+
a.Tenant = tk
|
| 72 |
+
return a
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
func (a *Article) WithVector(vector []float32) *Article {
|
| 76 |
+
a.Vector = vector
|
| 77 |
+
return a
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
func (a *Article) Object() *models.Object {
|
| 81 |
+
obj := models.Object(*a)
|
| 82 |
+
return &obj
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
func NewArticle() *Article {
|
| 86 |
+
return &Article{
|
| 87 |
+
Class: "Article",
|
| 88 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 89 |
+
Properties: make(map[string]interface{}),
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
type Paragraph models.Object
|
| 94 |
+
|
| 95 |
+
func (p *Paragraph) WithID(id strfmt.UUID) *Paragraph {
|
| 96 |
+
p.ID = id
|
| 97 |
+
return p
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
func (p *Paragraph) WithContents(contents string) *Paragraph {
|
| 101 |
+
props := p.Properties.(map[string]interface{})
|
| 102 |
+
props["contents"] = contents
|
| 103 |
+
return p
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
func (p *Paragraph) WithVector(vec []float32) *Paragraph {
|
| 107 |
+
p.Vector = vec
|
| 108 |
+
return p
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
func (p *Paragraph) WithTenant(tk string) *Paragraph {
|
| 112 |
+
p.Tenant = tk
|
| 113 |
+
return p
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
func (p *Paragraph) Object() *models.Object {
|
| 117 |
+
obj := models.Object(*p)
|
| 118 |
+
return &obj
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
func NewParagraph() *Paragraph {
|
| 122 |
+
return &Paragraph{
|
| 123 |
+
Class: "Paragraph",
|
| 124 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 125 |
+
Properties: make(map[string]interface{}),
|
| 126 |
+
}
|
| 127 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/books/books.go
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package books
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"github.com/go-openapi/strfmt"
|
| 16 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 17 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 18 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 19 |
+
"github.com/weaviate/weaviate/usecases/config"
|
| 20 |
+
"google.golang.org/protobuf/types/known/structpb"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const DefaultClassName = "Books"
|
| 24 |
+
|
| 25 |
+
const (
|
| 26 |
+
Dune strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e000"
|
| 27 |
+
ProjectHailMary strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e001"
|
| 28 |
+
TheLordOfTheIceGarden strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e002"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
func ClassContextionaryVectorizer() *models.Class {
|
| 32 |
+
return class(DefaultClassName, "text2vec-contextionary")
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
func ClassModel2VecVectorizer() *models.Class {
|
| 36 |
+
return class(DefaultClassName, "text2vec-model2vec")
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func ClassModel2VecVectorizerWithName(className string) *models.Class {
|
| 40 |
+
return class(className, "text2vec-model2vec")
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
func ClassOpenAIWithOptions() *models.Class {
|
| 44 |
+
c := class(DefaultClassName, "text2vec-openai")
|
| 45 |
+
c.ModuleConfig.(map[string]interface{})["text2vec-openai"] = map[string]interface{}{
|
| 46 |
+
"model": "text-embedding-3-large",
|
| 47 |
+
"dimensions": 3072,
|
| 48 |
+
}
|
| 49 |
+
return c
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func ClassNamedOpenAIWithOptions() *models.Class {
|
| 53 |
+
vc := map[string]models.VectorConfig{
|
| 54 |
+
"all": {
|
| 55 |
+
Vectorizer: map[string]interface{}{
|
| 56 |
+
"text2vec-openai": map[string]interface{}{
|
| 57 |
+
"model": "text-embedding-3-large",
|
| 58 |
+
"dimensions": 3072,
|
| 59 |
+
},
|
| 60 |
+
},
|
| 61 |
+
VectorIndexType: "hnsw",
|
| 62 |
+
},
|
| 63 |
+
}
|
| 64 |
+
return classNamedVectors(DefaultClassName, vc)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
func ClassNamedContextionaryVectorizer() *models.Class {
|
| 68 |
+
vc := map[string]models.VectorConfig{
|
| 69 |
+
"all": {
|
| 70 |
+
Vectorizer: map[string]interface{}{
|
| 71 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 72 |
+
"vectorizeClassName": false,
|
| 73 |
+
},
|
| 74 |
+
},
|
| 75 |
+
VectorIndexType: "hnsw",
|
| 76 |
+
},
|
| 77 |
+
"title": {
|
| 78 |
+
Vectorizer: map[string]interface{}{
|
| 79 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 80 |
+
"vectorizeClassName": false,
|
| 81 |
+
"properties": []string{"title"},
|
| 82 |
+
},
|
| 83 |
+
},
|
| 84 |
+
VectorIndexType: "hnsw",
|
| 85 |
+
},
|
| 86 |
+
"description": {
|
| 87 |
+
Vectorizer: map[string]interface{}{
|
| 88 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 89 |
+
"vectorizeClassName": false,
|
| 90 |
+
"properties": []string{"description"},
|
| 91 |
+
},
|
| 92 |
+
},
|
| 93 |
+
VectorIndexType: "hnsw",
|
| 94 |
+
},
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
return classNamedVectors(DefaultClassName, vc)
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
func ClassMixedContextionaryVectorizer() *models.Class {
|
| 101 |
+
vc := map[string]models.VectorConfig{
|
| 102 |
+
"contextionary_all": {
|
| 103 |
+
Vectorizer: map[string]interface{}{
|
| 104 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 105 |
+
"vectorizeClassName": true,
|
| 106 |
+
},
|
| 107 |
+
},
|
| 108 |
+
VectorIndexType: "hnsw",
|
| 109 |
+
},
|
| 110 |
+
"title": {
|
| 111 |
+
Vectorizer: map[string]interface{}{
|
| 112 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 113 |
+
"vectorizeClassName": false,
|
| 114 |
+
"properties": []string{"title"},
|
| 115 |
+
},
|
| 116 |
+
},
|
| 117 |
+
VectorIndexType: "hnsw",
|
| 118 |
+
},
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return classBase(DefaultClassName, "text2vec-contextionary", vc)
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
func ClassContextionaryVectorizerWithName(className string) *models.Class {
|
| 125 |
+
return class(className, "text2vec-contextionary")
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
func ClassContextionaryVectorizerWithSumTransformers() *models.Class {
|
| 129 |
+
return class(DefaultClassName, "text2vec-contextionary", "sum-transformers")
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
func ClassContextionaryVectorizerWithQnATransformers() *models.Class {
|
| 133 |
+
return class(DefaultClassName, "text2vec-contextionary", "qna-transformers")
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
func ClassTransformersVectorizer() *models.Class {
|
| 137 |
+
return class(DefaultClassName, "text2vec-transformers")
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
func ClassTransformersVectorizerWithName(className string) *models.Class {
|
| 141 |
+
return class(className, "text2vec-transformers")
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
func ClassTransformersVectorizerWithQnATransformersWithName(className string) *models.Class {
|
| 145 |
+
return class(className, "text2vec-transformers", "qna-transformers")
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
func ClassCLIPVectorizer() *models.Class {
|
| 149 |
+
c := class(DefaultClassName, "multi2vec-clip")
|
| 150 |
+
c.ModuleConfig.(map[string]interface{})["multi2vec-clip"] = map[string]interface{}{
|
| 151 |
+
"textFields": []string{"title", "tags", "description"},
|
| 152 |
+
}
|
| 153 |
+
return c
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
func ClassBindVectorizer() *models.Class {
|
| 157 |
+
c := class(DefaultClassName, "multi2vec-bind")
|
| 158 |
+
c.ModuleConfig.(map[string]interface{})["multi2vec-bind"] = map[string]interface{}{
|
| 159 |
+
"textFields": []string{"title", "tags", "description"},
|
| 160 |
+
}
|
| 161 |
+
return c
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
func classNamedVectors(className string, vectorConfig map[string]models.VectorConfig, additionalModules ...string) *models.Class {
|
| 165 |
+
return classBase(className, "", vectorConfig, additionalModules...)
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
func class(className, vectorizer string, additionalModules ...string) *models.Class {
|
| 169 |
+
return classBase(className, vectorizer, nil, additionalModules...)
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
func classBase(className, vectorizer string, vectorConfig map[string]models.VectorConfig, additionalModules ...string) *models.Class {
|
| 173 |
+
moduleConfig := map[string]interface{}{}
|
| 174 |
+
propModuleConfig := map[string]interface{}{}
|
| 175 |
+
if vectorizer != "" {
|
| 176 |
+
moduleConfig[vectorizer] = map[string]interface{}{
|
| 177 |
+
"vectorizeClassName": true,
|
| 178 |
+
}
|
| 179 |
+
propModuleConfig[vectorizer] = map[string]interface{}{"skip": false}
|
| 180 |
+
}
|
| 181 |
+
if len(additionalModules) > 0 {
|
| 182 |
+
for _, module := range additionalModules {
|
| 183 |
+
moduleConfig[module] = map[string]interface{}{}
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
return &models.Class{
|
| 188 |
+
Class: className,
|
| 189 |
+
Vectorizer: vectorizer,
|
| 190 |
+
ModuleConfig: moduleConfig,
|
| 191 |
+
InvertedIndexConfig: &models.InvertedIndexConfig{
|
| 192 |
+
IndexNullState: true,
|
| 193 |
+
IndexTimestamps: true,
|
| 194 |
+
IndexPropertyLength: true,
|
| 195 |
+
UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND,
|
| 196 |
+
},
|
| 197 |
+
VectorConfig: vectorConfig,
|
| 198 |
+
Properties: []*models.Property{
|
| 199 |
+
{
|
| 200 |
+
Name: "title",
|
| 201 |
+
DataType: schema.DataTypeText.PropString(),
|
| 202 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 203 |
+
ModuleConfig: propModuleConfig,
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
Name: "tags",
|
| 207 |
+
DataType: schema.DataTypeTextArray.PropString(),
|
| 208 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 209 |
+
ModuleConfig: propModuleConfig,
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
Name: "description",
|
| 213 |
+
DataType: schema.DataTypeText.PropString(),
|
| 214 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 215 |
+
ModuleConfig: propModuleConfig,
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
Name: "meta", DataType: schema.DataTypeObject.PropString(),
|
| 219 |
+
NestedProperties: []*models.NestedProperty{
|
| 220 |
+
{Name: "isbn", DataType: schema.DataTypeText.PropString()},
|
| 221 |
+
{
|
| 222 |
+
Name: "obj", DataType: schema.DataTypeObject.PropString(),
|
| 223 |
+
NestedProperties: []*models.NestedProperty{{Name: "text", DataType: schema.DataTypeText.PropString()}},
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
Name: "objs", DataType: schema.DataTypeObjectArray.PropString(),
|
| 227 |
+
NestedProperties: []*models.NestedProperty{{Name: "text", DataType: schema.DataTypeText.PropString()}},
|
| 228 |
+
},
|
| 229 |
+
},
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
Name: "reviews", DataType: schema.DataTypeObjectArray.PropString(),
|
| 233 |
+
NestedProperties: []*models.NestedProperty{{Name: "tags", DataType: schema.DataTypeTextArray.PropString()}},
|
| 234 |
+
},
|
| 235 |
+
},
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
func Objects() []*models.Object {
|
| 240 |
+
return objects(DefaultClassName)
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
func BatchObjects() []*pb.BatchObject {
|
| 244 |
+
return batchObjects(DefaultClassName)
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
func ObjectsWithName(className string) []*models.Object {
|
| 248 |
+
return objects(className)
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
func objects(className string) []*models.Object {
|
| 252 |
+
return []*models.Object{
|
| 253 |
+
{
|
| 254 |
+
Class: className,
|
| 255 |
+
ID: Dune,
|
| 256 |
+
Properties: map[string]interface{}{
|
| 257 |
+
"title": "Dune",
|
| 258 |
+
"description": "Dune is a 1965 epic science fiction novel by American author Frank Herbert.",
|
| 259 |
+
},
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
Class: className,
|
| 263 |
+
ID: ProjectHailMary,
|
| 264 |
+
Properties: map[string]interface{}{
|
| 265 |
+
"title": "Project Hail Mary",
|
| 266 |
+
"description": "Project Hail Mary is a 2021 science fiction novel by American novelist Andy Weir.",
|
| 267 |
+
},
|
| 268 |
+
},
|
| 269 |
+
{
|
| 270 |
+
Class: className,
|
| 271 |
+
ID: TheLordOfTheIceGarden,
|
| 272 |
+
Properties: map[string]interface{}{
|
| 273 |
+
"title": "The Lord of the Ice Garden",
|
| 274 |
+
"tags": []string{"three", "three", "three"},
|
| 275 |
+
"description": "The Lord of the Ice Garden (Polish: Pan Lodowego Ogrodu) is a four-volume science fiction and fantasy novel by Polish writer Jaroslaw Grzedowicz.",
|
| 276 |
+
},
|
| 277 |
+
},
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
func batchObjects(className string) []*pb.BatchObject {
|
| 282 |
+
scifi := "sci-fi"
|
| 283 |
+
return []*pb.BatchObject{
|
| 284 |
+
{
|
| 285 |
+
Collection: className,
|
| 286 |
+
Uuid: Dune.String(),
|
| 287 |
+
Properties: &pb.BatchObject_Properties{
|
| 288 |
+
NonRefProperties: &structpb.Struct{
|
| 289 |
+
Fields: map[string]*structpb.Value{
|
| 290 |
+
"title": structpb.NewStringValue("Dune"),
|
| 291 |
+
"description": structpb.NewStringValue("Dune is a 1965 epic science fiction novel by American author Frank Herbert."),
|
| 292 |
+
},
|
| 293 |
+
},
|
| 294 |
+
ObjectProperties: []*pb.ObjectProperties{{
|
| 295 |
+
PropName: "meta",
|
| 296 |
+
Value: &pb.ObjectPropertiesValue{
|
| 297 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"isbn": structpb.NewStringValue("978-0593099322")}},
|
| 298 |
+
ObjectProperties: []*pb.ObjectProperties{{
|
| 299 |
+
PropName: "obj",
|
| 300 |
+
Value: &pb.ObjectPropertiesValue{
|
| 301 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
|
| 302 |
+
},
|
| 303 |
+
}},
|
| 304 |
+
ObjectArrayProperties: []*pb.ObjectArrayProperties{{
|
| 305 |
+
PropName: "objs",
|
| 306 |
+
Values: []*pb.ObjectPropertiesValue{{
|
| 307 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
|
| 308 |
+
}},
|
| 309 |
+
}},
|
| 310 |
+
},
|
| 311 |
+
}},
|
| 312 |
+
ObjectArrayProperties: []*pb.ObjectArrayProperties{{
|
| 313 |
+
PropName: "reviews",
|
| 314 |
+
Values: []*pb.ObjectPropertiesValue{{TextArrayProperties: []*pb.TextArrayProperties{{PropName: "tags", Values: []string{scifi, "epic"}}}}},
|
| 315 |
+
}},
|
| 316 |
+
},
|
| 317 |
+
},
|
| 318 |
+
{
|
| 319 |
+
Collection: className,
|
| 320 |
+
Uuid: ProjectHailMary.String(),
|
| 321 |
+
Properties: &pb.BatchObject_Properties{
|
| 322 |
+
NonRefProperties: &structpb.Struct{
|
| 323 |
+
Fields: map[string]*structpb.Value{
|
| 324 |
+
"title": structpb.NewStringValue("Project Hail Mary"),
|
| 325 |
+
"description": structpb.NewStringValue("Project Hail Mary is a 2021 science fiction novel by American novelist Andy Weir."),
|
| 326 |
+
},
|
| 327 |
+
},
|
| 328 |
+
ObjectProperties: []*pb.ObjectProperties{{
|
| 329 |
+
PropName: "meta",
|
| 330 |
+
Value: &pb.ObjectPropertiesValue{
|
| 331 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"isbn": structpb.NewStringValue("978-0593135204")}},
|
| 332 |
+
ObjectProperties: []*pb.ObjectProperties{{
|
| 333 |
+
PropName: "obj",
|
| 334 |
+
Value: &pb.ObjectPropertiesValue{NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}}},
|
| 335 |
+
}},
|
| 336 |
+
ObjectArrayProperties: []*pb.ObjectArrayProperties{{
|
| 337 |
+
PropName: "objs",
|
| 338 |
+
Values: []*pb.ObjectPropertiesValue{{
|
| 339 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
|
| 340 |
+
}},
|
| 341 |
+
}},
|
| 342 |
+
},
|
| 343 |
+
}},
|
| 344 |
+
ObjectArrayProperties: []*pb.ObjectArrayProperties{{
|
| 345 |
+
PropName: "reviews",
|
| 346 |
+
Values: []*pb.ObjectPropertiesValue{{TextArrayProperties: []*pb.TextArrayProperties{{PropName: "tags", Values: []string{scifi}}}}},
|
| 347 |
+
}},
|
| 348 |
+
},
|
| 349 |
+
},
|
| 350 |
+
{
|
| 351 |
+
Collection: className,
|
| 352 |
+
Uuid: TheLordOfTheIceGarden.String(),
|
| 353 |
+
Properties: &pb.BatchObject_Properties{
|
| 354 |
+
NonRefProperties: &structpb.Struct{
|
| 355 |
+
Fields: map[string]*structpb.Value{
|
| 356 |
+
"title": structpb.NewStringValue("The Lord of the Ice Garden"),
|
| 357 |
+
"description": structpb.NewStringValue("The Lord of the Ice Garden (Polish: Pan Lodowego Ogrodu) is a four-volume science fiction and fantasy novel by Polish writer Jaroslaw Grzedowicz."),
|
| 358 |
+
},
|
| 359 |
+
},
|
| 360 |
+
ObjectProperties: []*pb.ObjectProperties{{
|
| 361 |
+
PropName: "meta",
|
| 362 |
+
Value: &pb.ObjectPropertiesValue{
|
| 363 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"isbn": structpb.NewStringValue("978-8374812962")}},
|
| 364 |
+
ObjectProperties: []*pb.ObjectProperties{{
|
| 365 |
+
PropName: "obj",
|
| 366 |
+
Value: &pb.ObjectPropertiesValue{NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}}},
|
| 367 |
+
}},
|
| 368 |
+
ObjectArrayProperties: []*pb.ObjectArrayProperties{{
|
| 369 |
+
PropName: "objs",
|
| 370 |
+
Values: []*pb.ObjectPropertiesValue{{
|
| 371 |
+
NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
|
| 372 |
+
}},
|
| 373 |
+
}},
|
| 374 |
+
},
|
| 375 |
+
}},
|
| 376 |
+
ObjectArrayProperties: []*pb.ObjectArrayProperties{{
|
| 377 |
+
PropName: "reviews",
|
| 378 |
+
Values: []*pb.ObjectPropertiesValue{{TextArrayProperties: []*pb.TextArrayProperties{{PropName: "tags", Values: []string{scifi, "fantasy"}}}}},
|
| 379 |
+
}},
|
| 380 |
+
},
|
| 381 |
+
},
|
| 382 |
+
}
|
| 383 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/cities/cities.go
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package cities
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
"time"
|
| 18 |
+
|
| 19 |
+
"github.com/go-openapi/strfmt"
|
| 20 |
+
"github.com/google/uuid"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 22 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 23 |
+
"github.com/weaviate/weaviate/entities/schema/crossref"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 25 |
+
"github.com/weaviate/weaviate/usecases/config"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
const (
|
| 29 |
+
Country = "Country"
|
| 30 |
+
City = "City"
|
| 31 |
+
Airport = "Airport"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
const (
|
| 35 |
+
Netherlands strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e57a"
|
| 36 |
+
Germany strfmt.UUID = "561eea29-b733-4079-b50b-cfabd78190b7"
|
| 37 |
+
Amsterdam strfmt.UUID = "8f5f8e44-d348-459c-88b1-c1a44bb8f8be"
|
| 38 |
+
Rotterdam strfmt.UUID = "660db307-a163-41d2-8182-560782cd018f"
|
| 39 |
+
Berlin strfmt.UUID = "9b9cbea5-e87e-4cd0-89af-e2f424fd52d6"
|
| 40 |
+
Dusseldorf strfmt.UUID = "6ffb03f8-a853-4ec5-a5d8-302e45aaaf13"
|
| 41 |
+
Missingisland strfmt.UUID = "823abeca-eef3-41c7-b587-7a6977b08003"
|
| 42 |
+
Nullisland strfmt.UUID = "823abeca-eef3-41c7-b587-7a6977b08067"
|
| 43 |
+
Airport1 strfmt.UUID = "4770bb19-20fd-406e-ac64-9dac54c27a0f"
|
| 44 |
+
Airport2 strfmt.UUID = "cad6ab9b-5bb9-4388-a933-a5bdfd23db37"
|
| 45 |
+
Airport3 strfmt.UUID = "55a4dbbb-e2af-4b2a-901d-98146d1eeca7"
|
| 46 |
+
Airport4 strfmt.UUID = "62d15920-b546-4844-bc87-3ae33268fab5"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
const (
|
| 50 |
+
HistoryAmsterdam = "Due to its geographical location in what used to be wet peatland, the founding of Amsterdam is of a younger age than the founding of other urban centers in the Low Countries. However, in and around the area of what later became Amsterdam, local farmers settled as early as three millennia ago. They lived along the prehistoric IJ river and upstream of its tributary Amstel. The prehistoric IJ was a shallow and quiet stream in peatland behind beach ridges. This secluded area could grow there into an important local settlement center, especially in the late Bronze Age, the Iron Age and the Roman Age. Neolithic and Roman artefacts have also been found downstream of this area, in the prehistoric Amstel bedding under Amsterdam's Damrak and Rokin, such as shards of Bell Beaker culture pottery (2200-2000 BC) and a granite grinding stone (2700-2750 BC).[27][28] But the location of these artefacts around the river banks of the Amstel probably point to a presence of a modest semi-permanent or seasonal settlement of the previous mentioned local farmers. A permanent settlement would not have been possible, since the river mouth and the banks of the Amstel in this period in time were too wet for permanent habitation"
|
| 51 |
+
HistoryRotterdam = "On 7 July 1340, Count Willem IV of Holland granted city rights to Rotterdam, whose population then was only a few thousand.[14] Around the year 1350, a shipping canal (the Rotterdamse Schie) was completed, which provided Rotterdam access to the larger towns in the north, allowing it to become a local trans-shipment centre between the Netherlands, England and Germany, and to urbanize"
|
| 52 |
+
HistoryBerlin = "The earliest evidence of settlements in the area of today's Berlin are remnants of a house foundation dated to 1174, found in excavations in Berlin Mitte,[27] and a wooden beam dated from approximately 1192.[28] The first written records of towns in the area of present-day Berlin date from the late 12th century. Spandau is first mentioned in 1197 and Köpenick in 1209, although these areas did not join Berlin until 1920.[29] The central part of Berlin can be traced back to two towns. Cölln on the Fischerinsel is first mentioned in a 1237 document, and Berlin, across the Spree in what is now called the Nikolaiviertel, is referenced in a document from 1244.[28] 1237 is considered the founding date of the city.[30] The two towns over time formed close economic and social ties, and profited from the staple right on the two important trade routes Via Imperii and from Bruges to Novgorod.[12] In 1307, they formed an alliance with a common external policy, their internal administrations still being separated"
|
| 53 |
+
HistoryDusseldorf = "The first written mention of Düsseldorf (then called Dusseldorp in the local Low Rhenish dialect) dates back to 1135. Under Emperor Friedrich Barbarossa the small town of Kaiserswerth to the north of Düsseldorf became a well-fortified outpost, where soldiers kept a watchful eye on every movement on the Rhine. Kaiserswerth eventually became a suburb of Düsseldorf in 1929. In 1186, Düsseldorf came under the rule of the Counts of Berg. 14 August 1288 is one of the most important dates in the history of Düsseldorf. On this day the sovereign Count Adolf VIII of Berg granted the village on the banks of the Düssel town privileges. Before this, a bloody struggle for power had taken place between the Archbishop of Cologne and the count of Berg, culminating in the Battle of Worringen"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
func CreateCountryCityAirportSchema(t *testing.T, host string) {
|
| 57 |
+
helper.SetupClient(host)
|
| 58 |
+
helper.CreateClass(t, &models.Class{
|
| 59 |
+
Class: Country,
|
| 60 |
+
Vectorizer: "text2vec-contextionary",
|
| 61 |
+
ModuleConfig: map[string]interface{}{
|
| 62 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 63 |
+
"vectorizeClassName": true,
|
| 64 |
+
},
|
| 65 |
+
},
|
| 66 |
+
Properties: []*models.Property{
|
| 67 |
+
{
|
| 68 |
+
Name: "name",
|
| 69 |
+
DataType: schema.DataTypeText.PropString(),
|
| 70 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 71 |
+
},
|
| 72 |
+
},
|
| 73 |
+
})
|
| 74 |
+
|
| 75 |
+
// City class has only one vectorizable field: "name"
|
| 76 |
+
// the rest of the fields are explicitly set to skip vectorization
|
| 77 |
+
// to not to downgrade the distance/certainty result on which the
|
| 78 |
+
// aggregate tests are based on.
|
| 79 |
+
helper.CreateClass(t, &models.Class{
|
| 80 |
+
Class: City,
|
| 81 |
+
Vectorizer: "text2vec-contextionary",
|
| 82 |
+
ModuleConfig: map[string]interface{}{
|
| 83 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 84 |
+
"vectorizeClassName": true,
|
| 85 |
+
},
|
| 86 |
+
},
|
| 87 |
+
InvertedIndexConfig: &models.InvertedIndexConfig{IndexNullState: true, IndexPropertyLength: true, IndexTimestamps: true, UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND},
|
| 88 |
+
Properties: []*models.Property{
|
| 89 |
+
{
|
| 90 |
+
Name: "name",
|
| 91 |
+
DataType: schema.DataTypeText.PropString(),
|
| 92 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 93 |
+
ModuleConfig: map[string]interface{}{
|
| 94 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 95 |
+
"skip": false,
|
| 96 |
+
},
|
| 97 |
+
},
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
Name: "inCountry",
|
| 101 |
+
DataType: []string{Country},
|
| 102 |
+
ModuleConfig: map[string]interface{}{
|
| 103 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 104 |
+
"skip": true,
|
| 105 |
+
},
|
| 106 |
+
},
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
Name: "population",
|
| 110 |
+
DataType: []string{"int"},
|
| 111 |
+
ModuleConfig: map[string]interface{}{
|
| 112 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 113 |
+
"skip": true,
|
| 114 |
+
},
|
| 115 |
+
},
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
Name: "location",
|
| 119 |
+
DataType: []string{"geoCoordinates"},
|
| 120 |
+
ModuleConfig: map[string]interface{}{
|
| 121 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 122 |
+
"skip": true,
|
| 123 |
+
},
|
| 124 |
+
},
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
Name: "isCapital",
|
| 128 |
+
DataType: []string{"boolean"},
|
| 129 |
+
ModuleConfig: map[string]interface{}{
|
| 130 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 131 |
+
"skip": true,
|
| 132 |
+
},
|
| 133 |
+
},
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
Name: "cityArea",
|
| 137 |
+
DataType: []string{"number"},
|
| 138 |
+
ModuleConfig: map[string]interface{}{
|
| 139 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 140 |
+
"skip": true,
|
| 141 |
+
},
|
| 142 |
+
},
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
Name: "cityRights",
|
| 146 |
+
DataType: []string{"date"},
|
| 147 |
+
ModuleConfig: map[string]interface{}{
|
| 148 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 149 |
+
"skip": true,
|
| 150 |
+
},
|
| 151 |
+
},
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
Name: "timezones",
|
| 155 |
+
DataType: schema.DataTypeTextArray.PropString(),
|
| 156 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 157 |
+
ModuleConfig: map[string]interface{}{
|
| 158 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 159 |
+
"skip": true,
|
| 160 |
+
},
|
| 161 |
+
},
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
Name: "museums",
|
| 165 |
+
DataType: []string{"text[]"},
|
| 166 |
+
ModuleConfig: map[string]interface{}{
|
| 167 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 168 |
+
"skip": true,
|
| 169 |
+
},
|
| 170 |
+
},
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
Name: "history",
|
| 174 |
+
DataType: []string{"text"},
|
| 175 |
+
ModuleConfig: map[string]interface{}{
|
| 176 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 177 |
+
"skip": true,
|
| 178 |
+
},
|
| 179 |
+
},
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
Name: "phoneNumber",
|
| 183 |
+
DataType: []string{"phoneNumber"},
|
| 184 |
+
ModuleConfig: map[string]interface{}{
|
| 185 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 186 |
+
"skip": true,
|
| 187 |
+
},
|
| 188 |
+
},
|
| 189 |
+
},
|
| 190 |
+
},
|
| 191 |
+
})
|
| 192 |
+
|
| 193 |
+
helper.CreateClass(t, &models.Class{
|
| 194 |
+
Class: Airport,
|
| 195 |
+
Vectorizer: "text2vec-contextionary",
|
| 196 |
+
ModuleConfig: map[string]interface{}{
|
| 197 |
+
"text2vec-contextionary": map[string]interface{}{
|
| 198 |
+
"vectorizeClassName": true,
|
| 199 |
+
},
|
| 200 |
+
},
|
| 201 |
+
InvertedIndexConfig: &models.InvertedIndexConfig{
|
| 202 |
+
CleanupIntervalSeconds: 60,
|
| 203 |
+
Stopwords: &models.StopwordConfig{
|
| 204 |
+
Preset: "en",
|
| 205 |
+
},
|
| 206 |
+
IndexTimestamps: true,
|
| 207 |
+
UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND,
|
| 208 |
+
},
|
| 209 |
+
Properties: []*models.Property{
|
| 210 |
+
{
|
| 211 |
+
Name: "code",
|
| 212 |
+
DataType: schema.DataTypeText.PropString(),
|
| 213 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
Name: "phone",
|
| 217 |
+
DataType: []string{"phoneNumber"},
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
Name: "inCity",
|
| 221 |
+
DataType: []string{City},
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
Name: "airportId",
|
| 225 |
+
DataType: []string{"uuid"},
|
| 226 |
+
},
|
| 227 |
+
},
|
| 228 |
+
})
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
func InsertCountryCityAirportObjects(t *testing.T, host string) {
|
| 232 |
+
helper.SetupClient(host)
|
| 233 |
+
// countries
|
| 234 |
+
helper.CreateObject(t, &models.Object{
|
| 235 |
+
Class: Country,
|
| 236 |
+
ID: Netherlands,
|
| 237 |
+
Properties: map[string]interface{}{
|
| 238 |
+
"name": "Netherlands",
|
| 239 |
+
},
|
| 240 |
+
})
|
| 241 |
+
helper.CreateObject(t, &models.Object{
|
| 242 |
+
Class: Country,
|
| 243 |
+
ID: Germany,
|
| 244 |
+
Properties: map[string]interface{}{
|
| 245 |
+
"name": "Germany",
|
| 246 |
+
},
|
| 247 |
+
})
|
| 248 |
+
|
| 249 |
+
// cities
|
| 250 |
+
helper.CreateObject(t, &models.Object{
|
| 251 |
+
Class: City,
|
| 252 |
+
ID: Amsterdam,
|
| 253 |
+
Properties: map[string]interface{}{
|
| 254 |
+
"name": "Amsterdam",
|
| 255 |
+
"population": 1800000,
|
| 256 |
+
"location": map[string]interface{}{
|
| 257 |
+
"latitude": 52.366667,
|
| 258 |
+
"longitude": 4.9,
|
| 259 |
+
},
|
| 260 |
+
"inCountry": []interface{}{
|
| 261 |
+
map[string]interface{}{
|
| 262 |
+
"beacon": crossref.NewLocalhost(Country, Netherlands).String(),
|
| 263 |
+
},
|
| 264 |
+
},
|
| 265 |
+
"isCapital": true,
|
| 266 |
+
"cityArea": float64(891.95),
|
| 267 |
+
"cityRights": mustParseYear("1400"),
|
| 268 |
+
"timezones": []string{"CET", "CEST"},
|
| 269 |
+
"museums": []string{"Stedelijk Museum", "Rijksmuseum"},
|
| 270 |
+
"history": HistoryAmsterdam,
|
| 271 |
+
"phoneNumber": map[string]interface{}{
|
| 272 |
+
"input": "+311000004",
|
| 273 |
+
},
|
| 274 |
+
},
|
| 275 |
+
})
|
| 276 |
+
helper.CreateObject(t, &models.Object{
|
| 277 |
+
Class: City,
|
| 278 |
+
ID: Rotterdam,
|
| 279 |
+
Properties: map[string]interface{}{
|
| 280 |
+
"name": "Rotterdam",
|
| 281 |
+
"population": 600000,
|
| 282 |
+
"inCountry": []interface{}{
|
| 283 |
+
map[string]interface{}{
|
| 284 |
+
"beacon": crossref.NewLocalhost(Country, Netherlands).String(),
|
| 285 |
+
},
|
| 286 |
+
},
|
| 287 |
+
"isCapital": false,
|
| 288 |
+
"cityArea": float64(319.35),
|
| 289 |
+
"cityRights": mustParseYear("1283"),
|
| 290 |
+
"timezones": []string{"CET", "CEST"},
|
| 291 |
+
"museums": []string{"Museum Boijmans Van Beuningen", "Wereldmuseum", "Witte de With Center for Contemporary Art"},
|
| 292 |
+
"history": HistoryRotterdam,
|
| 293 |
+
"phoneNumber": map[string]interface{}{
|
| 294 |
+
"input": "+311000000",
|
| 295 |
+
},
|
| 296 |
+
},
|
| 297 |
+
})
|
| 298 |
+
helper.CreateObject(t, &models.Object{
|
| 299 |
+
Class: City,
|
| 300 |
+
ID: Berlin,
|
| 301 |
+
Properties: map[string]interface{}{
|
| 302 |
+
"name": "Berlin",
|
| 303 |
+
"population": 3470000,
|
| 304 |
+
"inCountry": []interface{}{
|
| 305 |
+
map[string]interface{}{
|
| 306 |
+
"beacon": crossref.NewLocalhost(Country, Germany).String(),
|
| 307 |
+
},
|
| 308 |
+
},
|
| 309 |
+
"isCapital": true,
|
| 310 |
+
"cityArea": float64(891.96),
|
| 311 |
+
"cityRights": mustParseYear("1400"),
|
| 312 |
+
"timezones": []string{"CET", "CEST"},
|
| 313 |
+
"museums": []string{"German Historical Museum"},
|
| 314 |
+
"history": HistoryBerlin,
|
| 315 |
+
"phoneNumber": map[string]interface{}{
|
| 316 |
+
"input": "+311000002",
|
| 317 |
+
},
|
| 318 |
+
},
|
| 319 |
+
})
|
| 320 |
+
helper.CreateObject(t, &models.Object{
|
| 321 |
+
Class: City,
|
| 322 |
+
ID: Dusseldorf,
|
| 323 |
+
Properties: map[string]interface{}{
|
| 324 |
+
"name": "Dusseldorf",
|
| 325 |
+
"population": 600000,
|
| 326 |
+
"inCountry": []interface{}{
|
| 327 |
+
map[string]interface{}{
|
| 328 |
+
"beacon": crossref.NewLocalhost(Country, Germany).String(),
|
| 329 |
+
},
|
| 330 |
+
},
|
| 331 |
+
"location": map[string]interface{}{
|
| 332 |
+
"latitude": 51.225556,
|
| 333 |
+
"longitude": 6.782778,
|
| 334 |
+
},
|
| 335 |
+
"isCapital": false,
|
| 336 |
+
"cityArea": float64(217.22),
|
| 337 |
+
"cityRights": mustParseYear("1135"),
|
| 338 |
+
"timezones": []string{"CET", "CEST"},
|
| 339 |
+
"museums": []string{"Schlossturm", "Schiffahrt Museum", "Onomato"},
|
| 340 |
+
"history": HistoryDusseldorf,
|
| 341 |
+
"phoneNumber": map[string]interface{}{
|
| 342 |
+
"input": "+311000001",
|
| 343 |
+
},
|
| 344 |
+
},
|
| 345 |
+
})
|
| 346 |
+
|
| 347 |
+
helper.CreateObject(t, &models.Object{
|
| 348 |
+
Class: City,
|
| 349 |
+
ID: Missingisland,
|
| 350 |
+
Properties: map[string]interface{}{
|
| 351 |
+
"name": "Missing Island",
|
| 352 |
+
"population": 0,
|
| 353 |
+
"location": map[string]interface{}{
|
| 354 |
+
"latitude": 0,
|
| 355 |
+
"longitude": 0,
|
| 356 |
+
},
|
| 357 |
+
"isCapital": false,
|
| 358 |
+
},
|
| 359 |
+
})
|
| 360 |
+
|
| 361 |
+
helper.CreateObject(t, &models.Object{
|
| 362 |
+
Class: City,
|
| 363 |
+
ID: Nullisland,
|
| 364 |
+
Properties: map[string]interface{}{
|
| 365 |
+
"name": nil,
|
| 366 |
+
"population": nil,
|
| 367 |
+
"inCountry": nil,
|
| 368 |
+
"location": nil,
|
| 369 |
+
"isCapital": nil,
|
| 370 |
+
"cityArea": nil,
|
| 371 |
+
"cityRights": nil,
|
| 372 |
+
"timezones": nil,
|
| 373 |
+
"museums": nil,
|
| 374 |
+
"history": nil,
|
| 375 |
+
"phoneNumber": nil,
|
| 376 |
+
},
|
| 377 |
+
})
|
| 378 |
+
|
| 379 |
+
// airports
|
| 380 |
+
helper.CreateObject(t, &models.Object{
|
| 381 |
+
Class: Airport,
|
| 382 |
+
ID: Airport1,
|
| 383 |
+
Properties: map[string]interface{}{
|
| 384 |
+
"code": "10000",
|
| 385 |
+
"airportId": uuid.MustParse("00000000-0000-0000-0000-000000010000").String(),
|
| 386 |
+
"phone": map[string]interface{}{
|
| 387 |
+
"input": "+311234567",
|
| 388 |
+
},
|
| 389 |
+
"inCity": []interface{}{
|
| 390 |
+
map[string]interface{}{
|
| 391 |
+
"beacon": crossref.NewLocalhost(City, Amsterdam).String(),
|
| 392 |
+
},
|
| 393 |
+
},
|
| 394 |
+
},
|
| 395 |
+
})
|
| 396 |
+
helper.CreateObject(t, &models.Object{
|
| 397 |
+
Class: Airport,
|
| 398 |
+
ID: Airport2,
|
| 399 |
+
Properties: map[string]interface{}{
|
| 400 |
+
"code": "20000",
|
| 401 |
+
"airportId": uuid.MustParse("00000000-0000-0000-0000-000000020000").String(),
|
| 402 |
+
"inCity": []interface{}{
|
| 403 |
+
map[string]interface{}{
|
| 404 |
+
"beacon": crossref.NewLocalhost(City, Rotterdam).String(),
|
| 405 |
+
},
|
| 406 |
+
},
|
| 407 |
+
},
|
| 408 |
+
})
|
| 409 |
+
helper.CreateObject(t, &models.Object{
|
| 410 |
+
Class: Airport,
|
| 411 |
+
ID: Airport3,
|
| 412 |
+
Properties: map[string]interface{}{
|
| 413 |
+
"code": "30000",
|
| 414 |
+
"airportId": uuid.MustParse("00000000-0000-0000-0000-000000030000").String(),
|
| 415 |
+
"inCity": []interface{}{
|
| 416 |
+
map[string]interface{}{
|
| 417 |
+
"beacon": crossref.NewLocalhost(City, Dusseldorf).String(),
|
| 418 |
+
},
|
| 419 |
+
},
|
| 420 |
+
},
|
| 421 |
+
})
|
| 422 |
+
helper.CreateObject(t, &models.Object{
|
| 423 |
+
Class: Airport,
|
| 424 |
+
ID: Airport4,
|
| 425 |
+
Properties: map[string]interface{}{
|
| 426 |
+
"code": "40000",
|
| 427 |
+
"airportId": uuid.MustParse("00000000-0000-0000-0000-000000040000").String(),
|
| 428 |
+
"inCity": []interface{}{
|
| 429 |
+
map[string]interface{}{
|
| 430 |
+
"beacon": crossref.NewLocalhost(City, Berlin).String(),
|
| 431 |
+
},
|
| 432 |
+
},
|
| 433 |
+
},
|
| 434 |
+
})
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
func DeleteCountryCityAirportSchema(t *testing.T, host string) {
|
| 438 |
+
helper.SetupClient(host)
|
| 439 |
+
helper.DeleteClassObject(t, Airport)
|
| 440 |
+
helper.DeleteClassObject(t, City)
|
| 441 |
+
helper.DeleteClassObject(t, Country)
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
func mustParseYear(year string) time.Time {
|
| 445 |
+
date := fmt.Sprintf("%s-01-01T00:00:00+02:00", year)
|
| 446 |
+
asTime, err := time.Parse(time.RFC3339, date)
|
| 447 |
+
if err != nil {
|
| 448 |
+
panic(err)
|
| 449 |
+
}
|
| 450 |
+
return asTime
|
| 451 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/companies/companies.go
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package companies
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/go-openapi/strfmt"
|
| 21 |
+
"github.com/stretchr/testify/assert"
|
| 22 |
+
"github.com/stretchr/testify/require"
|
| 23 |
+
"github.com/weaviate/weaviate/client/batch"
|
| 24 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 25 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 26 |
+
"github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 27 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 28 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
const DefaultTimeout = 2 * time.Minute
|
| 32 |
+
|
| 33 |
+
const (
|
| 34 |
+
OpenAI strfmt.UUID = "00000000-0000-0000-0000-000000000001"
|
| 35 |
+
SpaceX strfmt.UUID = "00000000-0000-0000-0000-000000000002"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
var Companies = []struct {
|
| 39 |
+
ID strfmt.UUID
|
| 40 |
+
Name, Description string
|
| 41 |
+
}{
|
| 42 |
+
{
|
| 43 |
+
ID: OpenAI,
|
| 44 |
+
Name: "OpenAI",
|
| 45 |
+
Description: `OpenAI is a research organization and AI development company that focuses on artificial intelligence (AI) and machine learning (ML).
|
| 46 |
+
Founded in December 2015, OpenAI's mission is to ensure that artificial general intelligence (AGI) benefits all of humanity.
|
| 47 |
+
The organization has been at the forefront of AI research, producing cutting-edge advancements in natural language processing,
|
| 48 |
+
reinforcement learning, robotics, and other AI-related fields.
|
| 49 |
+
|
| 50 |
+
OpenAI has garnered attention for its work on various projects, including the development of the GPT (Generative Pre-trained Transformer)
|
| 51 |
+
series of models, such as GPT-2 and GPT-3, which have demonstrated remarkable capabilities in generating human-like text.
|
| 52 |
+
Additionally, OpenAI has contributed to advancements in reinforcement learning through projects like OpenAI Five, an AI system
|
| 53 |
+
capable of playing the complex strategy game Dota 2 at a high level.`,
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
ID: SpaceX,
|
| 57 |
+
Name: "SpaceX",
|
| 58 |
+
Description: `SpaceX, short for Space Exploration Technologies Corp., is an American aerospace manufacturer and space transportation company
|
| 59 |
+
founded by Elon Musk in 2002. The company's primary goal is to reduce space transportation costs and enable the colonization of Mars,
|
| 60 |
+
among other ambitious objectives.
|
| 61 |
+
|
| 62 |
+
SpaceX has made significant strides in the aerospace industry by developing advanced rocket technology, spacecraft,
|
| 63 |
+
and satellite systems. The company is best known for its Falcon series of rockets, including the Falcon 1, Falcon 9,
|
| 64 |
+
and Falcon Heavy, which have been designed with reusability in mind. Reusability has been a key innovation pioneered by SpaceX,
|
| 65 |
+
aiming to drastically reduce the cost of space travel by reusing rocket components multiple times.`,
|
| 66 |
+
},
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
func BaseClass(className string) *models.Class {
|
| 70 |
+
return &models.Class{
|
| 71 |
+
Class: className,
|
| 72 |
+
Properties: []*models.Property{
|
| 73 |
+
{
|
| 74 |
+
Name: "name", DataType: []string{schema.DataTypeText.String()},
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
Name: "description", DataType: []string{schema.DataTypeText.String()},
|
| 78 |
+
},
|
| 79 |
+
},
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
func InsertObjects(t *testing.T, host string, className string) {
|
| 84 |
+
for _, company := range Companies {
|
| 85 |
+
obj := &models.Object{
|
| 86 |
+
Class: className,
|
| 87 |
+
ID: company.ID,
|
| 88 |
+
Properties: map[string]interface{}{
|
| 89 |
+
"name": company.Name,
|
| 90 |
+
"description": company.Description,
|
| 91 |
+
},
|
| 92 |
+
}
|
| 93 |
+
helper.SetupClient(host)
|
| 94 |
+
err := helper.CreateObjectWithTimeout(t, obj, DefaultTimeout)
|
| 95 |
+
require.NoError(t, err)
|
| 96 |
+
getObj := helper.AssertGetObjectEventually(t, obj.Class, obj.ID)
|
| 97 |
+
require.NotNil(t, getObj)
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
func BatchInsertObjects(t *testing.T, host string, className string) {
|
| 102 |
+
var objects []*models.Object
|
| 103 |
+
for _, company := range Companies {
|
| 104 |
+
objects = append(objects, &models.Object{
|
| 105 |
+
Class: className,
|
| 106 |
+
ID: company.ID,
|
| 107 |
+
Properties: map[string]interface{}{
|
| 108 |
+
"name": company.Name,
|
| 109 |
+
"description": company.Description,
|
| 110 |
+
},
|
| 111 |
+
})
|
| 112 |
+
}
|
| 113 |
+
helper.SetupClient(host)
|
| 114 |
+
|
| 115 |
+
returnedFields := "ALL"
|
| 116 |
+
params := batch.NewBatchObjectsCreateParams().WithBody(
|
| 117 |
+
batch.BatchObjectsCreateBody{
|
| 118 |
+
Objects: objects,
|
| 119 |
+
Fields: []*string{&returnedFields},
|
| 120 |
+
})
|
| 121 |
+
|
| 122 |
+
resp, err := helper.BatchClient(t).BatchObjectsCreate(params, nil)
|
| 123 |
+
|
| 124 |
+
// ensure that the response is OK
|
| 125 |
+
helper.AssertRequestOk(t, resp, err, func() {
|
| 126 |
+
objectsCreateResponse := resp.Payload
|
| 127 |
+
|
| 128 |
+
// check if the batch response contains two batched responses
|
| 129 |
+
assert.Equal(t, 2, len(objectsCreateResponse))
|
| 130 |
+
|
| 131 |
+
for _, elem := range resp.Payload {
|
| 132 |
+
assert.Nil(t, elem.Result.Errors)
|
| 133 |
+
}
|
| 134 |
+
})
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
func PerformAllSearchTests(t *testing.T, rest, grpc string, className string) {
|
| 138 |
+
// vector search with gql
|
| 139 |
+
t.Run("perform vector search with gql", func(t *testing.T) {
|
| 140 |
+
PerformVectorSearchTest(t, rest, className)
|
| 141 |
+
})
|
| 142 |
+
// vector search with grpc
|
| 143 |
+
t.Run("perform vector search with grpc", func(t *testing.T) {
|
| 144 |
+
PerformVectorSearchGRPCTest(t, grpc, className)
|
| 145 |
+
})
|
| 146 |
+
// hybrid search with gql
|
| 147 |
+
t.Run("perform hybrid search with gql", func(t *testing.T) {
|
| 148 |
+
PerformHybridSearchTest(t, rest, className)
|
| 149 |
+
})
|
| 150 |
+
// hybrid search with grpc
|
| 151 |
+
t.Run("perform hybrid search with grpc", func(t *testing.T) {
|
| 152 |
+
PerformHybridSearchGRPCTest(t, grpc, className)
|
| 153 |
+
})
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
func PerformVectorSearchTest(t *testing.T, host string, className string) {
|
| 157 |
+
query := fmt.Sprintf(`
|
| 158 |
+
{
|
| 159 |
+
Get {
|
| 160 |
+
%s(
|
| 161 |
+
nearText:{
|
| 162 |
+
concepts:["SpaceX"]
|
| 163 |
+
}
|
| 164 |
+
){
|
| 165 |
+
name
|
| 166 |
+
_additional {
|
| 167 |
+
id
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
`, className)
|
| 173 |
+
assertResults(t, host, className, query)
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
func PerformVectorSearchGRPCTest(t *testing.T, host string, className string) {
|
| 177 |
+
req := protocol.SearchRequest{
|
| 178 |
+
Collection: className,
|
| 179 |
+
NearText: &protocol.NearTextSearch{
|
| 180 |
+
Query: []string{"SpaceX"},
|
| 181 |
+
},
|
| 182 |
+
Properties: &protocol.PropertiesRequest{
|
| 183 |
+
NonRefProperties: []string{"name"},
|
| 184 |
+
},
|
| 185 |
+
Metadata: &protocol.MetadataRequest{
|
| 186 |
+
Uuid: true,
|
| 187 |
+
},
|
| 188 |
+
Uses_127Api: true,
|
| 189 |
+
}
|
| 190 |
+
assertResultsGRPC(t, host, &req)
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
func PerformHybridSearchWithTextTest(t *testing.T, host string, className, text string) {
|
| 194 |
+
query := fmt.Sprintf(`
|
| 195 |
+
{
|
| 196 |
+
Get {
|
| 197 |
+
%s(
|
| 198 |
+
hybrid:{
|
| 199 |
+
query:"%s"
|
| 200 |
+
alpha:0.75
|
| 201 |
+
}
|
| 202 |
+
){
|
| 203 |
+
name
|
| 204 |
+
_additional {
|
| 205 |
+
id
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
`, className, text)
|
| 211 |
+
assertResults(t, host, className, query)
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
func PerformHybridSearchTest(t *testing.T, host string, className string) {
|
| 215 |
+
PerformHybridSearchWithTextTest(t, host, className, "SpaceX")
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
func PerformHybridSearchGRPCTest(t *testing.T, host string, className string) {
|
| 219 |
+
req := protocol.SearchRequest{
|
| 220 |
+
Collection: className,
|
| 221 |
+
HybridSearch: &protocol.Hybrid{
|
| 222 |
+
Query: "SpaceX",
|
| 223 |
+
Alpha: 0.75,
|
| 224 |
+
},
|
| 225 |
+
Properties: &protocol.PropertiesRequest{
|
| 226 |
+
NonRefProperties: []string{"name"},
|
| 227 |
+
},
|
| 228 |
+
Metadata: &protocol.MetadataRequest{
|
| 229 |
+
Uuid: true,
|
| 230 |
+
},
|
| 231 |
+
Uses_127Api: true,
|
| 232 |
+
}
|
| 233 |
+
assertResultsGRPC(t, host, &req)
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
func assertResults(t *testing.T, host string, className, query string) {
|
| 237 |
+
helper.SetupClient(host)
|
| 238 |
+
result := graphqlhelper.AssertGraphQLWithTimeout(t, helper.RootAuth, DefaultTimeout, query)
|
| 239 |
+
objs := result.Get("Get", className).AsSlice()
|
| 240 |
+
require.Len(t, objs, 2)
|
| 241 |
+
for _, obj := range objs {
|
| 242 |
+
name := obj.(map[string]interface{})["name"]
|
| 243 |
+
assert.NotEmpty(t, name)
|
| 244 |
+
additional, ok := obj.(map[string]interface{})["_additional"].(map[string]interface{})
|
| 245 |
+
require.True(t, ok)
|
| 246 |
+
require.NotNil(t, additional)
|
| 247 |
+
id, ok := additional["id"].(string)
|
| 248 |
+
require.True(t, ok)
|
| 249 |
+
require.NotEmpty(t, id)
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
func assertResultsGRPC(t *testing.T, host string, req *protocol.SearchRequest) {
|
| 254 |
+
helper.SetupGRPCClient(t, host)
|
| 255 |
+
client := helper.ClientGRPC(t)
|
| 256 |
+
resp, err := client.Search(context.Background(), req)
|
| 257 |
+
if err != nil {
|
| 258 |
+
t.Fatalf("search request failed: %v", err)
|
| 259 |
+
}
|
| 260 |
+
require.Len(t, resp.Results, 2)
|
| 261 |
+
for _, res := range resp.Results {
|
| 262 |
+
assert.NotEmpty(t, res.GetProperties().GetNonRefProps().GetFields()["name"].GetTextValue())
|
| 263 |
+
assert.NotEmpty(t, res.GetMetadata().GetId())
|
| 264 |
+
}
|
| 265 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/documents/documents.go
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package documents
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
|
| 17 |
+
"github.com/go-openapi/strfmt"
|
| 18 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/schema/crossref"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
const (
|
| 23 |
+
Document = "Document"
|
| 24 |
+
Passage = "Passage"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
var DocumentIDs = []strfmt.UUID{
|
| 28 |
+
"00000000-0000-0000-0000-000000000011",
|
| 29 |
+
"00000000-0000-0000-0000-000000000012",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
var PassageIDs = []strfmt.UUID{
|
| 33 |
+
"00000000-0000-0000-0000-000000000001",
|
| 34 |
+
"00000000-0000-0000-0000-000000000002",
|
| 35 |
+
"00000000-0000-0000-0000-000000000003",
|
| 36 |
+
"00000000-0000-0000-0000-000000000004",
|
| 37 |
+
"00000000-0000-0000-0000-000000000005",
|
| 38 |
+
"00000000-0000-0000-0000-000000000006",
|
| 39 |
+
"00000000-0000-0000-0000-000000000007",
|
| 40 |
+
"00000000-0000-0000-0000-000000000008",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
var multiShardConfig = map[string]interface{}{
|
| 44 |
+
"actualCount": float64(4),
|
| 45 |
+
"actualVirtualCount": float64(128),
|
| 46 |
+
"desiredCount": float64(4),
|
| 47 |
+
"desiredVirtualCount": float64(128),
|
| 48 |
+
"function": "murmur3",
|
| 49 |
+
"key": "_id",
|
| 50 |
+
"strategy": "hash",
|
| 51 |
+
"virtualPerPhysical": float64(128),
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
var docTypes = []string{"private", "public"}
|
| 55 |
+
|
| 56 |
+
func ClassesContextionaryVectorizer(multishard bool) []*models.Class {
|
| 57 |
+
return []*models.Class{
|
| 58 |
+
document("text2vec-contextionary", multishard),
|
| 59 |
+
passage("text2vec-contextionary", multishard),
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
func ClassesModel2VecVectorizer(multishard bool) []*models.Class {
|
| 64 |
+
return []*models.Class{
|
| 65 |
+
document("text2vec-model2vec", multishard),
|
| 66 |
+
passage("text2vec-model2vec", multishard),
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
func document(vectorizer string, multishard bool) *models.Class {
|
| 71 |
+
class := &models.Class{
|
| 72 |
+
Class: Document,
|
| 73 |
+
Vectorizer: vectorizer,
|
| 74 |
+
ModuleConfig: map[string]interface{}{
|
| 75 |
+
vectorizer: map[string]interface{}{
|
| 76 |
+
"vectorizeClassName": false,
|
| 77 |
+
},
|
| 78 |
+
},
|
| 79 |
+
Properties: []*models.Property{
|
| 80 |
+
{
|
| 81 |
+
Name: "title",
|
| 82 |
+
DataType: []string{"text"},
|
| 83 |
+
ModuleConfig: map[string]interface{}{
|
| 84 |
+
vectorizer: map[string]interface{}{
|
| 85 |
+
"vectorizePropertyName": false,
|
| 86 |
+
},
|
| 87 |
+
},
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
Name: "pageCount",
|
| 91 |
+
DataType: []string{"int"},
|
| 92 |
+
ModuleConfig: map[string]interface{}{
|
| 93 |
+
vectorizer: map[string]interface{}{
|
| 94 |
+
"vectorizePropertyName": false,
|
| 95 |
+
"skip": true,
|
| 96 |
+
},
|
| 97 |
+
},
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
Name: "docType",
|
| 101 |
+
DataType: []string{"text"},
|
| 102 |
+
ModuleConfig: map[string]interface{}{
|
| 103 |
+
vectorizer: map[string]interface{}{
|
| 104 |
+
"vectorizePropertyName": false,
|
| 105 |
+
"skip": true,
|
| 106 |
+
},
|
| 107 |
+
},
|
| 108 |
+
},
|
| 109 |
+
},
|
| 110 |
+
}
|
| 111 |
+
if multishard {
|
| 112 |
+
class.ShardingConfig = multiShardConfig
|
| 113 |
+
}
|
| 114 |
+
return class
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
func passage(vectorizer string, multishard bool) *models.Class {
|
| 118 |
+
class := &models.Class{
|
| 119 |
+
Class: Passage,
|
| 120 |
+
Vectorizer: vectorizer,
|
| 121 |
+
ModuleConfig: map[string]interface{}{
|
| 122 |
+
vectorizer: map[string]interface{}{
|
| 123 |
+
"vectorizeClassName": false,
|
| 124 |
+
},
|
| 125 |
+
},
|
| 126 |
+
Properties: []*models.Property{
|
| 127 |
+
{
|
| 128 |
+
Name: "content",
|
| 129 |
+
DataType: []string{"text"},
|
| 130 |
+
ModuleConfig: map[string]interface{}{
|
| 131 |
+
vectorizer: map[string]interface{}{
|
| 132 |
+
"vectorizePropertyName": false,
|
| 133 |
+
},
|
| 134 |
+
},
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
Name: "ofDocument",
|
| 138 |
+
DataType: []string{Document},
|
| 139 |
+
ModuleConfig: map[string]interface{}{
|
| 140 |
+
vectorizer: map[string]interface{}{
|
| 141 |
+
"vectorizePropertyName": false,
|
| 142 |
+
},
|
| 143 |
+
},
|
| 144 |
+
},
|
| 145 |
+
},
|
| 146 |
+
}
|
| 147 |
+
if multishard {
|
| 148 |
+
class.ShardingConfig = multiShardConfig
|
| 149 |
+
}
|
| 150 |
+
return class
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
func Objects() []*models.Object {
|
| 154 |
+
return append(documentObjects(), passageObjects()...)
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
func documentObjects() []*models.Object {
|
| 158 |
+
getDocType := func(i int) string {
|
| 159 |
+
if i == 0 {
|
| 160 |
+
return docTypes[0]
|
| 161 |
+
}
|
| 162 |
+
return docTypes[1]
|
| 163 |
+
}
|
| 164 |
+
objects := make([]*models.Object, len(DocumentIDs))
|
| 165 |
+
for i, id := range DocumentIDs {
|
| 166 |
+
objects[i] = &models.Object{
|
| 167 |
+
Class: Document,
|
| 168 |
+
ID: id,
|
| 169 |
+
Properties: map[string]interface{}{
|
| 170 |
+
"title": fmt.Sprintf("Document title %v", i),
|
| 171 |
+
"pageCount": 100 + i,
|
| 172 |
+
"docType": getDocType(i),
|
| 173 |
+
},
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
return objects
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
func passageObjects() []*models.Object {
|
| 180 |
+
getDocumentID := func(i int) strfmt.UUID {
|
| 181 |
+
if i < 6 {
|
| 182 |
+
return DocumentIDs[0]
|
| 183 |
+
}
|
| 184 |
+
return DocumentIDs[1]
|
| 185 |
+
}
|
| 186 |
+
objects := make([]*models.Object, len(PassageIDs))
|
| 187 |
+
for i, id := range PassageIDs {
|
| 188 |
+
objects[i] = &models.Object{
|
| 189 |
+
Class: Passage,
|
| 190 |
+
ID: id,
|
| 191 |
+
Properties: map[string]interface{}{
|
| 192 |
+
"content": fmt.Sprintf("Content of Passage %v", i),
|
| 193 |
+
"ofDocument": []interface{}{
|
| 194 |
+
map[string]interface{}{
|
| 195 |
+
"beacon": crossref.NewLocalhost("Document", getDocumentID(i)).String(),
|
| 196 |
+
},
|
| 197 |
+
},
|
| 198 |
+
},
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
return objects
|
| 202 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/data.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
,id,image_title,image_description,video_title,video_description
|
| 2 |
+
0,00000000-0000-0000-0000-000000000001,"sunrise","Beautiful sunrise at the beach","cat","A cat cleaning himself with a paw"
|
| 3 |
+
1,00000000-0000-0000-0000-000000000002,"waterfalls","A picture of Krka waterfalls in Croatia","dog","A dog giving a high five to a human"
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/images/1.jpg
ADDED
|
Git LFS Details
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/images/2.jpg
ADDED
|
Git LFS Details
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/videos/1.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ebdc456b77069e3034049be754f566af2999cc98a2f9148f4f96c46b6d5e995a
|
| 3 |
+
size 587027
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/data/videos/2.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:48a31aae619f7a3557724501b91d0aadd4054269f4ff99b1ff8aa73466b124d0
|
| 3 |
+
size 427446
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multimodal/multimodal.go
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package multimodal
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/csv"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"io"
|
| 19 |
+
"os"
|
| 20 |
+
"strings"
|
| 21 |
+
"testing"
|
| 22 |
+
"time"
|
| 23 |
+
|
| 24 |
+
"github.com/go-openapi/strfmt"
|
| 25 |
+
"github.com/stretchr/testify/assert"
|
| 26 |
+
"github.com/stretchr/testify/require"
|
| 27 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 28 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 29 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 30 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
const DefaultTimeout = 2 * time.Minute
|
| 34 |
+
|
| 35 |
+
const (
|
| 36 |
+
PropertyImageTitle = "image_title"
|
| 37 |
+
PropertyImageDescription = "image_description"
|
| 38 |
+
PropertyImage = "image"
|
| 39 |
+
PropertyVideoTitle = "video_title"
|
| 40 |
+
PropertyVideoDescription = "video_description"
|
| 41 |
+
PropertyVideo = "video"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
func BaseClass(className string, withVideo bool) *models.Class {
|
| 45 |
+
properties := []*models.Property{
|
| 46 |
+
{
|
| 47 |
+
Name: PropertyImageTitle, DataType: []string{schema.DataTypeText.String()},
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
Name: PropertyImageDescription, DataType: []string{schema.DataTypeText.String()},
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
Name: PropertyImage, DataType: []string{schema.DataTypeBlob.String()},
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
if withVideo {
|
| 57 |
+
videoProperties := []*models.Property{
|
| 58 |
+
{
|
| 59 |
+
Name: PropertyVideoTitle, DataType: []string{schema.DataTypeText.String()},
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
Name: PropertyVideoDescription, DataType: []string{schema.DataTypeText.String()},
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
Name: PropertyVideo, DataType: []string{schema.DataTypeBlob.String()},
|
| 66 |
+
},
|
| 67 |
+
}
|
| 68 |
+
properties = append(properties, videoProperties...)
|
| 69 |
+
}
|
| 70 |
+
return &models.Class{
|
| 71 |
+
Class: className,
|
| 72 |
+
Properties: properties,
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
func InsertObjects(t *testing.T, dataFolderPath, className string, withVideo bool) {
|
| 77 |
+
f, err := GetCSV(dataFolderPath)
|
| 78 |
+
require.NoError(t, err)
|
| 79 |
+
defer f.Close()
|
| 80 |
+
var objs []*models.Object
|
| 81 |
+
i := 0
|
| 82 |
+
csvReader := csv.NewReader(f)
|
| 83 |
+
for {
|
| 84 |
+
line, err := csvReader.Read()
|
| 85 |
+
if err == io.EOF {
|
| 86 |
+
break
|
| 87 |
+
}
|
| 88 |
+
require.NoError(t, err)
|
| 89 |
+
if i > 0 {
|
| 90 |
+
id := line[1]
|
| 91 |
+
imageTitle := line[2]
|
| 92 |
+
imageDescription := line[3]
|
| 93 |
+
imageBlob, err := GetImageBlob(dataFolderPath, i)
|
| 94 |
+
require.NoError(t, err)
|
| 95 |
+
properties := map[string]interface{}{
|
| 96 |
+
PropertyImageTitle: imageTitle,
|
| 97 |
+
PropertyImageDescription: imageDescription,
|
| 98 |
+
PropertyImage: imageBlob,
|
| 99 |
+
}
|
| 100 |
+
if withVideo {
|
| 101 |
+
videoTitle := line[4]
|
| 102 |
+
videoDescription := line[5]
|
| 103 |
+
videoBlob, err := GetVideoBlob(dataFolderPath, i)
|
| 104 |
+
require.NoError(t, err)
|
| 105 |
+
properties[PropertyVideoTitle] = videoTitle
|
| 106 |
+
properties[PropertyVideoDescription] = videoDescription
|
| 107 |
+
properties[PropertyVideo] = videoBlob
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
obj := &models.Object{
|
| 111 |
+
Class: className,
|
| 112 |
+
ID: strfmt.UUID(id),
|
| 113 |
+
Properties: properties,
|
| 114 |
+
}
|
| 115 |
+
objs = append(objs, obj)
|
| 116 |
+
}
|
| 117 |
+
i++
|
| 118 |
+
}
|
| 119 |
+
for _, obj := range objs {
|
| 120 |
+
err := helper.CreateObjectWithTimeout(t, obj, DefaultTimeout)
|
| 121 |
+
require.NoError(t, err)
|
| 122 |
+
obj := helper.AssertGetObjectEventually(t, obj.Class, obj.ID)
|
| 123 |
+
require.NotNil(t, obj)
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
func GetIDs(t *testing.T, dataFolderPath string) []string {
|
| 128 |
+
f, err := GetCSV(dataFolderPath)
|
| 129 |
+
require.NoError(t, err)
|
| 130 |
+
defer f.Close()
|
| 131 |
+
var ids []string
|
| 132 |
+
i := 0
|
| 133 |
+
csvReader := csv.NewReader(f)
|
| 134 |
+
for {
|
| 135 |
+
line, err := csvReader.Read()
|
| 136 |
+
if err == io.EOF {
|
| 137 |
+
break
|
| 138 |
+
}
|
| 139 |
+
require.NoError(t, err)
|
| 140 |
+
if i > 0 {
|
| 141 |
+
ids = append(ids, line[1])
|
| 142 |
+
}
|
| 143 |
+
i++
|
| 144 |
+
}
|
| 145 |
+
return ids
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
func CheckObjects(t *testing.T, dataFolderPath, className string, vectors, multivectors []string) {
|
| 149 |
+
for _, id := range GetIDs(t, dataFolderPath) {
|
| 150 |
+
t.Run(id, func(t *testing.T) {
|
| 151 |
+
obj, err := helper.GetObject(t, className, strfmt.UUID(id), "vector")
|
| 152 |
+
require.NoError(t, err)
|
| 153 |
+
require.NotNil(t, obj)
|
| 154 |
+
require.GreaterOrEqual(t, len(obj.Vectors), len(vectors)+len(multivectors))
|
| 155 |
+
for _, vec := range vectors {
|
| 156 |
+
require.IsType(t, []float32{}, obj.Vectors[vec])
|
| 157 |
+
require.True(t, len(obj.Vectors[vec].([]float32)) > 0)
|
| 158 |
+
}
|
| 159 |
+
for _, multivec := range multivectors {
|
| 160 |
+
require.IsType(t, [][]float32{}, obj.Vectors[multivec])
|
| 161 |
+
require.True(t, len(obj.Vectors[multivec].([][]float32)) > 0)
|
| 162 |
+
}
|
| 163 |
+
})
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
func GetImageBlob(dataFolderPath string, i int) (string, error) {
|
| 168 |
+
path := fmt.Sprintf("%s/images/%v.jpg", dataFolderPath, i)
|
| 169 |
+
return helper.GetBase64EncodedData(path)
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
func GetVideoBlob(dataFolderPath string, i int) (string, error) {
|
| 173 |
+
path := fmt.Sprintf("%s/videos/%v.mp4", dataFolderPath, i)
|
| 174 |
+
return helper.GetBase64EncodedData(path)
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
func GetCSV(dataFolderPath string) (*os.File, error) {
|
| 178 |
+
return os.Open(fmt.Sprintf("%s/data.csv", dataFolderPath))
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
// query test helper
|
| 182 |
+
func TestQuery(t *testing.T,
|
| 183 |
+
className, nearMediaArgument, titleProperty, titlePropertyValue string,
|
| 184 |
+
targetVectors map[string]int,
|
| 185 |
+
) {
|
| 186 |
+
var targetVectorsList []string
|
| 187 |
+
for targetVector := range targetVectors {
|
| 188 |
+
targetVectorsList = append(targetVectorsList, targetVector)
|
| 189 |
+
}
|
| 190 |
+
additionalVectors := ""
|
| 191 |
+
if len(targetVectorsList) > 0 {
|
| 192 |
+
additionalVectors = fmt.Sprintf("vectors {%s}", strings.Join(targetVectorsList, ","))
|
| 193 |
+
}
|
| 194 |
+
query := fmt.Sprintf(`
|
| 195 |
+
{
|
| 196 |
+
Get {
|
| 197 |
+
%s(
|
| 198 |
+
%s
|
| 199 |
+
){
|
| 200 |
+
%s
|
| 201 |
+
_additional {
|
| 202 |
+
certainty
|
| 203 |
+
%s
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
`, className, nearMediaArgument, titleProperty, additionalVectors)
|
| 209 |
+
|
| 210 |
+
result := graphqlhelper.AssertGraphQLWithTimeout(t, helper.RootAuth, DefaultTimeout, query)
|
| 211 |
+
objs := result.Get("Get", className).AsSlice()
|
| 212 |
+
require.Len(t, objs, 2)
|
| 213 |
+
title := objs[0].(map[string]interface{})[titleProperty]
|
| 214 |
+
assert.Equal(t, titlePropertyValue, title)
|
| 215 |
+
additional, ok := objs[0].(map[string]interface{})["_additional"].(map[string]interface{})
|
| 216 |
+
require.True(t, ok)
|
| 217 |
+
certainty := additional["certainty"].(json.Number)
|
| 218 |
+
assert.NotNil(t, certainty)
|
| 219 |
+
certaintyValue, err := certainty.Float64()
|
| 220 |
+
require.NoError(t, err)
|
| 221 |
+
assert.Greater(t, certaintyValue, 0.0)
|
| 222 |
+
assert.GreaterOrEqual(t, certaintyValue, 0.9)
|
| 223 |
+
if len(targetVectorsList) > 0 {
|
| 224 |
+
vectors, ok := additional["vectors"].(map[string]interface{})
|
| 225 |
+
require.True(t, ok)
|
| 226 |
+
|
| 227 |
+
targetVectorsMap := make(map[string][]float32)
|
| 228 |
+
for targetVector := range targetVectors {
|
| 229 |
+
vector, ok := vectors[targetVector].([]interface{})
|
| 230 |
+
require.True(t, ok)
|
| 231 |
+
|
| 232 |
+
vec := make([]float32, len(vector))
|
| 233 |
+
for i := range vector {
|
| 234 |
+
val, err := vector[i].(json.Number).Float64()
|
| 235 |
+
require.NoError(t, err)
|
| 236 |
+
vec[i] = float32(val)
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
targetVectorsMap[targetVector] = vec
|
| 240 |
+
}
|
| 241 |
+
for targetVector, targetVectorDimensions := range targetVectors {
|
| 242 |
+
require.Len(t, targetVectorsMap[targetVector], targetVectorDimensions)
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/multishard/multishard.go
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package multishard
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"github.com/go-openapi/strfmt"
|
| 16 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 17 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
const (
|
| 21 |
+
MultiShardID1 strfmt.UUID = "aa44bbee-ca5f-4db7-a412-5fc6a23c534a"
|
| 22 |
+
MultiShardID2 strfmt.UUID = "aa44bbee-ca5f-4db7-a412-5fc6a23c534b"
|
| 23 |
+
MultiShardID3 strfmt.UUID = "aa44bbee-ca5f-4db7-a412-5fc6a23c534c"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
func ClassContextionaryVectorizer() *models.Class {
|
| 27 |
+
return class("text2vec-contextionary")
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
func ClassTransformersVectorizer() *models.Class {
|
| 31 |
+
return class("text2vec-transformers")
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
func class(vectorizer string) *models.Class {
|
| 35 |
+
return &models.Class{
|
| 36 |
+
Class: "MultiShard",
|
| 37 |
+
ModuleConfig: map[string]interface{}{
|
| 38 |
+
vectorizer: map[string]interface{}{
|
| 39 |
+
"vectorizeClassName": false,
|
| 40 |
+
},
|
| 41 |
+
},
|
| 42 |
+
Vectorizer: vectorizer,
|
| 43 |
+
Properties: []*models.Property{
|
| 44 |
+
{
|
| 45 |
+
Name: "name",
|
| 46 |
+
DataType: schema.DataTypeText.PropString(),
|
| 47 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 48 |
+
ModuleConfig: map[string]interface{}{
|
| 49 |
+
vectorizer: map[string]interface{}{
|
| 50 |
+
"vectorizePropertyName": false,
|
| 51 |
+
},
|
| 52 |
+
},
|
| 53 |
+
},
|
| 54 |
+
},
|
| 55 |
+
ShardingConfig: map[string]interface{}{
|
| 56 |
+
"actualCount": float64(2),
|
| 57 |
+
"actualVirtualCount": float64(128),
|
| 58 |
+
"desiredCount": float64(2),
|
| 59 |
+
"desiredVirtualCount": float64(128),
|
| 60 |
+
"function": "murmur3",
|
| 61 |
+
"key": "_id",
|
| 62 |
+
"strategy": "hash",
|
| 63 |
+
"virtualPerPhysical": float64(128),
|
| 64 |
+
},
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
func Objects() []*models.Object {
|
| 69 |
+
return []*models.Object{
|
| 70 |
+
{
|
| 71 |
+
Class: "MultiShard",
|
| 72 |
+
ID: MultiShardID1,
|
| 73 |
+
Properties: map[string]interface{}{
|
| 74 |
+
"name": "multi shard one",
|
| 75 |
+
},
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
Class: "MultiShard",
|
| 79 |
+
ID: MultiShardID2,
|
| 80 |
+
Properties: map[string]interface{}{
|
| 81 |
+
"name": "multi shard two",
|
| 82 |
+
},
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
Class: "MultiShard",
|
| 86 |
+
ID: MultiShardID3,
|
| 87 |
+
Properties: map[string]interface{}{
|
| 88 |
+
"name": "multi shard three",
|
| 89 |
+
},
|
| 90 |
+
},
|
| 91 |
+
}
|
| 92 |
+
}
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/planets/data/images/earth.jpg
ADDED
|
Git LFS Details
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/planets/data/images/mars.jpg
ADDED
|
Git LFS Details
|
platform/dbops/binaries/weaviate-src/test/helper/sample-schema/planets/planets.go
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package planets
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"strings"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/go-openapi/strfmt"
|
| 21 |
+
"github.com/stretchr/testify/assert"
|
| 22 |
+
"github.com/stretchr/testify/require"
|
| 23 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 24 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 25 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 26 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 27 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 28 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
type Planet struct {
|
| 32 |
+
ID strfmt.UUID
|
| 33 |
+
Name, Description string
|
| 34 |
+
Satellites []string
|
| 35 |
+
MeanRadius float64
|
| 36 |
+
IsHabitable bool
|
| 37 |
+
SurfaceTemperaturesCelcius []float64
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
var Planets = []Planet{
|
| 41 |
+
{
|
| 42 |
+
ID: strfmt.UUID("00000000-0000-0000-0000-000000000001"),
|
| 43 |
+
Name: "Earth",
|
| 44 |
+
Description: `
|
| 45 |
+
The Earth's surface is predominantly covered by oceans, accounting for about 71% of its total area, while continents provide
|
| 46 |
+
the stage for bustling cities, towering mountains, and sprawling forests. Its atmosphere, composed mostly of nitrogen and oxygen,
|
| 47 |
+
protects life from harmful solar radiation and regulates the planet's climate, creating the conditions necessary for life to flourish.
|
| 48 |
+
|
| 49 |
+
Humans, as the dominant species, have left an indelible mark on Earth, shaping its landscapes and ecosystems in profound ways.
|
| 50 |
+
However, with this influence comes the responsibility to steward and preserve our planet for future generations.
|
| 51 |
+
`,
|
| 52 |
+
Satellites: []string{"Moon"},
|
| 53 |
+
MeanRadius: 6371.0,
|
| 54 |
+
IsHabitable: true,
|
| 55 |
+
SurfaceTemperaturesCelcius: []float64{-89.2, 14.76, 56.7},
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
ID: strfmt.UUID("00000000-0000-0000-0000-000000000002"),
|
| 59 |
+
Name: "Mars",
|
| 60 |
+
Description: `
|
| 61 |
+
Mars, often called the "Red Planet" due to its rusty reddish hue, is the fourth planet from the Sun in our solar system.
|
| 62 |
+
It's a world of stark contrasts and mysterious allure, captivating the imaginations of scientists, explorers, and dreamers alike.
|
| 63 |
+
|
| 64 |
+
With its barren, rocky terrain and thin atmosphere primarily composed of carbon dioxide, Mars presents a harsh environment vastly
|
| 65 |
+
different from Earth. Yet, beneath its desolate surface lie tantalizing clues about its past, including evidence of ancient rivers,
|
| 66 |
+
lakes, and even the possibility of microbial life.
|
| 67 |
+
`,
|
| 68 |
+
Satellites: []string{"Phobos", "Deimos"},
|
| 69 |
+
MeanRadius: 3389.5,
|
| 70 |
+
IsHabitable: false,
|
| 71 |
+
SurfaceTemperaturesCelcius: []float64{-110, -60, 35},
|
| 72 |
+
},
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
func BaseClass(className string) *models.Class {
|
| 76 |
+
return &models.Class{
|
| 77 |
+
Class: className,
|
| 78 |
+
Properties: []*models.Property{
|
| 79 |
+
{
|
| 80 |
+
Name: "name", DataType: []string{schema.DataTypeText.String()},
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
Name: "description", DataType: []string{schema.DataTypeText.String()},
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
Name: "image", DataType: []string{schema.DataTypeBlob.String()},
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
Name: "satellites", DataType: []string{string(schema.DataTypeTextArray.String())},
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
Name: "meanRadius", DataType: []string{string(schema.DataTypeNumber.String())},
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
Name: "isHabitable", DataType: []string{string(schema.DataTypeBoolean.String())},
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
Name: "surfaceTemperaturesCelcius", DataType: []string{string(schema.DataTypeNumberArray.String())},
|
| 99 |
+
},
|
| 100 |
+
},
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
func InsertObjects(t *testing.T, className string) {
|
| 105 |
+
InsertObjectsWithImages(t, className, "")
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
func InsertObjectsWithImages(t *testing.T, className, dataFolderPath string) {
|
| 109 |
+
getProperties := func(t *testing.T, planet Planet, dataFolderPath string) map[string]interface{} {
|
| 110 |
+
properties := map[string]interface{}{
|
| 111 |
+
"name": planet.Name,
|
| 112 |
+
"description": planet.Description,
|
| 113 |
+
"satellites": planet.Satellites,
|
| 114 |
+
"meanRadius": planet.MeanRadius,
|
| 115 |
+
"isHabitable": planet.IsHabitable,
|
| 116 |
+
"surfaceTemperaturesCelcius": planet.SurfaceTemperaturesCelcius,
|
| 117 |
+
}
|
| 118 |
+
if dataFolderPath != "" {
|
| 119 |
+
imageBase64, err := GetImageBlob(dataFolderPath, strings.ToLower(planet.Name))
|
| 120 |
+
require.NoError(t, err)
|
| 121 |
+
properties["image"] = imageBase64
|
| 122 |
+
}
|
| 123 |
+
return properties
|
| 124 |
+
}
|
| 125 |
+
for _, planet := range Planets {
|
| 126 |
+
obj := &models.Object{
|
| 127 |
+
Class: className,
|
| 128 |
+
ID: planet.ID,
|
| 129 |
+
Properties: getProperties(t, planet, dataFolderPath),
|
| 130 |
+
}
|
| 131 |
+
helper.CreateObject(t, obj)
|
| 132 |
+
helper.AssertGetObjectEventually(t, obj.Class, obj.ID)
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
func CreateTweetTest(t *testing.T, className string) {
|
| 137 |
+
CreateTweetTestWithParams(t, className, "")
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
func CreateTweetTestWithParams(t *testing.T, className, params string) {
|
| 141 |
+
CreatePromptTestWithParams(t, className, "Write a short tweet about planet {name}", params)
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
func CreatePromptTestWithParams(t *testing.T, className, prompt, params string) {
|
| 145 |
+
CreatePromptTestWithParamsWithDebug(t, className, prompt, params, false)
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
func CreatePromptTestWithParamsWithDebug(t *testing.T, className, prompt, params string, debug bool) {
|
| 149 |
+
debugParams := []string{"", ""}
|
| 150 |
+
if debug {
|
| 151 |
+
debugParams = []string{"debug:true", "debug{prompt}"}
|
| 152 |
+
}
|
| 153 |
+
query := fmt.Sprintf(`
|
| 154 |
+
{
|
| 155 |
+
Get {
|
| 156 |
+
%s{
|
| 157 |
+
name
|
| 158 |
+
_additional {
|
| 159 |
+
generate(
|
| 160 |
+
singleResult: {
|
| 161 |
+
prompt: """
|
| 162 |
+
%s
|
| 163 |
+
"""
|
| 164 |
+
%s
|
| 165 |
+
%s
|
| 166 |
+
}
|
| 167 |
+
) {
|
| 168 |
+
singleResult
|
| 169 |
+
error
|
| 170 |
+
%s
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
`, className, prompt, params, debugParams[0], debugParams[1])
|
| 177 |
+
result := graphqlhelper.AssertGraphQLWithTimeout(t, helper.RootAuth, 10*time.Minute, query)
|
| 178 |
+
objs := result.Get("Get", className).AsSlice()
|
| 179 |
+
require.Len(t, objs, 2)
|
| 180 |
+
for i, obj := range objs {
|
| 181 |
+
name := obj.(map[string]interface{})["name"]
|
| 182 |
+
assert.NotEmpty(t, name)
|
| 183 |
+
additional, ok := obj.(map[string]interface{})["_additional"].(map[string]interface{})
|
| 184 |
+
require.True(t, ok)
|
| 185 |
+
require.NotNil(t, additional)
|
| 186 |
+
generate, ok := additional["generate"].(map[string]interface{})
|
| 187 |
+
require.True(t, ok)
|
| 188 |
+
require.NotNil(t, generate)
|
| 189 |
+
require.Nil(t, generate["error"])
|
| 190 |
+
require.NotNil(t, generate["singleResult"])
|
| 191 |
+
singleResult, ok := generate["singleResult"].(string)
|
| 192 |
+
require.True(t, ok)
|
| 193 |
+
require.NotEmpty(t, singleResult)
|
| 194 |
+
// print the results of the prompt
|
| 195 |
+
if debug {
|
| 196 |
+
debugResult, ok := generate["debug"].(map[string]interface{})
|
| 197 |
+
require.True(t, ok)
|
| 198 |
+
require.NotNil(t, debugResult["prompt"])
|
| 199 |
+
debugPrompt, ok := debugResult["prompt"].(string)
|
| 200 |
+
require.True(t, ok)
|
| 201 |
+
t.Logf("---------------\n[%v]Prompt: %s\n[%v]Debug.prompt: %v\n[%v]Result: %s\n---------------\n", i, prompt, i, debugPrompt, i, singleResult)
|
| 202 |
+
} else {
|
| 203 |
+
t.Logf("---------------\n[%v]Prompt: %s\n[%v]Result: %s\n---------------\n", i, prompt, i, singleResult)
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
func CreateTweetTestGRPC(t *testing.T, className string) {
|
| 209 |
+
CreateTweetTestWithParamsGRPC(t, className, nil)
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
func CreateTweetTestWithParamsGRPC(t *testing.T, className string, params *pb.GenerativeProvider) {
|
| 213 |
+
CreatePromptTestWithParamsGRPC(t, className, "Write a short tweet about planet {name}", "Write a short tweet about the following planets", params)
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
func CreatePromptTestWithParamsGRPC(t *testing.T, className, singlePrompt, groupPrompt string, params *pb.GenerativeProvider) {
|
| 217 |
+
var queries []*pb.GenerativeProvider
|
| 218 |
+
if params != nil {
|
| 219 |
+
queries = []*pb.GenerativeProvider{params}
|
| 220 |
+
}
|
| 221 |
+
req := &pb.SearchRequest{
|
| 222 |
+
Collection: className,
|
| 223 |
+
Limit: 2,
|
| 224 |
+
Generative: &pb.GenerativeSearch{
|
| 225 |
+
Single: &pb.GenerativeSearch_Single{
|
| 226 |
+
Prompt: singlePrompt,
|
| 227 |
+
Queries: queries,
|
| 228 |
+
},
|
| 229 |
+
Grouped: &pb.GenerativeSearch_Grouped{
|
| 230 |
+
Task: groupPrompt,
|
| 231 |
+
Properties: &pb.TextArray{Values: []string{"name"}},
|
| 232 |
+
Queries: queries,
|
| 233 |
+
},
|
| 234 |
+
},
|
| 235 |
+
Uses_127Api: true,
|
| 236 |
+
}
|
| 237 |
+
resp := grpchelper.AssertSearchWithTimeout(t, req, 10*time.Minute)
|
| 238 |
+
require.NotNil(t, resp)
|
| 239 |
+
require.Len(t, resp.Results, 2)
|
| 240 |
+
for i, res := range resp.Results {
|
| 241 |
+
assertGenerative(t, res.Generative, params)
|
| 242 |
+
t.Logf("---------------\n[%v]Single Prompt: %s\n[%v]Result: %s\n---------------\n", i, singlePrompt, i, res.Generative.GetValues()[0].Result)
|
| 243 |
+
}
|
| 244 |
+
assertGenerative(t, resp.GenerativeGroupedResults, params)
|
| 245 |
+
t.Logf("---------------\nGrouped Prompt: %s\nResult: %s\n---------------\n", groupPrompt, resp.GenerativeGroupedResults.GetValues()[0].Result)
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
func assertGenerative(t *testing.T, generative *pb.GenerativeResult, params *pb.GenerativeProvider) {
|
| 249 |
+
require.Len(t, generative.GetValues(), 1)
|
| 250 |
+
require.NotEmpty(t, generative.GetValues()[0].Result)
|
| 251 |
+
if params.GetReturnMetadata() {
|
| 252 |
+
metadata := generative.GetValues()[0].GetMetadata()
|
| 253 |
+
require.NotEmpty(t, metadata)
|
| 254 |
+
if params.GetAnthropic() != nil {
|
| 255 |
+
anthropic := metadata.GetAnthropic()
|
| 256 |
+
require.NotEmpty(t, anthropic)
|
| 257 |
+
usage := anthropic.GetUsage()
|
| 258 |
+
require.NotEmpty(t, usage)
|
| 259 |
+
require.NotEmpty(t, usage.GetInputTokens())
|
| 260 |
+
require.NotEmpty(t, usage.GetOutputTokens())
|
| 261 |
+
}
|
| 262 |
+
if params.GetCohere() != nil {
|
| 263 |
+
require.NotEmpty(t, metadata.GetCohere())
|
| 264 |
+
}
|
| 265 |
+
if params.GetMistral() != nil {
|
| 266 |
+
require.NotEmpty(t, metadata.GetMistral())
|
| 267 |
+
}
|
| 268 |
+
if params.GetOpenai() != nil {
|
| 269 |
+
require.NotEmpty(t, metadata.GetOpenai())
|
| 270 |
+
}
|
| 271 |
+
if params.GetGoogle() != nil {
|
| 272 |
+
require.NotEmpty(t, metadata.GetGoogle())
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
func GetImageBlob(dataFolderPath, name string) (string, error) {
|
| 278 |
+
path := fmt.Sprintf("%s/images/%s.jpg", dataFolderPath, name)
|
| 279 |
+
return helper.GetBase64EncodedData(path)
|
| 280 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-azure/backup_backend_test.go
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"os"
|
| 19 |
+
"testing"
|
| 20 |
+
"time"
|
| 21 |
+
|
| 22 |
+
"github.com/sirupsen/logrus"
|
| 23 |
+
"github.com/stretchr/testify/assert"
|
| 24 |
+
"github.com/stretchr/testify/require"
|
| 25 |
+
|
| 26 |
+
"github.com/weaviate/weaviate/entities/backup"
|
| 27 |
+
"github.com/weaviate/weaviate/entities/moduletools"
|
| 28 |
+
mod "github.com/weaviate/weaviate/modules/backup-azure"
|
| 29 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 30 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 31 |
+
ubak "github.com/weaviate/weaviate/usecases/backup"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
func Test_AzureBackend_Start(t *testing.T) {
|
| 35 |
+
tests := []struct {
|
| 36 |
+
name string
|
| 37 |
+
overrideBucket string
|
| 38 |
+
overridePath string
|
| 39 |
+
}{
|
| 40 |
+
{
|
| 41 |
+
name: "default overrides",
|
| 42 |
+
overrideBucket: "",
|
| 43 |
+
overridePath: "",
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
name: "test bucket and path overrides",
|
| 47 |
+
overrideBucket: "testbucketoverride",
|
| 48 |
+
overridePath: "testBucketPathOverride",
|
| 49 |
+
},
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
for _, tt := range tests {
|
| 53 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 54 |
+
testAzureBackendBackup(tt.overrideBucket, tt.overridePath)(t)
|
| 55 |
+
})
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
func testAzureBackendBackup(overrideBucket, overridePath string) func(t *testing.T) {
|
| 60 |
+
return func(t *testing.T) {
|
| 61 |
+
ctx := context.Background()
|
| 62 |
+
compose, err := docker.New().WithAzurite().Start(ctx)
|
| 63 |
+
if err != nil {
|
| 64 |
+
t.Fatalf("cannot start: %v", err)
|
| 65 |
+
}
|
| 66 |
+
defer func() {
|
| 67 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 68 |
+
t.Fatalf("failed to terminate test containers: %v", err)
|
| 69 |
+
}
|
| 70 |
+
}()
|
| 71 |
+
|
| 72 |
+
t.Setenv(envAzureEndpoint, compose.GetAzurite().URI())
|
| 73 |
+
|
| 74 |
+
subTests := []struct {
|
| 75 |
+
name string
|
| 76 |
+
test func(t *testing.T)
|
| 77 |
+
}{
|
| 78 |
+
{
|
| 79 |
+
name: "store backup meta",
|
| 80 |
+
test: func(t *testing.T) {
|
| 81 |
+
moduleLevelStoreBackupMeta(t, overrideBucket, overridePath)
|
| 82 |
+
},
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
name: "copy objects",
|
| 86 |
+
test: func(t *testing.T) {
|
| 87 |
+
moduleLevelCopyObjects(t, overrideBucket, overridePath)
|
| 88 |
+
},
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
name: "copy files",
|
| 92 |
+
test: func(t *testing.T) {
|
| 93 |
+
moduleLevelCopyFiles(t, overrideBucket, overridePath)
|
| 94 |
+
},
|
| 95 |
+
},
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
for _, st := range subTests {
|
| 99 |
+
t.Run(st.name, st.test)
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
func moduleLevelStoreBackupMeta(t *testing.T, overrideBucket, overridePath string) {
|
| 105 |
+
testCtx := context.Background()
|
| 106 |
+
|
| 107 |
+
className := "BackupClass"
|
| 108 |
+
backupID := "backup_id"
|
| 109 |
+
containerName := "container-level-store-backup-meta"
|
| 110 |
+
if overrideBucket != "" {
|
| 111 |
+
containerName = overrideBucket
|
| 112 |
+
}
|
| 113 |
+
endpoint := os.Getenv(envAzureEndpoint)
|
| 114 |
+
metadataFilename := "backup.json"
|
| 115 |
+
|
| 116 |
+
t.Log("setup env")
|
| 117 |
+
t.Setenv(envAzureEndpoint, endpoint)
|
| 118 |
+
t.Setenv(envAzureStorageConnectionString, fmt.Sprintf(connectionString, endpoint))
|
| 119 |
+
t.Setenv(envAzureContainer, containerName)
|
| 120 |
+
moduleshelper.CreateAzureContainer(testCtx, t, endpoint, containerName)
|
| 121 |
+
defer moduleshelper.DeleteAzureContainer(testCtx, t, endpoint, containerName)
|
| 122 |
+
|
| 123 |
+
t.Run("store backup meta in Azure", func(t *testing.T) {
|
| 124 |
+
t.Setenv(envAzureContainer, containerName)
|
| 125 |
+
azure := mod.New()
|
| 126 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 127 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 128 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: t.TempDir()})
|
| 129 |
+
err := azure.Init(testCtx, params)
|
| 130 |
+
require.Nil(t, err)
|
| 131 |
+
|
| 132 |
+
t.Run("access permissions", func(t *testing.T) {
|
| 133 |
+
err := azure.Initialize(testCtx, backupID, overrideBucket, overridePath)
|
| 134 |
+
assert.Nil(t, err)
|
| 135 |
+
})
|
| 136 |
+
|
| 137 |
+
t.Run("backup meta does not exist yet", func(t *testing.T) {
|
| 138 |
+
meta, err := azure.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 139 |
+
assert.Nil(t, meta)
|
| 140 |
+
assert.NotNil(t, err)
|
| 141 |
+
assert.IsType(t, backup.ErrNotFound{}, err)
|
| 142 |
+
})
|
| 143 |
+
|
| 144 |
+
t.Run("put backup meta on backend", func(t *testing.T) {
|
| 145 |
+
desc := &backup.BackupDescriptor{
|
| 146 |
+
StartedAt: time.Now(),
|
| 147 |
+
CompletedAt: time.Time{},
|
| 148 |
+
ID: backupID,
|
| 149 |
+
Classes: []backup.ClassDescriptor{
|
| 150 |
+
{
|
| 151 |
+
Name: className,
|
| 152 |
+
},
|
| 153 |
+
},
|
| 154 |
+
Status: string(backup.Started),
|
| 155 |
+
Version: ubak.Version,
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
b, err := json.Marshal(desc)
|
| 159 |
+
require.Nil(t, err)
|
| 160 |
+
|
| 161 |
+
err = azure.PutObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath, b)
|
| 162 |
+
require.Nil(t, err)
|
| 163 |
+
|
| 164 |
+
dest := azure.HomeDir(backupID, overrideBucket, overridePath)
|
| 165 |
+
|
| 166 |
+
expected := fmt.Sprintf("http://%s/devstoreaccount1/%s/%s", os.Getenv(envAzureEndpoint), containerName, backupID)
|
| 167 |
+
if overridePath != "" {
|
| 168 |
+
expected = fmt.Sprintf("http://%s/devstoreaccount1/%s/%s/%s", os.Getenv(envAzureEndpoint), containerName, overridePath, backupID)
|
| 169 |
+
}
|
| 170 |
+
assert.Equal(t, expected, dest)
|
| 171 |
+
})
|
| 172 |
+
|
| 173 |
+
t.Run("assert backup meta contents", func(t *testing.T) {
|
| 174 |
+
obj, err := azure.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 175 |
+
t.Logf("Error: %+v", err)
|
| 176 |
+
require.Nil(t, err)
|
| 177 |
+
|
| 178 |
+
var meta backup.BackupDescriptor
|
| 179 |
+
err = json.Unmarshal(obj, &meta)
|
| 180 |
+
require.Nil(t, err)
|
| 181 |
+
assert.NotEmpty(t, meta.StartedAt)
|
| 182 |
+
assert.Empty(t, meta.CompletedAt)
|
| 183 |
+
assert.Equal(t, meta.Status, string(backup.Started))
|
| 184 |
+
assert.Empty(t, meta.Error)
|
| 185 |
+
assert.Len(t, meta.Classes, 1)
|
| 186 |
+
assert.Equal(t, meta.Classes[0].Name, className)
|
| 187 |
+
assert.Equal(t, meta.Version, ubak.Version)
|
| 188 |
+
assert.Nil(t, meta.Classes[0].Error)
|
| 189 |
+
})
|
| 190 |
+
})
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
func moduleLevelCopyObjects(t *testing.T, overrideBucket, overridePath string) {
|
| 194 |
+
testCtx := context.Background()
|
| 195 |
+
|
| 196 |
+
key := "moduleLevelCopyObjects"
|
| 197 |
+
backupID := "backup_id"
|
| 198 |
+
containerName := "container-level-copy-objects"
|
| 199 |
+
if overrideBucket != "" {
|
| 200 |
+
containerName = overrideBucket
|
| 201 |
+
}
|
| 202 |
+
endpoint := os.Getenv(envAzureEndpoint)
|
| 203 |
+
|
| 204 |
+
t.Log("setup env")
|
| 205 |
+
t.Setenv(envAzureEndpoint, endpoint)
|
| 206 |
+
t.Setenv(envAzureStorageConnectionString, fmt.Sprintf(connectionString, endpoint))
|
| 207 |
+
t.Setenv(envAzureContainer, containerName)
|
| 208 |
+
moduleshelper.CreateAzureContainer(testCtx, t, endpoint, containerName)
|
| 209 |
+
defer moduleshelper.DeleteAzureContainer(testCtx, t, endpoint, containerName)
|
| 210 |
+
|
| 211 |
+
t.Run("copy objects", func(t *testing.T) {
|
| 212 |
+
t.Setenv(envAzureContainer, containerName)
|
| 213 |
+
azure := mod.New()
|
| 214 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 215 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 216 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: t.TempDir()})
|
| 217 |
+
err := azure.Init(testCtx, params)
|
| 218 |
+
require.Nil(t, err)
|
| 219 |
+
|
| 220 |
+
t.Run("put object to bucket", func(t *testing.T) {
|
| 221 |
+
err := azure.PutObject(testCtx, backupID, key, overrideBucket, overridePath, []byte("hello"))
|
| 222 |
+
t.Logf("Error: %+v", err)
|
| 223 |
+
assert.Nil(t, err)
|
| 224 |
+
})
|
| 225 |
+
|
| 226 |
+
t.Run("get object from bucket", func(t *testing.T) {
|
| 227 |
+
meta, err := azure.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 228 |
+
assert.Nil(t, err)
|
| 229 |
+
assert.Equal(t, []byte("hello"), meta)
|
| 230 |
+
})
|
| 231 |
+
})
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
func moduleLevelCopyFiles(t *testing.T, overrideBucket, overridePath string) {
|
| 235 |
+
testCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
| 236 |
+
defer cancel()
|
| 237 |
+
|
| 238 |
+
dataDir := t.TempDir()
|
| 239 |
+
key := "moduleLevelCopyFiles"
|
| 240 |
+
backupID := "backup_id"
|
| 241 |
+
containerName := "container-level-copy-files"
|
| 242 |
+
if overrideBucket != "" {
|
| 243 |
+
containerName = overrideBucket
|
| 244 |
+
}
|
| 245 |
+
endpoint := os.Getenv(envAzureEndpoint)
|
| 246 |
+
|
| 247 |
+
t.Log("setup env")
|
| 248 |
+
t.Setenv(envAzureEndpoint, endpoint)
|
| 249 |
+
t.Setenv(envAzureStorageConnectionString, fmt.Sprintf(connectionString, endpoint))
|
| 250 |
+
t.Logf("Connection string: %s\n", os.Getenv(envAzureStorageConnectionString))
|
| 251 |
+
t.Setenv(envAzureContainer, containerName)
|
| 252 |
+
t.Logf("Creating container %s\n", containerName)
|
| 253 |
+
moduleshelper.CreateAzureContainer(testCtx, t, endpoint, containerName)
|
| 254 |
+
defer moduleshelper.DeleteAzureContainer(testCtx, t, endpoint, containerName)
|
| 255 |
+
|
| 256 |
+
t.Run("copy files", func(t *testing.T) {
|
| 257 |
+
fpaths := moduleshelper.CreateTestFiles(t, dataDir)
|
| 258 |
+
fpath := fpaths[0]
|
| 259 |
+
expectedContents, err := os.ReadFile(fpath)
|
| 260 |
+
require.Nil(t, err)
|
| 261 |
+
require.NotNil(t, expectedContents)
|
| 262 |
+
|
| 263 |
+
t.Setenv(envAzureContainer, containerName)
|
| 264 |
+
azure := mod.New()
|
| 265 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 266 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 267 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: dataDir})
|
| 268 |
+
err = azure.Init(testCtx, params)
|
| 269 |
+
require.Nil(t, err)
|
| 270 |
+
|
| 271 |
+
t.Run("verify source data path", func(t *testing.T) {
|
| 272 |
+
assert.Equal(t, dataDir, azure.SourceDataPath())
|
| 273 |
+
})
|
| 274 |
+
|
| 275 |
+
t.Run("copy file to backend", func(t *testing.T) {
|
| 276 |
+
err = azure.PutObject(testCtx, backupID, key, overrideBucket, overridePath, expectedContents)
|
| 277 |
+
require.Nil(t, err)
|
| 278 |
+
|
| 279 |
+
contents, err := azure.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 280 |
+
require.Nil(t, err)
|
| 281 |
+
assert.Equal(t, expectedContents, contents)
|
| 282 |
+
})
|
| 283 |
+
|
| 284 |
+
t.Run("fetch file from backend", func(t *testing.T) {
|
| 285 |
+
destPath := dataDir + "/file_0.copy.db"
|
| 286 |
+
|
| 287 |
+
err := azure.WriteToFile(testCtx, backupID, key, destPath, overrideBucket, overridePath)
|
| 288 |
+
require.Nil(t, err)
|
| 289 |
+
|
| 290 |
+
contents, err := os.ReadFile(destPath)
|
| 291 |
+
require.Nil(t, err)
|
| 292 |
+
assert.Equal(t, expectedContents, contents)
|
| 293 |
+
})
|
| 294 |
+
})
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
type fakeStorageProvider struct {
|
| 298 |
+
dataPath string
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
func (f *fakeStorageProvider) Storage(name string) (moduletools.Storage, error) {
|
| 302 |
+
return nil, nil
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
func (f *fakeStorageProvider) DataPath() string {
|
| 306 |
+
return f.dataPath
|
| 307 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-azure/backup_journey_test.go
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
|
| 21 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 24 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
const (
|
| 28 |
+
envAzureEndpoint = "AZURE_ENDPOINT"
|
| 29 |
+
envAzureContainer = "BACKUP_AZURE_CONTAINER"
|
| 30 |
+
|
| 31 |
+
envAzureStorageConnectionString = "AZURE_STORAGE_CONNECTION_STRING"
|
| 32 |
+
connectionString = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://%s/devstoreaccount1;"
|
| 33 |
+
|
| 34 |
+
azureBackupJourneyClassName = "AzureBackup"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
func Test_BackupJourney(t *testing.T) {
|
| 38 |
+
ctx := context.Background()
|
| 39 |
+
|
| 40 |
+
backupJourneyStart(t, ctx, false, "backups", "", "")
|
| 41 |
+
t.Run("with override bucket and path", func(t *testing.T) {
|
| 42 |
+
backupJourneyStart(t, ctx, true, "testbucketoverride", "testbucketoverride", "testBucketPathOverride")
|
| 43 |
+
})
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func backupJourneyStart(t *testing.T, ctx context.Context, override bool, containerName, overrideBucket, overridePath string) {
|
| 47 |
+
azureBackupJourneyBackupIDCluster := "azure-backup-cluster"
|
| 48 |
+
if override {
|
| 49 |
+
azureBackupJourneyBackupIDCluster = "azure-backup-cluster-override"
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
t.Run("multiple node", func(t *testing.T) {
|
| 53 |
+
t.Log("pre-instance env setup")
|
| 54 |
+
azureBackupJourneyContainerName := "azure-multiple-nodes"
|
| 55 |
+
t.Setenv(envAzureContainer, azureBackupJourneyContainerName)
|
| 56 |
+
|
| 57 |
+
compose, err := docker.New().
|
| 58 |
+
WithBackendAzure(azureBackupJourneyContainerName).
|
| 59 |
+
WithText2VecContextionary().
|
| 60 |
+
WithWeaviateCluster(3).
|
| 61 |
+
Start(ctx)
|
| 62 |
+
require.Nil(t, err)
|
| 63 |
+
defer func() {
|
| 64 |
+
require.Nil(t, compose.Terminate(ctx))
|
| 65 |
+
}()
|
| 66 |
+
|
| 67 |
+
t.Log("post-instance env setup")
|
| 68 |
+
azuriteEndpoint := compose.GetAzurite().URI()
|
| 69 |
+
t.Setenv(envAzureEndpoint, azuriteEndpoint)
|
| 70 |
+
t.Setenv(envAzureStorageConnectionString, fmt.Sprintf(connectionString, azuriteEndpoint))
|
| 71 |
+
|
| 72 |
+
// Create the default container
|
| 73 |
+
moduleshelper.CreateAzureContainer(ctx, t, azuriteEndpoint, azureBackupJourneyContainerName)
|
| 74 |
+
defer moduleshelper.DeleteAzureContainer(ctx, t, azuriteEndpoint, azureBackupJourneyContainerName)
|
| 75 |
+
|
| 76 |
+
// If using override, create the override container as well
|
| 77 |
+
if override {
|
| 78 |
+
moduleshelper.CreateAzureContainer(ctx, t, azuriteEndpoint, overrideBucket)
|
| 79 |
+
defer moduleshelper.DeleteAzureContainer(ctx, t, azuriteEndpoint, overrideBucket)
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 83 |
+
|
| 84 |
+
t.Run("backup-azure", func(t *testing.T) {
|
| 85 |
+
journey.BackupJourneyTests_Cluster(t, "azure", azureBackupJourneyClassName,
|
| 86 |
+
azureBackupJourneyBackupIDCluster, nil, override, overrideBucket, overridePath, compose.GetWeaviate().URI(), compose.GetWeaviateNode(2).URI())
|
| 87 |
+
})
|
| 88 |
+
})
|
| 89 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-azure/multi_tenant_backup_test.go
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
|
| 21 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 24 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
const (
|
| 28 |
+
numTenants = 50
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
func Test_MultiTenantBackupJourney(t *testing.T) {
|
| 32 |
+
ctx := context.Background()
|
| 33 |
+
|
| 34 |
+
multiTenantBackupJourneyStart(t, ctx, false, "backups", "", "")
|
| 35 |
+
t.Run("with override bucket and path", func(t *testing.T) {
|
| 36 |
+
multiTenantBackupJourneyStart(t, ctx, true, "testbucketoverride", "testbucketoverride", "testBucketPathOverride")
|
| 37 |
+
})
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func multiTenantBackupJourneyStart(t *testing.T, ctx context.Context, override bool, containerName, overrideBucket, overridePath string) {
|
| 41 |
+
azureBackupJourneyBackupIDCluster := "azure-backup-cluster-multi-tenant"
|
| 42 |
+
if override {
|
| 43 |
+
azureBackupJourneyBackupIDCluster = "azure-backup-cluster-multi-tenant-override"
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
tenantNames := make([]string, numTenants)
|
| 47 |
+
for i := range tenantNames {
|
| 48 |
+
tenantNames[i] = fmt.Sprintf("Tenant%d", i)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
t.Run("multiple node", func(t *testing.T) {
|
| 52 |
+
ctx := context.Background()
|
| 53 |
+
t.Log("pre-instance env setup")
|
| 54 |
+
containerToUse := containerName
|
| 55 |
+
if override {
|
| 56 |
+
containerToUse = overrideBucket
|
| 57 |
+
}
|
| 58 |
+
t.Setenv(envAzureContainer, containerToUse)
|
| 59 |
+
|
| 60 |
+
compose, err := docker.New().
|
| 61 |
+
WithBackendAzure(containerToUse).
|
| 62 |
+
WithText2VecContextionary().
|
| 63 |
+
WithWeaviateCluster(3).
|
| 64 |
+
Start(ctx)
|
| 65 |
+
require.Nil(t, err)
|
| 66 |
+
defer func() {
|
| 67 |
+
require.Nil(t, compose.Terminate(ctx))
|
| 68 |
+
}()
|
| 69 |
+
|
| 70 |
+
t.Log("post-instance env setup")
|
| 71 |
+
azuriteEndpoint := compose.GetAzurite().URI()
|
| 72 |
+
t.Setenv(envAzureEndpoint, azuriteEndpoint)
|
| 73 |
+
t.Setenv(envAzureStorageConnectionString, fmt.Sprintf(connectionString, azuriteEndpoint))
|
| 74 |
+
|
| 75 |
+
moduleshelper.CreateAzureContainer(ctx, t, azuriteEndpoint, containerToUse)
|
| 76 |
+
defer moduleshelper.DeleteAzureContainer(ctx, t, azuriteEndpoint, containerToUse)
|
| 77 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 78 |
+
|
| 79 |
+
t.Run("backup-azure", func(t *testing.T) {
|
| 80 |
+
journey.BackupJourneyTests_Cluster(t, "azure", azureBackupJourneyClassName,
|
| 81 |
+
azureBackupJourneyBackupIDCluster, tenantNames, override, overrideBucket, overridePath, compose.GetWeaviate().URI(), compose.GetWeaviateNode(2).URI())
|
| 82 |
+
})
|
| 83 |
+
})
|
| 84 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-filesystem/backup_backend_test.go
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"os"
|
| 19 |
+
"testing"
|
| 20 |
+
"time"
|
| 21 |
+
|
| 22 |
+
"github.com/prometheus/client_golang/prometheus"
|
| 23 |
+
"github.com/sirupsen/logrus/hooks/test"
|
| 24 |
+
"github.com/stretchr/testify/assert"
|
| 25 |
+
"github.com/stretchr/testify/require"
|
| 26 |
+
|
| 27 |
+
"github.com/weaviate/weaviate/entities/backup"
|
| 28 |
+
"github.com/weaviate/weaviate/entities/moduletools"
|
| 29 |
+
modstgfs "github.com/weaviate/weaviate/modules/backup-filesystem"
|
| 30 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 31 |
+
ubak "github.com/weaviate/weaviate/usecases/backup"
|
| 32 |
+
"github.com/weaviate/weaviate/usecases/config"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
func Test_FileSystemBackend_Start(t *testing.T) {
|
| 36 |
+
filesystemBackend_Backup(t, "", "", "")
|
| 37 |
+
filesystemBackend_Backup(t, "", "bucketPath", " with override") // Note: no bucket parameter, because it is not supported by the filesystem backend
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func filesystemBackend_Backup(t *testing.T, overrideBucket, overridePath, overrideDescription string) {
|
| 41 |
+
t.Run("store backup meta"+overrideDescription, func(t *testing.T) { moduleLevelStoreBackupMeta(t, overrideBucket, overridePath, overrideDescription) })
|
| 42 |
+
t.Run("copy objects"+overrideDescription, func(t *testing.T) { moduleLevelCopyObjects(t, overrideBucket, overridePath, overrideDescription) })
|
| 43 |
+
t.Run("copy files"+overrideDescription, func(t *testing.T) { moduleLevelCopyFiles(t, overrideBucket, overridePath, overrideDescription) })
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func moduleLevelStoreBackupMeta(t *testing.T, overrideBucket, overridePath, overrideDescription string) {
|
| 47 |
+
testCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
| 48 |
+
defer cancel()
|
| 49 |
+
|
| 50 |
+
dataDir := t.TempDir()
|
| 51 |
+
backupDir := t.TempDir()
|
| 52 |
+
overrideDir := t.TempDir()
|
| 53 |
+
if overridePath != "" {
|
| 54 |
+
overridePath = overrideDir
|
| 55 |
+
}
|
| 56 |
+
className := "BackupClass"
|
| 57 |
+
backupID := "backup_id"
|
| 58 |
+
metadataFilename := "backup.json"
|
| 59 |
+
|
| 60 |
+
t.Setenv("BACKUP_FILESYSTEM_PATH", backupDir)
|
| 61 |
+
|
| 62 |
+
t.Run("store backup meta in fs"+overrideDescription, func(t *testing.T) {
|
| 63 |
+
logger, _ := test.NewNullLogger()
|
| 64 |
+
sp := fakeStorageProvider{dataDir}
|
| 65 |
+
params := moduletools.NewInitParams(sp, nil, &config.Config{}, logger, prometheus.NewPedanticRegistry())
|
| 66 |
+
|
| 67 |
+
fs := modstgfs.New()
|
| 68 |
+
err := fs.Init(testCtx, params)
|
| 69 |
+
require.Nil(t, err)
|
| 70 |
+
|
| 71 |
+
t.Run("access permissions"+overrideDescription, func(t *testing.T) {
|
| 72 |
+
err := fs.Initialize(testCtx, backupID, overrideBucket, overridePath)
|
| 73 |
+
assert.Nil(t, err)
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
t.Run("backup meta does not exist yet"+overrideDescription, func(t *testing.T) {
|
| 77 |
+
meta, err := fs.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 78 |
+
assert.Nil(t, meta)
|
| 79 |
+
assert.NotNil(t, err)
|
| 80 |
+
assert.IsType(t, backup.ErrNotFound{}, err)
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
t.Run("put backup meta on backend"+overrideDescription, func(t *testing.T) {
|
| 84 |
+
desc := &backup.BackupDescriptor{
|
| 85 |
+
StartedAt: time.Now(),
|
| 86 |
+
CompletedAt: time.Time{},
|
| 87 |
+
ID: backupID,
|
| 88 |
+
Classes: []backup.ClassDescriptor{
|
| 89 |
+
{
|
| 90 |
+
Name: className,
|
| 91 |
+
},
|
| 92 |
+
},
|
| 93 |
+
Status: string(backup.Started),
|
| 94 |
+
Version: ubak.Version,
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
b, err := json.Marshal(desc)
|
| 98 |
+
require.Nil(t, err)
|
| 99 |
+
|
| 100 |
+
err = fs.PutObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath, b) // Note: no bucket parameter, because it is not supported by the filesystem backend
|
| 101 |
+
require.Nil(t, err)
|
| 102 |
+
|
| 103 |
+
dest := fs.HomeDir(backupID, overrideBucket, overridePath)
|
| 104 |
+
if overridePath == "" {
|
| 105 |
+
expected := fmt.Sprintf("%s/%s", backupDir, backupID)
|
| 106 |
+
assert.Equal(t, expected, dest)
|
| 107 |
+
} else {
|
| 108 |
+
expected := fmt.Sprintf("%s/%s", overridePath, backupID)
|
| 109 |
+
assert.Equal(t, expected, dest)
|
| 110 |
+
}
|
| 111 |
+
})
|
| 112 |
+
})
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
func moduleLevelCopyObjects(t *testing.T, overrideBucket, overridePath, overrideDescription string) {
|
| 116 |
+
testCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
| 117 |
+
defer cancel()
|
| 118 |
+
|
| 119 |
+
dataDir := t.TempDir()
|
| 120 |
+
backupDir := t.TempDir()
|
| 121 |
+
key := "moduleLevelCopyObjects"
|
| 122 |
+
backupID := "backup_id"
|
| 123 |
+
|
| 124 |
+
t.Setenv("BACKUP_FILESYSTEM_PATH", backupDir)
|
| 125 |
+
|
| 126 |
+
t.Run("copy objects"+overrideDescription, func(t *testing.T) {
|
| 127 |
+
logger, _ := test.NewNullLogger()
|
| 128 |
+
sp := fakeStorageProvider{dataDir}
|
| 129 |
+
params := moduletools.NewInitParams(sp, nil, &config.Config{}, logger, prometheus.NewPedanticRegistry())
|
| 130 |
+
|
| 131 |
+
fs := modstgfs.New()
|
| 132 |
+
err := fs.Init(testCtx, params)
|
| 133 |
+
require.Nil(t, err)
|
| 134 |
+
|
| 135 |
+
t.Run("put object to bucket"+overrideDescription, func(t *testing.T) {
|
| 136 |
+
err := fs.PutObject(testCtx, backupID, key, overrideBucket, overridePath, []byte("hello"))
|
| 137 |
+
assert.Nil(t, err)
|
| 138 |
+
})
|
| 139 |
+
|
| 140 |
+
t.Run("get object from bucket"+overrideDescription, func(t *testing.T) {
|
| 141 |
+
meta, err := fs.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 142 |
+
assert.Nil(t, err)
|
| 143 |
+
assert.Equal(t, []byte("hello"), meta)
|
| 144 |
+
})
|
| 145 |
+
})
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
func moduleLevelCopyFiles(t *testing.T, overrideBucket, overridePath, overrideDescription string) {
|
| 149 |
+
testCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
| 150 |
+
defer cancel()
|
| 151 |
+
|
| 152 |
+
dataDir := t.TempDir()
|
| 153 |
+
backupDir := t.TempDir()
|
| 154 |
+
key := "moduleLevelCopyFiles"
|
| 155 |
+
backupID := "backup_id"
|
| 156 |
+
|
| 157 |
+
t.Setenv("BACKUP_FILESYSTEM_PATH", backupDir)
|
| 158 |
+
|
| 159 |
+
t.Run("copy files"+overrideDescription, func(t *testing.T) {
|
| 160 |
+
fpaths := moduleshelper.CreateTestFiles(t, dataDir)
|
| 161 |
+
fpath := fpaths[0]
|
| 162 |
+
expectedContents, err := os.ReadFile(fpath)
|
| 163 |
+
require.Nil(t, err)
|
| 164 |
+
require.NotNil(t, expectedContents)
|
| 165 |
+
|
| 166 |
+
logger, _ := test.NewNullLogger()
|
| 167 |
+
sp := fakeStorageProvider{dataDir}
|
| 168 |
+
params := moduletools.NewInitParams(sp, nil, &config.Config{}, logger, prometheus.NewPedanticRegistry())
|
| 169 |
+
|
| 170 |
+
fs := modstgfs.New()
|
| 171 |
+
err = fs.Init(testCtx, params)
|
| 172 |
+
require.Nil(t, err)
|
| 173 |
+
|
| 174 |
+
t.Run("verify source data path"+overrideDescription, func(t *testing.T) {
|
| 175 |
+
assert.Equal(t, dataDir, fs.SourceDataPath())
|
| 176 |
+
})
|
| 177 |
+
|
| 178 |
+
t.Logf("Source data path: %s\n"+overrideDescription, fs.SourceDataPath())
|
| 179 |
+
|
| 180 |
+
t.Run("copy file to backend", func(t *testing.T) {
|
| 181 |
+
err := fs.PutObject(testCtx, backupID, key, overrideBucket, overridePath, expectedContents)
|
| 182 |
+
require.Nil(t, err)
|
| 183 |
+
|
| 184 |
+
contents, err := fs.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 185 |
+
require.Nil(t, err)
|
| 186 |
+
assert.Equal(t, expectedContents, contents)
|
| 187 |
+
})
|
| 188 |
+
|
| 189 |
+
t.Run("fetch file from backend"+overrideDescription, func(t *testing.T) {
|
| 190 |
+
destPath := dataDir + "/file_0.copy.db"
|
| 191 |
+
|
| 192 |
+
t.Logf("Calling WriteToFile with backupID: %s, key: %s, destPath: %s, override: %s\n", backupID, key, destPath, overrideBucket+"/"+overridePath)
|
| 193 |
+
err := fs.WriteToFile(testCtx, backupID, key, destPath, overrideBucket, overridePath)
|
| 194 |
+
t.Logf("Error: %+v", err)
|
| 195 |
+
require.Nil(t, err)
|
| 196 |
+
|
| 197 |
+
contents, err := os.ReadFile(destPath)
|
| 198 |
+
require.Nil(t, err)
|
| 199 |
+
assert.Equal(t, expectedContents, contents)
|
| 200 |
+
})
|
| 201 |
+
})
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
type fakeStorageProvider struct {
|
| 205 |
+
dataPath string
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
func (sp fakeStorageProvider) Storage(name string) (moduletools.Storage, error) {
|
| 209 |
+
return nil, nil
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
func (sp fakeStorageProvider) DataPath() string {
|
| 213 |
+
return sp.dataPath
|
| 214 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-filesystem/backup_journey_test.go
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"testing"
|
| 17 |
+
"time"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
modstgfilesystem "github.com/weaviate/weaviate/modules/backup-filesystem"
|
| 21 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
const (
|
| 27 |
+
fsBackupJourneyClassName = "FileSystemBackup"
|
| 28 |
+
fsBackupJourneyBackupIDSingleNode = "fs-backup-single-node"
|
| 29 |
+
fsBackupJourneyBackupIDCluster = "fs-backup-cluster"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
func Test_BackupJourney(t *testing.T) {
|
| 33 |
+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
| 34 |
+
defer cancel()
|
| 35 |
+
|
| 36 |
+
t.Run("single node", func(t *testing.T) {
|
| 37 |
+
compose, err := docker.New().
|
| 38 |
+
WithBackendFilesystem().
|
| 39 |
+
WithText2VecContextionary().
|
| 40 |
+
WithWeaviate().
|
| 41 |
+
Start(ctx)
|
| 42 |
+
require.Nil(t, err)
|
| 43 |
+
|
| 44 |
+
defer func() {
|
| 45 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 46 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 47 |
+
}
|
| 48 |
+
}()
|
| 49 |
+
|
| 50 |
+
t.Run("backup-filesystem", func(t *testing.T) {
|
| 51 |
+
journey.BackupJourneyTests_SingleNode(t, compose.GetWeaviate().URI(),
|
| 52 |
+
"filesystem", fsBackupJourneyClassName, fsBackupJourneyBackupIDSingleNode, nil, false, "", "")
|
| 53 |
+
})
|
| 54 |
+
})
|
| 55 |
+
|
| 56 |
+
t.Run("single node", func(t *testing.T) {
|
| 57 |
+
compose, err := docker.New().
|
| 58 |
+
WithBackendFilesystem().
|
| 59 |
+
WithText2VecContextionary().
|
| 60 |
+
WithWeaviateEnv("ENABLE_CLEANUP_UNFINISHED_BACKUPS", "true").
|
| 61 |
+
WithWeaviate().
|
| 62 |
+
Start(ctx)
|
| 63 |
+
require.Nil(t, err)
|
| 64 |
+
|
| 65 |
+
defer func() {
|
| 66 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 67 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 68 |
+
}
|
| 69 |
+
}()
|
| 70 |
+
|
| 71 |
+
t.Run("backup-filesystem", func(t *testing.T) {
|
| 72 |
+
journey.BackupJourneyTests_SingleNode(t, compose.GetWeaviate().URI(),
|
| 73 |
+
"filesystem", fsBackupJourneyClassName, fsBackupJourneyBackupIDSingleNode, nil, true, "testbucketoverride", "testBucketPathOverride")
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
t.Run("cancel after restart", func(t *testing.T) {
|
| 77 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 78 |
+
journey.CancelFromRestartJourney(t, compose, compose.GetWeaviate().Name(), modstgfilesystem.Name)
|
| 79 |
+
})
|
| 80 |
+
})
|
| 81 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-filesystem/multi_tenant_backup_test.go
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/require"
|
| 21 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
const numTenants = 50
|
| 26 |
+
|
| 27 |
+
func Test_MultiTenantBackup(t *testing.T) {
|
| 28 |
+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
| 29 |
+
defer cancel()
|
| 30 |
+
|
| 31 |
+
t.Run("single node", func(t *testing.T) {
|
| 32 |
+
compose, err := docker.New().
|
| 33 |
+
WithBackendFilesystem().
|
| 34 |
+
WithText2VecContextionary().
|
| 35 |
+
WithWeaviate().
|
| 36 |
+
Start(ctx)
|
| 37 |
+
require.Nil(t, err)
|
| 38 |
+
|
| 39 |
+
defer func() {
|
| 40 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 41 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 42 |
+
}
|
| 43 |
+
}()
|
| 44 |
+
|
| 45 |
+
t.Run("backup-filesystem", func(t *testing.T) {
|
| 46 |
+
tenantNames := make([]string, numTenants)
|
| 47 |
+
for i := range tenantNames {
|
| 48 |
+
tenantNames[i] = fmt.Sprintf("Tenant%d", i)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
journey.BackupJourneyTests_SingleNode(t,
|
| 52 |
+
compose.GetWeaviate().URI(), "filesystem", fsBackupJourneyClassName,
|
| 53 |
+
fsBackupJourneyBackupIDSingleNode, tenantNames, false, "", "")
|
| 54 |
+
})
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
t.Run("single node", func(t *testing.T) {
|
| 58 |
+
compose, err := docker.New().
|
| 59 |
+
WithBackendFilesystem().
|
| 60 |
+
WithText2VecContextionary().
|
| 61 |
+
WithWeaviate().
|
| 62 |
+
Start(ctx)
|
| 63 |
+
require.Nil(t, err)
|
| 64 |
+
|
| 65 |
+
defer func() {
|
| 66 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 67 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 68 |
+
}
|
| 69 |
+
}()
|
| 70 |
+
|
| 71 |
+
t.Run("backup-filesystem", func(t *testing.T) {
|
| 72 |
+
tenantNames := make([]string, numTenants)
|
| 73 |
+
for i := range tenantNames {
|
| 74 |
+
tenantNames[i] = fmt.Sprintf("Tenant%d", i)
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
journey.BackupJourneyTests_SingleNode(t,
|
| 78 |
+
compose.GetWeaviate().URI(), "filesystem", fsBackupJourneyClassName,
|
| 79 |
+
fsBackupJourneyBackupIDSingleNode, tenantNames, true, "testbucketoverride", "testBucketPathOverride")
|
| 80 |
+
})
|
| 81 |
+
})
|
| 82 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-gcs/backup_backend_test.go
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"os"
|
| 19 |
+
"testing"
|
| 20 |
+
"time"
|
| 21 |
+
|
| 22 |
+
"github.com/pkg/errors"
|
| 23 |
+
"github.com/sirupsen/logrus"
|
| 24 |
+
"github.com/stretchr/testify/assert"
|
| 25 |
+
"github.com/stretchr/testify/require"
|
| 26 |
+
|
| 27 |
+
"github.com/weaviate/weaviate/entities/backup"
|
| 28 |
+
"github.com/weaviate/weaviate/entities/moduletools"
|
| 29 |
+
mod "github.com/weaviate/weaviate/modules/backup-gcs"
|
| 30 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 31 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 32 |
+
ubak "github.com/weaviate/weaviate/usecases/backup"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
func Test_GcsBackend_Start(t *testing.T) {
|
| 36 |
+
gCSBackend_Backup(t, "", "")
|
| 37 |
+
|
| 38 |
+
gCSBackend_Backup(t, "gcsbetestbucketoverride", "gcsbetestBucketPathOverride")
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
func gCSBackend_Backup(t *testing.T, overrideBucket, overridePath string) {
|
| 42 |
+
ctx := context.Background()
|
| 43 |
+
compose, err := docker.New().WithGCS().Start(ctx)
|
| 44 |
+
if err != nil {
|
| 45 |
+
t.Fatal(errors.Wrapf(err, "cannot start"))
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
t.Setenv(envGCSEndpoint, compose.GetGCS().URI())
|
| 49 |
+
|
| 50 |
+
t.Run("store backup meta", func(t *testing.T) { moduleLevelStoreBackupMeta(t, overrideBucket, overridePath) })
|
| 51 |
+
t.Run("copy objects", func(t *testing.T) { moduleLevelCopyObjects(t, overrideBucket, overridePath) })
|
| 52 |
+
t.Run("copy files", func(t *testing.T) { moduleLevelCopyFiles(t, overrideBucket, overridePath) })
|
| 53 |
+
|
| 54 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 55 |
+
t.Fatal(errors.Wrapf(err, "failed to terminate test containers"))
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
func moduleLevelStoreBackupMeta(t *testing.T, overrideBucket, overridePath string) {
|
| 60 |
+
testCtx := context.Background()
|
| 61 |
+
|
| 62 |
+
className := "BackupClass"
|
| 63 |
+
backupID := "backup_id"
|
| 64 |
+
bucketName := "bucket-level-store-backup-meta"
|
| 65 |
+
if overrideBucket != "" {
|
| 66 |
+
bucketName = overrideBucket
|
| 67 |
+
}
|
| 68 |
+
projectID := "project-id"
|
| 69 |
+
endpoint := os.Getenv(envGCSEndpoint)
|
| 70 |
+
metadataFilename := "backup.json"
|
| 71 |
+
gcsUseAuth := "false"
|
| 72 |
+
|
| 73 |
+
t.Log("setup env")
|
| 74 |
+
t.Setenv(envGCSEndpoint, endpoint)
|
| 75 |
+
t.Setenv(envGCSStorageEmulatorHost, endpoint)
|
| 76 |
+
t.Setenv(envGCSCredentials, "")
|
| 77 |
+
t.Setenv(envGCSProjectID, projectID)
|
| 78 |
+
t.Setenv(envGCSBucket, bucketName)
|
| 79 |
+
t.Setenv(envGCSUseAuth, gcsUseAuth)
|
| 80 |
+
moduleshelper.CreateGCSBucket(testCtx, t, projectID, bucketName)
|
| 81 |
+
defer moduleshelper.DeleteGCSBucket(testCtx, t, bucketName)
|
| 82 |
+
|
| 83 |
+
t.Run("store backup meta in gcs", func(t *testing.T) {
|
| 84 |
+
t.Setenv("BACKUP_GCS_BUCKET", bucketName)
|
| 85 |
+
gcs := mod.New()
|
| 86 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 87 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 88 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: t.TempDir()})
|
| 89 |
+
err := gcs.Init(testCtx, params)
|
| 90 |
+
require.Nil(t, err)
|
| 91 |
+
|
| 92 |
+
t.Run("access permissions", func(t *testing.T) {
|
| 93 |
+
err := gcs.Initialize(testCtx, backupID, overrideBucket, overridePath)
|
| 94 |
+
assert.Nil(t, err)
|
| 95 |
+
})
|
| 96 |
+
|
| 97 |
+
t.Run("backup meta does not exist yet", func(t *testing.T) {
|
| 98 |
+
meta, err := gcs.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 99 |
+
assert.Nil(t, meta)
|
| 100 |
+
assert.NotNil(t, err)
|
| 101 |
+
assert.IsType(t, backup.ErrNotFound{}, err)
|
| 102 |
+
})
|
| 103 |
+
|
| 104 |
+
t.Run("put backup meta on backend", func(t *testing.T) {
|
| 105 |
+
desc := &backup.BackupDescriptor{
|
| 106 |
+
StartedAt: time.Now(),
|
| 107 |
+
CompletedAt: time.Time{},
|
| 108 |
+
ID: backupID,
|
| 109 |
+
Classes: []backup.ClassDescriptor{
|
| 110 |
+
{
|
| 111 |
+
Name: className,
|
| 112 |
+
},
|
| 113 |
+
},
|
| 114 |
+
Status: string(backup.Started),
|
| 115 |
+
Version: ubak.Version,
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
b, err := json.Marshal(desc)
|
| 119 |
+
require.Nil(t, err)
|
| 120 |
+
|
| 121 |
+
err = gcs.PutObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath, b)
|
| 122 |
+
require.Nil(t, err)
|
| 123 |
+
|
| 124 |
+
dest := gcs.HomeDir(backupID, overrideBucket, overridePath)
|
| 125 |
+
if overridePath == "" {
|
| 126 |
+
expected := fmt.Sprintf("gs://%s/%s", bucketName, backupID)
|
| 127 |
+
assert.Equal(t, expected, dest)
|
| 128 |
+
} else {
|
| 129 |
+
expected := fmt.Sprintf("gs://%s/%s/%s", bucketName, overridePath, backupID)
|
| 130 |
+
assert.Equal(t, expected, dest)
|
| 131 |
+
}
|
| 132 |
+
})
|
| 133 |
+
|
| 134 |
+
t.Run("assert backup meta contents", func(t *testing.T) {
|
| 135 |
+
obj, err := gcs.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 136 |
+
require.Nil(t, err)
|
| 137 |
+
|
| 138 |
+
var meta backup.BackupDescriptor
|
| 139 |
+
err = json.Unmarshal(obj, &meta)
|
| 140 |
+
require.Nil(t, err)
|
| 141 |
+
assert.NotEmpty(t, meta.StartedAt)
|
| 142 |
+
assert.Empty(t, meta.CompletedAt)
|
| 143 |
+
assert.Equal(t, meta.Status, string(backup.Started))
|
| 144 |
+
assert.Empty(t, meta.Error)
|
| 145 |
+
assert.Len(t, meta.Classes, 1)
|
| 146 |
+
assert.Equal(t, meta.Classes[0].Name, className)
|
| 147 |
+
assert.Equal(t, meta.Version, ubak.Version)
|
| 148 |
+
assert.Nil(t, meta.Classes[0].Error)
|
| 149 |
+
})
|
| 150 |
+
})
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
func moduleLevelCopyObjects(t *testing.T, overrideBucket, overridePath string) {
|
| 154 |
+
testCtx := context.Background()
|
| 155 |
+
|
| 156 |
+
key := "moduleLevelCopyObjects"
|
| 157 |
+
backupID := "backup_id"
|
| 158 |
+
bucketName := "bucket-level-copy-objects"
|
| 159 |
+
if overrideBucket != "" {
|
| 160 |
+
bucketName = overrideBucket
|
| 161 |
+
}
|
| 162 |
+
projectID := "project-id"
|
| 163 |
+
endpoint := os.Getenv(envGCSEndpoint)
|
| 164 |
+
gcsUseAuth := "false"
|
| 165 |
+
|
| 166 |
+
t.Log("setup env")
|
| 167 |
+
t.Setenv(envGCSEndpoint, endpoint)
|
| 168 |
+
t.Setenv(envGCSStorageEmulatorHost, endpoint)
|
| 169 |
+
t.Setenv(envGCSCredentials, "")
|
| 170 |
+
t.Setenv(envGCSProjectID, projectID)
|
| 171 |
+
t.Setenv(envGCSBucket, bucketName)
|
| 172 |
+
t.Setenv(envGCSUseAuth, gcsUseAuth)
|
| 173 |
+
moduleshelper.CreateGCSBucket(testCtx, t, projectID, bucketName)
|
| 174 |
+
defer moduleshelper.DeleteGCSBucket(testCtx, t, bucketName)
|
| 175 |
+
|
| 176 |
+
t.Run("copy objects", func(t *testing.T) {
|
| 177 |
+
t.Setenv("BACKUP_GCS_BUCKET", bucketName)
|
| 178 |
+
gcs := mod.New()
|
| 179 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 180 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 181 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: t.TempDir()})
|
| 182 |
+
err := gcs.Init(testCtx, params)
|
| 183 |
+
require.Nil(t, err)
|
| 184 |
+
|
| 185 |
+
t.Run("put object to bucket", func(t *testing.T) {
|
| 186 |
+
err := gcs.PutObject(testCtx, backupID, key, overrideBucket, overridePath, []byte("hello"))
|
| 187 |
+
assert.Nil(t, err)
|
| 188 |
+
})
|
| 189 |
+
|
| 190 |
+
t.Run("get object from bucket", func(t *testing.T) {
|
| 191 |
+
meta, err := gcs.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 192 |
+
assert.Nil(t, err)
|
| 193 |
+
assert.Equal(t, []byte("hello"), meta)
|
| 194 |
+
})
|
| 195 |
+
})
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
func moduleLevelCopyFiles(t *testing.T, overrideBucket, overridePath string) {
|
| 199 |
+
testCtx := context.Background()
|
| 200 |
+
|
| 201 |
+
dataDir := t.TempDir()
|
| 202 |
+
key := "moduleLevelCopyFiles"
|
| 203 |
+
backupID := "backup_id"
|
| 204 |
+
bucketName := "bucket-level-copy-files"
|
| 205 |
+
if overrideBucket != "" {
|
| 206 |
+
bucketName = overrideBucket
|
| 207 |
+
}
|
| 208 |
+
projectID := "project-id"
|
| 209 |
+
endpoint := os.Getenv(envGCSEndpoint)
|
| 210 |
+
gcsUseAuth := "false"
|
| 211 |
+
|
| 212 |
+
t.Log("setup env")
|
| 213 |
+
t.Setenv(envGCSEndpoint, endpoint)
|
| 214 |
+
t.Setenv(envGCSStorageEmulatorHost, endpoint)
|
| 215 |
+
t.Setenv(envGCSCredentials, "")
|
| 216 |
+
t.Setenv(envGCSProjectID, projectID)
|
| 217 |
+
t.Setenv(envGCSBucket, bucketName)
|
| 218 |
+
t.Setenv(envGCSUseAuth, gcsUseAuth)
|
| 219 |
+
moduleshelper.CreateGCSBucket(testCtx, t, projectID, bucketName)
|
| 220 |
+
defer moduleshelper.DeleteGCSBucket(testCtx, t, bucketName)
|
| 221 |
+
|
| 222 |
+
t.Run("copy files", func(t *testing.T) {
|
| 223 |
+
fpaths := moduleshelper.CreateTestFiles(t, dataDir)
|
| 224 |
+
fpath := fpaths[0]
|
| 225 |
+
expectedContents, err := os.ReadFile(fpath)
|
| 226 |
+
require.Nil(t, err)
|
| 227 |
+
require.NotNil(t, expectedContents)
|
| 228 |
+
|
| 229 |
+
t.Setenv("BACKUP_GCS_BUCKET", bucketName)
|
| 230 |
+
gcs := mod.New()
|
| 231 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 232 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 233 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: dataDir})
|
| 234 |
+
err = gcs.Init(testCtx, params)
|
| 235 |
+
require.Nil(t, err)
|
| 236 |
+
|
| 237 |
+
t.Run("verify source data path", func(t *testing.T) {
|
| 238 |
+
assert.Equal(t, dataDir, gcs.SourceDataPath())
|
| 239 |
+
})
|
| 240 |
+
|
| 241 |
+
t.Run("copy file to backend", func(t *testing.T) {
|
| 242 |
+
err := gcs.PutObject(testCtx, backupID, key, overrideBucket, overridePath, expectedContents)
|
| 243 |
+
require.Nil(t, err)
|
| 244 |
+
|
| 245 |
+
contents, err := gcs.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 246 |
+
require.Nil(t, err)
|
| 247 |
+
assert.Equal(t, expectedContents, contents)
|
| 248 |
+
})
|
| 249 |
+
|
| 250 |
+
t.Run("fetch file from backend", func(t *testing.T) {
|
| 251 |
+
destPath := dataDir + "/file_0.copy.db"
|
| 252 |
+
|
| 253 |
+
err := gcs.WriteToFile(testCtx, backupID, key, destPath, overrideBucket, overridePath)
|
| 254 |
+
require.Nil(t, err)
|
| 255 |
+
|
| 256 |
+
contents, err := os.ReadFile(destPath)
|
| 257 |
+
require.Nil(t, err)
|
| 258 |
+
assert.Equal(t, expectedContents, contents)
|
| 259 |
+
})
|
| 260 |
+
})
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
type fakeStorageProvider struct {
|
| 264 |
+
dataPath string
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
func (f *fakeStorageProvider) Storage(name string) (moduletools.Storage, error) {
|
| 268 |
+
return nil, nil
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
func (f *fakeStorageProvider) DataPath() string {
|
| 272 |
+
return f.dataPath
|
| 273 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-gcs/backup_journey_test.go
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 22 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
const (
|
| 26 |
+
envGCSEndpoint = "GCS_ENDPOINT"
|
| 27 |
+
envGCSStorageEmulatorHost = "STORAGE_EMULATOR_HOST"
|
| 28 |
+
envGCSCredentials = "GOOGLE_APPLICATION_CREDENTIALS"
|
| 29 |
+
envGCSProjectID = "GOOGLE_CLOUD_PROJECT"
|
| 30 |
+
envGCSBucket = "BACKUP_GCS_BUCKET"
|
| 31 |
+
envGCSUseAuth = "BACKUP_GCS_USE_AUTH"
|
| 32 |
+
|
| 33 |
+
gcsBackupJourneyClassName = "GcsBackup"
|
| 34 |
+
gcsBackupJourneyBackupIDCluster = "gcs_backup_cluster"
|
| 35 |
+
gcsBackupJourneyProjectID = "gcs_backup_journey"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
func Test_BackupJourney(t *testing.T) {
|
| 39 |
+
tests := []struct {
|
| 40 |
+
name string
|
| 41 |
+
overrideBucket bool
|
| 42 |
+
bucket string
|
| 43 |
+
bucketOverride string
|
| 44 |
+
pathOverride string
|
| 45 |
+
}{
|
| 46 |
+
{
|
| 47 |
+
name: "default backup",
|
| 48 |
+
overrideBucket: false,
|
| 49 |
+
bucket: "backups",
|
| 50 |
+
bucketOverride: "",
|
| 51 |
+
pathOverride: "",
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
name: "with override bucket and path",
|
| 55 |
+
overrideBucket: true,
|
| 56 |
+
bucket: "backups",
|
| 57 |
+
bucketOverride: "gcsbjtestbucketoverride",
|
| 58 |
+
pathOverride: "gcsbjtstBuckPathOveride",
|
| 59 |
+
},
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
ctx := context.Background()
|
| 63 |
+
|
| 64 |
+
for _, tt := range tests {
|
| 65 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 66 |
+
runBackupJourney(t, ctx, tt.overrideBucket, tt.bucket, tt.bucketOverride, tt.pathOverride)
|
| 67 |
+
})
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
func runBackupJourney(t *testing.T, ctx context.Context, override bool, containerName, overrideBucket, overridePath string) {
|
| 72 |
+
t.Run("multiple node", func(t *testing.T) {
|
| 73 |
+
ctx := context.Background()
|
| 74 |
+
t.Log("pre-instance env setup")
|
| 75 |
+
gcsBackupJourneyBucketName := "gcp-multiple-nodes"
|
| 76 |
+
t.Setenv(envGCSCredentials, "")
|
| 77 |
+
t.Setenv(envGCSProjectID, gcsBackupJourneyProjectID)
|
| 78 |
+
t.Setenv(envGCSBucket, gcsBackupJourneyBucketName)
|
| 79 |
+
|
| 80 |
+
compose, err := docker.New().
|
| 81 |
+
WithBackendGCS(gcsBackupJourneyBucketName).
|
| 82 |
+
WithText2VecContextionary().
|
| 83 |
+
WithWeaviateEnv("ENABLE_CLEANUP_UNFINISHED_BACKUPS", "true").
|
| 84 |
+
WithWeaviateCluster(3).
|
| 85 |
+
Start(ctx)
|
| 86 |
+
require.Nil(t, err)
|
| 87 |
+
defer func() {
|
| 88 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 89 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 90 |
+
}
|
| 91 |
+
}()
|
| 92 |
+
|
| 93 |
+
t.Log("post-instance env setup")
|
| 94 |
+
t.Setenv(envGCSEndpoint, compose.GetGCS().URI())
|
| 95 |
+
t.Setenv(envGCSStorageEmulatorHost, compose.GetGCS().URI())
|
| 96 |
+
moduleshelper.CreateGCSBucket(ctx, t, gcsBackupJourneyProjectID, gcsBackupJourneyBucketName)
|
| 97 |
+
if override {
|
| 98 |
+
moduleshelper.CreateGCSBucket(ctx, t, gcsBackupJourneyProjectID, overrideBucket)
|
| 99 |
+
defer moduleshelper.DeleteGCSBucket(ctx, t, overrideBucket)
|
| 100 |
+
}
|
| 101 |
+
defer moduleshelper.DeleteGCSBucket(ctx, t, gcsBackupJourneyBucketName)
|
| 102 |
+
|
| 103 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 104 |
+
|
| 105 |
+
t.Run("backup-gcs", func(t *testing.T) {
|
| 106 |
+
journey.BackupJourneyTests_Cluster(t, "gcs", gcsBackupJourneyClassName,
|
| 107 |
+
gcsBackupJourneyBackupIDCluster+overrideBucket, nil, override, overrideBucket, overridePath, compose.GetWeaviate().URI(), compose.GetWeaviateNode(2).URI())
|
| 108 |
+
})
|
| 109 |
+
})
|
| 110 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-gcs/multi_tenant_backup_test.go
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
|
| 21 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 24 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
const numTenants = 50
|
| 28 |
+
|
| 29 |
+
func Test_MultiTenantBackupJourney(t *testing.T) {
|
| 30 |
+
// Set up a context with a 30-minute timeout to manage test duration
|
| 31 |
+
ctx := context.Background()
|
| 32 |
+
|
| 33 |
+
// Define test cases using a table-driven approach
|
| 34 |
+
tests := []struct {
|
| 35 |
+
name string // Name for the subtest
|
| 36 |
+
override bool // Whether to override bucket/path
|
| 37 |
+
bucket string // Bucket name
|
| 38 |
+
overrideBucket string // Override bucket name (if any)
|
| 39 |
+
overrideBucketPath string // Override path for bucket (if any)
|
| 40 |
+
}{
|
| 41 |
+
{
|
| 42 |
+
name: "default backup journey",
|
| 43 |
+
override: false,
|
| 44 |
+
bucket: "backups",
|
| 45 |
+
overrideBucket: "",
|
| 46 |
+
overrideBucketPath: "",
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
name: "with override bucket and path",
|
| 50 |
+
override: true,
|
| 51 |
+
bucket: "backups",
|
| 52 |
+
overrideBucket: "gcsmbjtestbucketoverride",
|
| 53 |
+
overrideBucketPath: "testBucketPathOverride",
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Run each test case as a subtest
|
| 58 |
+
for _, tt := range tests {
|
| 59 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 60 |
+
// Execute the multi-tenant backup journey with the specified parameters
|
| 61 |
+
multiTenantBackupJourneyStart(
|
| 62 |
+
t,
|
| 63 |
+
ctx,
|
| 64 |
+
tt.override, // Apply override if true
|
| 65 |
+
tt.bucket, // Primary bucket name
|
| 66 |
+
tt.overrideBucket, // Override bucket name, if set
|
| 67 |
+
tt.overrideBucketPath, // Override path, if set
|
| 68 |
+
)
|
| 69 |
+
})
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
func multiTenantBackupJourneyStart(t *testing.T, ctx context.Context, override bool, containerName, overrideBucket, overridePath string) {
|
| 74 |
+
tenantNames := make([]string, numTenants)
|
| 75 |
+
for i := range tenantNames {
|
| 76 |
+
tenantNames[i] = fmt.Sprintf("Tenant%d", i)
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
t.Run("multiple node", func(t *testing.T) {
|
| 80 |
+
ctx := context.Background()
|
| 81 |
+
t.Log("pre-instance env setup")
|
| 82 |
+
gcsBackupJourneyBucketName := "gcp-multiple-nodes"
|
| 83 |
+
t.Setenv(envGCSCredentials, "")
|
| 84 |
+
t.Setenv(envGCSProjectID, gcsBackupJourneyProjectID)
|
| 85 |
+
t.Setenv(envGCSBucket, gcsBackupJourneyBucketName)
|
| 86 |
+
|
| 87 |
+
compose, err := docker.New().
|
| 88 |
+
WithBackendGCS(gcsBackupJourneyBucketName).
|
| 89 |
+
WithText2VecContextionary().
|
| 90 |
+
WithWeaviateCluster(3).
|
| 91 |
+
Start(ctx)
|
| 92 |
+
require.Nil(t, err)
|
| 93 |
+
defer func() {
|
| 94 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 95 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 96 |
+
}
|
| 97 |
+
}()
|
| 98 |
+
|
| 99 |
+
t.Log("post-instance env setup")
|
| 100 |
+
t.Setenv(envGCSEndpoint, compose.GetGCS().URI())
|
| 101 |
+
t.Setenv(envGCSStorageEmulatorHost, compose.GetGCS().URI())
|
| 102 |
+
moduleshelper.CreateGCSBucket(ctx, t, gcsBackupJourneyProjectID, gcsBackupJourneyBucketName)
|
| 103 |
+
if override {
|
| 104 |
+
moduleshelper.CreateGCSBucket(ctx, t, gcsBackupJourneyProjectID, overrideBucket)
|
| 105 |
+
defer moduleshelper.DeleteGCSBucket(ctx, t, overrideBucket)
|
| 106 |
+
}
|
| 107 |
+
defer moduleshelper.DeleteGCSBucket(ctx, t, gcsBackupJourneyBucketName)
|
| 108 |
+
|
| 109 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 110 |
+
|
| 111 |
+
t.Run("backup-gcs", func(t *testing.T) {
|
| 112 |
+
journey.BackupJourneyTests_Cluster(t, "gcs", gcsBackupJourneyClassName,
|
| 113 |
+
gcsBackupJourneyBackupIDCluster+overrideBucket, tenantNames, override, overrideBucket, overridePath,
|
| 114 |
+
compose.GetWeaviate().URI(), compose.GetWeaviateNode(2).URI())
|
| 115 |
+
})
|
| 116 |
+
})
|
| 117 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-s3/backup_backend_test.go
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"encoding/json"
|
| 17 |
+
"fmt"
|
| 18 |
+
"os"
|
| 19 |
+
"testing"
|
| 20 |
+
"time"
|
| 21 |
+
|
| 22 |
+
"github.com/pkg/errors"
|
| 23 |
+
"github.com/sirupsen/logrus"
|
| 24 |
+
"github.com/stretchr/testify/assert"
|
| 25 |
+
"github.com/stretchr/testify/require"
|
| 26 |
+
|
| 27 |
+
"github.com/weaviate/weaviate/entities/backup"
|
| 28 |
+
"github.com/weaviate/weaviate/entities/moduletools"
|
| 29 |
+
mod "github.com/weaviate/weaviate/modules/backup-s3"
|
| 30 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 31 |
+
moduleshelper "github.com/weaviate/weaviate/test/helper/modules"
|
| 32 |
+
ubak "github.com/weaviate/weaviate/usecases/backup"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
func Test_S3Backend_Start(t *testing.T) {
|
| 36 |
+
s3Backend_Backup(t, false, "backups", "", "")
|
| 37 |
+
|
| 38 |
+
s3Backend_Backup(t, true, "testbucketoverride", "testbucketoverride", "testBucketPathOverride")
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
func s3Backend_Backup(t *testing.T, override bool, containerName, overrideBucket, overridePath string) {
|
| 42 |
+
bucketName := containerName
|
| 43 |
+
|
| 44 |
+
ctx := context.Background()
|
| 45 |
+
|
| 46 |
+
t.Log("setup env")
|
| 47 |
+
region := "eu-west-1"
|
| 48 |
+
t.Setenv(envAwsRegion, region)
|
| 49 |
+
t.Setenv(envS3AccessKey, "aws_access_key")
|
| 50 |
+
t.Setenv(envS3SecretKey, "aws_secret_key")
|
| 51 |
+
t.Setenv(envS3Bucket, bucketName)
|
| 52 |
+
|
| 53 |
+
t.Logf("Starting test with bucket: %s, %s\n", bucketName, region)
|
| 54 |
+
compose, err := docker.New().WithBackendS3(bucketName, region).Start(ctx)
|
| 55 |
+
if err != nil {
|
| 56 |
+
t.Fatal(errors.Wrapf(err, "cannot start"))
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
t.Setenv(envMinioEndpoint, compose.GetMinIO().URI())
|
| 60 |
+
|
| 61 |
+
t.Logf("running tests with bucket %v and path overrides: %v\n", bucketName, override)
|
| 62 |
+
t.Run("store backup meta",
|
| 63 |
+
func(t *testing.T) {
|
| 64 |
+
moduleLevelStoreBackupMeta(t, override, containerName, overrideBucket, overridePath)
|
| 65 |
+
})
|
| 66 |
+
t.Run("copy objects", func(t *testing.T) {
|
| 67 |
+
moduleLevelCopyObjects(t, override, containerName, overrideBucket, overridePath)
|
| 68 |
+
})
|
| 69 |
+
t.Run("copy files", func(t *testing.T) {
|
| 70 |
+
moduleLevelCopyFiles(t, override, containerName, overrideBucket, overridePath)
|
| 71 |
+
})
|
| 72 |
+
|
| 73 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 74 |
+
t.Fatal(errors.Wrapf(err, "failed to terminate test containers"))
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
func moduleLevelStoreBackupMeta(t *testing.T, override bool, containerName, overrideBucket, overridePath string) {
|
| 79 |
+
testCtx := context.Background()
|
| 80 |
+
|
| 81 |
+
bucketName := containerName
|
| 82 |
+
|
| 83 |
+
className := "BackupClass"
|
| 84 |
+
backupID := "backup_id"
|
| 85 |
+
endpoint := os.Getenv(envMinioEndpoint)
|
| 86 |
+
metadataFilename := "backup.json"
|
| 87 |
+
|
| 88 |
+
t.Logf("storing metadata with override: %v", override)
|
| 89 |
+
|
| 90 |
+
t.Run("store backup meta in s3", func(t *testing.T) {
|
| 91 |
+
t.Setenv(envS3UseSSL, "false")
|
| 92 |
+
t.Setenv(envS3Endpoint, endpoint)
|
| 93 |
+
s3 := mod.New()
|
| 94 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 95 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 96 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: t.TempDir()})
|
| 97 |
+
err := s3.Init(testCtx, params)
|
| 98 |
+
require.Nil(t, err)
|
| 99 |
+
|
| 100 |
+
t.Run("access permissions", func(t *testing.T) {
|
| 101 |
+
err := s3.Initialize(testCtx, backupID, overrideBucket, overridePath)
|
| 102 |
+
assert.Nil(t, err)
|
| 103 |
+
})
|
| 104 |
+
|
| 105 |
+
t.Run("backup meta does not exist yet", func(t *testing.T) {
|
| 106 |
+
meta, err := s3.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 107 |
+
assert.Nil(t, meta)
|
| 108 |
+
assert.NotNil(t, err)
|
| 109 |
+
t.Log(err)
|
| 110 |
+
assert.IsType(t, backup.ErrNotFound{}, err)
|
| 111 |
+
})
|
| 112 |
+
|
| 113 |
+
t.Run("put backup meta in backend", func(t *testing.T) {
|
| 114 |
+
desc := &backup.BackupDescriptor{
|
| 115 |
+
StartedAt: time.Now(),
|
| 116 |
+
CompletedAt: time.Time{},
|
| 117 |
+
ID: backupID,
|
| 118 |
+
Classes: []backup.ClassDescriptor{
|
| 119 |
+
{
|
| 120 |
+
Name: className,
|
| 121 |
+
},
|
| 122 |
+
},
|
| 123 |
+
Status: string(backup.Started),
|
| 124 |
+
Version: ubak.Version,
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
b, err := json.Marshal(desc)
|
| 128 |
+
require.Nil(t, err)
|
| 129 |
+
|
| 130 |
+
err = s3.PutObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath, b)
|
| 131 |
+
require.Nil(t, err)
|
| 132 |
+
|
| 133 |
+
dest := s3.HomeDir(backupID, overrideBucket, overridePath)
|
| 134 |
+
if overridePath != "" {
|
| 135 |
+
expected := fmt.Sprintf("s3://%s/%s/%s", overrideBucket, overridePath, backupID)
|
| 136 |
+
assert.Equal(t, expected, dest)
|
| 137 |
+
} else {
|
| 138 |
+
expected := fmt.Sprintf("s3://%s/%s", bucketName, backupID)
|
| 139 |
+
assert.Equal(t, expected, dest)
|
| 140 |
+
}
|
| 141 |
+
})
|
| 142 |
+
|
| 143 |
+
t.Run("assert backup meta contents", func(t *testing.T) {
|
| 144 |
+
obj, err := s3.GetObject(testCtx, backupID, metadataFilename, overrideBucket, overridePath)
|
| 145 |
+
require.Nil(t, err)
|
| 146 |
+
|
| 147 |
+
var meta backup.BackupDescriptor
|
| 148 |
+
err = json.Unmarshal(obj, &meta)
|
| 149 |
+
require.Nil(t, err)
|
| 150 |
+
assert.NotEmpty(t, meta.StartedAt)
|
| 151 |
+
assert.Empty(t, meta.CompletedAt)
|
| 152 |
+
assert.Equal(t, meta.Status, string(backup.Started))
|
| 153 |
+
assert.Empty(t, meta.Error)
|
| 154 |
+
assert.Len(t, meta.Classes, 1)
|
| 155 |
+
assert.Equal(t, meta.Classes[0].Name, className)
|
| 156 |
+
assert.Equal(t, meta.Version, ubak.Version)
|
| 157 |
+
assert.Nil(t, meta.Classes[0].Error)
|
| 158 |
+
})
|
| 159 |
+
})
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
func moduleLevelCopyObjects(t *testing.T, override bool, containerName, overrideBucket, overridePath string) {
|
| 163 |
+
testCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
| 164 |
+
defer cancel()
|
| 165 |
+
|
| 166 |
+
key := "moduleLevelCopyObjects"
|
| 167 |
+
backupID := "backup_id"
|
| 168 |
+
endpoint := os.Getenv(envMinioEndpoint)
|
| 169 |
+
|
| 170 |
+
t.Log("setup env")
|
| 171 |
+
|
| 172 |
+
t.Logf("copy objects with override: %v", override)
|
| 173 |
+
|
| 174 |
+
t.Run("copy objects", func(t *testing.T) {
|
| 175 |
+
t.Setenv(envS3UseSSL, "false")
|
| 176 |
+
t.Setenv(envS3Endpoint, endpoint)
|
| 177 |
+
s3 := mod.New()
|
| 178 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 179 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 180 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: t.TempDir()})
|
| 181 |
+
err := s3.Init(testCtx, params)
|
| 182 |
+
require.Nil(t, err)
|
| 183 |
+
|
| 184 |
+
t.Run("put object to bucket", func(t *testing.T) {
|
| 185 |
+
t.Logf("put object with override: %v", override)
|
| 186 |
+
err := s3.PutObject(testCtx, backupID, key, overrideBucket, overridePath, []byte("hello"))
|
| 187 |
+
assert.Nil(t, err, "expected nil, got: %v", err)
|
| 188 |
+
})
|
| 189 |
+
|
| 190 |
+
t.Run("get object from bucket", func(t *testing.T) {
|
| 191 |
+
t.Logf("get object with override: %v", override)
|
| 192 |
+
meta, err := s3.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 193 |
+
assert.Nil(t, err, "expected nil, got: %v", err)
|
| 194 |
+
assert.Equal(t, []byte("hello"), meta)
|
| 195 |
+
})
|
| 196 |
+
})
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
func moduleLevelCopyFiles(t *testing.T, override bool, containerName, overrideBucket, overridePath string) {
|
| 200 |
+
testCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
| 201 |
+
defer cancel()
|
| 202 |
+
|
| 203 |
+
dataDir := t.TempDir()
|
| 204 |
+
key := "moduleLevelCopyFiles"
|
| 205 |
+
backupID := "backup_id"
|
| 206 |
+
endpoint := os.Getenv(envMinioEndpoint)
|
| 207 |
+
|
| 208 |
+
t.Run("copy files", func(t *testing.T) {
|
| 209 |
+
fpaths := moduleshelper.CreateTestFiles(t, dataDir)
|
| 210 |
+
fpath := fpaths[0]
|
| 211 |
+
expectedContents, err := os.ReadFile(fpath)
|
| 212 |
+
require.Nil(t, err)
|
| 213 |
+
require.NotNil(t, expectedContents)
|
| 214 |
+
|
| 215 |
+
t.Setenv(envS3UseSSL, "false")
|
| 216 |
+
t.Setenv(envS3Endpoint, endpoint)
|
| 217 |
+
s3 := mod.New()
|
| 218 |
+
params := moduletools.NewMockModuleInitParams(t)
|
| 219 |
+
params.EXPECT().GetLogger().Return(logrus.New())
|
| 220 |
+
params.EXPECT().GetStorageProvider().Return(&fakeStorageProvider{dataPath: dataDir})
|
| 221 |
+
err = s3.Init(testCtx, params)
|
| 222 |
+
require.Nil(t, err)
|
| 223 |
+
|
| 224 |
+
t.Run("verify source data path", func(t *testing.T) {
|
| 225 |
+
t.Log("source data path", s3.SourceDataPath())
|
| 226 |
+
assert.Equal(t, dataDir, s3.SourceDataPath())
|
| 227 |
+
})
|
| 228 |
+
|
| 229 |
+
t.Run("copy file to backend", func(t *testing.T) {
|
| 230 |
+
err := s3.PutObject(testCtx, backupID, key, overrideBucket, overridePath, expectedContents)
|
| 231 |
+
require.Nil(t, err)
|
| 232 |
+
|
| 233 |
+
contents, err := s3.GetObject(testCtx, backupID, key, overrideBucket, overridePath)
|
| 234 |
+
require.Nil(t, err)
|
| 235 |
+
assert.Equal(t, expectedContents, contents)
|
| 236 |
+
})
|
| 237 |
+
|
| 238 |
+
t.Run("fetch file from backend", func(t *testing.T) {
|
| 239 |
+
destPath := dataDir + "/file_0.copy.db"
|
| 240 |
+
|
| 241 |
+
t.Logf("download file with override: %v", override)
|
| 242 |
+
err := s3.WriteToFile(testCtx, backupID, key, destPath, overrideBucket, overridePath)
|
| 243 |
+
require.Nil(t, err)
|
| 244 |
+
|
| 245 |
+
contents, err := os.ReadFile(destPath)
|
| 246 |
+
require.Nil(t, err)
|
| 247 |
+
assert.Equal(t, expectedContents, contents)
|
| 248 |
+
})
|
| 249 |
+
})
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
type fakeStorageProvider struct {
|
| 253 |
+
dataPath string
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
func (f *fakeStorageProvider) Storage(name string) (moduletools.Storage, error) {
|
| 257 |
+
return nil, nil
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
func (f *fakeStorageProvider) DataPath() string {
|
| 261 |
+
return f.dataPath
|
| 262 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-s3/backup_journey_test.go
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
const (
|
| 25 |
+
envMinioEndpoint = "MINIO_ENDPOINT"
|
| 26 |
+
envAwsRegion = "AWS_REGION"
|
| 27 |
+
envS3AccessKey = "AWS_ACCESS_KEY_ID"
|
| 28 |
+
envS3SecretKey = "AWS_SECRET_KEY"
|
| 29 |
+
envS3Bucket = "BACKUP_S3_BUCKET"
|
| 30 |
+
envS3Endpoint = "BACKUP_S3_ENDPOINT"
|
| 31 |
+
envS3UseSSL = "BACKUP_S3_USE_SSL"
|
| 32 |
+
|
| 33 |
+
s3BackupJourneyClassName = "S3Backup"
|
| 34 |
+
s3BackupJourneyBackupIDCluster = "s3-backup-cluster"
|
| 35 |
+
s3BackupJourneyRegion = "eu-west-1"
|
| 36 |
+
s3BackupJourneyAccessKey = "aws_access_key"
|
| 37 |
+
s3BackupJourneySecretKey = "aws_secret_key"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
func Test_BackupJourney(t *testing.T) {
|
| 41 |
+
ctx := context.Background()
|
| 42 |
+
|
| 43 |
+
runBackupJourney(t, ctx, false, "backups", "", "")
|
| 44 |
+
t.Run("with override bucket and path", func(t *testing.T) {
|
| 45 |
+
runBackupJourney(t, ctx, true, "testbucketoverride", "testbucketoverride", "testBucketPathOverride")
|
| 46 |
+
})
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
func runBackupJourney(t *testing.T, ctx context.Context, override bool, containerName, overrideBucket, overridePath string) {
|
| 50 |
+
s3BackupJourneyBucketName := containerName
|
| 51 |
+
|
| 52 |
+
t.Run("multiple node", func(t *testing.T) {
|
| 53 |
+
ctx := context.Background()
|
| 54 |
+
|
| 55 |
+
t.Log("pre-instance env setup")
|
| 56 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 57 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 58 |
+
t.Setenv(envS3Bucket, s3BackupJourneyBucketName)
|
| 59 |
+
|
| 60 |
+
compose, err := docker.New().
|
| 61 |
+
WithBackendS3(s3BackupJourneyBucketName, s3BackupJourneyRegion).
|
| 62 |
+
WithText2VecContextionary().
|
| 63 |
+
WithWeaviateCluster(3).
|
| 64 |
+
Start(ctx)
|
| 65 |
+
require.Nil(t, err)
|
| 66 |
+
defer func() {
|
| 67 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 68 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 69 |
+
}
|
| 70 |
+
}()
|
| 71 |
+
|
| 72 |
+
t.Run("post-instance env setup", func(t *testing.T) {
|
| 73 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
t.Run("backup-s3", func(t *testing.T) {
|
| 77 |
+
journey.BackupJourneyTests_Cluster(t, "s3", s3BackupJourneyClassName,
|
| 78 |
+
s3BackupJourneyBackupIDCluster, nil, override, overrideBucket, overridePath,
|
| 79 |
+
compose.GetWeaviate().URI(), compose.GetWeaviateNode(2).URI())
|
| 80 |
+
})
|
| 81 |
+
})
|
| 82 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/backup-s3/multi_tenant_backup_test.go
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package test
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper/journey"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
const numTenants = 50
|
| 26 |
+
|
| 27 |
+
func Test_MultiTenantBackupJourney(t *testing.T) {
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
|
| 30 |
+
multiTenantBackupJourneyStart(t, ctx, false, "backups", "", "")
|
| 31 |
+
t.Run("with override bucket and path", func(t *testing.T) {
|
| 32 |
+
multiTenantBackupJourneyStart(t, ctx, true, "testbucketoverride", "testbucketoverride", "testBucketPathOverride")
|
| 33 |
+
})
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
func multiTenantBackupJourneyStart(t *testing.T, ctx context.Context, override bool, containerName, overrideBucket, overridePath string) {
|
| 37 |
+
s3BackupJourneyBucketName := containerName
|
| 38 |
+
|
| 39 |
+
tenantNames := make([]string, numTenants)
|
| 40 |
+
for i := range tenantNames {
|
| 41 |
+
tenantNames[i] = fmt.Sprintf("Tenant%d", i)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
t.Run("multiple node", func(t *testing.T) {
|
| 45 |
+
ctx := context.Background()
|
| 46 |
+
|
| 47 |
+
t.Log("pre-instance env setup")
|
| 48 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 49 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 50 |
+
t.Setenv(envS3Bucket, s3BackupJourneyBucketName)
|
| 51 |
+
|
| 52 |
+
compose, err := docker.New().
|
| 53 |
+
WithBackendS3(s3BackupJourneyBucketName, s3BackupJourneyRegion).
|
| 54 |
+
WithText2VecContextionary().
|
| 55 |
+
WithWeaviateCluster(3).
|
| 56 |
+
Start(ctx)
|
| 57 |
+
require.Nil(t, err)
|
| 58 |
+
defer func() {
|
| 59 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 60 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 61 |
+
}
|
| 62 |
+
}()
|
| 63 |
+
|
| 64 |
+
t.Run("post-instance env setup", func(t *testing.T) {
|
| 65 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
t.Run("backup-s3", func(t *testing.T) {
|
| 69 |
+
journey.BackupJourneyTests_Cluster(t, "s3", s3BackupJourneyClassName,
|
| 70 |
+
s3BackupJourneyBackupIDCluster, tenantNames, override, overrideBucket, overridePath,
|
| 71 |
+
compose.GetWeaviate().URI(), compose.GetWeaviateNode(2).URI())
|
| 72 |
+
})
|
| 73 |
+
})
|
| 74 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-anthropic/generative_anthropic_test.go
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/assert"
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func testGenerativeAnthropic(rest, grpc string) func(t *testing.T) {
|
| 28 |
+
return func(t *testing.T) {
|
| 29 |
+
helper.SetupClient(rest)
|
| 30 |
+
helper.SetupGRPCClient(t, grpc)
|
| 31 |
+
// Define path to test/helper/sample-schema/planets/data folder
|
| 32 |
+
dataFolderPath := "../../../test/helper/sample-schema/planets/data"
|
| 33 |
+
// Data
|
| 34 |
+
data := planets.Planets
|
| 35 |
+
// Define class
|
| 36 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 37 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 38 |
+
"description": {
|
| 39 |
+
Vectorizer: map[string]interface{}{
|
| 40 |
+
"text2vec-transformers": map[string]interface{}{
|
| 41 |
+
"properties": []interface{}{"description"},
|
| 42 |
+
"vectorizeClassName": false,
|
| 43 |
+
},
|
| 44 |
+
},
|
| 45 |
+
VectorIndexType: "flat",
|
| 46 |
+
},
|
| 47 |
+
}
|
| 48 |
+
tests := []struct {
|
| 49 |
+
name string
|
| 50 |
+
generativeModel string
|
| 51 |
+
absentModuleConfig bool
|
| 52 |
+
withImages bool
|
| 53 |
+
}{
|
| 54 |
+
{
|
| 55 |
+
name: "claude-3-5-sonnet-20240620",
|
| 56 |
+
generativeModel: "claude-3-5-sonnet-20240620",
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
name: "claude-3-opus-20240229",
|
| 60 |
+
generativeModel: "claude-3-opus-20240229",
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
name: "claude-3-sonnet-20240229",
|
| 64 |
+
generativeModel: "claude-3-sonnet-20240229",
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
name: "claude-3-haiku-20240307",
|
| 68 |
+
generativeModel: "claude-3-haiku-20240307",
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
name: "absent module config",
|
| 72 |
+
generativeModel: "claude-3-5-sonnet-20240620",
|
| 73 |
+
absentModuleConfig: true,
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
name: "claude-3-5-sonnet-20241022",
|
| 77 |
+
generativeModel: "claude-3-5-sonnet-20241022",
|
| 78 |
+
withImages: true,
|
| 79 |
+
},
|
| 80 |
+
}
|
| 81 |
+
for _, tt := range tests {
|
| 82 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 83 |
+
if tt.absentModuleConfig {
|
| 84 |
+
t.Log("skipping adding module config configuration to class")
|
| 85 |
+
} else {
|
| 86 |
+
class.ModuleConfig = map[string]interface{}{
|
| 87 |
+
"generative-anthropic": map[string]interface{}{
|
| 88 |
+
"model": tt.generativeModel,
|
| 89 |
+
},
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
// create schema
|
| 93 |
+
helper.CreateClass(t, class)
|
| 94 |
+
defer helper.DeleteClass(t, class.Class)
|
| 95 |
+
// create objects
|
| 96 |
+
t.Run("create objects", func(t *testing.T) {
|
| 97 |
+
if tt.withImages {
|
| 98 |
+
planets.InsertObjectsWithImages(t, class.Class, dataFolderPath)
|
| 99 |
+
} else {
|
| 100 |
+
planets.InsertObjects(t, class.Class)
|
| 101 |
+
}
|
| 102 |
+
})
|
| 103 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 104 |
+
for _, planet := range data {
|
| 105 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 106 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 107 |
+
require.NoError(t, err)
|
| 108 |
+
require.NotNil(t, obj)
|
| 109 |
+
require.Len(t, obj.Vectors, 1)
|
| 110 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 111 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 112 |
+
})
|
| 113 |
+
}
|
| 114 |
+
})
|
| 115 |
+
// generative task
|
| 116 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 117 |
+
planets.CreateTweetTest(t, class.Class)
|
| 118 |
+
})
|
| 119 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 120 |
+
params := fmt.Sprintf("anthropic:{topP:0.9 topK:90 model:%q}", tt.generativeModel)
|
| 121 |
+
if tt.absentModuleConfig {
|
| 122 |
+
params = fmt.Sprintf("anthropic:{topP:0.9 topK:90 model:%q baseURL:\"%s\"}", tt.generativeModel, "https://api.anthropic.com")
|
| 123 |
+
}
|
| 124 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 125 |
+
})
|
| 126 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 127 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 128 |
+
})
|
| 129 |
+
|
| 130 |
+
params := func() *pb.GenerativeAnthropic {
|
| 131 |
+
params := &pb.GenerativeAnthropic{
|
| 132 |
+
MaxTokens: grpchelper.ToPtr(int64(90)),
|
| 133 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 134 |
+
Temperature: grpchelper.ToPtr(0.9),
|
| 135 |
+
TopK: grpchelper.ToPtr(int64(90)),
|
| 136 |
+
TopP: grpchelper.ToPtr(0.9),
|
| 137 |
+
StopSequences: &pb.TextArray{Values: []string{"stop"}},
|
| 138 |
+
}
|
| 139 |
+
if tt.absentModuleConfig {
|
| 140 |
+
params.BaseUrl = grpchelper.ToPtr("https://api.anthropic.com")
|
| 141 |
+
}
|
| 142 |
+
return params
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 146 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 147 |
+
ReturnMetadata: true,
|
| 148 |
+
Kind: &pb.GenerativeProvider_Anthropic{Anthropic: params()},
|
| 149 |
+
})
|
| 150 |
+
})
|
| 151 |
+
if tt.withImages {
|
| 152 |
+
t.Run("image prompt", func(t *testing.T) {
|
| 153 |
+
t.Run("graphql", func(t *testing.T) {
|
| 154 |
+
prompt := "Describe image"
|
| 155 |
+
params := "anthropic:{imageProperties:\"image\"}"
|
| 156 |
+
planets.CreatePromptTestWithParams(t, class.Class, prompt, params)
|
| 157 |
+
})
|
| 158 |
+
|
| 159 |
+
singlePrompt := "Give a short answer: What's on the image?"
|
| 160 |
+
groupPrompt := "Give a short answer: What are on the following images?"
|
| 161 |
+
|
| 162 |
+
t.Run("grpc server stored images", func(t *testing.T) {
|
| 163 |
+
params := params()
|
| 164 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 165 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 166 |
+
ReturnMetadata: true,
|
| 167 |
+
Kind: &pb.GenerativeProvider_Anthropic{Anthropic: params},
|
| 168 |
+
})
|
| 169 |
+
})
|
| 170 |
+
|
| 171 |
+
t.Run("grpc user provided images", func(t *testing.T) {
|
| 172 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 173 |
+
require.NoError(t, err)
|
| 174 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 175 |
+
require.NoError(t, err)
|
| 176 |
+
|
| 177 |
+
params := params()
|
| 178 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 179 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 180 |
+
ReturnMetadata: true,
|
| 181 |
+
Kind: &pb.GenerativeProvider_Anthropic{Anthropic: params},
|
| 182 |
+
})
|
| 183 |
+
})
|
| 184 |
+
|
| 185 |
+
t.Run("grpc mixed images", func(t *testing.T) {
|
| 186 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 187 |
+
require.NoError(t, err)
|
| 188 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 189 |
+
require.NoError(t, err)
|
| 190 |
+
|
| 191 |
+
params := params()
|
| 192 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 193 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 194 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 195 |
+
ReturnMetadata: true,
|
| 196 |
+
Kind: &pb.GenerativeProvider_Anthropic{Anthropic: params},
|
| 197 |
+
})
|
| 198 |
+
})
|
| 199 |
+
})
|
| 200 |
+
}
|
| 201 |
+
})
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-anthropic/setup_test.go
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeAnthropic_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("ANTHROPIC_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, ANTHROPIC_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 35 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 36 |
+
|
| 37 |
+
t.Run("tests", testGenerativeAnthropic(endpointREST, endpointGRPC))
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 41 |
+
) (compose *docker.DockerCompose, err error) {
|
| 42 |
+
compose, err = composeModules(apiKey).
|
| 43 |
+
WithWeaviateWithGRPC().
|
| 44 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", "120s").
|
| 45 |
+
Start(ctx)
|
| 46 |
+
return
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 50 |
+
composeModules = docker.New().
|
| 51 |
+
WithText2VecTransformers().
|
| 52 |
+
WithGenerativeAnthropic(apiKey)
|
| 53 |
+
return
|
| 54 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-aws/generative_aws_test.go
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// _ _
|
| 2 |
+
// __ _____ __ ___ ___ __ _| |_ ___
|
| 3 |
+
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
|
| 4 |
+
// \ V V / __/ (_| |\ V /| | (_| | || __/
|
| 5 |
+
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
|
| 6 |
+
//
|
| 7 |
+
// Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
|
| 8 |
+
//
|
| 9 |
+
// CONTACT: hello@weaviate.io
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
package tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/assert"
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func testGenerativeAWS(rest, grpc, region string) func(t *testing.T) {
|
| 28 |
+
return func(t *testing.T) {
|
| 29 |
+
helper.SetupClient(rest)
|
| 30 |
+
helper.SetupGRPCClient(t, grpc)
|
| 31 |
+
// Define path to test/helper/sample-schema/planets/data folder
|
| 32 |
+
dataFolderPath := "../../../test/helper/sample-schema/planets/data"
|
| 33 |
+
// Data
|
| 34 |
+
data := planets.Planets
|
| 35 |
+
// Define class
|
| 36 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 37 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 38 |
+
"description": {
|
| 39 |
+
Vectorizer: map[string]interface{}{
|
| 40 |
+
"text2vec-aws": map[string]interface{}{
|
| 41 |
+
"properties": []interface{}{"description"},
|
| 42 |
+
"vectorizeClassName": false,
|
| 43 |
+
"service": "bedrock",
|
| 44 |
+
"region": region,
|
| 45 |
+
"model": "amazon.titan-embed-text-v2:0",
|
| 46 |
+
},
|
| 47 |
+
},
|
| 48 |
+
VectorIndexType: "flat",
|
| 49 |
+
},
|
| 50 |
+
}
|
| 51 |
+
tests := []struct {
|
| 52 |
+
name string
|
| 53 |
+
generativeModel string
|
| 54 |
+
absentModuleConfig bool
|
| 55 |
+
withImages bool
|
| 56 |
+
}{
|
| 57 |
+
// Amazon Titan
|
| 58 |
+
{
|
| 59 |
+
name: "amazon.titan-text-lite-v1",
|
| 60 |
+
generativeModel: "amazon.titan-text-lite-v1",
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
name: "amazon.titan-text-express-v1",
|
| 64 |
+
generativeModel: "amazon.titan-text-express-v1",
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
name: "amazon.titan-text-premier-v1:0",
|
| 68 |
+
generativeModel: "amazon.titan-text-premier-v1:0",
|
| 69 |
+
},
|
| 70 |
+
// Anthropic
|
| 71 |
+
{
|
| 72 |
+
name: "anthropic.claude-3-sonnet-20240229-v1:0",
|
| 73 |
+
generativeModel: "anthropic.claude-3-sonnet-20240229-v1:0",
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
name: "anthropic.claude-3-haiku-20240307-v1:0",
|
| 77 |
+
generativeModel: "anthropic.claude-3-haiku-20240307-v1:0",
|
| 78 |
+
withImages: true,
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
name: "anthropic.claude-v2:1",
|
| 82 |
+
generativeModel: "anthropic.claude-v2:1",
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
name: "anthropic.claude-v2",
|
| 86 |
+
generativeModel: "anthropic.claude-v2",
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
name: "anthropic.claude-instant-v1",
|
| 90 |
+
generativeModel: "anthropic.claude-instant-v1",
|
| 91 |
+
},
|
| 92 |
+
// Cohere
|
| 93 |
+
{
|
| 94 |
+
name: "cohere.command-r-v1:0",
|
| 95 |
+
generativeModel: "cohere.command-r-v1:0",
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
name: "cohere.command-r-plus-v1:0",
|
| 99 |
+
generativeModel: "cohere.command-r-plus-v1:0",
|
| 100 |
+
},
|
| 101 |
+
// Meta
|
| 102 |
+
{
|
| 103 |
+
name: "meta.llama3-8b-instruct-v1:0",
|
| 104 |
+
generativeModel: "meta.llama3-8b-instruct-v1:0",
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
name: "meta.llama3-70b-instruct-v1:0",
|
| 108 |
+
generativeModel: "meta.llama3-70b-instruct-v1:0",
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
name: "absent module config",
|
| 112 |
+
generativeModel: "meta.llama3-70b-instruct-v1:0",
|
| 113 |
+
absentModuleConfig: true,
|
| 114 |
+
},
|
| 115 |
+
// Mistral AI
|
| 116 |
+
{
|
| 117 |
+
name: "mistral.mistral-7b-instruct-v0:2",
|
| 118 |
+
generativeModel: "mistral.mistral-7b-instruct-v0:2",
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
name: "mistral.mixtral-8x7b-instruct-v0:1",
|
| 122 |
+
generativeModel: "mistral.mixtral-8x7b-instruct-v0:1",
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
name: "mistral.mistral-large-2402-v1:0",
|
| 126 |
+
generativeModel: "mistral.mistral-large-2402-v1:0",
|
| 127 |
+
},
|
| 128 |
+
}
|
| 129 |
+
for _, tt := range tests {
|
| 130 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 131 |
+
if tt.absentModuleConfig {
|
| 132 |
+
t.Log("skipping adding module config configuration to class")
|
| 133 |
+
} else {
|
| 134 |
+
class.ModuleConfig = map[string]interface{}{
|
| 135 |
+
"generative-aws": map[string]interface{}{
|
| 136 |
+
"service": "bedrock",
|
| 137 |
+
"region": region,
|
| 138 |
+
"model": tt.generativeModel,
|
| 139 |
+
},
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
// create schema
|
| 143 |
+
helper.CreateClass(t, class)
|
| 144 |
+
defer helper.DeleteClass(t, class.Class)
|
| 145 |
+
// create objects
|
| 146 |
+
t.Run("create objects", func(t *testing.T) {
|
| 147 |
+
if tt.withImages {
|
| 148 |
+
planets.InsertObjectsWithImages(t, class.Class, dataFolderPath)
|
| 149 |
+
} else {
|
| 150 |
+
planets.InsertObjects(t, class.Class)
|
| 151 |
+
}
|
| 152 |
+
})
|
| 153 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 154 |
+
for _, planet := range data {
|
| 155 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 156 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 157 |
+
require.NoError(t, err)
|
| 158 |
+
require.NotNil(t, obj)
|
| 159 |
+
require.Len(t, obj.Vectors, 1)
|
| 160 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 161 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 162 |
+
})
|
| 163 |
+
}
|
| 164 |
+
})
|
| 165 |
+
// generative task
|
| 166 |
+
if tt.absentModuleConfig {
|
| 167 |
+
t.Log("skipping create tweet tests with default values as e2e tests rely on specific AWS settings")
|
| 168 |
+
} else {
|
| 169 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 170 |
+
planets.CreateTweetTest(t, class.Class)
|
| 171 |
+
})
|
| 172 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 173 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 174 |
+
})
|
| 175 |
+
}
|
| 176 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 177 |
+
params := "aws:{temperature:0.1}"
|
| 178 |
+
if tt.absentModuleConfig {
|
| 179 |
+
params = fmt.Sprintf("aws:{temperature:0.1 service:\"bedrock\" region:\"%s\" model:\"%s\"}", region, tt.generativeModel)
|
| 180 |
+
}
|
| 181 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 182 |
+
})
|
| 183 |
+
|
| 184 |
+
params := func() *pb.GenerativeAWS {
|
| 185 |
+
params := &pb.GenerativeAWS{
|
| 186 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 187 |
+
Temperature: grpchelper.ToPtr(0.9),
|
| 188 |
+
}
|
| 189 |
+
if tt.absentModuleConfig {
|
| 190 |
+
params.Region = grpchelper.ToPtr(region)
|
| 191 |
+
params.Service = grpchelper.ToPtr("bedrock")
|
| 192 |
+
}
|
| 193 |
+
return params
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 197 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 198 |
+
ReturnMetadata: false, // no metadata for aws
|
| 199 |
+
Kind: &pb.GenerativeProvider_Aws{Aws: params()},
|
| 200 |
+
})
|
| 201 |
+
})
|
| 202 |
+
if tt.withImages {
|
| 203 |
+
t.Run("image prompt", func(t *testing.T) {
|
| 204 |
+
t.Run("graphql", func(t *testing.T) {
|
| 205 |
+
prompt := "Caption image"
|
| 206 |
+
params := "aws:{imageProperties:\"image\"}"
|
| 207 |
+
planets.CreatePromptTestWithParams(t, class.Class, prompt, params)
|
| 208 |
+
})
|
| 209 |
+
|
| 210 |
+
singlePrompt := "Give a short answer: What's on the image?"
|
| 211 |
+
groupPrompt := "Give a short answer: What are on the following images?"
|
| 212 |
+
|
| 213 |
+
t.Run("grpc server stored images", func(t *testing.T) {
|
| 214 |
+
params := params()
|
| 215 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 216 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 217 |
+
ReturnMetadata: false,
|
| 218 |
+
Kind: &pb.GenerativeProvider_Aws{Aws: params},
|
| 219 |
+
})
|
| 220 |
+
})
|
| 221 |
+
|
| 222 |
+
t.Run("grpc user provided images", func(t *testing.T) {
|
| 223 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 224 |
+
require.NoError(t, err)
|
| 225 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 226 |
+
require.NoError(t, err)
|
| 227 |
+
|
| 228 |
+
params := params()
|
| 229 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 230 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 231 |
+
ReturnMetadata: false,
|
| 232 |
+
Kind: &pb.GenerativeProvider_Aws{Aws: params},
|
| 233 |
+
})
|
| 234 |
+
})
|
| 235 |
+
|
| 236 |
+
t.Run("grpc mixed images", func(t *testing.T) {
|
| 237 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 238 |
+
require.NoError(t, err)
|
| 239 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 240 |
+
require.NoError(t, err)
|
| 241 |
+
|
| 242 |
+
params := params()
|
| 243 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 244 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 245 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 246 |
+
ReturnMetadata: false,
|
| 247 |
+
Kind: &pb.GenerativeProvider_Aws{Aws: params},
|
| 248 |
+
})
|
| 249 |
+
})
|
| 250 |
+
})
|
| 251 |
+
}
|
| 252 |
+
})
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
}
|