/
DefaultAmqp10ConfigTest.java
142 lines (126 loc) · 7.3 KB
/
DefaultAmqp10ConfigTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.connectivity.service.config;
import static org.mutabilitydetector.unittesting.AllowedReason.assumingFields;
import static org.mutabilitydetector.unittesting.AllowedReason.provided;
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;
import java.time.Duration;
import java.util.Map;
import org.assertj.core.api.JUnitSoftAssertions;
import org.eclipse.ditto.base.service.config.ThrottlingConfig;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import nl.jqno.equalsverifier.EqualsVerifier;
/**
* Unit test for {@link org.eclipse.ditto.connectivity.service.config.DefaultAmqp10Config}.
*/
public final class DefaultAmqp10ConfigTest {
private static Config amqp10TestConf;
@Rule
public final JUnitSoftAssertions softly = new JUnitSoftAssertions();
@BeforeClass
public static void initTestFixture() {
amqp10TestConf = ConfigFactory.load("amqp10-test");
}
@Test
public void assertImmutability() {
assertInstancesOf(DefaultAmqp10Config.class,
areImmutable(),
provided(BackOffConfig.class, ThrottlingConfig.class).isAlsoImmutable(),
assumingFields("hmacAlgorithms").areSafelyCopiedUnmodifiableCollectionsWithImmutableElements());
}
@Test
public void testHashCodeAndEquals() {
EqualsVerifier.forClass(DefaultAmqp10Config.class)
.usingGetClass()
.verify();
}
@Test
public void underTestReturnsDefaultValuesIfBaseConfigWasEmpty() {
final DefaultAmqp10Config underTest = DefaultAmqp10Config.of(ConfigFactory.empty());
softly.assertThat(underTest.isConsumerRateLimitEnabled())
.as(Amqp10Config.Amqp10ConfigValue.CONSUMER_RATE_LIMIT_ENABLED.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.CONSUMER_RATE_LIMIT_ENABLED.getDefaultValue());
softly.assertThat(underTest.getConsumerMaxInFlight())
.as(Amqp10Config.Amqp10ConfigValue.CONSUMER_MAX_IN_FLIGHT.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.CONSUMER_MAX_IN_FLIGHT.getDefaultValue());
softly.assertThat(underTest.getConsumerRedeliveryExpectationTimeout())
.as(Amqp10Config.Amqp10ConfigValue.CONSUMER_REDELIVERY_EXPECTATION_TIMEOUT.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.CONSUMER_REDELIVERY_EXPECTATION_TIMEOUT.getDefaultValue());
softly.assertThat(underTest.getProducerCacheSize())
.as(Amqp10Config.Amqp10ConfigValue.PRODUCER_CACHE_SIZE.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.PRODUCER_CACHE_SIZE.getDefaultValue());
softly.assertThat(underTest.getMaxQueueSize())
.as(Amqp10Config.Amqp10ConfigValue.MAX_QUEUE_SIZE.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.MAX_QUEUE_SIZE.getDefaultValue());
softly.assertThat(underTest.getPublisherParallelism())
.as(Amqp10Config.Amqp10ConfigValue.MESSAGE_PUBLISHING_PARALLELISM.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.MESSAGE_PUBLISHING_PARALLELISM.getDefaultValue());
softly.assertThat(underTest.getGlobalConnectTimeout())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_CONNECT_TIMEOUT.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.GLOBAL_CONNECT_TIMEOUT.getDefaultValue());
softly.assertThat(underTest.getGlobalSendTimeout())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_SEND_TIMEOUT.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.GLOBAL_SEND_TIMEOUT.getDefaultValue());
softly.assertThat(underTest.getGlobalRequestTimeout())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_REQUEST_TIMEOUT.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.GLOBAL_REQUEST_TIMEOUT.getDefaultValue());
softly.assertThat(underTest.getGlobalPrefetchPolicyAllCount())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_PREFETCH_POLICY_ALL_COUNT.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.GLOBAL_PREFETCH_POLICY_ALL_COUNT.getDefaultValue());
softly.assertThat(underTest.getHmacAlgorithms())
.as(Amqp10Config.Amqp10ConfigValue.HMAC_ALGORITHMS.getConfigPath())
.isEqualTo(Amqp10Config.Amqp10ConfigValue.HMAC_ALGORITHMS.getDefaultValue());
}
@Test
public void underTestReturnsValuesOfConfigFile() {
final DefaultAmqp10Config underTest = DefaultAmqp10Config.of(amqp10TestConf);
softly.assertThat(underTest.isConsumerRateLimitEnabled())
.as(Amqp10Config.Amqp10ConfigValue.CONSUMER_RATE_LIMIT_ENABLED.getConfigPath())
.isEqualTo(false);
softly.assertThat(underTest.getConsumerMaxInFlight())
.as(Amqp10Config.Amqp10ConfigValue.CONSUMER_MAX_IN_FLIGHT.getConfigPath())
.isEqualTo(1337);
softly.assertThat(underTest.getConsumerRedeliveryExpectationTimeout())
.as(Amqp10Config.Amqp10ConfigValue.CONSUMER_REDELIVERY_EXPECTATION_TIMEOUT.getConfigPath())
.isEqualTo(Duration.ofSeconds(1337));
softly.assertThat(underTest.getProducerCacheSize())
.as(Amqp10Config.Amqp10ConfigValue.PRODUCER_CACHE_SIZE.getConfigPath())
.isEqualTo(11);
softly.assertThat(underTest.getMaxQueueSize())
.as(Amqp10Config.Amqp10ConfigValue.MAX_QUEUE_SIZE.getConfigPath())
.isEqualTo(39);
softly.assertThat(underTest.getPublisherParallelism())
.as(Amqp10Config.Amqp10ConfigValue.MESSAGE_PUBLISHING_PARALLELISM.getConfigPath())
.isEqualTo(3);
softly.assertThat(underTest.getGlobalConnectTimeout())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_CONNECT_TIMEOUT.getConfigPath())
.isEqualTo(Duration.ofSeconds(11));
softly.assertThat(underTest.getGlobalSendTimeout())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_SEND_TIMEOUT.getConfigPath())
.isEqualTo(Duration.ofSeconds(22));
softly.assertThat(underTest.getGlobalRequestTimeout())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_REQUEST_TIMEOUT.getConfigPath())
.isEqualTo(Duration.ofSeconds(33));
softly.assertThat(underTest.getGlobalPrefetchPolicyAllCount())
.as(Amqp10Config.Amqp10ConfigValue.GLOBAL_PREFETCH_POLICY_ALL_COUNT.getConfigPath())
.isEqualTo(44);
softly.assertThat(underTest.getHmacAlgorithms())
.as(Amqp10Config.Amqp10ConfigValue.HMAC_ALGORITHMS.getConfigPath())
.isEqualTo(Map.of("algorithm1", "factory1", "algorithm2", "factory2"));
}
}