blob: 05336e0416b445f428e96808e18f11a3a27a8917 (
plain) (
blame)
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc.messagebus;
import com.yahoo.container.jdisc.messagebus.SessionCache.DynamicThrottlePolicySignature;
import com.yahoo.container.jdisc.messagebus.SessionCache.SourceSessionKey;
import com.yahoo.container.jdisc.messagebus.SessionCache.StaticThrottlePolicySignature;
import com.yahoo.container.jdisc.messagebus.SessionCache.UnknownThrottlePolicySignature;
import com.yahoo.messagebus.DynamicThrottlePolicy;
import com.yahoo.messagebus.SourceSessionParams;
import com.yahoo.messagebus.StaticThrottlePolicy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Check the completeness of the mbus session key classes.
*
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
*/
public class MbusSessionKeyTestCase {
@Test
public final void staticThrottlePolicySignature() {
final StaticThrottlePolicy base = new StaticThrottlePolicy();
final StaticThrottlePolicy other = new StaticThrottlePolicy();
other.setMaxPendingCount(500);
other.setMaxPendingSize(500 * 1000 * 1000);
base.setMaxPendingCount(1);
base.setMaxPendingSize(1000);
final StaticThrottlePolicySignature sigBase = new StaticThrottlePolicySignature(
base);
final StaticThrottlePolicySignature sigOther = new StaticThrottlePolicySignature(
other);
assertFalse("The policies are different, but signatures are equal.",
sigBase.equals(sigOther));
assertTrue("Sigs created from same policy evaluated as different.",
sigBase.equals(new StaticThrottlePolicySignature(base)));
other.setMaxPendingCount(1);
other.setMaxPendingSize(1000);
assertTrue(
"Sigs created from different policies with same settings evaluated as different.",
sigBase.equals(new StaticThrottlePolicySignature(other)));
}
@Test
public final void dynamicThrottlePolicySignature() {
final DynamicThrottlePolicy base = new DynamicThrottlePolicy();
final DynamicThrottlePolicy other = new DynamicThrottlePolicy();
base.setEfficiencyThreshold(5);
base.setMaxPendingCount(3);
base.setMaxPendingSize(3 * 100);
base.setMaxThroughput(1e6);
base.setMaxWindowSize(1e9);
base.setMinWindowSize(1e5);
base.setWeight(1.0);
base.setWindowSizeBackOff(.6);
base.setWindowSizeIncrement(500);
other.setEfficiencyThreshold(5 + 1);
other.setMaxPendingCount(3 + 1);
other.setMaxPendingSize(3 * 100 + 1);
other.setMaxThroughput(1e6 + 1);
other.setMaxWindowSize(1e9 + 1);
other.setMinWindowSize(1e5 + 1);
other.setWeight(1.0 + 1);
other.setWindowSizeBackOff(.6 + 1);
other.setWindowSizeIncrement(500 + 1);
final DynamicThrottlePolicySignature sigBase = new DynamicThrottlePolicySignature(
base);
final DynamicThrottlePolicySignature sigOther = new DynamicThrottlePolicySignature(
other);
assertFalse("The policies are different, but signatures are equal.",
sigBase.equals(sigOther));
assertTrue("Sigs created from same policy evaluated as different.",
sigBase.equals(new DynamicThrottlePolicySignature(base)));
other.setEfficiencyThreshold(5);
other.setMaxPendingCount(3);
other.setMaxPendingSize(3 * 100);
other.setMaxThroughput(1e6);
other.setMaxWindowSize(1e9);
other.setMinWindowSize(1e5);
other.setWeight(1.0);
other.setWindowSizeBackOff(.6);
other.setWindowSizeIncrement(500);
assertTrue(
"Sigs created from different policies with same settings evaluated as different.",
sigBase.equals(new DynamicThrottlePolicySignature(other)));
}
@Test
public final void unknownThrottlePolicySignature() {
final UnknownThrottlePolicySignature baseSig = new UnknownThrottlePolicySignature(
new StaticThrottlePolicy());
final UnknownThrottlePolicySignature otherSig = new UnknownThrottlePolicySignature(
new StaticThrottlePolicy());
assertEquals(baseSig, baseSig);
assertFalse(otherSig.equals(baseSig));
}
// TODO the session key tests are just smoke tests
@Test
public final void sourceSessionKey() {
final SourceSessionParams base = new SourceSessionParams();
final SourceSessionParams other = new SourceSessionParams();
assertEquals(new SourceSessionKey(base), new SourceSessionKey(other));
other.setTimeout(other.getTimeout() + 1);
assertFalse(new SourceSessionKey(base).equals(new SourceSessionKey(
other)));
}
}
|