Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/LICENSE → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2018 Split Software
Copyright © 2020 Split Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions client/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES

3.3.3 (Apr 7, 2020)
- Fix issue regarding special characters come from split/segments fetchers.

3.3.2 (Jan 24, 2020)
- Shade com.google.guava as well

Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</parent>
<artifactId>java-client</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

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

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



String json = EntityUtils.toString(response.getEntity());
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (_log.isDebugEnabled()) {
_log.debug("Received json: " + json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

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

Expand Down Expand Up @@ -68,7 +69,7 @@ public SplitChange fetch(long since) {
}


String json = EntityUtils.toString(response.getEntity());
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (_log.isDebugEnabled()) {
_log.debug("Received json: " + json);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package io.split.client;

import io.split.client.dtos.SegmentChange;
import io.split.engine.metrics.Metrics;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

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

@Test
public void testFetcherWithSpecialCharacters() throws URISyntaxException, IOException {
URI rootTarget = URI.create("https://api.split.io/api/segmentChanges");

CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
CloseableHttpResponse httpResponseMock = Mockito.mock(CloseableHttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
StatusLine statusLineMock = Mockito.mock(StatusLine.class);
HttpEntity entityMock = Mockito.mock(HttpEntity.class);

Mockito.when(statusLineMock.getStatusCode()).thenReturn(200);
Mockito.when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
Mockito.when(entityMock.getContent()).thenReturn(getClass().getClassLoader().getResourceAsStream("segment-change-special-chatacters.json"));
Mockito.when(httpResponseMock.getEntity()).thenReturn(entityMock);

Mockito.when(httpClientMock.execute((HttpUriRequest) Mockito.anyObject())).thenReturn(httpResponseMock);

Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
HttpSegmentChangeFetcher fetcher = HttpSegmentChangeFetcher.create(httpClientMock, rootTarget, metrics);

SegmentChange change = fetcher.fetch("some_segment", 1234567);

Assert.assertNotNull(change);
Assert.assertEquals(1, change.added.size());
Assert.assertEquals("grüne_Straße", change.added.get(0));
Assert.assertEquals(1, change.removed.size());
Assert.assertEquals("other_user", change.removed.get(0));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package io.split.client;

import io.split.client.dtos.Split;
import io.split.client.dtos.SplitChange;
import io.split.engine.metrics.Metrics;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

public class HttpSplitChangeFetcherTest {

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

@Test
public void testFetcherWithSpecialCharacters() throws URISyntaxException, IOException {
URI rootTarget = URI.create("https://api.split.io");

CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
CloseableHttpResponse httpResponseMock = Mockito.mock(CloseableHttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
StatusLine statusLineMock = Mockito.mock(StatusLine.class);
HttpEntity entityMock = Mockito.mock(HttpEntity.class);

Mockito.when(statusLineMock.getStatusCode()).thenReturn(200);
Mockito.when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
Mockito.when(entityMock.getContent()).thenReturn(getClass().getClassLoader().getResourceAsStream("split-change-special-characters.json"));
Mockito.when(httpResponseMock.getEntity()).thenReturn(entityMock);

Mockito.when(httpClientMock.execute((HttpUriRequest) Mockito.anyObject())).thenReturn(httpResponseMock);

Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, metrics);

SplitChange change = fetcher.fetch(1234567);

Assert.assertNotNull(change);
Assert.assertEquals(1, change.splits.size());
Assert.assertNotNull(change.splits.get(0));

Split split = change.splits.get(0);
Map<String, String> configs = split.configurations;
Assert.assertEquals(2, configs.size());
Assert.assertEquals("{\"test\": \"blue\",\"grüne Straße\": 13}", configs.get("on"));
Assert.assertEquals("{\"test\": \"blue\",\"size\": 15}", configs.get("off"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "employees",
"added": [
"grüne_Straße"
],
"removed": [
"other_user"
],
"since": -1,
"till": 1489542661161
}
55 changes: 55 additions & 0 deletions client/src/test/resources/split-change-special-characters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"splits": [
{
"trafficTypeName": "user",
"name": "DEMO_MURMUR2",
"trafficAllocation": 100,
"trafficAllocationSeed": 1314112417,
"seed": -2059033614,
"status": "ACTIVE",
"killed": false,
"defaultTreatment": "of",
"changeNumber": 1491244291288,
"algo": 2,
"configurations": {
"on": "{\"test\": \"blue\",\"grüne Straße\": 13}",
"off": "{\"test\": \"blue\",\"size\": 15}"
},
"conditions": [
{
"conditionType": "ROLLOUT",
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"keySelector": {
"trafficType": "user",
"attribute": null
},
"matcherType": "ALL_KEYS",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null,
"unaryNumericMatcherData": null,
"betweenMatcherData": null
}
]
},
"partitions": [
{
"treatment": "on",
"size": 0
},
{
"treatment": "of",
"size": 100
}
],
"label": "in segment all"
}
]
}
],
"since": 1491244291288,
"till": 1491244291288
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
<dependencyManagement>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</parent>

<artifactId>java-client-testing</artifactId>
Expand Down