friendly apis for constructors

This commit is contained in:
Anton Kaliaev
2018-06-20 12:40:25 +04:00
parent cd11a54f7a
commit 84812145cb
11 changed files with 53 additions and 20 deletions
+12 -2
View File
@@ -88,7 +88,7 @@ type Mempool struct {
}
// NewMempool returns a new Mempool with the given configuration and connection to an application.
func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64, metrics *Metrics) *Mempool {
func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64, options ...func(*Mempool)) *Mempool {
mempool := &Mempool{
config: config,
proxyAppConn: proxyAppConn,
@@ -100,9 +100,12 @@ func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, he
recheckEnd: nil,
logger: log.NewNopLogger(),
cache: newTxCache(config.CacheSize),
metrics: metrics,
metrics: NopMetrics(),
}
proxyAppConn.SetResponseCallback(mempool.resCb)
for _, option := range options {
option(mempool)
}
return mempool
}
@@ -118,6 +121,13 @@ func (mem *Mempool) SetLogger(l log.Logger) {
mem.logger = l
}
// WithMetrics sets the metrics.
func WithMetrics(metrics *Metrics) func(*Mempool) {
return func(mem *Mempool) {
mem.metrics = metrics
}
}
// CloseWAL closes and discards the underlying WAL file.
// Any further writes will not be relayed to disk.
func (mem *Mempool) CloseWAL() bool {
+2 -2
View File
@@ -33,7 +33,7 @@ func newMempoolWithApp(cc proxy.ClientCreator) *Mempool {
if err != nil {
panic(err)
}
mempool := NewMempool(config.Mempool, appConnMem, 0, NopMetrics())
mempool := NewMempool(config.Mempool, appConnMem, 0)
mempool.SetLogger(log.TestingLogger())
return mempool
}
@@ -241,7 +241,7 @@ func TestMempoolCloseWAL(t *testing.T) {
app := kvstore.NewKVStoreApplication()
cc := proxy.NewLocalClientCreator(app)
appConnMem, _ := cc.NewABCIClient()
mempool := NewMempool(wcfg, appConnMem, 10, NopMetrics())
mempool := NewMempool(wcfg, appConnMem, 10)
mempool.InitWAL()
// 4. Ensure that the directory contains the WAL file