1
1
package com .indeed .proctor .consumer ;
2
2
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
4
+ import com .fasterxml .jackson .databind .ObjectMapper ;
5
+ import com .google .common .collect .ImmutableList ;
3
6
import com .google .common .collect .ImmutableMap ;
4
7
import com .google .common .collect .ImmutableSortedMap ;
5
8
import com .google .common .collect .Ordering ;
9
+ import com .indeed .proctor .common .PayloadProperty ;
6
10
import com .indeed .proctor .common .ProctorResult ;
7
11
import com .indeed .proctor .common .model .Allocation ;
8
12
import com .indeed .proctor .common .model .ConsumableTestDefinition ;
13
+ import com .indeed .proctor .common .model .PayloadExperimentConfig ;
9
14
import com .indeed .proctor .common .model .TestBucket ;
15
+ import com .indeed .proctor .common .model .TestDefinition ;
16
+ import com .indeed .proctor .common .model .TestType ;
10
17
import com .indeed .proctor .consumer .logging .TestGroupFormatter ;
11
18
import org .assertj .core .util .Strings ;
12
19
import org .junit .Test ;
@@ -25,6 +32,8 @@ public class ProctorGroupsWriterTest {
25
32
private static final String GROUP1_TEST_NAME = "d_foo_tst" ;
26
33
private static final String SILENT_TEST_NAME = "e_silent_tst" ;
27
34
private static final String FORCED_TEST_NAME = "f_forced_tst" ;
35
+ private static final String PAYLOAD_PROPERTY_TEST_NAME = "g_payload_tst" ;
36
+ private static final String WINNING_PAYLOAD_PROPERTY_TEST_NAME = "h_winning_payload_tst" ;
28
37
29
38
// for this test, buckets can be reused between test definitions, sorting by testname
30
39
public static final TestBucket INACTIVE_BUCKET = new TestBucket ("fooname" , -1 , "foodesc" );
@@ -46,6 +55,8 @@ public class ProctorGroupsWriterTest {
46
55
.put (GROUP1_TEST_NAME , GROUP1_BUCKET )
47
56
.put (SILENT_TEST_NAME , GROUP1_BUCKET )
48
57
.put (FORCED_TEST_NAME , GROUP1_BUCKET )
58
+ .put (WINNING_PAYLOAD_PROPERTY_TEST_NAME , GROUP1_BUCKET )
59
+ .put (PAYLOAD_PROPERTY_TEST_NAME , GROUP1_BUCKET )
49
60
.build ();
50
61
private static final Map <String , Allocation > ALLOCATIONS =
51
62
new ImmutableSortedMap .Builder <String , Allocation >(Ordering .natural ())
@@ -54,19 +65,65 @@ public class ProctorGroupsWriterTest {
54
65
.put (EMPTY_ALLOCID_DEFINITION_TEST_NAME , ALLOCATION_EMPTY_ID )
55
66
.put (GROUP1_TEST_NAME , ALLOCATION_A )
56
67
.put (SILENT_TEST_NAME , ALLOCATION_A )
68
+ .put (WINNING_PAYLOAD_PROPERTY_TEST_NAME , ALLOCATION_A )
69
+ .put (PAYLOAD_PROPERTY_TEST_NAME , ALLOCATION_A )
57
70
.build ();
58
71
72
+ static final ConsumableTestDefinition PROPERTY_TD =
73
+ ConsumableTestDefinition .fromTestDefinition (
74
+ TestDefinition .builder ()
75
+ .setTestType (TestType .RANDOM )
76
+ .setSalt ("foo" )
77
+ .setForceLogging (true )
78
+ .setPayloadExperimentConfig (
79
+ PayloadExperimentConfig .builder ()
80
+ .priority ("123" )
81
+ .namespaces (ImmutableList .of ("test" ))
82
+ .build ())
83
+ .build ());
84
+ static final ConsumableTestDefinition WINNING_PROPERTY_TD =
85
+ ConsumableTestDefinition .fromTestDefinition (
86
+ TestDefinition .builder ()
87
+ .setTestType (TestType .RANDOM )
88
+ .setSalt ("foo" )
89
+ .setForceLogging (true )
90
+ .setPayloadExperimentConfig (
91
+ PayloadExperimentConfig .builder ()
92
+ .priority ("20000" )
93
+ .namespaces (ImmutableList .of ("test" ))
94
+ .build ())
95
+ .build ());
96
+
59
97
private static final Map <String , ConsumableTestDefinition > DEFINITIONS =
60
98
ImmutableMap .<String , ConsumableTestDefinition >builder ()
61
99
.put (INACTIVE_TEST_NAME , stubDefinition (INACTIVE_BUCKET ))
62
100
.put (EMPTY_ALLOCID_DEFINITION_TEST_NAME , stubDefinition (GROUP1_BUCKET ))
63
101
.put (GROUP1_TEST_NAME , stubDefinition (GROUP1_BUCKET ))
64
102
.put (SILENT_TEST_NAME , stubDefinition (GROUP1_BUCKET , d -> d .setSilent (true )))
65
103
.put (FORCED_TEST_NAME , stubDefinition (GROUP1_BUCKET ))
104
+ .put (WINNING_PAYLOAD_PROPERTY_TEST_NAME , WINNING_PROPERTY_TD )
105
+ .put (PAYLOAD_PROPERTY_TEST_NAME , PROPERTY_TD )
66
106
.build ();
107
+ private static final Map <String , PayloadProperty > PROPERTIES ;
108
+
109
+ static {
110
+ try {
111
+ PROPERTIES =
112
+ ImmutableMap .<String , PayloadProperty >builder ()
113
+ .put (
114
+ "foo" ,
115
+ PayloadProperty .builder ()
116
+ .value (new ObjectMapper ().readTree ("1" ))
117
+ .testName (WINNING_PAYLOAD_PROPERTY_TEST_NAME )
118
+ .build ())
119
+ .build ();
120
+ } catch (final JsonProcessingException e ) {
121
+ throw new RuntimeException (e );
122
+ }
123
+ }
67
124
68
125
private static final ProctorResult PROCTOR_RESULT =
69
- new ProctorResult (null , BUCKETS , ALLOCATIONS , DEFINITIONS );
126
+ new ProctorResult (null , BUCKETS , ALLOCATIONS , DEFINITIONS , PROPERTIES );
70
127
71
128
@ Test
72
129
public void testWithEmptyResult () {
@@ -86,7 +143,7 @@ public void testWithEmptyResult() {
86
143
public void testDoubleFormattingWriter () {
87
144
// legacy Indeed behavior
88
145
final String expected =
89
- "b_missing_definition0,c_empty_alloc_id0,d_foo_tst1,f_forced_tst1,#A:b_missing_definition0,#A:d_foo_tst1,f_forced_tst1" ;
146
+ "b_missing_definition0,c_empty_alloc_id0,d_foo_tst1,f_forced_tst1,h_winning_payload_tst1, #A:b_missing_definition0,#A:d_foo_tst1,f_forced_tst1,#A:h_winning_payload_tst1 " ;
90
147
91
148
final ProctorGroupsWriter defaultWriter =
92
149
new ProctorGroupsWriter .Builder (
@@ -101,9 +158,11 @@ public void testDoubleFormattingWriter() {
101
158
EMPTY_ALLOCID_DEFINITION_TEST_NAME + 0 ,
102
159
GROUP1_TEST_NAME + 1 ,
103
160
FORCED_TEST_NAME + 1 ,
161
+ WINNING_PAYLOAD_PROPERTY_TEST_NAME + 1 ,
104
162
"#A:" + MISSING_DEFINITION_TEST_NAME + 0 ,
105
163
"#A:" + GROUP1_TEST_NAME + 1 ,
106
- FORCED_TEST_NAME + 1 )
164
+ FORCED_TEST_NAME + 1 ,
165
+ "#A:" + WINNING_PAYLOAD_PROPERTY_TEST_NAME + 1 )
107
166
.with ("," ));
108
167
}
109
168
@@ -116,15 +175,17 @@ public void testCustomWriter() {
116
175
.setIncludeInactiveGroups (true )
117
176
.build ();
118
177
assertThat (writerWithAllocIds .writeGroupsAsString (PROCTOR_RESULT ))
119
- .isEqualTo ("#A:a_inactive_tst-1,#A:d_foo_tst1,#A:e_silent_tst1,f_forced_tst1" );
178
+ .isEqualTo (
179
+ "#A:a_inactive_tst-1,#A:d_foo_tst1,#A:e_silent_tst1,f_forced_tst1,#A:h_winning_payload_tst1" );
120
180
121
181
final ProctorGroupsWriter writerWithoutAllocIds =
122
182
new ProctorGroupsWriter .Builder (TestGroupFormatter .WITHOUT_ALLOC_ID )
123
183
.setIncludeSilentTests (true )
124
184
.setIncludeTestWithoutDefinition (false )
125
185
.build ();
126
186
assertThat (writerWithoutAllocIds .writeGroupsAsString (PROCTOR_RESULT ))
127
- .isEqualTo ("c_empty_alloc_id0,d_foo_tst1,e_silent_tst1,f_forced_tst1" );
187
+ .isEqualTo (
188
+ "c_empty_alloc_id0,d_foo_tst1,e_silent_tst1,f_forced_tst1,h_winning_payload_tst1" );
128
189
}
129
190
130
191
@ Test
0 commit comments