Skip to content

Commit

Permalink
[FAB-2735] (PA) Clean up config mocks
Browse files Browse the repository at this point in the history
The config mock structure did not keep up with the changes in the config
code, and was therefore using old interface names and paths.

This CR fixes the mock config structures to use the correct name, and
restructures them in the same way the real config structures were
restructured.

Change-Id: If5201b3ca73c498b56701eea3c6bf50d7e587178
Signed-off-by: Jason Yellick <[email protected]>
Signed-off-by: Kostas Christidis <[email protected]>
  • Loading branch information
Jason Yellick authored and kchristidis committed Apr 26, 2017
1 parent 0fcb145 commit 3fb58c8
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package channel
package config

import "github.com/hyperledger/fabric/common/util"

func nearIdentityHash(input []byte) []byte {
return util.ConcatenateBytes([]byte("FakeHash("), input, []byte(""))
}

// SharedConfig is a mock implementation of sharedconfig.SharedConfig
type SharedConfig struct {
// Channel is a mock implementation of config.Channel
type Channel struct {
// HashingAlgorithmVal is returned as the result of HashingAlgorithm() if set
HashingAlgorithmVal func([]byte) []byte
// BlockDataHashingStructureWidthVal is returned as the result of BlockDataHashingStructureWidth()
Expand All @@ -33,19 +33,19 @@ type SharedConfig struct {
}

// HashingAlgorithm returns the HashingAlgorithmVal if set, otherwise a fake simple hash function
func (scm *SharedConfig) HashingAlgorithm() func([]byte) []byte {
func (scm *Channel) HashingAlgorithm() func([]byte) []byte {
if scm.HashingAlgorithmVal == nil {
return nearIdentityHash
}
return scm.HashingAlgorithmVal
}

// BlockDataHashingStructureWidth returns the BlockDataHashingStructureWidthVal
func (scm *SharedConfig) BlockDataHashingStructureWidth() uint32 {
func (scm *Channel) BlockDataHashingStructureWidth() uint32 {
return scm.BlockDataHashingStructureWidthVal
}

// OrdererAddresses returns the OrdererAddressesVal
func (scm *SharedConfig) OrdererAddresses() []string {
func (scm *Channel) OrdererAddresses() []string {
return scm.OrdererAddressesVal
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package channel
package config

import (
"testing"

"github.com/hyperledger/fabric/common/config"
)

func TestChainConfigInterface(t *testing.T) {
_ = config.Channel(&SharedConfig{})
func TestChannelConfigInterface(t *testing.T) {
_ = config.Channel(&Channel{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package config

import ab "github.com/hyperledger/fabric/protos/orderer"
import "time"
import (
"time"

// SharedConfig is a mock implementation of sharedconfig.SharedConfig
type SharedConfig struct {
ab "github.com/hyperledger/fabric/protos/orderer"
)

// Orderer is a mock implementation of config.Orderer
type Orderer struct {
// ConsensusTypeVal is returned as the result of ConsensusType()
ConsensusTypeVal string
// BatchSizeVal is returned as the result of BatchSize()
Expand All @@ -34,26 +37,26 @@ type SharedConfig struct {
}

// ConsensusType returns the ConsensusTypeVal
func (scm *SharedConfig) ConsensusType() string {
func (scm *Orderer) ConsensusType() string {
return scm.ConsensusTypeVal
}

// BatchSize returns the BatchSizeVal
func (scm *SharedConfig) BatchSize() *ab.BatchSize {
func (scm *Orderer) BatchSize() *ab.BatchSize {
return scm.BatchSizeVal
}

// BatchTimeout returns the BatchTimeoutVal
func (scm *SharedConfig) BatchTimeout() time.Duration {
func (scm *Orderer) BatchTimeout() time.Duration {
return scm.BatchTimeoutVal
}

// KafkaBrokers returns the KafkaBrokersVal
func (scm *SharedConfig) KafkaBrokers() []string {
func (scm *Orderer) KafkaBrokers() []string {
return scm.KafkaBrokersVal
}

// MaxChannelsCount returns the MaxChannelsCountVal
func (scm *SharedConfig) MaxChannelsCount() uint64 {
func (scm *Orderer) MaxChannelsCount() uint64 {
return scm.MaxChannelsCountVal
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package config

import (
"testing"

"github.com/hyperledger/fabric/common/config"
)

func TestSharedConfigInterface(t *testing.T) {
_ = config.Orderer(&SharedConfig{})
func TestOrdererConfigInterface(t *testing.T) {
_ = config.Orderer(&Orderer{})
}
16 changes: 8 additions & 8 deletions orderer/common/blockcutter/blockcutter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"testing"

mockconfigtxorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
"github.com/hyperledger/fabric/orderer/common/filter"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestNormalBatch(t *testing.T) {
maxMessageCount := uint32(2)
absoluteMaxBytes := uint32(1000)
preferredMaxBytes := uint32(100)
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)

batches, committers, ok := r.Ordered(goodTx)

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestBadMessageInBatch(t *testing.T) {
maxMessageCount := uint32(2)
absoluteMaxBytes := uint32(1000)
preferredMaxBytes := uint32(100)
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)

batches, committers, ok := r.Ordered(badTx)

Expand Down Expand Up @@ -150,7 +150,7 @@ func TestUnmatchedMessageInBatch(t *testing.T) {
maxMessageCount := uint32(2)
absoluteMaxBytes := uint32(1000)
preferredMaxBytes := uint32(100)
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)

batches, committers, ok := r.Ordered(unmatchedTx)

Expand Down Expand Up @@ -188,7 +188,7 @@ func TestIsolatedEmptyBatch(t *testing.T) {
maxMessageCount := uint32(2)
absoluteMaxBytes := uint32(1000)
preferredMaxBytes := uint32(100)
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)

batches, committers, ok := r.Ordered(isolatedTx)

Expand All @@ -214,7 +214,7 @@ func TestIsolatedPartialBatch(t *testing.T) {
maxMessageCount := uint32(2)
absoluteMaxBytes := uint32(1000)
preferredMaxBytes := uint32(100)
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)

batches, committers, ok := r.Ordered(goodTx)

Expand Down Expand Up @@ -264,7 +264,7 @@ func TestBatchSizePreferredMaxBytesOverflow(t *testing.T) {
// set message count > 9
maxMessageCount := uint32(20)

r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 2, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 2, PreferredMaxBytes: preferredMaxBytes}}, filters)

// enqueue 9 messages
for i := 0; i < 9; i++ {
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestBatchSizePreferredMaxBytesOverflowNoPending(t *testing.T) {
// set message count > 1
maxMessageCount := uint32(20)

r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 3, PreferredMaxBytes: preferredMaxBytes}}, filters)
r := NewReceiverImpl(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 3, PreferredMaxBytes: preferredMaxBytes}}, filters)

// submit large message
batches, committers, ok := r.Ordered(goodTxLarge)
Expand Down
24 changes: 12 additions & 12 deletions orderer/kafka/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/Shopify/sarama"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
mockconfigvaluesorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
"github.com/hyperledger/fabric/orderer/localconfig"
mockblockcutter "github.com/hyperledger/fabric/orderer/mocks/blockcutter"
mockmultichain "github.com/hyperledger/fabric/orderer/mocks/multichain"
Expand All @@ -36,8 +36,8 @@ import (

var cp = newChainPartition(provisional.TestChainID, rawPartition)

func newMockSharedConfigManager() *mockconfigvaluesorderer.SharedConfig {
return &mockconfigvaluesorderer.SharedConfig{KafkaBrokersVal: testGenesisConf.Orderer.Kafka.Brokers}
func newMockSharedConfigManager() *mockconfig.Orderer {
return &mockconfig.Orderer{KafkaBrokersVal: testGenesisConf.Orderer.Kafka.Brokers}
}

type mockConsenterImpl struct {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestKafkaConsenterEmptyBatch(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: testTimePadding},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: testTimePadding},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -167,7 +167,7 @@ func TestKafkaConsenterBatchTimer(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -219,7 +219,7 @@ func TestKafkaConsenterTimerHaltOnFilledBatch(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -279,7 +279,7 @@ func TestKafkaConsenterConfigStyleMultiBatch(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: testTimePadding},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: testTimePadding},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -329,7 +329,7 @@ func TestKafkaConsenterTimeToCutForced(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -386,7 +386,7 @@ func TestKafkaConsenterTimeToCutDuplicate(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -475,7 +475,7 @@ func TestKafkaConsenterTimeToCutStale(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -534,7 +534,7 @@ func TestKafkaConsenterTimeToCutLarger(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down Expand Up @@ -616,7 +616,7 @@ func TestKafkaConsenterRestart(t *testing.T) {
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
ChainIDVal: provisional.TestChainID,
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(cs.BlockCutterVal.Block)

Expand Down
4 changes: 2 additions & 2 deletions orderer/mocks/multichain/multichain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package multichain

import (
"github.com/hyperledger/fabric/common/config"
mockconfigtxorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
"github.com/hyperledger/fabric/orderer/common/blockcutter"
"github.com/hyperledger/fabric/orderer/common/filter"
mockblockcutter "github.com/hyperledger/fabric/orderer/mocks/blockcutter"
Expand All @@ -34,7 +34,7 @@ var logger = logging.MustGetLogger("orderer/mocks/multichain")
// Whenever a block is written, it writes to the Batches channel to allow for synchronization
type ConsenterSupport struct {
// SharedConfigVal is the value returned by SharedConfig()
SharedConfigVal *mockconfigtxorderer.SharedConfig
SharedConfigVal *mockconfig.Orderer

// BlockCutterVal is the value returned by BlockCutter()
BlockCutterVal *mockblockcutter.Receiver
Expand Down
6 changes: 3 additions & 3 deletions orderer/multichain/systemchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/hyperledger/fabric/common/config"
"github.com/hyperledger/fabric/common/configtx"
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx"
mockconfigvaluesorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer"
"github.com/hyperledger/fabric/orderer/common/filter"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
Expand All @@ -33,12 +33,12 @@ import (
)

type mockSupport struct {
msc *mockconfigvaluesorderer.SharedConfig
msc *mockconfig.Orderer
}

func newMockSupport() *mockSupport {
return &mockSupport{
msc: &mockconfigvaluesorderer.SharedConfig{},
msc: &mockconfig.Orderer{},
}
}

Expand Down
10 changes: 5 additions & 5 deletions orderer/solo/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"
"time"

mockconfigvaluesorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
mockblockcutter "github.com/hyperledger/fabric/orderer/mocks/blockcutter"
mockmultichain "github.com/hyperledger/fabric/orderer/mocks/multichain"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestEmptyBatch(t *testing.T) {
support := &mockmultichain.ConsenterSupport{
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(support.BlockCutterVal.Block)
bs := newChain(support)
Expand All @@ -80,7 +80,7 @@ func TestBatchTimer(t *testing.T) {
support := &mockmultichain.ConsenterSupport{
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(support.BlockCutterVal.Block)
bs := newChain(support)
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestBatchTimerHaltOnFilledBatch(t *testing.T) {
support := &mockmultichain.ConsenterSupport{
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(support.BlockCutterVal.Block)

Expand Down Expand Up @@ -158,7 +158,7 @@ func TestConfigStyleMultiBatch(t *testing.T) {
support := &mockmultichain.ConsenterSupport{
Batches: make(chan []*cb.Envelope),
BlockCutterVal: mockblockcutter.NewReceiver(),
SharedConfigVal: &mockconfigvaluesorderer.SharedConfig{BatchTimeoutVal: batchTimeout},
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
}
defer close(support.BlockCutterVal.Block)
bs := newChain(support)
Expand Down

0 comments on commit 3fb58c8

Please sign in to comment.