You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by dh...@apache.org on 2017/04/19 00:52:16 UTC
[4/8] beam git commit: Delete AttemptBoundedExponentialBackoff
Delete AttemptBoundedExponentialBackoff
and tests
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/c9e61329
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/c9e61329
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/c9e61329
Branch: refs/heads/master
Commit: c9e61329c2e0331a555711541b1e91d19482188b
Parents: 403a736
Author: Dan Halperin <dh...@google.com>
Authored: Mon Apr 17 23:41:39 2017 -0700
Committer: Dan Halperin <dh...@google.com>
Committed: Tue Apr 18 16:22:51 2017 -0700
----------------------------------------------------------------------
.../dataflow/DataflowPipelineJobTest.java | 2 +-
.../util/AttemptBoundedExponentialBackOff.java | 86 --------------------
.../AttemptBoundedExponentialBackOffTest.java | 85 -------------------
3 files changed, 1 insertion(+), 172 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/beam/blob/c9e61329/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowPipelineJobTest.java
----------------------------------------------------------------------
diff --git a/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowPipelineJobTest.java b/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowPipelineJobTest.java
index e7f2b48..9cab5e8 100644
--- a/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowPipelineJobTest.java
+++ b/runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowPipelineJobTest.java
@@ -133,7 +133,7 @@ public class DataflowPipelineJobTest {
/**
* Validates that a given time is valid for the total time slept by a
- * AttemptBoundedExponentialBackOff given the number of retries and
+ * BackOff given the number of retries and
* an initial polling interval.
*
* @param pollingInterval The initial polling interval given.
http://git-wip-us.apache.org/repos/asf/beam/blob/c9e61329/sdks/java/core/src/main/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOff.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOff.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOff.java
deleted file mode 100644
index 8f6f854..0000000
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOff.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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 org.apache.beam.sdk.util;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import com.google.api.client.util.BackOff;
-
-
-/**
- * Implementation of {@link BackOff} that increases the back off period for each retry attempt
- * using a randomization function that grows exponentially.
- *
- * <p>Example: The initial interval is .5 seconds and the maximum number of retries is 10.
- * For 10 tries the sequence will be (values in seconds):
- *
- * <pre>
- * retry# retry_interval randomized_interval
- * 1 0.5 [0.25, 0.75]
- * 2 0.75 [0.375, 1.125]
- * 3 1.125 [0.562, 1.687]
- * 4 1.687 [0.8435, 2.53]
- * 5 2.53 [1.265, 3.795]
- * 6 3.795 [1.897, 5.692]
- * 7 5.692 [2.846, 8.538]
- * 8 8.538 [4.269, 12.807]
- * 9 12.807 [6.403, 19.210]
- * 10 {@link BackOff#STOP}
- * </pre>
- *
- * <p>Implementation is not thread-safe.
- */
-@Deprecated
-public class AttemptBoundedExponentialBackOff implements BackOff {
- public static final double DEFAULT_MULTIPLIER = 1.5;
- public static final double DEFAULT_RANDOMIZATION_FACTOR = 0.5;
- private final int maximumNumberOfAttempts;
- private final long initialIntervalMillis;
- private int currentAttempt;
-
- public AttemptBoundedExponentialBackOff(int maximumNumberOfAttempts, long initialIntervalMillis) {
- checkArgument(maximumNumberOfAttempts > 0,
- "Maximum number of attempts must be greater than zero.");
- checkArgument(initialIntervalMillis > 0, "Initial interval must be greater than zero.");
- this.maximumNumberOfAttempts = maximumNumberOfAttempts;
- this.initialIntervalMillis = initialIntervalMillis;
- reset();
- }
-
- @Override
- public void reset() {
- currentAttempt = 1;
- }
-
- @Override
- public long nextBackOffMillis() {
- if (currentAttempt >= maximumNumberOfAttempts) {
- return BackOff.STOP;
- }
- double currentIntervalMillis = initialIntervalMillis
- * Math.pow(DEFAULT_MULTIPLIER, currentAttempt - 1);
- double randomOffset = (Math.random() * 2 - 1)
- * DEFAULT_RANDOMIZATION_FACTOR * currentIntervalMillis;
- currentAttempt += 1;
- return Math.round(currentIntervalMillis + randomOffset);
- }
-
- public boolean atMaxAttempts() {
- return currentAttempt >= maximumNumberOfAttempts;
- }
-}
http://git-wip-us.apache.org/repos/asf/beam/blob/c9e61329/sdks/java/core/src/test/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOffTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOffTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOffTest.java
deleted file mode 100644
index 44e435e..0000000
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/AttemptBoundedExponentialBackOffTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 org.apache.beam.sdk.util;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.lessThan;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import com.google.api.client.util.BackOff;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link AttemptBoundedExponentialBackOff}. */
-@RunWith(JUnit4.class)
-@SuppressWarnings("deprecation") // test of deprecated class
-public class AttemptBoundedExponentialBackOffTest {
- @Rule public ExpectedException exception = ExpectedException.none();
-
- @Test
- public void testUsingInvalidInitialInterval() throws Exception {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage("Initial interval must be greater than zero.");
- new AttemptBoundedExponentialBackOff(10, 0L);
- }
-
- @Test
- public void testUsingInvalidMaximumNumberOfRetries() throws Exception {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage("Maximum number of attempts must be greater than zero.");
- new AttemptBoundedExponentialBackOff(-1, 10L);
- }
-
- @Test
- public void testThatFixedNumberOfAttemptsExits() throws Exception {
- BackOff backOff = new AttemptBoundedExponentialBackOff(3, 500);
- assertThat(backOff.nextBackOffMillis(), allOf(greaterThan(249L), lessThan(751L)));
- assertThat(backOff.nextBackOffMillis(), allOf(greaterThan(374L), lessThan(1126L)));
- assertEquals(BackOff.STOP, backOff.nextBackOffMillis());
- }
-
- @Test
- public void testThatResettingAllowsReuse() throws Exception {
- BackOff backOff = new AttemptBoundedExponentialBackOff(3, 500);
- assertThat(backOff.nextBackOffMillis(), allOf(greaterThan(249L), lessThan(751L)));
- assertThat(backOff.nextBackOffMillis(), allOf(greaterThan(374L), lessThan(1126L)));
- assertEquals(BackOff.STOP, backOff.nextBackOffMillis());
- backOff.reset();
- assertThat(backOff.nextBackOffMillis(), allOf(greaterThan(249L), lessThan(751L)));
- assertThat(backOff.nextBackOffMillis(), allOf(greaterThan(374L), lessThan(1126L)));
- assertEquals(BackOff.STOP, backOff.nextBackOffMillis());
- }
-
- @Test
- public void testAtMaxAttempts() throws Exception {
- AttemptBoundedExponentialBackOff backOff = new AttemptBoundedExponentialBackOff(3, 500);
- assertFalse(backOff.atMaxAttempts());
- backOff.nextBackOffMillis();
- assertFalse(backOff.atMaxAttempts());
- backOff.nextBackOffMillis();
- assertTrue(backOff.atMaxAttempts());
- assertEquals(BackOff.STOP, backOff.nextBackOffMillis());
- }
-}