Skip to content

Commit 119aba6

Browse files
hqinedenhill
authored andcommitted
integration tests (confluentinc#9)
* integration tests moved integration tests from example/ to kafka/ * improvements based on code review feedback * fixed Offset.Set() API bug * fixed code that caused crash in integration tests * changed CC and PC to consumerCtrl and producerCtrl for readability * integration tests moved integration tests from example/ to kafka/ improvements based on code review feedback fixed Offset.Set() API bug fixed code that caused crash in integration tests changed CC and PC to consumerCtrl and producerCtrl for readability * improvements based on code review feedback * improvements based on code review feedback * fix code formatting
1 parent 3d75ce2 commit 119aba6

11 files changed

+1029
-7
lines changed

kafka/README

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Testing
1515
=======
1616

1717

18-
Some of the tests included in this directory, the benchmark tests in particular,
18+
Some of the tests included in this directory, the benchmark and integration tests in particular,
1919
require an existing Kafka cluster and a testconf.json configuration file to
2020
provide tests with bootstrap brokers, topic name, etc.
2121

@@ -39,7 +39,10 @@ To run benchmark tests:
3939

4040
$ go test -bench .
4141

42+
For the code coverage:
4243

44+
$ go test -coverprofile=coverage.out -bench=.
45+
$ go tool cover -func=coverage.out
4346

4447

4548
Build tags (static linking)

kafka/config_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright 2016 Confluent Inc.
3+
*
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.
15+
*/
16+
17+
package kafka
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
)
23+
24+
// A custom type with Stringer interface to be used to test config map APIs
25+
type HostPortType struct {
26+
Host string
27+
Port int
28+
}
29+
30+
// implements String() interface
31+
func (hp HostPortType) String() string {
32+
return fmt.Sprintf("%s:%d", hp.Host, hp.Port)
33+
}
34+
35+
//Test config map APIs
36+
func TestConfigMapAPIs(t *testing.T) {
37+
config := &ConfigMap{}
38+
39+
// set a good key via SetKey()
40+
err := config.SetKey("bootstrap.servers", testconf.Brokers)
41+
if err != nil {
42+
t.Errorf("Failed to set key via SetKey(). Error: %s\n", err)
43+
}
44+
45+
// test custom Stringer type
46+
hostPort := HostPortType{Host: "localhost", Port: 9092}
47+
err = config.SetKey("bootstrap.servers", hostPort)
48+
if err != nil {
49+
t.Errorf("Failed to set custom Stringer type via SetKey(). Error: %s\n", err)
50+
}
51+
52+
// test boolean type
53+
err = config.SetKey("{topic}.produce.offset.report", true)
54+
if err != nil {
55+
t.Errorf("Failed to set key via SetKey(). Error: %s\n", err)
56+
}
57+
58+
// test offset literal string
59+
err = config.SetKey("{topic}.auto.offset.reset", "earliest")
60+
if err != nil {
61+
t.Errorf("Failed to set key via SetKey(). Error: %s\n", err)
62+
}
63+
64+
//test offset constant
65+
err = config.SetKey("{topic}.auto.offset.reset", OffsetBeginning)
66+
if err != nil {
67+
t.Errorf("Failed to set key via SetKey(). Error: %s\n", err)
68+
}
69+
70+
//test integer offset
71+
err = config.SetKey("{topic}.message.timeout.ms", 10)
72+
if err != nil {
73+
t.Errorf("Failed to set integer value via SetKey(). Error: %s\n", err)
74+
}
75+
76+
// set a good key-value pair via Set()
77+
err = config.Set("group.id=test.id")
78+
if err != nil {
79+
t.Errorf("Failed to set key-value pair via Set(). Error: %s\n", err)
80+
}
81+
82+
// negative test cases
83+
// set a bad key-value pair via Set()
84+
err = config.Set("group.id:test.id")
85+
if err == nil {
86+
t.Errorf("Expected failure when setting invalid key-value pair via Set()")
87+
}
88+
89+
}

kafka/event_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2016 Confluent Inc.
3+
*
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.
15+
*/
16+
17+
package kafka
18+
19+
import (
20+
"testing"
21+
)
22+
23+
// TestEventAPIs dry-tests the public event related APIs, no broker is needed.
24+
func TestEventAPIs(t *testing.T) {
25+
assignedPartitions := AssignedPartitions{}
26+
t.Logf("%s\n", assignedPartitions.String())
27+
28+
revokedPartitions := RevokedPartitions{}
29+
t.Logf("%s\n", revokedPartitions.String())
30+
31+
topic := "test"
32+
partition := PartitionEOF{Topic: &topic}
33+
t.Logf("%s\n", partition.String())
34+
35+
partition = PartitionEOF{}
36+
t.Logf("%s\n", partition.String())
37+
38+
committedOffsets := OffsetsCommitted{}
39+
t.Logf("%s\n", committedOffsets.String())
40+
}

0 commit comments

Comments
 (0)