Skip to content

Commit be66bc9

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

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.
@@ -147,13 +147,7 @@ public String putIfAbsent(String key, String value) {
147147
}
148148
catch (KeeperException.NodeExistsException e) {
149149
// so the data actually exists, we can read it
150-
try {
151-
byte[] bytes = this.client.getData().forPath(getPath(key));
152-
return IntegrationUtils.bytesToString(bytes, this.encoding);
153-
}
154-
catch (Exception exceptionDuringGet) {
155-
throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", e);
156-
}
150+
return get(key);
157151
}
158152
catch (Exception e) {
159153
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)