From d8ec8352ff3dbb933f0dcec35eafe45e1c79ba6e Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 8 Mar 2019 12:36:57 -0500 Subject: [PATCH] Fix Zookeeper Issues - `tryLock()` didn't throw `InterruptedException` - `putIfAbsent()` use `get()` for current value 1 --- .../zookeeper/lock/ZookeeperLockRegistry.java | 10 ++++++++-- .../zookeeper/metadata/ZookeeperMetadataStore.java | 10 ++-------- .../metadata/ZookeeperMetadataStoreTests.java | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java index d20d9e899f..5bcaf35f81 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -301,9 +301,15 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB } } catch (TimeoutException e) { - future.cancel(true); + if (future != null) { + future.cancel(true); + } return false; } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw e; + } catch (Exception e) { throw new MessagingException("Failed to acquire mutex at " + this.path, e); } diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java index 6443c01a61..23e0562d3b 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,13 +122,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } catch (KeeperException.NodeExistsException e) { // so the data actually exists, we can read it - try { - byte[] bytes = this.client.getData().forPath(getPath(key)); - return IntegrationUtils.bytesToString(bytes, this.encoding); - } - catch (Exception exceptionDuringGet) { - throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", e); - } + return get(key); } catch (Exception e) { throw new ZookeeperMetadataStoreException("Error while trying to set '" + key + "':", e); diff --git a/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java b/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java index 4a1941887e..d046b25612 100644 --- a/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java +++ b/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -288,6 +288,7 @@ public class ZookeeperMetadataStoreTests extends ZookeeperTestSupport { CuratorFramework otherClient = createNewClient(); ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient); + otherMetadataStore.start(); // register listeners final List> notifiedChanges = new ArrayList>();