This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infinite retry policy to zookeeper client used by tests
This change is to improve the tests running on travis ci Author: jiazhai <zhaijia03@gmail.com> Reviewers: Sijie Guo <sijie@apache.org> Closes #25 from jiazhai/zhaijia/fix_federated_namespace
- Loading branch information
Showing
25 changed files
with
185 additions
and
102 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
distributedlog-core/src/main/java/com/twitter/distributedlog/util/RetryPolicyUtils.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,45 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 com.twitter.distributedlog.util; | ||
|
||
import org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy; | ||
import org.apache.bookkeeper.zookeeper.RetryPolicy; | ||
|
||
/** | ||
* Utils for {@link org.apache.bookkeeper.zookeeper.RetryPolicy} | ||
*/ | ||
public class RetryPolicyUtils { | ||
|
||
/** | ||
* Infinite retry policy | ||
*/ | ||
public static final RetryPolicy DEFAULT_INFINITE_RETRY_POLICY = infiniteRetry(200, 2000); | ||
|
||
/** | ||
* Create an infinite retry policy with backoff time between <i>baseBackOffTimeMs</i> and | ||
* <i>maxBackoffTimeMs</i>. | ||
* | ||
* @param baseBackoffTimeMs base backoff time in milliseconds | ||
* @param maxBackoffTimeMs maximum backoff time in milliseconds | ||
* @return an infinite retry policy | ||
*/ | ||
public static RetryPolicy infiniteRetry(long baseBackoffTimeMs, long maxBackoffTimeMs) { | ||
return new BoundExponentialBackoffRetryPolicy(baseBackoffTimeMs, maxBackoffTimeMs, Integer.MAX_VALUE); | ||
} | ||
|
||
} |
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
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
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
57 changes: 57 additions & 0 deletions
57
distributedlog-core/src/test/java/com/twitter/distributedlog/TestZooKeeperClientBuilder.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,57 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 com.twitter.distributedlog; | ||
|
||
import com.twitter.distributedlog.util.RetryPolicyUtils; | ||
import org.apache.bookkeeper.stats.NullStatsLogger; | ||
|
||
/** | ||
* The zookeeper client builder used for testing. | ||
*/ | ||
public class TestZooKeeperClientBuilder { | ||
|
||
/** | ||
* Return a zookeeper client builder for testing. | ||
* | ||
* @return a zookeeper client builder | ||
*/ | ||
public static ZooKeeperClientBuilder newBuilder() { | ||
return ZooKeeperClientBuilder.newBuilder() | ||
.retryPolicy(RetryPolicyUtils.DEFAULT_INFINITE_RETRY_POLICY) | ||
.connectionTimeoutMs(10000) | ||
.sessionTimeoutMs(60000) | ||
.zkAclId(null) | ||
.statsLogger(NullStatsLogger.INSTANCE); | ||
} | ||
|
||
/** | ||
* Create a zookeeper client builder with provided <i>conf</i> for testing. | ||
* | ||
* @param conf distributedlog configuration | ||
* @return zookeeper client builder | ||
*/ | ||
public static ZooKeeperClientBuilder newBuilder(DistributedLogConfiguration conf) { | ||
return ZooKeeperClientBuilder.newBuilder() | ||
.retryPolicy(RetryPolicyUtils.DEFAULT_INFINITE_RETRY_POLICY) | ||
.sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()) | ||
.zkAclId(conf.getZkAclId()) | ||
.retryThreadCount(conf.getZKClientNumberRetryThreads()) | ||
.requestRateLimit(conf.getZKRequestRateLimit()) | ||
.statsLogger(NullStatsLogger.INSTANCE); | ||
} | ||
} |
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
Oops, something went wrong.