Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 7fc4b3b

Browse files
prepare 4.10.1 release (#179)
1 parent 095823b commit 7fc4b3b

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

build.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ buildscript {
8888
}
8989
dependencies {
9090
classpath 'org.ajoberstar:gradle-git:1.5.0-rc.1'
91-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
91+
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
9292
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.8.0"
9393
classpath "org.eclipse.virgo.util:org.eclipse.virgo.util.osgi.manifest:3.5.0.RELEASE"
9494
classpath "org.osgi:osgi_R4_core:1.0"
@@ -385,7 +385,21 @@ publishing {
385385
pom.withXml {
386386
def root = asNode()
387387
root.appendNode('description', 'Official LaunchDarkly SDK for Java')
388-
asNode().children().last() + pomConfig
388+
389+
// The following workaround is for a known issue where the Shadow plugin assumes that all
390+
// non-shaded dependencies should have "runtime" scope rather than "compile".
391+
// https://github.com/johnrengelman/shadow/issues/321
392+
// https://github.com/launchdarkly/java-server-sdk/issues/151
393+
// Currently there doesn't seem to be any way way around this other than simply hacking the
394+
// pom at this point after it has been generated by Shadow. All of the dependencies that
395+
// are in the pom at this point should have compile scope.
396+
def dependenciesNode = root.getAt('dependencies').get(0)
397+
dependenciesNode.each { dependencyNode ->
398+
def scopeNode = dependencyNode.getAt('scope').get(0)
399+
scopeNode.setValue('compile')
400+
}
401+
402+
root.children().last() + pomConfig
389403
}
390404
}
391405
}

src/test/java/com/launchdarkly/client/VariationOrRolloutTest.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,58 @@
11
package com.launchdarkly.client;
22

3-
import static org.junit.Assert.assertEquals;
3+
import com.launchdarkly.client.VariationOrRollout.WeightedVariation;
44

5+
import org.hamcrest.Matchers;
56
import org.junit.Test;
67

8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
13+
import static org.junit.Assert.assertEquals;
14+
15+
@SuppressWarnings("javadoc")
716
public class VariationOrRolloutTest {
17+
@Test
18+
public void variationIndexIsReturnedForBucket() {
19+
LDUser user = new LDUser.Builder("userkey").build();
20+
String flagKey = "flagkey";
21+
String salt = "salt";
22+
23+
// First verify that with our test inputs, the bucket value will be greater than zero and less than 100000,
24+
// so we can construct a rollout whose second bucket just barely contains that value
25+
int bucketValue = (int)(VariationOrRollout.bucketUser(user, flagKey, "key", salt) * 100000);
26+
assertThat(bucketValue, greaterThanOrEqualTo(1));
27+
assertThat(bucketValue, Matchers.lessThan(100000));
28+
29+
int badVariationA = 0, matchedVariation = 1, badVariationB = 2;
30+
List<WeightedVariation> variations = Arrays.asList(
31+
new WeightedVariation(badVariationA, bucketValue), // end of bucket range is not inclusive, so it will *not* match the target value
32+
new WeightedVariation(matchedVariation, 1), // size of this bucket is 1, so it only matches that specific value
33+
new WeightedVariation(badVariationB, 100000 - (bucketValue + 1)));
34+
VariationOrRollout vr = new VariationOrRollout(null, new VariationOrRollout.Rollout(variations, null));
35+
36+
Integer resultVariation = vr.variationIndexForUser(user, flagKey, salt);
37+
assertEquals(Integer.valueOf(matchedVariation), resultVariation);
38+
}
39+
40+
@Test
41+
public void lastBucketIsUsedIfBucketValueEqualsTotalWeight() {
42+
LDUser user = new LDUser.Builder("userkey").build();
43+
String flagKey = "flagkey";
44+
String salt = "salt";
45+
46+
// We'll construct a list of variations that stops right at the target bucket value
47+
int bucketValue = (int)(VariationOrRollout.bucketUser(user, flagKey, "key", salt) * 100000);
48+
49+
List<WeightedVariation> variations = Arrays.asList(new WeightedVariation(0, bucketValue));
50+
VariationOrRollout vr = new VariationOrRollout(null, new VariationOrRollout.Rollout(variations, null));
51+
52+
Integer resultVariation = vr.variationIndexForUser(user, flagKey, salt);
53+
assertEquals(Integer.valueOf(0), resultVariation);
54+
}
55+
856
@Test
957
public void canBucketByIntAttributeSameAsString() {
1058
LDUser user = new LDUser.Builder("key")

0 commit comments

Comments
 (0)