Skip to content

Commit d8ec835

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

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-2017 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.
@@ -301,9 +301,15 @@ public Boolean call() throws Exception {
301301
}
302302
}
303303
catch (TimeoutException e) {
304-
future.cancel(true);
304+
if (future != null) {
305+
future.cancel(true);
306+
}
305307
return false;
306308
}
309+
catch (InterruptedException e) {
310+
Thread.currentThread().interrupt();
311+
throw e;
312+
}
307313
catch (Exception e) {
308314
throw new MessagingException("Failed to acquire mutex at " + this.path, e);
309315
}

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.
@@ -288,6 +288,7 @@ public void testListenerInvokedOnRemoteChanges() throws Exception {
288288

289289
CuratorFramework otherClient = createNewClient();
290290
ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
291+
otherMetadataStore.start();
291292

292293
// register listeners
293294
final List<List<String>> notifiedChanges = new ArrayList<List<String>>();

0 commit comments

Comments
 (0)