github.com/weaviate/weaviate@v1.24.6/test/helper/journey/single_node_backup_journey.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package 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,
    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)
    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,
    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)
    89  	})
    90  
    91  	t.Run("cleanup", func(t *testing.T) {
    92  		helper.DeleteClass(t, className)
    93  	})
    94  }
    95  
    96  func singleNodeNodeMappingBackupJourney_Backup(t *testing.T,
    97  	weaviateEndpoint, backend, className, backupID string,
    98  	tenantNames []string,
    99  ) {
   100  	if weaviateEndpoint != "" {
   101  		helper.SetupClient(weaviateEndpoint)
   102  	}
   103  
   104  	if len(tenantNames) > 0 {
   105  		t.Run("add test data", func(t *testing.T) {
   106  			addTestClass(t, className, multiTenant)
   107  			tenants := make([]*models.Tenant, len(tenantNames))
   108  			for i := range tenantNames {
   109  				tenants[i] = &models.Tenant{Name: tenantNames[i]}
   110  			}
   111  			helper.CreateTenants(t, className, tenants)
   112  			addTestObjects(t, className, tenantNames)
   113  		})
   114  	} else {
   115  		t.Run("add test data", func(t *testing.T) {
   116  			addTestClass(t, className, !multiTenant)
   117  			addTestObjects(t, className, nil)
   118  		})
   119  	}
   120  
   121  	t.Run("single node backup", func(t *testing.T) {
   122  		nodeMappingBackupJourney_Backup(t, className, backend, backupID, tenantNames)
   123  	})
   124  }
   125  
   126  func singleNodeNodeMappingBackupJourney_Restore(t *testing.T,
   127  	weaviateEndpoint, backend, className, backupID string,
   128  	tenantNames []string, nodeMapping map[string]string,
   129  ) {
   130  	if weaviateEndpoint != "" {
   131  		helper.SetupClient(weaviateEndpoint)
   132  	}
   133  
   134  	t.Run("single node restore", func(t *testing.T) {
   135  		nodeMappingBackupJourney_Restore(t, className, backend, backupID, tenantNames, nodeMapping)
   136  	})
   137  }