github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/integration/peers_bootstrap_simple_test.go (about)

     1  // +build integration
     2  
     3  // Copyright (c) 2016 Uber Technologies, Inc.
     4  //
     5  // Permission is hereby granted, free of charge, to any person obtaining a copy
     6  // of this software and associated documentation files (the "Software"), to deal
     7  // in the Software without restriction, including without limitation the rights
     8  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     9  // copies of the Software, and to permit persons to whom the Software is
    10  // furnished to do so, subject to the following conditions:
    11  //
    12  // The above copyright notice and this permission notice shall be included in
    13  // all copies or substantial portions of the Software.
    14  //
    15  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    16  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    17  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    18  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    19  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    21  // THE SOFTWARE.
    22  
    23  package integration
    24  
    25  import (
    26  	"testing"
    27  	"time"
    28  
    29  	"github.com/m3db/m3/src/dbnode/integration/generate"
    30  	"github.com/m3db/m3/src/dbnode/namespace"
    31  	"github.com/m3db/m3/src/dbnode/retention"
    32  	xtest "github.com/m3db/m3/src/x/test"
    33  
    34  	"github.com/stretchr/testify/require"
    35  )
    36  
    37  func TestPeersBootstrapSimple(t *testing.T) {
    38  	testPeersBootstrapSimple(t, nil, nil)
    39  }
    40  
    41  func TestProtoPeersBootstrapSimple(t *testing.T) {
    42  	testPeersBootstrapSimple(t, setProtoTestOptions, setProtoTestInputConfig)
    43  }
    44  
    45  func testPeersBootstrapSimple(t *testing.T, setTestOpts setTestOptions, updateInputConfig generate.UpdateBlockConfig) {
    46  	if testing.Short() {
    47  		t.SkipNow()
    48  	}
    49  
    50  	// Test setups
    51  	log := xtest.NewLogger(t)
    52  	retentionOpts := retention.NewOptions().
    53  		SetRetentionPeriod(20 * time.Hour).
    54  		SetBlockSize(2 * time.Hour).
    55  		SetBufferPast(10 * time.Minute).
    56  		SetBufferFuture(2 * time.Minute)
    57  	namesp, err := namespace.NewMetadata(testNamespaces[0], namespace.NewOptions().SetRetentionOptions(retentionOpts))
    58  	require.NoError(t, err)
    59  	opts := NewTestOptions(t).
    60  		SetNamespaces([]namespace.Metadata{namesp}).
    61  		// Use TChannel clients for writing / reading because we want to target individual nodes at a time
    62  		// and not write/read all nodes in the cluster.
    63  		SetUseTChannelClientForWriting(true).
    64  		SetUseTChannelClientForReading(true)
    65  	if setTestOpts != nil {
    66  		opts = setTestOpts(t, opts)
    67  		namesp = opts.Namespaces()[0]
    68  	}
    69  
    70  	setupOpts := []BootstrappableTestSetupOptions{
    71  		{DisablePeersBootstrapper: true},
    72  		{
    73  			DisableCommitLogBootstrapper: true,
    74  			DisablePeersBootstrapper:     false,
    75  		},
    76  	}
    77  	setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
    78  	defer closeFn()
    79  
    80  	// Write test data for first node
    81  	now := setups[0].NowFn()()
    82  	blockSize := retentionOpts.BlockSize()
    83  	// Make sure we have multiple blocks of data for multiple series to exercise
    84  	// the grouping and aggregating logic in the client peer bootstrapping process
    85  	inputData := []generate.BlockConfig{
    86  		{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: now.Add(-4 * blockSize)},
    87  		{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: now.Add(-3 * blockSize)},
    88  		{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: now.Add(-2 * blockSize)},
    89  		{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: now.Add(-blockSize)},
    90  		{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: now},
    91  	}
    92  	if updateInputConfig != nil {
    93  		updateInputConfig(inputData)
    94  	}
    95  	seriesMaps := generate.BlocksByStart(inputData)
    96  	require.NoError(t, writeTestDataToDisk(namesp, setups[0], seriesMaps, 0))
    97  
    98  	// Start the first server with filesystem bootstrapper
    99  	require.NoError(t, setups[0].StartServer())
   100  
   101  	// Start the last server with peers and filesystem bootstrappers
   102  	require.NoError(t, setups[1].StartServer())
   103  	log.Debug("servers are now up")
   104  
   105  	// Stop the servers
   106  	defer func() {
   107  		setups.parallel(func(s TestSetup) {
   108  			require.NoError(t, s.StopServer())
   109  		})
   110  		log.Debug("servers are now down")
   111  	}()
   112  
   113  	// Verify in-memory data match what we expect
   114  	for _, setup := range setups {
   115  		verifySeriesMaps(t, setup, namesp.ID(), seriesMaps)
   116  	}
   117  }