Skip to content

Commit f3eabe9

Browse files
committed
[FAB-4336] Switch partition UTs to the assert pkg
Change-Id: I6bd7228a0541d1272eb5c4665bf059b9ac3d8cde Signed-off-by: Kostas Christidis <[email protected]>
1 parent 56d06f7 commit f3eabe9

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

orderer/kafka/partitioner.go

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package kafka
188

199
import "github.com/Shopify/sarama"
2010

11+
type staticPartitioner struct {
12+
partitionID int32
13+
}
14+
2115
// newStaticPartitioner returns a PartitionerConstructor that
2216
// returns a Partitioner that always chooses the specified partition.
2317
func newStaticPartitioner(partition int32) sarama.PartitionerConstructor {
@@ -26,17 +20,13 @@ func newStaticPartitioner(partition int32) sarama.PartitionerConstructor {
2620
}
2721
}
2822

29-
type staticPartitioner struct {
30-
partitionID int32
31-
}
32-
3323
// Partition takes a message and partition count and chooses a partition.
34-
func (p *staticPartitioner) Partition(message *sarama.ProducerMessage, numPartitions int32) (int32, error) {
35-
return p.partitionID, nil
24+
func (prt *staticPartitioner) Partition(message *sarama.ProducerMessage, numPartitions int32) (int32, error) {
25+
return prt.partitionID, nil
3626
}
3727

38-
// RequiresConsistency indicates to the user of the partitioner
39-
// whether the mapping of key->partition is consistent or not.
40-
func (p *staticPartitioner) RequiresConsistency() bool {
28+
// RequiresConsistency indicates to the user of the partitioner whether the
29+
// mapping of key->partition is consistent or not.
30+
func (prt *staticPartitioner) RequiresConsistency() bool {
4131
return true
4232
}

orderer/kafka/partitioner_test.go

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package kafka
@@ -20,23 +10,19 @@ import (
2010
"testing"
2111

2212
"github.com/Shopify/sarama"
23-
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
13+
"github.com/stretchr/testify/assert"
2414
)
2515

2616
func TestStaticPartitioner(t *testing.T) {
2717
var partition int32 = 3
2818
var numberOfPartitions int32 = 6
2919

3020
partitionerConstructor := newStaticPartitioner(partition)
31-
partitioner := partitionerConstructor(provisional.TestChainID)
21+
partitioner := partitionerConstructor("channelFoo")
3222

3323
for i := 0; i < 10; i++ {
3424
assignedPartition, err := partitioner.Partition(new(sarama.ProducerMessage), numberOfPartitions)
35-
if err != nil {
36-
t.Fatal("Partitioner not functioning as expected:", err)
37-
}
38-
if assignedPartition != partition {
39-
t.Fatalf("Partitioner not returning the expected partition - expected %d, got %v", partition, assignedPartition)
40-
}
25+
assert.NoError(t, err, "Partitioner not functioning as expected:", err)
26+
assert.Equal(t, partition, assignedPartition, "Partitioner not returning the expected partition - expected %d, got %v", partition, assignedPartition)
4127
}
4228
}

0 commit comments

Comments
 (0)