Skip to content

Commit 2ded76a

Browse files
committed
Fix Zookeeper Issues
- `tryLock()` didn't throw `InterruptedException` - `putIfAbsent()` use `get()` for current value
1 parent 047790e commit 2ded76a

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/lock/ZookeeperLockRegistry.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2016 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -307,9 +307,15 @@ public Boolean call() throws Exception {
307307
}
308308
}
309309
catch (TimeoutException e) {
310-
future.cancel(true);
310+
if (future != null) {
311+
future.cancel(true);
312+
}
311313
return false;
312314
}
315+
catch (InterruptedException e) {
316+
Thread.currentThread().interrupt();
317+
throw e;
318+
}
313319
catch (Exception e) {
314320
throw new MessagingException("Failed to acquire mutex at " + this.path, e);
315321
}

spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -122,13 +122,7 @@ public String putIfAbsent(String key, String value) {
122122
}
123123
catch (KeeperException.NodeExistsException e) {
124124
// so the data actually exists, we can read it
125-
try {
126-
byte[] bytes = this.client.getData().forPath(getPath(key));
127-
return IntegrationUtils.bytesToString(bytes, this.encoding);
128-
}
129-
catch (Exception exceptionDuringGet) {
130-
throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", e);
131-
}
125+
return get(key);
132126
}
133127
catch (Exception e) {
134128
throw new ZookeeperMetadataStoreException("Error while trying to set '" + key + "':", e);

spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -308,6 +308,7 @@ public void testListenerInvokedOnRemoteChanges() throws Exception {
308308

309309
CuratorFramework otherClient = createNewClient();
310310
ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
311+
otherMetadataStore.start();
311312

312313
// register listeners
313314
final List<List<String>> notifiedChanges = new ArrayList<List<String>>();

0 commit comments

Comments
 (0)