|
1 | 1 | /* |
2 | | -* |
3 | | -* Licensed to the Apache Software Foundation (ASF) under one |
4 | | -* or more contributor license agreements. See the NOTICE file |
5 | | -* distributed with this work for additional information |
6 | | -* regarding copyright ownership. The ASF licenses this file |
7 | | -* to you under the Apache License, Version 2.0 (the |
8 | | -* "License"); you may not use this file except in compliance |
9 | | -* with the License. You may obtain a copy of the License at |
10 | | -* |
11 | | -* http://www.apache.org/licenses/LICENSE-2.0 |
12 | | -* |
13 | | -* Unless required by applicable law or agreed to in writing, |
14 | | -* software distributed under the License is distributed on an |
15 | | -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
16 | | -* KIND, either express or implied. See the License for the |
17 | | -* specific language governing permissions and limitations |
18 | | -* under the License. |
19 | | -* |
20 | | -*/ |
| 2 | + * |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE |
| 4 | + * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| 5 | + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the |
| 6 | + * License. You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 11 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 12 | + * specific language governing permissions and limitations under the License. |
| 13 | + * |
| 14 | + */ |
21 | 15 | package org.apache.bookkeeper.client; |
22 | 16 |
|
23 | 17 | import org.apache.bookkeeper.test.BookKeeperClusterTestCase; |
24 | 18 | import org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture; |
25 | 19 | import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase; |
26 | 20 | import org.apache.zookeeper.ZooKeeper; |
27 | | -import org.junit.Test; |
| 21 | +import org.junit.jupiter.api.Test; |
28 | 22 | import org.slf4j.Logger; |
29 | 23 | import org.slf4j.LoggerFactory; |
30 | 24 |
|
31 | 25 | /** |
32 | 26 | * Test the bookkeeper client while losing a ZK session. |
33 | 27 | */ |
34 | 28 | public class BookKeeperClientZKSessionExpiry extends BookKeeperClusterTestCase { |
35 | | - private static final Logger LOG = LoggerFactory.getLogger(BookKeeperClientZKSessionExpiry.class); |
36 | 29 |
|
37 | | - public BookKeeperClientZKSessionExpiry() { |
38 | | - super(4); |
39 | | - } |
| 30 | + private static final Logger LOG = LoggerFactory.getLogger(BookKeeperClientZKSessionExpiry.class); |
40 | 31 |
|
41 | | - @Test |
42 | | - public void testSessionLossWhileWriting() throws Exception { |
| 32 | + public BookKeeperClientZKSessionExpiry() { |
| 33 | + super(4); |
| 34 | + } |
43 | 35 |
|
44 | | - Thread expiryThread = new Thread() { |
45 | | - @Override |
46 | | - public void run() { |
47 | | - try { |
48 | | - while (true) { |
49 | | - Thread.sleep(5000); |
50 | | - long sessionId = bkc.getZkHandle().getSessionId(); |
51 | | - byte[] sessionPasswd = bkc.getZkHandle().getSessionPasswd(); |
| 36 | + @Test |
| 37 | + void sessionLossWhileWriting() throws Exception { |
52 | 38 |
|
53 | | - try { |
54 | | - ZooKeeperWatcherBase watcher = new ZooKeeperWatcherBase(10000, false); |
55 | | - ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000, |
56 | | - watcher, sessionId, sessionPasswd); |
57 | | - zk.close(); |
58 | | - } catch (Exception e) { |
59 | | - LOG.info("Error killing session", e); |
60 | | - } |
61 | | - } |
62 | | - } catch (InterruptedException ie) { |
63 | | - Thread.currentThread().interrupt(); |
64 | | - return; |
65 | | - } |
66 | | - } |
67 | | - }; |
68 | | - expiryThread.start(); |
| 39 | + Thread expiryThread = new Thread() { |
| 40 | + @Override |
| 41 | + public void run() { |
| 42 | + try { |
| 43 | + while (true) { |
| 44 | + Thread.sleep(5000); |
| 45 | + long sessionId = bkc.getZkHandle().getSessionId(); |
| 46 | + byte[] sessionPasswd = bkc.getZkHandle().getSessionPasswd(); |
69 | 47 |
|
70 | | - for (int i = 0; i < 3; i++) { |
71 | | - LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.MAC, "foobar".getBytes()); |
72 | | - for (int j = 0; j < 100; j++) { |
73 | | - lh.asyncAddEntry("foobar".getBytes(), new AddCallbackFuture(j), null); |
| 48 | + try { |
| 49 | + ZooKeeperWatcherBase watcher = new ZooKeeperWatcherBase(10000, true); |
| 50 | + ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000, watcher, |
| 51 | + sessionId, |
| 52 | + sessionPasswd); |
| 53 | + zk.close(); |
| 54 | + } catch (Exception e) { |
| 55 | + LOG.info("Error killing session", e); |
74 | 56 | } |
75 | | - startNewBookie(); |
76 | | - killBookie(0); |
| 57 | + } |
| 58 | + } catch (InterruptedException ie) { |
| 59 | + Thread.currentThread().interrupt(); |
| 60 | + return; |
| 61 | + } |
| 62 | + } |
| 63 | + }; |
| 64 | + expiryThread.start(); |
77 | 65 |
|
78 | | - lh.addEntry("lastEntry".getBytes()); |
| 66 | + for (int i = 0; i < 3; i++) { |
| 67 | + LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.MAC, "foobar".getBytes()); |
| 68 | + for (int j = 0; j < 100; j++) { |
| 69 | + lh.asyncAddEntry("foobar".getBytes(), new AddCallbackFuture(j), null); |
| 70 | + } |
| 71 | + startNewBookie(); |
| 72 | + killBookie(0); |
79 | 73 |
|
80 | | - lh.close(); |
81 | | - } |
| 74 | + lh.addEntry("lastEntry".getBytes()); |
| 75 | + |
| 76 | + lh.close(); |
82 | 77 | } |
| 78 | + } |
83 | 79 | } |
0 commit comments