hlteoh37 commented on code in PR #20245:
URL: https://github.com/apache/flink/pull/20245#discussion_r918861002


##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/sink/writer/strategy/AIMDScalingStrategyTest.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.flink.connector.base.sink.writer.strategy;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+/** Test class for {@link AIMDScalingStrategy}. */
+public class AIMDScalingStrategyTest {
+
+    @Test
+    public void testScaleUpAdditively() {
+        final int increaseRate = 10;
+        final int currentRate = 4;
+
+        AIMDScalingStrategy scalingStrategy =
+                AIMDScalingStrategy.builder()
+                        .setIncreaseRate(increaseRate)
+                        .setDecreaseFactor(0.5)
+                        .setRateThreshold(1000)
+                        .build();
+
+        
assertThat(scalingStrategy.scaleUp(currentRate)).isEqualTo(increaseRate + 
currentRate);
+    }
+
+    @Test
+    public void testScaleUpRespectsRateThreshold() {
+        final int increaseRate = 10;
+        final int currentRate = 14;
+        final int rateThreshold = 20;
+
+        AIMDScalingStrategy scalingStrategy =
+                AIMDScalingStrategy.builder()
+                        .setIncreaseRate(increaseRate)
+                        .setDecreaseFactor(0.5)
+                        .setRateThreshold(rateThreshold)
+                        .build();
+
+        assertThat(scalingStrategy.scaleUp(increaseRate + 
currentRate)).isEqualTo(rateThreshold);
+    }
+
+    @Test
+    public void testScaleDownByFactor() {
+        final double decreaseFactor = 0.4;
+
+        AIMDScalingStrategy scalingStrategy =
+                AIMDScalingStrategy.builder()
+                        .setIncreaseRate(10)
+                        .setDecreaseFactor(decreaseFactor)
+                        .setRateThreshold(1000)
+                        .build();
+
+        // roundDown(10 * 0.4 = 4) = 4
+        assertThat(scalingStrategy.scaleDown(10)).isEqualTo(4);
+
+        // roundDown(314 * 0.4 = 125.6) = 125

Review Comment:
   Good catch



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to