github.com/m3db/m3@v1.5.0/src/dbnode/integration/fs_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 TestFilesystemBootstrap(t *testing.T) { 37 testFilesystemBootstrap(t, nil, nil) 38 } 39 40 func TestProtoFilesystemBootstrap(t *testing.T) { 41 testFilesystemBootstrap(t, setProtoTestOptions, setProtoTestInputConfig) 42 } 43 44 func testFilesystemBootstrap(t *testing.T, setTestOpts setTestOptions, updateInputConfig generate.UpdateBlockConfig) { 45 if testing.Short() { 46 t.SkipNow() // Just skip if we're doing a short run 47 } 48 49 var ( 50 blockSize = 2 * time.Hour 51 rOpts = retention.NewOptions().SetRetentionPeriod(2 * time.Hour).SetBlockSize(blockSize) 52 ) 53 ns1, err := namespace.NewMetadata(testNamespaces[0], namespace.NewOptions().SetRetentionOptions(rOpts)) 54 require.NoError(t, err) 55 ns2, err := namespace.NewMetadata(testNamespaces[1], namespace.NewOptions().SetRetentionOptions(rOpts)) 56 require.NoError(t, err) 57 58 opts := NewTestOptions(t). 59 SetNamespaces([]namespace.Metadata{ns1, ns2}) 60 if setTestOpts != nil { 61 opts = setTestOpts(t, opts) 62 ns1 = opts.Namespaces()[0] 63 ns2 = opts.Namespaces()[1] 64 } 65 66 // Test setup 67 setup, err := NewTestSetup(t, opts, nil) 68 require.NoError(t, err) 69 defer setup.Close() 70 71 require.NoError(t, setup.InitializeBootstrappers(InitializeBootstrappersOptions{ 72 WithFileSystem: true, 73 })) 74 75 // Write test data 76 now := setup.NowFn()() 77 inputData := []generate.BlockConfig{ 78 {IDs: []string{"foo", "bar"}, NumPoints: 100, Start: now.Add(-blockSize)}, 79 {IDs: []string{"foo", "baz"}, NumPoints: 50, Start: now}, 80 } 81 if updateInputConfig != nil { 82 updateInputConfig(inputData) 83 } 84 seriesMaps := generate.BlocksByStart(inputData) 85 require.NoError(t, writeTestDataToDisk(ns1, setup, seriesMaps, 0)) 86 require.NoError(t, writeTestDataToDisk(ns2, setup, nil, 0)) 87 88 // Start the server with filesystem bootstrapper 89 log := setup.StorageOpts().InstrumentOptions().Logger() 90 log.Debug("filesystem bootstrap test") 91 require.NoError(t, setup.StartServer()) 92 log.Debug("server is now up") 93 94 // Stop the server 95 defer func() { 96 require.NoError(t, setup.StopServer()) 97 log.Debug("server is now down") 98 }() 99 100 // Verify in-memory data match what we expect 101 verifySeriesMaps(t, setup, testNamespaces[0], seriesMaps) 102 verifySeriesMaps(t, setup, testNamespaces[1], nil) 103 }