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
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public static void main(String[] args) throws MalformedURLException, Interrupted
final FeatureProbe fpClient = new FeatureProbe(FEATURE_PROBE_SERVER_SDK_KEY, config);

// Create one user.
FPUser user = new FPUser("00001") // key is for percentage rollout, normally use userId as key
.with("userId", "00001"); // "userId" is used in rules, should be filled in.
FPUser user = new FPUser()
.stableRollout("00001") // key is for percentage rollout, normally use userId as key
.with("userId", "00001"); // "userId" is used in rules, should be filled in.

// Get toggle result for this user.
final String YOUR_TOGGLE_KEY = "campaign_allow_list";
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/featureprobe/sdk/server/FPUser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.featureprobe.sdk.server;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -13,14 +12,29 @@ public class FPUser {

private Map<String, String> attrs = new HashMap<>();

/**
* Creates a new FPUser
*/
public FPUser() {}

/**
* Creates a new FPUser
* @param key user unique id for percentage rollout
*/
@Deprecated
public FPUser(String key) {
this.key = key;
}

/**
* Set user unique id for percentage rollout
* @param key user unique id for percentage rollout
*/
public FPUser stableRollout(String key) {
this.key = key;
return this;
}

/**
* Add an attribute to the user
* @param name attribute name
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/featureprobe/sdk/server/model/Split.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Split(List<List<List<Integer>>> distribution) {
}

public HitResult findIndex(FPUser user, String toggleKey) {
String hashKey = user.getKey();
String hashKey = user.getKey() != null ? user.getKey() : String.valueOf(System.nanoTime());
Copy link
Member

Choose a reason for hiding this comment

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

Should set this value back to user.key. This user may be used many times.

if (StringUtils.isNotBlank(bucketBy)) {
if (user.containAttr(bucketBy)) {
hashKey = user.getAttr(bucketBy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AccessRecorderSpec extends Specification {

def setup() {
accessRecorder = new AccessRecorder()
FPUser user = new FPUser("test_user")
FPUser user = new FPUser().stableRollout("test_user")
event = new AccessEvent(System.currentTimeMillis(), user, "test_toggle", "true", 1, 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConditionSpec extends Specification {
condition = new Condition()
condition.setType(ConditionType.STRING)
condition.setSubject("userId")
user = new FPUser("test_user")
user = new FPUser().stableRollout("test_user")
segments = ["test_project\$test_segment": new Segment(uniqueId: "test_project\$test_segment", version: 1,
rules: [new SegmentRule(conditions: [new Condition(type: ConditionType.STRING, subject: "userId",
predicate: PredicateType.IS_ONE_OF, objects: ["1", "2"])])])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FeatureProbeSpec extends Specification {
def caseName = testCase.get("name").asText()
println("starting execute scenario : " + name + ",case : " + caseName)
def userCase = testCase.get("user")
FPUser user = new FPUser(userCase.get("key").asText())
FPUser user = new FPUser().stableRollout(userCase.get("key").asText())
def customValues = userCase.get("customValues").asList()
for (int x = 0; x < customValues.size(); x++) {
def customValue = customValues.get(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SplitSpec extends Specification {

def setup() {
split = new Split([[[0, 5000]], [[5000, 10000]]])
user = new FPUser("test_user_key")
user = new FPUser().stableRollout("test_user_key")
}

def "Get user group"() {
Expand Down