github.com/m3db/m3@v1.5.0/src/dbnode/integration/disk_flush_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 xtime "github.com/m3db/m3/src/x/time" 31 32 "github.com/stretchr/testify/require" 33 ) 34 35 func TestDiskFlushSimple(t *testing.T) { 36 if testing.Short() { 37 t.SkipNow() // Just skip if we're doing a short run 38 } 39 // Test setup 40 testOpts := NewTestOptions(t). 41 SetTickMinimumInterval(time.Second) 42 testSetup, err := NewTestSetup(t, testOpts, nil) 43 require.NoError(t, err) 44 defer testSetup.Close() 45 46 md := testSetup.NamespaceMetadataOrFail(testNamespaces[0]) 47 blockSize := md.Options().RetentionOptions().BlockSize() 48 filePathPrefix := testSetup.StorageOpts().CommitLogOptions().FilesystemOptions().FilePathPrefix() 49 50 // Start the server 51 log := testSetup.StorageOpts().InstrumentOptions().Logger() 52 log.Debug("disk flush test") 53 require.NoError(t, testSetup.StartServer()) 54 log.Debug("server is now up") 55 56 // Stop the server 57 defer func() { 58 require.NoError(t, testSetup.StopServer()) 59 log.Debug("server is now down") 60 }() 61 62 // Write test data 63 now := testSetup.NowFn()() 64 seriesMaps := make(map[xtime.UnixNano]generate.SeriesBlock) 65 inputData := []generate.BlockConfig{ 66 {IDs: []string{"foo", "bar"}, NumPoints: 100, Start: now}, 67 {IDs: []string{"foo", "baz"}, NumPoints: 50, Start: now.Add(blockSize)}, 68 } 69 for _, input := range inputData { 70 testSetup.SetNowFn(input.Start) 71 testData := generate.Block(input) 72 seriesMaps[input.Start] = testData 73 require.NoError(t, testSetup.WriteBatch(testNamespaces[0], testData)) 74 } 75 log.Debug("test data is now written") 76 77 // Advance time to make sure all data are flushed. Because data 78 // are flushed to disk asynchronously, need to poll to check 79 // when data are written. 80 testSetup.SetNowFn(testSetup.NowFn()().Add(blockSize * 2)) 81 maxWaitTime := time.Minute 82 require.NoError(t, waitUntilDataFilesFlushed(filePathPrefix, testSetup.ShardSet(), testNamespaces[0], seriesMaps, maxWaitTime)) 83 84 // Verify on-disk data match what we expect 85 verifyFlushedDataFiles(t, testSetup.ShardSet(), testSetup.StorageOpts(), testNamespaces[0], seriesMaps) 86 }