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
3 changes: 0 additions & 3 deletions src/main/java/io/getunleash/DefaultUnleash.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.getunleash.event.IsEnabledImpressionEvent;
import io.getunleash.event.ToggleEvaluated;
import io.getunleash.event.VariantImpressionEvent;
import io.getunleash.metric.UnleashMetricService;
import io.getunleash.repository.FeatureRepository;
import io.getunleash.repository.YggdrasilAdapters;
import io.getunleash.strategy.*;
Expand All @@ -27,7 +26,6 @@ public class DefaultUnleash implements Unleash {

private static ConcurrentHashMap<String, LongAdder> initCounts = new ConcurrentHashMap<>();

private final UnleashMetricService metricService;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All handled by the EngineProxy

private final FeatureRepository featureRepository;
private final UnleashContextProvider contextProvider;
private final EventDispatcher eventDispatcher;
Expand Down Expand Up @@ -69,7 +67,6 @@ public DefaultUnleash(

this.config = unleashConfig;
this.featureRepository = engineProxy;
this.metricService = engineProxy;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All handled by the EngineProxy

But but..

this.contextProvider = contextProvider;
this.eventDispatcher = eventDispatcher;
initCounts.compute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UnleashMetricServiceImpl implements UnleashMetricService {
private static final Logger LOGGER = LoggerFactory.getLogger(UnleashMetricServiceImpl.class);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used

private final LocalDateTime started;
private final UnleashConfig unleashConfig;
private final MetricSender metricSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public void setInterval(Runnable command, long initialDelaySec, long periodSec)

@Override
public Future<Void> scheduleOnce(Runnable runnable) {
return (Future<Void>) executorService.submit(runnable);
return executorService.submit(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this was just wrong but didn't matter because the result wasn't really used. Pretty sure this is correct but still won't matter

Linter stops freaking though, which is nice

() -> {
runnable.run();
return null;
});
}

@Override
Expand Down
19 changes: 8 additions & 11 deletions src/test/java/io/getunleash/DefaultUnleashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import io.getunleash.util.UnleashConfig;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a bunch of unuseds which don't impact the test runs in anyway

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -56,7 +54,6 @@ public void setup() {
UnleashConfig unleashConfig =
UnleashConfig.builder().unleashAPI("http://fakeAPI").appName("fakeApp").build();
engineProxy = mock(EngineProxy.class);
Map<String, Strategy> strategyMap = new HashMap<>();
contextProvider = mock(UnleashContextProvider.class);
eventDispatcher = mock(EventDispatcher.class);

Expand Down Expand Up @@ -145,7 +142,7 @@ public void not_setting_current_time_falls_back_to_correct_now_instant() {

@Test
public void multiple_instantiations_of_the_same_config_gives_errors() {
ListAppender<ILoggingEvent> appender = new ListAppender();
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
Logger unleashLogger = (Logger) LoggerFactory.getLogger(DefaultUnleash.class);
unleashLogger.addAppender(appender);
Expand All @@ -158,13 +155,13 @@ public void multiple_instantiations_of_the_same_config_gives_errors() {
.apiKey("default:development:1234567890123456")
.instanceId(instanceId)
.build();
Unleash unleash1 = new DefaultUnleash(config);
new DefaultUnleash(config);
// We've only instantiated the client once, so no errors should've been logged
assertThat(appender.list).isEmpty();
Unleash unleash2 = new DefaultUnleash(config);
new DefaultUnleash(config);
// We've now instantiated the client twice, so we expect an error log line.
assertThat(appender.list).hasSize(1);
String id = config.getClientIdentifier();
config.getClientIdentifier();
assertThat(appender.list)
.extracting(ILoggingEvent::getFormattedMessage)
.containsExactly(
Expand All @@ -174,7 +171,7 @@ public void multiple_instantiations_of_the_same_config_gives_errors() {
+ instanceId
+ "] running. Please double check your code where you are instantiating the Unleash SDK");
appender.list.clear();
Unleash unleash3 = new DefaultUnleash(config);
new DefaultUnleash(config);
// We've now instantiated the client twice, so we expect an error log line.
assertThat(appender.list).hasSize(1);
assertThat(appender.list)
Expand All @@ -197,10 +194,10 @@ public void supports_failing_hard_on_multiple_instantiations() {
.instanceId("multiple_connection_exception")
.build();
String id = config.getClientIdentifier();
Unleash unleash1 = new DefaultUnleash(config);
new DefaultUnleash(config);
assertThatThrownBy(
() -> {
Unleash unleash2 = new DefaultUnleash(config, null, null, null, true);
new DefaultUnleash(config, null, null, null, true);
})
.isInstanceOf(RuntimeException.class)
.withFailMessage(
Expand Down Expand Up @@ -294,7 +291,7 @@ public void asynchronous_fetch_on_initialisation_fails_silently_and_retries()
.unleashFeatureFetcherFactory((UnleashConfig c) -> fetcher)
.build();

Unleash unleash = new DefaultUnleash(config);
new DefaultUnleash(config);
Thread.sleep(1);
verify(fetcher, times(1)).fetchFeatures();
Thread.sleep(1200);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/getunleash/SynchronousTestExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void setInterval(Runnable command, long initialDelaySec, long periodSec)
}

@Override
public ScheduledFuture scheduleOnce(Runnable runnable) {
public ScheduledFuture<Void> scheduleOnce(Runnable runnable) {
runnable.run();
return new AlreadyCompletedScheduledFuture();
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/io/getunleash/UnleashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void fallback_function_should_be_invoked_and_return_true() {
.thenReturn(new FlatResponse<Boolean>(false, null));
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);

@SuppressWarnings("unchecked")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is correct thing to do here. Mocking is runtime goop so I don't think this has a meaningful way to determine the type

BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(true);

Expand All @@ -73,6 +74,7 @@ public void fallback_function_should_be_invoked_also_with_context() {
.thenReturn(new FlatResponse<Boolean>(false, null));
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);

@SuppressWarnings("unchecked")
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(true);

Expand All @@ -89,6 +91,7 @@ void fallback_function_should_be_invoked_and_return_false() {
.thenReturn(new FlatResponse<Boolean>(false, null));
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);

@SuppressWarnings("unchecked")
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(false);

Expand All @@ -103,6 +106,7 @@ void fallback_function_should_not_be_called_when_toggle_is_defined() {
.thenReturn(new FlatResponse<Boolean>(true, true));
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);

@SuppressWarnings("unchecked")
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void should_register_future_for_sending_interval_regualry() {
.unleashAPI("http://unleash.com")
.build();
UnleashScheduledExecutor executor = mock(UnleashScheduledExecutor.class);
UnleashMetricService unleashMetricService =
new UnleashMetricServiceImpl(config, executor, null);

new UnleashMetricServiceImpl(config, executor, null);

verify(executor, times(1)).setInterval(any(Runnable.class), eq(interval), eq(interval));
}
Expand Down Expand Up @@ -106,8 +106,7 @@ public void should_send_metrics() {
DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
UnleashEngine engine = new UnleashEngine();

UnleashMetricService unleashMetricService =
new UnleashMetricServiceImpl(config, sender, executor, engine);
new UnleashMetricServiceImpl(config, sender, executor, engine);

ArgumentCaptor<Runnable> sendMetricsCallback = ArgumentCaptor.forClass(Runnable.class);
verify(executor).setInterval(sendMetricsCallback.capture(), anyLong(), anyLong());
Expand All @@ -131,8 +130,7 @@ public void should_record_and_send_metrics()
DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
UnleashEngine engine = new UnleashEngine();

UnleashMetricService unleashMetricService =
new UnleashMetricServiceImpl(config, sender, executor, engine);
new UnleashMetricServiceImpl(config, sender, executor, engine);

engine.isEnabled("someToggle", new Context());
engine.isEnabled("someToggle", new Context());
Expand Down Expand Up @@ -374,8 +372,7 @@ public void should_add_new_metrics_data_to_bucket() {
DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
UnleashEngine engine = new UnleashEngine();

UnleashMetricService unleashMetricService =
new UnleashMetricServiceImpl(config, sender, executor, engine);
new UnleashMetricServiceImpl(config, sender, executor, engine);

ArgumentCaptor<Runnable> sendMetricsCallback = ArgumentCaptor.forClass(Runnable.class);
verify(executor).setInterval(sendMetricsCallback.capture(), anyLong(), anyLong());
Expand Down
48 changes: 22 additions & 26 deletions src/test/java/io/getunleash/repository/FeatureRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import io.getunleash.DefaultUnleash;
import io.getunleash.FeatureDefinition;
import io.getunleash.Unleash;
import io.getunleash.engine.UnleashEngine;
import io.getunleash.event.ClientFeaturesResponse;
import io.getunleash.streaming.StreamingFeatureFetcher;
Expand Down Expand Up @@ -147,14 +146,13 @@ public void should_perform_synchronous_fetch_on_initialisation() {
ClientFeaturesResponse.updated(loadMockFeatures("unleash-repo-v2.json"));
when(fetcher.fetchFeatures()).thenReturn(response);

FeatureRepository featureRepository =
new FeatureRepositoryImpl(
config,
backupHandler,
new UnleashEngine(),
fetcher,
streamingFetcher,
bootstrapHandler);
new FeatureRepositoryImpl(
config,
backupHandler,
new UnleashEngine(),
fetcher,
streamingFetcher,
bootstrapHandler);

verify(fetcher, times(1)).fetchFeatures();
}
Expand All @@ -171,14 +169,13 @@ public void should_not_perform_synchronous_fetch_on_initialisation() {

when(fetcher.fetchFeatures()).thenReturn(response);

FeatureRepositoryImpl featureRepository =
new FeatureRepositoryImpl(
config,
backupHandler,
new UnleashEngine(),
fetcher,
streamingFetcher,
bootstrapHandler);
new FeatureRepositoryImpl(
config,
backupHandler,
new UnleashEngine(),
fetcher,
streamingFetcher,
bootstrapHandler);

verify(fetcher, times(0)).fetchFeatures();
}
Expand Down Expand Up @@ -233,14 +230,13 @@ public void should_not_read_bootstrap_if_backup_was_found() {
UnleashConfig config =
defaultConfigBuilder().toggleBootstrapProvider(bootstrapHandler).build();

FeatureRepositoryImpl featureRepository =
new FeatureRepositoryImpl(
config,
backupHandler,
new UnleashEngine(),
fetcher,
streamingFetcher,
bootstrapHandler);
new FeatureRepositoryImpl(
config,
backupHandler,
new UnleashEngine(),
fetcher,
streamingFetcher,
bootstrapHandler);

verify(bootstrapHandler, times(0)).read();
}
Expand All @@ -263,7 +259,7 @@ public void shouldCallStartupExceptionHandlerIfStartupFails() {
.toggleBootstrapProvider(toggleBootstrapProvider)
.build();

Unleash unleash = new DefaultUnleash(config);
new DefaultUnleash(config);
assertThat(failed).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void should_not_set_empty_ifNoneMatchHeader() throws URISyntaxException {
URI uri = new URI("http://localhost:" + serverMock.getPort() + "/api/");
UnleashConfig config = UnleashConfig.builder().appName("test").unleashAPI(uri).build();
OkHttpFeatureFetcher okHttpToggleFetcher = new OkHttpFeatureFetcher(config);
ClientFeaturesResponse response = okHttpToggleFetcher.fetchFeatures();
okHttpToggleFetcher.fetchFeatures();

verify(getRequestedFor(urlMatching("/api/client/features")).withoutHeader("If-None-Match"));
}
Expand All @@ -265,7 +265,7 @@ public void should_add_project_filter_to_toggles_url_if_config_has_it_set()
UnleashConfig config =
UnleashConfig.builder().appName("test").unleashAPI(uri).projectName("name").build();
OkHttpFeatureFetcher okHttpFeatureFetcher = new OkHttpFeatureFetcher(config);
ClientFeaturesResponse response = okHttpFeatureFetcher.fetchFeatures();
okHttpFeatureFetcher.fetchFeatures();
verify(getRequestedFor(urlMatching("/api/client/features\\?project=name")));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.getunleash.integration;
package io.getunleash.streaming;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this was in the integration package. It's alone in there, doesn't match it's actual package structure and that doesn't follow the pattern for our test packages anyway


import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/getunleash/util/UnleashConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void should_add_custom_headers_from_provider_to_connection_if_present()
throws IOException {
String unleashAPI = "http://unleash.org";
Map<String, String> result =
new HashMap() {
new HashMap<String, String>() {
{
put("PROVIDER-HEADER", "Provider Value");
}
Expand Down
Loading