Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 6f573e2

Browse files
PROC-1525: Add unit tests for groups writer
1 parent c566c00 commit 6f573e2

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

proctor-consumer/src/main/java/com/indeed/proctor/consumer/ProctorGroupsWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public ProctorGroupsWriter build() {
212212
// Do not log payload experiments which were overwritten
213213
if (consumableTestDefinition != null
214214
&& consumableTestDefinition.getPayloadExperimentConfig() != null
215-
&& proctorResult.getProperties().values().stream()
215+
&& !proctorResult.getProperties().values().stream()
216216
.map(PayloadProperty::getTestName)
217217
.collect(Collectors.toSet())
218218
.contains(testName)) {

proctor-consumer/src/test/java/com/indeed/proctor/consumer/ProctorGroupsWriterTest.java

+66-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package com.indeed.proctor.consumer;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.google.common.collect.ImmutableList;
36
import com.google.common.collect.ImmutableMap;
47
import com.google.common.collect.ImmutableSortedMap;
58
import com.google.common.collect.Ordering;
9+
import com.indeed.proctor.common.PayloadProperty;
610
import com.indeed.proctor.common.ProctorResult;
711
import com.indeed.proctor.common.model.Allocation;
812
import com.indeed.proctor.common.model.ConsumableTestDefinition;
13+
import com.indeed.proctor.common.model.PayloadExperimentConfig;
914
import com.indeed.proctor.common.model.TestBucket;
15+
import com.indeed.proctor.common.model.TestDefinition;
16+
import com.indeed.proctor.common.model.TestType;
1017
import com.indeed.proctor.consumer.logging.TestGroupFormatter;
1118
import org.assertj.core.util.Strings;
1219
import org.junit.Test;
@@ -25,6 +32,8 @@ public class ProctorGroupsWriterTest {
2532
private static final String GROUP1_TEST_NAME = "d_foo_tst";
2633
private static final String SILENT_TEST_NAME = "e_silent_tst";
2734
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";
2837

2938
// for this test, buckets can be reused between test definitions, sorting by testname
3039
public static final TestBucket INACTIVE_BUCKET = new TestBucket("fooname", -1, "foodesc");
@@ -46,6 +55,8 @@ public class ProctorGroupsWriterTest {
4655
.put(GROUP1_TEST_NAME, GROUP1_BUCKET)
4756
.put(SILENT_TEST_NAME, GROUP1_BUCKET)
4857
.put(FORCED_TEST_NAME, GROUP1_BUCKET)
58+
.put(WINNING_PAYLOAD_PROPERTY_TEST_NAME, GROUP1_BUCKET)
59+
.put(PAYLOAD_PROPERTY_TEST_NAME, GROUP1_BUCKET)
4960
.build();
5061
private static final Map<String, Allocation> ALLOCATIONS =
5162
new ImmutableSortedMap.Builder<String, Allocation>(Ordering.natural())
@@ -54,19 +65,65 @@ public class ProctorGroupsWriterTest {
5465
.put(EMPTY_ALLOCID_DEFINITION_TEST_NAME, ALLOCATION_EMPTY_ID)
5566
.put(GROUP1_TEST_NAME, ALLOCATION_A)
5667
.put(SILENT_TEST_NAME, ALLOCATION_A)
68+
.put(WINNING_PAYLOAD_PROPERTY_TEST_NAME, ALLOCATION_A)
69+
.put(PAYLOAD_PROPERTY_TEST_NAME, ALLOCATION_A)
5770
.build();
5871

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+
5997
private static final Map<String, ConsumableTestDefinition> DEFINITIONS =
6098
ImmutableMap.<String, ConsumableTestDefinition>builder()
6199
.put(INACTIVE_TEST_NAME, stubDefinition(INACTIVE_BUCKET))
62100
.put(EMPTY_ALLOCID_DEFINITION_TEST_NAME, stubDefinition(GROUP1_BUCKET))
63101
.put(GROUP1_TEST_NAME, stubDefinition(GROUP1_BUCKET))
64102
.put(SILENT_TEST_NAME, stubDefinition(GROUP1_BUCKET, d -> d.setSilent(true)))
65103
.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)
66106
.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+
}
67124

68125
private static final ProctorResult PROCTOR_RESULT =
69-
new ProctorResult(null, BUCKETS, ALLOCATIONS, DEFINITIONS);
126+
new ProctorResult(null, BUCKETS, ALLOCATIONS, DEFINITIONS, PROPERTIES);
70127

71128
@Test
72129
public void testWithEmptyResult() {
@@ -86,7 +143,7 @@ public void testWithEmptyResult() {
86143
public void testDoubleFormattingWriter() {
87144
// legacy Indeed behavior
88145
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";
90147

91148
final ProctorGroupsWriter defaultWriter =
92149
new ProctorGroupsWriter.Builder(
@@ -101,9 +158,11 @@ public void testDoubleFormattingWriter() {
101158
EMPTY_ALLOCID_DEFINITION_TEST_NAME + 0,
102159
GROUP1_TEST_NAME + 1,
103160
FORCED_TEST_NAME + 1,
161+
WINNING_PAYLOAD_PROPERTY_TEST_NAME + 1,
104162
"#A:" + MISSING_DEFINITION_TEST_NAME + 0,
105163
"#A:" + GROUP1_TEST_NAME + 1,
106-
FORCED_TEST_NAME + 1)
164+
FORCED_TEST_NAME + 1,
165+
"#A:" + WINNING_PAYLOAD_PROPERTY_TEST_NAME + 1)
107166
.with(","));
108167
}
109168

@@ -116,15 +175,17 @@ public void testCustomWriter() {
116175
.setIncludeInactiveGroups(true)
117176
.build();
118177
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");
120180

121181
final ProctorGroupsWriter writerWithoutAllocIds =
122182
new ProctorGroupsWriter.Builder(TestGroupFormatter.WITHOUT_ALLOC_ID)
123183
.setIncludeSilentTests(true)
124184
.setIncludeTestWithoutDefinition(false)
125185
.build();
126186
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");
128189
}
129190

130191
@Test

0 commit comments

Comments
 (0)