github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/query/test/storage.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package test
    22  
    23  import (
    24  	"context"
    25  	"errors"
    26  	"time"
    27  
    28  	"github.com/m3db/m3/src/query/block"
    29  	"github.com/m3db/m3/src/query/storage"
    30  	"github.com/m3db/m3/src/query/storage/m3/consolidators"
    31  	"github.com/m3db/m3/src/query/storage/m3/storagemetadata"
    32  )
    33  
    34  // slowStorage slows down a request by delay
    35  type slowStorage struct {
    36  	storage storage.Storage
    37  	delay   time.Duration
    38  }
    39  
    40  func (s *slowStorage) FetchCompressed(ctx context.Context,
    41  	query *storage.FetchQuery, options *storage.FetchOptions) (consolidators.MultiFetchResult, error) {
    42  	time.Sleep(s.delay)
    43  	return s.storage.FetchCompressed(ctx, query, options)
    44  }
    45  
    46  // NewSlowStorage creates a new slow storage
    47  func NewSlowStorage(
    48  	storage storage.Storage,
    49  	delay time.Duration,
    50  ) storage.Storage {
    51  	return &slowStorage{storage: storage, delay: delay}
    52  }
    53  
    54  func (s *slowStorage) FetchProm(
    55  	ctx context.Context,
    56  	query *storage.FetchQuery,
    57  	options *storage.FetchOptions,
    58  ) (storage.PromResult, error) {
    59  	time.Sleep(s.delay)
    60  	return s.storage.FetchProm(ctx, query, options)
    61  }
    62  
    63  func (s *slowStorage) FetchBlocks(
    64  	ctx context.Context,
    65  	query *storage.FetchQuery,
    66  	options *storage.FetchOptions,
    67  ) (block.Result, error) {
    68  	time.Sleep(s.delay)
    69  	return s.storage.FetchBlocks(ctx, query, options)
    70  }
    71  
    72  func (s *slowStorage) SearchSeries(
    73  	ctx context.Context,
    74  	query *storage.FetchQuery,
    75  	options *storage.FetchOptions,
    76  ) (*storage.SearchResults, error) {
    77  	time.Sleep(s.delay)
    78  	return s.storage.SearchSeries(ctx, query, options)
    79  }
    80  
    81  func (s *slowStorage) CompleteTags(
    82  	ctx context.Context,
    83  	query *storage.CompleteTagsQuery,
    84  	options *storage.FetchOptions,
    85  ) (*consolidators.CompleteTagsResult, error) {
    86  	time.Sleep(s.delay)
    87  	return s.storage.CompleteTags(ctx, query, options)
    88  }
    89  
    90  func (s *slowStorage) Write(
    91  	ctx context.Context,
    92  	query *storage.WriteQuery,
    93  ) error {
    94  	time.Sleep(s.delay)
    95  	return s.storage.Write(ctx, query)
    96  }
    97  
    98  func (s *slowStorage) QueryStorageMetadataAttributes(
    99  	ctx context.Context,
   100  	queryStart, queryEnd time.Time,
   101  	opts *storage.FetchOptions,
   102  ) ([]storagemetadata.Attributes, error) {
   103  	return nil, errors.New("not implemented")
   104  }
   105  
   106  func (s *slowStorage) Type() storage.Type {
   107  	return storage.TypeMultiDC
   108  }
   109  
   110  func (s *slowStorage) Name() string {
   111  	return "slow"
   112  }
   113  
   114  func (s *slowStorage) ErrorBehavior() storage.ErrorBehavior {
   115  	return storage.BehaviorFail
   116  }
   117  
   118  func (s *slowStorage) Close() error {
   119  	return nil
   120  }