github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/orderer/kafka/partitioner_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package kafka
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/Shopify/sarama"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestStaticPartitioner(t *testing.T) {
    17  	var partition int32 = 3
    18  	var numberOfPartitions int32 = 6
    19  
    20  	partitionerConstructor := newStaticPartitioner(partition)
    21  	partitioner := partitionerConstructor(channelNameForTest(t))
    22  
    23  	for i := 0; i < 10; i++ {
    24  		assignedPartition, err := partitioner.Partition(new(sarama.ProducerMessage), numberOfPartitions)
    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)
    27  	}
    28  }