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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ dependencies {
return candidates.find { findProject(it) != null }
}

['main', 'logger', 'events', 'events-domain', 'api', 'http-api', 'http'].each { moduleName ->
['main', 'logger', 'events', 'events-domain', 'api', 'http-api', 'http', 'fallback'].each { moduleName ->
def resolvedPath = resolveProjectPath(moduleName)
if (resolvedPath != null) {
include project(resolvedPath)
Expand Down
4 changes: 4 additions & 0 deletions fallback/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
.gradle
*.iml
.DS_Store
10 changes: 10 additions & 0 deletions fallback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Fallback module

This module contains the fallback treatment logic for the Split SDK.

It provides the types and resolution strategy used when the SDK is unable to evaluate a feature flag normally (e.g. during initialization or on error), returning a configured fallback treatment instead of the default "control".

Key types:
- `FallbackTreatmentsConfiguration` — builder for configuring global and per-flag fallbacks
- `FallbackTreatment` — represents a fallback treatment value with optional config and label
- `FallbackTreatmentsCalculator` — resolves the applicable fallback for a given flag name
23 changes: 23 additions & 0 deletions fallback/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id 'com.android.library'
}

apply from: "$projectDir/../gradle/common-android-library.gradle"

android {
namespace 'io.split.android.client.fallback'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
api project(':logger')

implementation libs.annotation

testImplementation libs.junit4
testImplementation libs.mockitoCore
}
3 changes: 3 additions & 0 deletions fallback/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package io.split.android.client.fallback;

import static io.split.android.client.utils.Utils.checkNotNull;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Map;

import io.split.android.grammar.Treatments;
import java.util.Objects;

public final class FallbackTreatmentsCalculatorImpl implements FallbackTreatmentsCalculator {

private static final String LABEL_PREFIX = "fallback - ";
private static final String CONTROL = "control";

@NonNull
private final FallbackTreatmentsConfiguration mConfig;

public FallbackTreatmentsCalculatorImpl(@NonNull FallbackTreatmentsConfiguration config) {
mConfig = checkNotNull(config);
mConfig = Objects.requireNonNull(config);
}

@NonNull
Expand All @@ -40,7 +38,7 @@ public FallbackTreatment resolve(@NonNull String flagName, @Nullable String labe
if (global != null) {
return global.copyWithLabel(resolveLabel(label));
}
return new FallbackTreatment(Treatments.CONTROL, null, label);
return new FallbackTreatment(CONTROL, null, label);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.HashMap;
import java.util.Map;

import io.split.android.client.TreatmentLabels;

public class FallbackTreatmentsCalculatorTest {

@Test
Expand Down Expand Up @@ -103,7 +101,7 @@ public void labelIsPrefixed() {
.build();

FallbackTreatmentsCalculator calculator = new FallbackTreatmentsCalculatorImpl(config);
FallbackTreatment resolved = calculator.resolve("flagA", TreatmentLabels.EXCEPTION);
FallbackTreatment resolved = calculator.resolve("flagA", "exception");

assertNotNull(resolved);
assertEquals("fallback - exception", resolved.getLabel());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.split.android.client.utils.logger;

import android.util.Log;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;

public class LogPrinterStub implements LogPrinter {
private final Set<Integer> calls = new HashSet<>();
private final Map<Integer, ConcurrentLinkedDeque<String>> logs = new ConcurrentHashMap<>();

public LogPrinterStub() {
// Initialize for all Android log levels: VERBOSE(2) .. ASSERT(7)
for (int level = Log.VERBOSE; level <= Log.ASSERT; level++) {
logs.put(level, new ConcurrentLinkedDeque<>());
}
}

@Override
public void v(String tag, String msg, Throwable tr) {
logs.get(Log.VERBOSE).add(msg);
calls.add(Log.VERBOSE);
}

@Override
public void d(String tag, String msg, Throwable tr) {
logs.get(Log.DEBUG).add(msg);
calls.add(Log.DEBUG);
}

@Override
public void i(String tag, String msg, Throwable tr) {
logs.get(Log.INFO).add(msg);
calls.add(Log.INFO);
}

@Override
public void w(String tag, String msg, Throwable tr) {
logs.get(Log.WARN).add(msg);
calls.add(Log.WARN);
}

@Override
public void e(String tag, String msg, Throwable tr) {
logs.get(Log.ERROR).add(msg);
calls.add(Log.ERROR);
}

@Override
public void wtf(String tag, String msg, Throwable tr) {
logs.get(Log.ASSERT).add(msg);
calls.add(Log.ASSERT);
}

public boolean isCalled(Integer type) {
return calls.contains(type);
}

public Map<Integer, ConcurrentLinkedDeque<String>> getLoggedMessages() {
return new HashMap<>(logs);
}
}
1 change: 1 addition & 0 deletions main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
api project(':logger')
api project(':api')
api project(':http-api')
api project(':fallback')
// Internal module dependencies
implementation project(':http')
implementation project(':events-domain')
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include ':api'
include ':logger'
include ':http-api'
include ':http'
include ':fallback'
include ':main'
include ':events'
include ':events-domain'
Loading