Skip to content

Commit 1a3cf53

Browse files
committed
Merge branch 'improvement/impressionSeenAt' of github.com:splitio/java-client into improvement/impressionSeenAt
2 parents 5dfc51c + d5c5455 commit 1a3cf53

File tree

11 files changed

+202
-5
lines changed

11 files changed

+202
-5
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "Code scanning - action"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 21 * * 3'
8+
9+
jobs:
10+
CodeQL-Build:
11+
12+
# CodeQL runs on ubuntu-latest and windows-latest
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
with:
19+
# We must fetch at least the immediate parents so that if this is
20+
# a pull request then we can checkout the head.
21+
fetch-depth: 2
22+
23+
# If this run was triggered by a pull request event, then checkout
24+
# the head of the pull request instead of the merge commit.
25+
- run: git checkout HEAD^2
26+
if: ${{ github.event_name == 'pull_request' }}
27+
28+
# Initializes the CodeQL tools for scanning.
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v1
31+
# Override language selection by uncommenting this and choosing your languages
32+
# with:
33+
# languages: go, javascript, csharp, python, cpp, java
34+
35+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
36+
# If this step fails, then you should remove it and run the build manually (see below)
37+
- name: Autobuild
38+
uses: github/codeql-action/autobuild@v1
39+
40+
# ℹ️ Command-line programs to run using the OS shell.
41+
# 📚 https://git.io/JvXDl
42+
43+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
44+
# and modify them (or add more) to build your code if your project
45+
# uses a compiled language
46+
47+
#- run: |
48+
# make bootstrap
49+
# make release
50+
51+
- name: Perform CodeQL Analysis
52+
uses: github/codeql-action/analyze@v1

client/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
3.3.3 (Apr 7, 2020)
4+
- Fix issue regarding special characters come from split/segments fetchers.
5+
36
3.3.2 (Jan 24, 2020)
47
- Shade com.google.guava as well
58

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>3.3.3-rc1</version>
8+
<version>3.3.4-rc1</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/client/HttpSegmentChangeFetcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.net.URI;
1818
import java.net.URISyntaxException;
19+
import java.nio.charset.StandardCharsets;
1920

2021
import static com.google.common.base.Preconditions.checkNotNull;
2122

@@ -73,7 +74,7 @@ public SegmentChange fetch(String segmentName, long since) {
7374

7475

7576

76-
String json = EntityUtils.toString(response.getEntity());
77+
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
7778
if (_log.isDebugEnabled()) {
7879
_log.debug("Received json: " + json);
7980
}

client/src/main/java/io/split/client/HttpSplitChangeFetcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.net.URI;
1818
import java.net.URISyntaxException;
19+
import java.nio.charset.StandardCharsets;
1920

2021
import static com.google.common.base.Preconditions.checkNotNull;
2122

@@ -68,7 +69,7 @@ public SplitChange fetch(long since) {
6869
}
6970

7071

71-
String json = EntityUtils.toString(response.getEntity());
72+
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
7273
if (_log.isDebugEnabled()) {
7374
_log.debug("Received json: " + json);
7475
}

client/src/test/java/io/split/client/HttpSegmentChangeFetcherTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package io.split.client;
22

3+
import io.split.client.dtos.SegmentChange;
34
import io.split.engine.metrics.Metrics;
5+
import org.apache.http.HttpEntity;
6+
import org.apache.http.StatusLine;
7+
import org.apache.http.client.methods.CloseableHttpResponse;
8+
import org.apache.http.client.methods.HttpUriRequest;
49
import org.apache.http.impl.client.CloseableHttpClient;
510
import org.apache.http.impl.client.HttpClients;
611
import org.hamcrest.Matchers;
712
import org.junit.Assert;
813
import org.junit.Test;
14+
import org.mockito.Mockito;
915

16+
import java.io.IOException;
1017
import java.net.URI;
1118
import java.net.URISyntaxException;
1219

@@ -48,4 +55,31 @@ public void testCustomURLAppendingPathNoBackslash() throws URISyntaxException {
4855
Assert.assertThat(fetcher.getTarget().toString(), Matchers.is(Matchers.equalTo("https://kubernetesturl.com/split/api/segmentChanges")));
4956
}
5057

58+
@Test
59+
public void testFetcherWithSpecialCharacters() throws URISyntaxException, IOException {
60+
URI rootTarget = URI.create("https://api.split.io/api/segmentChanges");
61+
62+
CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
63+
CloseableHttpResponse httpResponseMock = Mockito.mock(CloseableHttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
64+
StatusLine statusLineMock = Mockito.mock(StatusLine.class);
65+
HttpEntity entityMock = Mockito.mock(HttpEntity.class);
66+
67+
Mockito.when(statusLineMock.getStatusCode()).thenReturn(200);
68+
Mockito.when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
69+
Mockito.when(entityMock.getContent()).thenReturn(getClass().getClassLoader().getResourceAsStream("segment-change-special-chatacters.json"));
70+
Mockito.when(httpResponseMock.getEntity()).thenReturn(entityMock);
71+
72+
Mockito.when(httpClientMock.execute((HttpUriRequest) Mockito.anyObject())).thenReturn(httpResponseMock);
73+
74+
Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
75+
HttpSegmentChangeFetcher fetcher = HttpSegmentChangeFetcher.create(httpClientMock, rootTarget, metrics);
76+
77+
SegmentChange change = fetcher.fetch("some_segment", 1234567);
78+
79+
Assert.assertNotNull(change);
80+
Assert.assertEquals(1, change.added.size());
81+
Assert.assertEquals("grüne_Straße", change.added.get(0));
82+
Assert.assertEquals(1, change.removed.size());
83+
Assert.assertEquals("other_user", change.removed.get(0));
84+
}
5185
}

client/src/test/java/io/split/client/HttpSplitChangeFetcherTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
package io.split.client;
22

3+
import io.split.client.dtos.Split;
4+
import io.split.client.dtos.SplitChange;
35
import io.split.engine.metrics.Metrics;
6+
import org.apache.http.HttpEntity;
7+
import org.apache.http.StatusLine;
8+
import org.apache.http.client.methods.CloseableHttpResponse;
9+
import org.apache.http.client.methods.HttpUriRequest;
410
import org.apache.http.impl.client.CloseableHttpClient;
511
import org.apache.http.impl.client.HttpClients;
612
import org.hamcrest.Matchers;
713
import org.junit.Assert;
814
import org.junit.Test;
15+
import org.mockito.Mockito;
916

17+
import java.io.IOException;
1018
import java.net.URI;
1119
import java.net.URISyntaxException;
20+
import java.util.Map;
1221

1322
public class HttpSplitChangeFetcherTest {
1423

@@ -48,4 +57,35 @@ public void testCustomURLAppendingPathNoBackslash() throws URISyntaxException {
4857
Assert.assertThat(fetcher.getTarget().toString(), Matchers.is(Matchers.equalTo("https://kubernetesturl.com/split/api/splitChanges")));
4958
}
5059

60+
@Test
61+
public void testFetcherWithSpecialCharacters() throws URISyntaxException, IOException {
62+
URI rootTarget = URI.create("https://api.split.io");
63+
64+
CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
65+
CloseableHttpResponse httpResponseMock = Mockito.mock(CloseableHttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
66+
StatusLine statusLineMock = Mockito.mock(StatusLine.class);
67+
HttpEntity entityMock = Mockito.mock(HttpEntity.class);
68+
69+
Mockito.when(statusLineMock.getStatusCode()).thenReturn(200);
70+
Mockito.when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
71+
Mockito.when(entityMock.getContent()).thenReturn(getClass().getClassLoader().getResourceAsStream("split-change-special-characters.json"));
72+
Mockito.when(httpResponseMock.getEntity()).thenReturn(entityMock);
73+
74+
Mockito.when(httpClientMock.execute((HttpUriRequest) Mockito.anyObject())).thenReturn(httpResponseMock);
75+
76+
Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
77+
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, metrics);
78+
79+
SplitChange change = fetcher.fetch(1234567);
80+
81+
Assert.assertNotNull(change);
82+
Assert.assertEquals(1, change.splits.size());
83+
Assert.assertNotNull(change.splits.get(0));
84+
85+
Split split = change.splits.get(0);
86+
Map<String, String> configs = split.configurations;
87+
Assert.assertEquals(2, configs.size());
88+
Assert.assertEquals("{\"test\": \"blue\",\"grüne Straße\": 13}", configs.get("on"));
89+
Assert.assertEquals("{\"test\": \"blue\",\"size\": 15}", configs.get("off"));
90+
}
5191
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "employees",
3+
"added": [
4+
"grüne_Straße"
5+
],
6+
"removed": [
7+
"other_user"
8+
],
9+
"since": -1,
10+
"till": 1489542661161
11+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"splits": [
3+
{
4+
"trafficTypeName": "user",
5+
"name": "DEMO_MURMUR2",
6+
"trafficAllocation": 100,
7+
"trafficAllocationSeed": 1314112417,
8+
"seed": -2059033614,
9+
"status": "ACTIVE",
10+
"killed": false,
11+
"defaultTreatment": "of",
12+
"changeNumber": 1491244291288,
13+
"algo": 2,
14+
"configurations": {
15+
"on": "{\"test\": \"blue\",\"grüne Straße\": 13}",
16+
"off": "{\"test\": \"blue\",\"size\": 15}"
17+
},
18+
"conditions": [
19+
{
20+
"conditionType": "ROLLOUT",
21+
"matcherGroup": {
22+
"combiner": "AND",
23+
"matchers": [
24+
{
25+
"keySelector": {
26+
"trafficType": "user",
27+
"attribute": null
28+
},
29+
"matcherType": "ALL_KEYS",
30+
"negate": false,
31+
"userDefinedSegmentMatcherData": null,
32+
"whitelistMatcherData": null,
33+
"unaryNumericMatcherData": null,
34+
"betweenMatcherData": null
35+
}
36+
]
37+
},
38+
"partitions": [
39+
{
40+
"treatment": "on",
41+
"size": 0
42+
},
43+
{
44+
"treatment": "of",
45+
"size": 100
46+
}
47+
],
48+
"label": "in segment all"
49+
}
50+
]
51+
}
52+
],
53+
"since": 1491244291288,
54+
"till": 1491244291288
55+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>3.3.3-rc1</version>
7+
<version>3.3.4-rc1</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

0 commit comments

Comments
 (0)