Skip to content

Commit d7d38ca

Browse files
committed
Implement comments
1 parent b383fb8 commit d7d38ca

File tree

8 files changed

+19
-30
lines changed

8 files changed

+19
-30
lines changed

core-api/src/main/java/com/optimizely/ab/config/DatafileProjectConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,20 @@ public class DatafileProjectConfig implements ProjectConfig {
103103
// v2 constructor
104104
public DatafileProjectConfig(String accountId, String projectId, String version, String revision, List<Group> groups,
105105
List<Experiment> experiments, List<Attribute> attributes, List<EventType> eventType,
106-
List<Audience> audiences, String region) {
107-
this(accountId, projectId, version, revision, groups, experiments, attributes, eventType, audiences, false, region);
106+
List<Audience> audiences) {
107+
this(accountId, projectId, version, revision, groups, experiments, attributes, eventType, audiences, false);
108108
}
109109

110110
// v3 constructor
111111
public DatafileProjectConfig(String accountId, String projectId, String version, String revision, List<Group> groups,
112112
List<Experiment> experiments, List<Attribute> attributes, List<EventType> eventType,
113-
List<Audience> audiences, boolean anonymizeIP, String region) {
113+
List<Audience> audiences, boolean anonymizeIP) {
114114
this(
115115
accountId,
116116
anonymizeIP,
117117
false,
118118
null,
119-
region,
119+
null,
120120
projectId,
121121
revision,
122122
null,

core-api/src/main/java/com/optimizely/ab/config/ProjectConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,5 @@ public String toString() {
143143
}
144144
}
145145

146-
147146
String getRegion();
148147
}

core-api/src/main/java/com/optimizely/ab/config/parser/JsonConfigParser.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
103103
String region = "US"; // Default to US
104104
if (rootObject.has("region")) {
105105
String regionString = rootObject.getString("region");
106-
if ("EU".equalsIgnoreCase(regionString)) {
107-
region = "EU";
108-
}
109106
}
110107

111108
return new DatafileProjectConfig(

core-api/src/main/java/com/optimizely/ab/config/parser/JsonSimpleConfigParser.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
106106
String region = "US"; // Default to US
107107
if (rootObject.containsKey("region")) {
108108
String regionString = (String) rootObject.get("region");
109-
if ("EU".equalsIgnoreCase(regionString)) {
110-
region = "EU";
111-
}
112109
}
113110

114111
return new DatafileProjectConfig(

core-api/src/main/java/com/optimizely/ab/event/internal/EventEndpoints.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717
package com.optimizely.ab.event.internal;
18-
1918
import java.util.HashMap;
2019
import java.util.Map;
2120

@@ -40,18 +39,9 @@ public class EventEndpoints {
4039
* @return the endpoint URL for the specified region, or US endpoint if region is null
4140
*/
4241
public static String getEndpointForRegion(String region) {
43-
if (region == null) {
44-
return LOGX_ENDPOINTS.get("US");
42+
if (region != null && region.equals("EU")) {
43+
return LOGX_ENDPOINTS.get("EU");
4544
}
46-
return LOGX_ENDPOINTS.get(region);
47-
}
48-
49-
/**
50-
* Get the default event endpoint URL (US region).
51-
*
52-
* @return the default endpoint URL
53-
*/
54-
public static String getDefaultEndpoint() {
5545
return LOGX_ENDPOINTS.get("US");
5646
}
5747
}

core-api/src/test/java/com/optimizely/ab/config/DatafileProjectConfigTestUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static ProjectConfig generateValidProjectConfigV2() {
156156
Collections.<TrafficAllocation>emptyList());
157157
List<Group> groups = asList(randomPolicyGroup, overlappingPolicyGroup);
158158

159-
return new DatafileProjectConfig("789", "1234", "2", "42", groups, experiments, attributes, events, audiences, "US");
159+
return new DatafileProjectConfig("789", "1234", "2", "42", groups, experiments, attributes, events, audiences);
160160
}
161161

162162
private static final ProjectConfig NO_AUDIENCE_PROJECT_CONFIG_V2 = generateNoAudienceProjectConfigV2();
@@ -209,7 +209,7 @@ private static ProjectConfig generateNoAudienceProjectConfigV2() {
209209
);
210210

211211
return new DatafileProjectConfig("789", "1234", "2", "42", Collections.<Group>emptyList(), experiments, attributes,
212-
events, Collections.<Audience>emptyList(), "US");
212+
events, Collections.<Audience>emptyList());
213213
}
214214

215215
private static final ProjectConfig VALID_PROJECT_CONFIG_V3 = generateValidProjectConfigV3();
@@ -326,7 +326,7 @@ private static ProjectConfig generateValidProjectConfigV3() {
326326
List<Group> groups = asList(randomPolicyGroup, overlappingPolicyGroup);
327327

328328
return new DatafileProjectConfig("789", "1234", "3", "42", groups, experiments, attributes, events, audiences,
329-
true, "US");
329+
true);
330330
}
331331

332332
private static final ProjectConfig NO_AUDIENCE_PROJECT_CONFIG_V3 = generateNoAudienceProjectConfigV3();
@@ -379,7 +379,7 @@ private static ProjectConfig generateNoAudienceProjectConfigV3() {
379379
);
380380

381381
return new DatafileProjectConfig("789", "1234", "3", "42", Collections.<Group>emptyList(), experiments, attributes,
382-
events, Collections.<Audience>emptyList(), true, "US");
382+
events, Collections.<Audience>emptyList(), true);
383383
}
384384

385385
private static final ProjectConfig VALID_PROJECT_CONFIG_V4 = generateValidProjectConfigV4();

core-api/src/test/java/com/optimizely/ab/event/ForwardingEventProcessorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void setUp() throws Exception {
5050
eventProcessor = new ForwardingEventProcessor(logEvent -> {
5151
assertNotNull(logEvent.getEventBatch());
5252
assertEquals(logEvent.getRequestMethod(), LogEvent.RequestMethod.POST);
53-
assertEquals(logEvent.getEndpointUrl(), EventEndpoints.getDefaultEndpoint());
53+
assertEquals(logEvent.getEndpointUrl(), EventEndpoints.getEndpointForRegion("US"));
5454
atomicBoolean.set(true);
5555
}, notificationCenter);
5656
}

core-api/src/test/java/com/optimizely/ab/event/internal/EventEndpointsTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void testGetEndpointForEURegion() {
3838

3939
@Test
4040
public void testGetDefaultEndpoint() {
41-
String defaultEndpoint = EventEndpoints.getDefaultEndpoint();
41+
String defaultEndpoint = EventEndpoints.getEndpointForRegion("US");
4242
assertEquals("https://logx.optimizely.com/v1/events", defaultEndpoint);
4343
}
4444

@@ -48,11 +48,17 @@ public void testGetEndpointForNullRegion() {
4848
assertEquals("https://logx.optimizely.com/v1/events", endpoint);
4949
}
5050

51+
@Test
52+
public void testGetEndpointForInvalidRegion() {
53+
String endpoint = EventEndpoints.getEndpointForRegion("ZZ");
54+
assertEquals("https://logx.optimizely.com/v1/events", endpoint);
55+
}
56+
5157
@Test
5258
public void testDefaultBehaviorAlwaysReturnsUS() {
5359
// Test that both null region and default endpoint return the same US endpoint
5460
String nullRegionEndpoint = EventEndpoints.getEndpointForRegion(null);
55-
String defaultEndpoint = EventEndpoints.getDefaultEndpoint();
61+
String defaultEndpoint = EventEndpoints.getEndpointForRegion("US");
5662
String usEndpoint = EventEndpoints.getEndpointForRegion("US");
5763

5864
assertEquals("All should return US endpoint", usEndpoint, nullRegionEndpoint);

0 commit comments

Comments
 (0)