-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The 0.7.6 version does not throw an exception when keepAliveOnce failed
#1254 Signed-off-by: Luca Burgazzoli <lburgazzoli@gmail.com>
- Loading branch information
1 parent
838b69c
commit 31a60ae
Showing
6 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
jetcd-core/src/test/java/io/etcd/jetcd/impl/LeaseOnceErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2016-2021 The jetcd authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.etcd.jetcd.impl; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.etcd.jetcd.Client; | ||
import io.etcd.jetcd.Lease; | ||
import io.etcd.jetcd.common.exception.EtcdException; | ||
import io.etcd.jetcd.lease.LeaseKeepAliveResponse; | ||
import io.etcd.jetcd.lease.LeaseRevokeResponse; | ||
import io.etcd.jetcd.test.EtcdClusterExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@Timeout(value = 45, unit = TimeUnit.SECONDS) | ||
public class LeaseOnceErrorTest { | ||
|
||
@RegisterExtension | ||
public static final EtcdClusterExtension CLUSTER = EtcdClusterExtension.builder() | ||
.withNodes(1) | ||
.build(); | ||
|
||
private Client client; | ||
private Lease leaseClient; | ||
|
||
private static final long TTL = 2; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
client = TestUtil.client(CLUSTER).build(); | ||
leaseClient = client.getLeaseClient(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
// https://github.com/etcd-io/jetcd/issues/1254 | ||
@Test | ||
public void testKeepAliveError() throws Exception { | ||
final long leaseID = leaseClient.grant(TTL).get(1, TimeUnit.SECONDS).getID(); | ||
|
||
LeaseKeepAliveResponse ka1 = leaseClient.keepAliveOnce(leaseID).get(1, TimeUnit.SECONDS); | ||
assertThat(ka1.getTTL()).isNotZero(); | ||
|
||
LeaseRevokeResponse r1 = leaseClient.revoke(leaseID).get(1, TimeUnit.SECONDS); | ||
assertThat(r1).isNotNull(); | ||
|
||
assertThatThrownBy(() -> leaseClient.keepAliveOnce(leaseID).get(1, TimeUnit.SECONDS)) | ||
.hasCauseInstanceOf(EtcdException.class) | ||
.hasMessageContaining("etcdserver: requested lease not found"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters