blob: d3958fe9a294f67522ee69fcb9689e14d9750433 [file] [log] [blame]
Jian Li52c11222018-06-07 11:39:17 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.openstacktelemetry.config;
17
18import com.google.common.collect.ImmutableMap;
19import com.google.common.testing.EqualsTester;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.openstacktelemetry.api.config.KafkaTelemetryConfig;
23
24import java.util.Map;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
Jian Liae3fcff2018-07-30 11:55:44 +090028import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Jian Li52c11222018-06-07 11:39:17 +090029
Jian Li3db90852018-06-10 22:29:16 +090030public final class DefaultKafkaTelemetryConfigTest {
Jian Li52c11222018-06-07 11:39:17 +090031
32 private static final String IP_ADDRESS_1 = "10.10.10.1";
33 private static final String IP_ADDRESS_2 = "20.20.20.1";
34
35 private static final int PORT_1 = 80;
36 private static final int PORT_2 = 8080;
37
38 private static final int RETRIES_1 = 1;
39 private static final int RETRIES_2 = 2;
40
41 private static final int BATCH_SIZE_1 = 100;
42 private static final int BATCH_SIZE_2 = 200;
43
44 private static final int MEMORY_BUFFER_1 = 1000;
45 private static final int MEMORY_BUFFER_2 = 2000;
46
47 private static final String REQUIRED_ACKS_1 = "all";
48 private static final String REQUIRED_ACKS_2 = "none";
49
50 private static final int LINGER_MS_1 = 1;
51 private static final int LINGER_MS_2 = 2;
52
53 private static final String KEY_SERIALIZER_1 = "keyserializer1";
54 private static final String KEY_SERIALIZER_2 = "keyserializer2";
55 private static final String VALUE_SERIALIZER_1 = "valueserializer1";
56 private static final String VALUE_SERIALIZER_2 = "valueserializer2";
57
58 private static final Map<String, Object> CONFIG_MAP_1 =
59 ImmutableMap.of("key1", "value1");
60 private static final Map<String, Object> CONFIG_MAP_2 =
61 ImmutableMap.of("key2", "value2");
62
63 private KafkaTelemetryConfig config1;
64 private KafkaTelemetryConfig sameAsConfig1;
65 private KafkaTelemetryConfig config2;
66
Jian Liae3fcff2018-07-30 11:55:44 +090067 /**
68 * Initial setup for this unit test.
69 */
Jian Li52c11222018-06-07 11:39:17 +090070 @Before
71 public void setup() {
72
73 KafkaTelemetryConfig.Builder builder1 =
74 new DefaultKafkaTelemetryConfig.DefaultBuilder();
75 KafkaTelemetryConfig.Builder builder2 =
76 new DefaultKafkaTelemetryConfig.DefaultBuilder();
77 KafkaTelemetryConfig.Builder builder3 =
78 new DefaultKafkaTelemetryConfig.DefaultBuilder();
79
80 config1 = builder1
81 .withAddress(IP_ADDRESS_1)
82 .withPort(PORT_1)
83 .withRetries(RETRIES_1)
84 .withBatchSize(BATCH_SIZE_1)
85 .withMemoryBuffer(MEMORY_BUFFER_1)
86 .withRequiredAcks(REQUIRED_ACKS_1)
87 .withLingerMs(LINGER_MS_1)
88 .withKeySerializer(KEY_SERIALIZER_1)
89 .withValueSerializer(VALUE_SERIALIZER_1)
90 .withConfigMap(CONFIG_MAP_1)
91 .build();
92
93 sameAsConfig1 = builder2
94 .withAddress(IP_ADDRESS_1)
95 .withPort(PORT_1)
96 .withRetries(RETRIES_1)
97 .withBatchSize(BATCH_SIZE_1)
98 .withMemoryBuffer(MEMORY_BUFFER_1)
99 .withRequiredAcks(REQUIRED_ACKS_1)
100 .withLingerMs(LINGER_MS_1)
101 .withKeySerializer(KEY_SERIALIZER_1)
102 .withValueSerializer(VALUE_SERIALIZER_1)
103 .withConfigMap(CONFIG_MAP_1)
104 .build();
105
106 config2 = builder3
107 .withAddress(IP_ADDRESS_2)
108 .withPort(PORT_2)
109 .withRetries(RETRIES_2)
110 .withBatchSize(BATCH_SIZE_2)
111 .withMemoryBuffer(MEMORY_BUFFER_2)
112 .withRequiredAcks(REQUIRED_ACKS_2)
113 .withLingerMs(LINGER_MS_2)
114 .withKeySerializer(KEY_SERIALIZER_2)
115 .withValueSerializer(VALUE_SERIALIZER_2)
116 .withConfigMap(CONFIG_MAP_2)
117 .build();
118 }
119
Jian Liae3fcff2018-07-30 11:55:44 +0900120 /**
121 * Tests class immutability.
122 */
123 @Test
124 public void testImmutability() {
125 assertThatClassIsImmutable(DefaultKafkaTelemetryConfig.class);
126 }
127
128 /**
129 * Tests object equality.
130 */
Jian Li52c11222018-06-07 11:39:17 +0900131 @Test
132 public void testEquality() {
133 new EqualsTester()
134 .addEqualityGroup(config1, sameAsConfig1)
135 .addEqualityGroup(config2).testEquals();
136 }
137
Jian Liae3fcff2018-07-30 11:55:44 +0900138 /**
139 * Tests object construction.
140 */
Jian Li52c11222018-06-07 11:39:17 +0900141 @Test
142 public void testConstruction() {
143 KafkaTelemetryConfig config = config1;
144
145 assertThat(config.address(), is(IP_ADDRESS_1));
146 assertThat(config.port(), is(PORT_1));
147 assertThat(config.retries(), is(RETRIES_1));
148 assertThat(config.batchSize(), is(BATCH_SIZE_1));
149 assertThat(config.memoryBuffer(), is(MEMORY_BUFFER_1));
150 assertThat(config.requiredAcks(), is(REQUIRED_ACKS_1));
151 assertThat(config.lingerMs(), is(LINGER_MS_1));
152 assertThat(config.keySerializer(), is(KEY_SERIALIZER_1));
153 assertThat(config.valueSerializer(), is(VALUE_SERIALIZER_1));
154 assertThat(config.configMap(), is(CONFIG_MAP_1));
155 }
156}