Skip to content

Commit

Permalink
Add StaticContentInputStreamProviver
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Sep 1, 2023
1 parent d9104b6 commit acbebf4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import io.split.client.utils.FileInputStreamProvider;
import io.split.client.utils.FileTypeEnum;
import io.split.client.utils.InputStreamProvider;
import io.split.client.utils.InputStreamProviderImp;
import io.split.client.utils.SDKMetadata;
import io.split.client.utils.StaticContentInputStreamProvider;
import io.split.engine.SDKReadinessGates;
import io.split.engine.common.ConsumerSyncManager;
import io.split.engine.common.ConsumerSynchronizer;
Expand Down Expand Up @@ -655,7 +655,7 @@ private SplitChangeFetcher createSplitChangeFetcher(SplitClientConfig splitClien
fileType = getFileTypeFromFileName(splitFile);
inputStreamProvider = new FileInputStreamProvider(splitFile);
} else {
inputStreamProvider = new InputStreamProviderImp(inputStream);
inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
}
try {
switch (fileType){
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.split.client.utils;

import io.split.client.exceptions.InputStreamProviderException;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

public class StaticContentInputStreamProvider implements InputStreamProvider {

private final String _streamContents;

public StaticContentInputStreamProvider(InputStream inputStream){
_streamContents = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
}

@Override
public InputStream get() throws InputStreamProviderException {
return new ByteArrayInputStream(_streamContents.getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.split.client.dtos.Status;
import io.split.client.utils.FileInputStreamProvider;
import io.split.client.utils.InputStreamProvider;
import io.split.client.utils.InputStreamProviderImp;
import io.split.client.utils.StaticContentInputStreamProvider;
import io.split.engine.common.FetchOptions;
import org.junit.Assert;
import org.junit.Rule;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class JsonLocalhostSplitChangeFetcherTest {
@Test
public void testParseSplitChange() throws FileNotFoundException {
InputStream inputStream = new FileInputStream("src/test/resources/split_init.json");
InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream);
InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider);
FetchOptions fetchOptions = Mockito.mock(FetchOptions.class);

Expand All @@ -50,7 +50,7 @@ public void testParseSplitChange() throws FileNotFoundException {
@Test
public void testSinceAndTillSanitization() throws FileNotFoundException {
InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangeTillSanitization.json");
InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream);
InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider);
FetchOptions fetchOptions = Mockito.mock(FetchOptions.class);

Expand All @@ -63,7 +63,7 @@ public void testSinceAndTillSanitization() throws FileNotFoundException {
@Test
public void testSplitChangeWithoutSplits() throws FileNotFoundException {
InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangeWithoutSplits.json");
InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream);
InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider);
FetchOptions fetchOptions = Mockito.mock(FetchOptions.class);

Expand All @@ -75,7 +75,7 @@ public void testSplitChangeWithoutSplits() throws FileNotFoundException {
@Test
public void testSplitChangeSplitsToSanitize() throws FileNotFoundException {
InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangeSplitsToSanitize.json");
InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream);
InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider);
FetchOptions fetchOptions = Mockito.mock(FetchOptions.class);

Expand All @@ -92,7 +92,7 @@ public void testSplitChangeSplitsToSanitize() throws FileNotFoundException {
@Test
public void testSplitChangeSplitsToSanitizeMatchersNull() throws FileNotFoundException {
InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangerMatchersNull.json");
InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream);
InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider);
FetchOptions fetchOptions = Mockito.mock(FetchOptions.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.split.client.LocalhostSegmentChangeFetcher;
import io.split.client.JsonLocalhostSplitChangeFetcher;
import io.split.client.utils.InputStreamProvider;
import io.split.client.utils.InputStreamProviderImp;
import io.split.client.utils.StaticContentInputStreamProvider;
import io.split.engine.common.FetchOptions;
import io.split.engine.experiments.SplitChangeFetcher;
import io.split.engine.experiments.SplitFetcher;
Expand Down Expand Up @@ -155,7 +155,7 @@ public void testLocalhostSegmentChangeFetcher() throws InterruptedException, Fil
SplitCache splitCacheProducer = new InMemoryCacheImp();

InputStream inputStream = new FileInputStream("src/test/resources/split_init.json");
InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream);
InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream);
SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider);
SplitParser splitParser = new SplitParser();
FetchOptions fetchOptions = new FetchOptions.Builder().build();
Expand Down

0 comments on commit acbebf4

Please sign in to comment.