github.com/m3db/m3@v1.5.0/src/x/config/pooling_test.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  package config
    21  
    22  import (
    23  	"testing"
    24  
    25  	"github.com/m3db/m3/src/x/sync"
    26  
    27  	"github.com/stretchr/testify/assert"
    28  )
    29  
    30  func TestWorkerPoolPolicyConvertsToOptionsDefault(t *testing.T) {
    31  	wpp := WorkerPoolPolicy{}
    32  	opts, size := wpp.Options()
    33  	defaultOpts := sync.NewPooledWorkerPoolOptions()
    34  
    35  	assert.False(t, opts.GrowOnDemand())
    36  	assert.Equal(t, defaultOpts.NumShards(), opts.NumShards())
    37  	assert.Equal(t, defaultOpts.KillWorkerProbability(), opts.KillWorkerProbability())
    38  	assert.Equal(t, defaultWorkerPoolStaticSize, size)
    39  }
    40  
    41  func TestWorkerPoolPolicyConvertsToOptionsDefaultGrow(t *testing.T) {
    42  	wpp := WorkerPoolPolicy{GrowOnDemand: true}
    43  	opts, size := wpp.Options()
    44  	defaultOpts := sync.NewPooledWorkerPoolOptions()
    45  
    46  	assert.True(t, opts.GrowOnDemand())
    47  	assert.Equal(t, defaultOpts.NumShards(), opts.NumShards())
    48  	assert.Equal(t, defaultGrowKillProbability, opts.KillWorkerProbability())
    49  	assert.Equal(t, opts.NumShards(), int64(size))
    50  }
    51  
    52  func TestWorkerPoolPolicyConvertsToOptions(t *testing.T) {
    53  	wpp := WorkerPoolPolicy{
    54  		GrowOnDemand:          true,
    55  		Size:                  100,
    56  		NumShards:             200,
    57  		KillWorkerProbability: 0.5,
    58  	}
    59  	opts, size := wpp.Options()
    60  	assert.True(t, opts.GrowOnDemand())
    61  	assert.Equal(t, int64(200), opts.NumShards())
    62  	assert.Equal(t, 0.5, opts.KillWorkerProbability())
    63  	assert.Equal(t, 100, size)
    64  
    65  }