Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Compatibility with float percentages #9

Merged
merged 2 commits into from
Jun 22, 2016
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
13 changes: 10 additions & 3 deletions src/main/java/com/librato/rollout/zk/RolloutZKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.librato.rollout.RolloutClient;
Expand Down Expand Up @@ -43,6 +44,7 @@ public RolloutZKClient(final CuratorFramework framework, final String rolloutPat
this.framework = framework;
this.rolloutPath = rolloutPath;
this.listener = new CuratorListener() {
@SuppressWarnings("ThrowFromFinallyBlock")
@Override
public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception {
if (framework.getState() != CuratorFrameworkState.STARTED ||
Expand All @@ -57,7 +59,12 @@ public void eventReceived(CuratorFramework client, CuratorEvent event) throws Ex
log.error("Error on event update", ex);
} finally {
// Set the watch just in case it was simply bad data
setWatch();
try {
setWatch();
} catch (Exception e) {
log.error("Could not set watch", e);
throw Throwables.propagate(e);
}
}
}
};
Expand Down Expand Up @@ -159,9 +166,9 @@ public static Entry fromString(String s, String key) {
}
int percentage = 0;
try {
percentage = Integer.parseInt(splitResult[0]);
percentage = (int) Double.parseDouble(splitResult[0]);
} catch (NumberFormatException ex) {
log.warn("Couldn't parse `{}` as a long, ignoring percentage for key `{}`", splitResult[0], key);
log.warn("Couldn't parse `{}` as a double, ignoring percentage for key `{}`", splitResult[0], key);
}
final List<String> groups = Arrays.asList(splitResult[2].split(","));
final List<Long> userIds = new ArrayList<Long>();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/librato/rollout/RolloutZKClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void testUserPercentageFeatureActive() throws Exception {
client.start();

assertFalse(client.userFeatureActive("nosuchfeature", 1, Lists.newArrayList("foo")));
framework.setData().forPath(rolloutPath, "{\"feature:hello\": \"25||\"}".getBytes());
framework.setData().forPath(rolloutPath, "{\"feature:hello\": \"25.0||\"}".getBytes());
Thread.sleep(100);
assertTrue(client.userFeatureActive("hello", 100, Lists.newArrayList("foo")));
assertTrue(client.userFeatureActive("hello", -100, Lists.newArrayList("foo")));
Expand Down