github.com/m3db/m3@v1.5.0/src/dbnode/integration/fs_data_expiry_bootstrap_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  
    33  	"github.com/stretchr/testify/require"
    34  )
    35  
    36  func TestFilesystemDataExpiryBootstrap(t *testing.T) {
    37  	if testing.Short() {
    38  		t.SkipNow() // Just skip if we're doing a short run
    39  	}
    40  	// Test setup
    41  	var (
    42  		ropts = retention.NewOptions().
    43  			SetRetentionPeriod(6 * time.Hour).
    44  			SetBlockSize(2 * time.Hour).
    45  			SetBufferPast(10 * time.Minute).
    46  			SetBufferFuture(2 * time.Minute).
    47  			SetBlockDataExpiry(true)
    48  		blockSize = ropts.BlockSize()
    49  		setup     TestSetup
    50  		err       error
    51  	)
    52  	namesp, err := namespace.NewMetadata(testNamespaces[0], namespace.NewOptions().SetRetentionOptions(ropts))
    53  	require.NoError(t, err)
    54  
    55  	opts := NewTestOptions(t).
    56  		SetNamespaces([]namespace.Metadata{namesp})
    57  
    58  	setup, err = NewTestSetup(t, opts, nil)
    59  	require.NoError(t, err)
    60  	defer setup.Close()
    61  
    62  	log := setup.StorageOpts().InstrumentOptions().Logger()
    63  
    64  	require.NoError(t, setup.InitializeBootstrappers(InitializeBootstrappersOptions{
    65  		WithFileSystem: true,
    66  	}))
    67  
    68  	// Write test data
    69  	now := setup.NowFn()()
    70  	seriesMaps := generate.BlocksByStart([]generate.BlockConfig{
    71  		{IDs: []string{"foo", "bar"}, NumPoints: 100, Start: now.Add(-blockSize)},
    72  	})
    73  	require.NoError(t, writeTestDataToDisk(namesp, setup, seriesMaps, 0))
    74  
    75  	// Start the server with filesystem bootstrapper
    76  	log.Debug("filesystem data expiry bootstrap test")
    77  	require.NoError(t, setup.StartServer())
    78  	log.Debug("server is now up")
    79  
    80  	// Stop the server
    81  	defer func() {
    82  		require.NoError(t, setup.StopServer())
    83  		log.Debug("server is now down")
    84  	}()
    85  
    86  	// Verify in-memory data match what we expect
    87  	verifySeriesMaps(t, setup, namesp.ID(), seriesMaps)
    88  }