From 63384eb5c17fa66a819d5f5d6676a857fd12b6cf Mon Sep 17 00:00:00 2001 From: Collin Van Dyck Date: Wed, 22 Jun 2016 12:26:30 -0700 Subject: [PATCH 1/2] Log error when failure to set watches in finally --- .../java/com/librato/rollout/zk/RolloutZKClient.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/librato/rollout/zk/RolloutZKClient.java b/src/main/java/com/librato/rollout/zk/RolloutZKClient.java index 48403ed..df36c9f 100644 --- a/src/main/java/com/librato/rollout/zk/RolloutZKClient.java +++ b/src/main/java/com/librato/rollout/zk/RolloutZKClient.java @@ -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; @@ -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 || @@ -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); + } } } }; From 2d679bc7b8d3673d2d9137579bb58ef82b2b42b6 Mon Sep 17 00:00:00 2001 From: Collin Van Dyck Date: Wed, 22 Jun 2016 12:35:50 -0700 Subject: [PATCH 2/2] Parse percentage as double, cast to int --- src/main/java/com/librato/rollout/zk/RolloutZKClient.java | 4 ++-- src/test/java/com/librato/rollout/RolloutZKClientTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/librato/rollout/zk/RolloutZKClient.java b/src/main/java/com/librato/rollout/zk/RolloutZKClient.java index df36c9f..eb7ed74 100644 --- a/src/main/java/com/librato/rollout/zk/RolloutZKClient.java +++ b/src/main/java/com/librato/rollout/zk/RolloutZKClient.java @@ -166,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 groups = Arrays.asList(splitResult[2].split(",")); final List userIds = new ArrayList(); diff --git a/src/test/java/com/librato/rollout/RolloutZKClientTest.java b/src/test/java/com/librato/rollout/RolloutZKClientTest.java index 728803f..8ea9d3b 100644 --- a/src/test/java/com/librato/rollout/RolloutZKClientTest.java +++ b/src/test/java/com/librato/rollout/RolloutZKClientTest.java @@ -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")));