github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/integration/repair/repair_and_replication_test.go (about) 1 //go:build cluster_integration 2 // +build cluster_integration 3 4 // 5 // Copyright (c) 2021 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package repair 26 27 import ( 28 "context" 29 "testing" 30 31 "github.com/m3db/m3/src/integration/resources" 32 "github.com/m3db/m3/src/integration/resources/docker/dockerexternal" 33 "github.com/m3db/m3/src/integration/resources/inprocess" 34 "github.com/m3db/m3/src/x/instrument" 35 36 "github.com/ory/dockertest/v3" 37 "github.com/stretchr/testify/assert" 38 "github.com/stretchr/testify/require" 39 ) 40 41 func TestRepairAndReplication(t *testing.T) { 42 t.Skip("failing after etcd containerization; fix.") 43 cluster1, cluster2, closer := testSetup(t) 44 defer closer() 45 46 RunTest(t, cluster1, cluster2) 47 } 48 49 func testSetup(t *testing.T) (resources.M3Resources, resources.M3Resources, func()) { 50 pool, err := dockertest.NewPool("") 51 require.NoError(t, err) 52 53 etcd1 := mustNewStartedEtcd(t, pool) 54 etcd2 := mustNewStartedEtcd(t, pool) 55 56 ep1 := []string{etcd1.Address()} 57 ep2 := []string{etcd2.Address()} 58 59 cluster1Opts := newTestClusterOptions() 60 cluster1Opts.EtcdEndpoints = ep1 61 62 cluster2Opts := newTestClusterOptions() 63 cluster2Opts.EtcdEndpoints = ep2 64 65 fullCfgs1 := getClusterFullConfgs(t, cluster1Opts) 66 fullCfgs2 := getClusterFullConfgs(t, cluster2Opts) 67 68 setRepairAndReplicationCfg( 69 &fullCfgs1, 70 "cluster-2", 71 ep2, 72 ) 73 setRepairAndReplicationCfg( 74 &fullCfgs2, 75 "cluster-1", 76 ep1, 77 ) 78 79 cluster1, err := inprocess.NewClusterFromSpecification(fullCfgs1, cluster1Opts) 80 require.NoError(t, err) 81 82 cluster2, err := inprocess.NewClusterFromSpecification(fullCfgs2, cluster2Opts) 83 require.NoError(t, err) 84 85 return cluster1, cluster2, func() { 86 etcd1.Close(context.TODO()) 87 etcd2.Close(context.TODO()) 88 assert.NoError(t, cluster1.Cleanup()) 89 assert.NoError(t, cluster2.Cleanup()) 90 } 91 } 92 93 func mustNewStartedEtcd(t *testing.T, pool *dockertest.Pool) *dockerexternal.EtcdNode { 94 etcd, err := dockerexternal.NewEtcd(pool, instrument.NewOptions()) 95 require.NoError(t, err) 96 require.NoError(t, etcd.Setup(context.TODO())) 97 return etcd 98 } 99 100 func getClusterFullConfgs(t *testing.T, clusterOptions resources.ClusterOptions) inprocess.ClusterSpecification { 101 cfgs, err := inprocess.NewClusterConfigsFromYAML( 102 TestRepairDBNodeConfig, TestRepairCoordinatorConfig, "", 103 ) 104 require.NoError(t, err) 105 106 fullCfgs, err := inprocess.GenerateClusterSpecification(cfgs, clusterOptions) 107 require.NoError(t, err) 108 109 return fullCfgs 110 } 111 112 func setRepairAndReplicationCfg(fullCfg *inprocess.ClusterSpecification, clusterName string, endpoints []string) { 113 for _, dbnode := range fullCfg.Configs.DBNodes { 114 dbnode.DB.Replication.Clusters[0].Name = clusterName 115 etcdService := &(dbnode.DB.Replication.Clusters[0].Client.EnvironmentConfig.Services[0].Service.ETCDClusters[0]) 116 etcdService.AutoSyncInterval = -1 117 etcdService.Endpoints = endpoints 118 } 119 } 120 121 func newTestClusterOptions() resources.ClusterOptions { 122 return resources.ClusterOptions{ 123 DBNode: &resources.DBNodeClusterOptions{ 124 RF: 2, 125 NumShards: 4, 126 NumInstances: 1, 127 NumIsolationGroups: 2, 128 }, 129 Coordinator: resources.CoordinatorClusterOptions{ 130 GeneratePorts: true, 131 }, 132 } 133 }