github.com/m3db/m3@v1.5.0/src/dbnode/integration/fs_bootstrap_multi_ns_test.go (about)

     1  // +build integration
     2  
     3  // Copyright (c) 2017 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  
    33  	"github.com/stretchr/testify/require"
    34  )
    35  
    36  func TestFilesystemBootstrapMultipleNamespaces(t *testing.T) {
    37  	if testing.Short() {
    38  		t.SkipNow() // Just skip if we're doing a short run
    39  	}
    40  
    41  	// Test setup
    42  	var (
    43  		rOpts        = retention.NewOptions().SetRetentionPeriod(6 * time.Hour)
    44  		ns1BlockSize = 2 * time.Hour
    45  		ns2BlockSize = 3 * time.Hour
    46  		ns1ROpts     = rOpts.SetBlockSize(ns1BlockSize)
    47  		ns2ROpts     = rOpts.SetBlockSize(ns2BlockSize)
    48  	)
    49  
    50  	ns1, err := namespace.NewMetadata(testNamespaces[0], namespace.NewOptions().SetRetentionOptions(ns1ROpts))
    51  	require.NoError(t, err)
    52  	ns2, err := namespace.NewMetadata(testNamespaces[1], namespace.NewOptions().SetRetentionOptions(ns2ROpts))
    53  	require.NoError(t, err)
    54  	opts := NewTestOptions(t).
    55  		SetNamespaces([]namespace.Metadata{ns1, ns2})
    56  
    57  	setup, err := NewTestSetup(t, opts, nil)
    58  	require.NoError(t, err)
    59  	defer setup.Close()
    60  
    61  	require.NoError(t, setup.InitializeBootstrappers(InitializeBootstrappersOptions{
    62  		WithFileSystem: true,
    63  	}))
    64  
    65  	log := setup.StorageOpts().InstrumentOptions().Logger()
    66  
    67  	log.Info("generating data")
    68  	// Write test data
    69  	now := setup.NowFn()()
    70  	ns1SeriesMaps := generate.BlocksByStart([]generate.BlockConfig{
    71  		{IDs: []string{"foo", "bar"}, NumPoints: 100, Start: now.Add(-ns1BlockSize)},
    72  		{IDs: []string{"foo", "baz"}, NumPoints: 50, Start: now},
    73  	})
    74  	ns2SeriesMaps := generate.BlocksByStart([]generate.BlockConfig{
    75  		{IDs: []string{"bar", "baz"}, NumPoints: 100, Start: now.Add(-2 * ns2BlockSize)},
    76  		{IDs: []string{"foo", "bar"}, NumPoints: 100, Start: now.Add(-ns2BlockSize)},
    77  		{IDs: []string{"foo", "baz"}, NumPoints: 50, Start: now},
    78  	})
    79  	require.NoError(t, writeTestDataToDiskWithIndex(ns1, setup, ns1SeriesMaps))
    80  	require.NoError(t, writeTestDataToDiskWithIndex(ns2, setup, ns2SeriesMaps))
    81  	log.Info("generated data")
    82  
    83  	// Start the server with filesystem bootstrapper
    84  	log.Info("filesystem bootstrap test")
    85  	require.NoError(t, setup.StartServer())
    86  	log.Info("server is now up")
    87  
    88  	// Stop the server
    89  	defer func() {
    90  		require.NoError(t, setup.StopServer())
    91  		log.Info("server is now down")
    92  	}()
    93  
    94  	// Verify in-memory data match what we expect
    95  	verifySeriesMaps(t, setup, testNamespaces[0], ns1SeriesMaps)
    96  	verifySeriesMaps(t, setup, testNamespaces[1], ns2SeriesMaps)
    97  }