blob: 6608d7a10c3dd21c30f9fce78d7a863ded4ca467 [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;
28
Jian Li3db90852018-06-10 22:29:16 +090029public final class DefaultKafkaTelemetryConfigTest {
Jian Li52c11222018-06-07 11:39:17 +090030
31 private static final String IP_ADDRESS_1 = "10.10.10.1";
32 private static final String IP_ADDRESS_2 = "20.20.20.1";
33
34 private static final int PORT_1 = 80;
35 private static final int PORT_2 = 8080;
36
37 private static final int RETRIES_1 = 1;
38 private static final int RETRIES_2 = 2;
39
40 private static final int BATCH_SIZE_1 = 100;
41 private static final int BATCH_SIZE_2 = 200;
42
43 private static final int MEMORY_BUFFER_1 = 1000;
44 private static final int MEMORY_BUFFER_2 = 2000;
45
46 private static final String REQUIRED_ACKS_1 = "all";
47 private static final String REQUIRED_ACKS_2 = "none";
48
49 private static final int LINGER_MS_1 = 1;
50 private static final int LINGER_MS_2 = 2;
51
52 private static final String KEY_SERIALIZER_1 = "keyserializer1";
53 private static final String KEY_SERIALIZER_2 = "keyserializer2";
54 private static final String VALUE_SERIALIZER_1 = "valueserializer1";
55 private static final String VALUE_SERIALIZER_2 = "valueserializer2";
56
57 private static final Map<String, Object> CONFIG_MAP_1 =
58 ImmutableMap.of("key1", "value1");
59 private static final Map<String, Object> CONFIG_MAP_2 =
60 ImmutableMap.of("key2", "value2");
61
62 private KafkaTelemetryConfig config1;
63 private KafkaTelemetryConfig sameAsConfig1;
64 private KafkaTelemetryConfig config2;
65
66 @Before
67 public void setup() {
68
69 KafkaTelemetryConfig.Builder builder1 =
70 new DefaultKafkaTelemetryConfig.DefaultBuilder();
71 KafkaTelemetryConfig.Builder builder2 =
72 new DefaultKafkaTelemetryConfig.DefaultBuilder();
73 KafkaTelemetryConfig.Builder builder3 =
74 new DefaultKafkaTelemetryConfig.DefaultBuilder();
75
76 config1 = builder1
77 .withAddress(IP_ADDRESS_1)
78 .withPort(PORT_1)
79 .withRetries(RETRIES_1)
80 .withBatchSize(BATCH_SIZE_1)
81 .withMemoryBuffer(MEMORY_BUFFER_1)
82 .withRequiredAcks(REQUIRED_ACKS_1)
83 .withLingerMs(LINGER_MS_1)
84 .withKeySerializer(KEY_SERIALIZER_1)
85 .withValueSerializer(VALUE_SERIALIZER_1)
86 .withConfigMap(CONFIG_MAP_1)
87 .build();
88
89 sameAsConfig1 = builder2
90 .withAddress(IP_ADDRESS_1)
91 .withPort(PORT_1)
92 .withRetries(RETRIES_1)
93 .withBatchSize(BATCH_SIZE_1)
94 .withMemoryBuffer(MEMORY_BUFFER_1)
95 .withRequiredAcks(REQUIRED_ACKS_1)
96 .withLingerMs(LINGER_MS_1)
97 .withKeySerializer(KEY_SERIALIZER_1)
98 .withValueSerializer(VALUE_SERIALIZER_1)
99 .withConfigMap(CONFIG_MAP_1)
100 .build();
101
102 config2 = builder3
103 .withAddress(IP_ADDRESS_2)
104 .withPort(PORT_2)
105 .withRetries(RETRIES_2)
106 .withBatchSize(BATCH_SIZE_2)
107 .withMemoryBuffer(MEMORY_BUFFER_2)
108 .withRequiredAcks(REQUIRED_ACKS_2)
109 .withLingerMs(LINGER_MS_2)
110 .withKeySerializer(KEY_SERIALIZER_2)
111 .withValueSerializer(VALUE_SERIALIZER_2)
112 .withConfigMap(CONFIG_MAP_2)
113 .build();
114 }
115
116 @Test
117 public void testEquality() {
118 new EqualsTester()
119 .addEqualityGroup(config1, sameAsConfig1)
120 .addEqualityGroup(config2).testEquals();
121 }
122
123 @Test
124 public void testConstruction() {
125 KafkaTelemetryConfig config = config1;
126
127 assertThat(config.address(), is(IP_ADDRESS_1));
128 assertThat(config.port(), is(PORT_1));
129 assertThat(config.retries(), is(RETRIES_1));
130 assertThat(config.batchSize(), is(BATCH_SIZE_1));
131 assertThat(config.memoryBuffer(), is(MEMORY_BUFFER_1));
132 assertThat(config.requiredAcks(), is(REQUIRED_ACKS_1));
133 assertThat(config.lingerMs(), is(LINGER_MS_1));
134 assertThat(config.keySerializer(), is(KEY_SERIALIZER_1));
135 assertThat(config.valueSerializer(), is(VALUE_SERIALIZER_1));
136 assertThat(config.configMap(), is(CONFIG_MAP_1));
137 }
138}