github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/subscriber/common/message/message_decoder_test.go (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package message
    16  
    17  import (
    18  	. "github.com/onsi/ginkgo"
    19  	. "github.com/onsi/gomega"
    20  	"github.com/uber-go/tally"
    21  	"github.com/uber/aresdb/client"
    22  	"github.com/uber/aresdb/subscriber/common/rules"
    23  	"github.com/uber/aresdb/subscriber/common/tools"
    24  	"github.com/uber/aresdb/subscriber/config"
    25  	"github.com/uber/aresdb/utils"
    26  	"go.uber.org/zap"
    27  	"os"
    28  )
    29  
    30  var _ = Describe("message decoder tests", func() {
    31  
    32  	It("StringMessage tests", func() {
    33  		msg := &StringMessage{
    34  			"topic",
    35  			"message",
    36  		}
    37  
    38  		Ω(string(msg.Key())).Should(Equal(""))
    39  		Ω(string(msg.Value())).Should(Equal("message"))
    40  		Ω(msg.Topic()).Should(Equal("topic"))
    41  		Ω(msg.Partition()).Should(Equal(int32(0)))
    42  		Ω(msg.Offset()).Should(Equal(int64(0)))
    43  		msg.Ack()
    44  		msg.Nack()
    45  	})
    46  
    47  	It("NewDefaultDecoder", func() {
    48  		serviceConfig := config.ServiceConfig{
    49  			Environment: utils.EnvironmentContext{
    50  				Deployment:         "test",
    51  				RuntimeEnvironment: "test",
    52  				Zone:               "local",
    53  			},
    54  			Logger: zap.NewNop(),
    55  			Scope:  tally.NoopScope,
    56  		}
    57  		serviceConfig.ActiveJobs = []string{"job1"}
    58  		sinkConfig := config.SinkConfig{
    59  			SinkModeStr:           "aresDB",
    60  			AresDBConnectorConfig: client.ConnectorConfig{Address: "localhost:8888"},
    61  		}
    62  		serviceConfig.ActiveAresClusters = map[string]config.SinkConfig{
    63  			"dev01": sinkConfig,
    64  		}
    65  
    66  		rootPath := tools.GetModulePath("")
    67  		os.Chdir(rootPath)
    68  		jobConfigs := make(rules.JobConfigs)
    69  		err := rules.AddLocalJobConfig(serviceConfig, jobConfigs)
    70  		if err != nil {
    71  			panic("Failed to AddLocalJobConfig")
    72  		}
    73  		if jobConfigs["job1"]["dev01"] == nil {
    74  			panic("Failed to get (jobConfigs[\"job1\"][\"dev01\"]")
    75  		} else {
    76  			jobConfigs["job1"]["dev01"].AresTableConfig.Cluster = "dev01"
    77  		}
    78  
    79  		decoder, err := NewDefaultDecoder(jobConfigs["job1"]["dev01"], serviceConfig)
    80  		Ω(decoder).ShouldNot(BeNil())
    81  		Ω(err).Should(BeNil())
    82  	})
    83  
    84  })