Skip to content

Commit 8a18b11

Browse files
plugatarevreswqa
authored andcommitted
[FLINK-21943][core] Remove redundant checkNotNull in Transformation#setResources
1 parent a447096 commit 8a18b11

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

flink-core/src/main/java/org/apache/flink/api/dag/Transformation.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javax.annotation.Nullable;
3434

3535
import java.util.Collections;
36+
import java.util.EnumMap;
3637
import java.util.HashMap;
3738
import java.util.HashSet;
3839
import java.util.List;
@@ -42,7 +43,6 @@
4243
import java.util.concurrent.atomic.AtomicInteger;
4344

4445
import static org.apache.flink.util.Preconditions.checkArgument;
45-
import static org.apache.flink.util.Preconditions.checkNotNull;
4646

4747
/**
4848
* A {@code Transformation} represents the operation that creates a DataStream. Every DataStream has
@@ -160,7 +160,7 @@ public static int getNewNodeId() {
160160
* will be shared by all the declaring transformations within a slot according to this weight.
161161
*/
162162
private final Map<ManagedMemoryUseCase, Integer> managedMemoryOperatorScopeUseCaseWeights =
163-
new HashMap<>();
163+
new EnumMap<>(ManagedMemoryUseCase.class);
164164

165165
/**
166166
* This map is a cache that stores transitive predecessors and used in {@code
@@ -306,8 +306,8 @@ public void setMaxParallelism(int maxParallelism) {
306306
*/
307307
public void setResources(ResourceSpec minResources, ResourceSpec preferredResources) {
308308
OperatorValidationUtils.validateMinAndPreferredResources(minResources, preferredResources);
309-
this.minResources = checkNotNull(minResources);
310-
this.preferredResources = checkNotNull(preferredResources);
309+
this.minResources = minResources;
310+
this.preferredResources = preferredResources;
311311
}
312312

313313
/**

flink-core/src/test/java/org/apache/flink/api/dag/TransformationTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.flink.api.dag;
2020

21+
import org.apache.flink.api.common.operators.ResourceSpec;
2122
import org.apache.flink.api.common.typeinfo.TypeInformation;
2223
import org.apache.flink.core.memory.ManagedMemoryUseCase;
2324
import org.apache.flink.core.testutils.CheckedThread;
@@ -134,6 +135,16 @@ void testDeclareManagedMemorySlotScopeUseCaseFailWrongScope() {
134135
.isInstanceOf(IllegalArgumentException.class);
135136
}
136137

138+
@Test
139+
void testSetResourcesUseCaseFailNullResources() {
140+
ResourceSpec resourceSpec = ResourceSpec.newBuilder(1.0, 100).build();
141+
142+
assertThatThrownBy(() -> transformation.setResources(null, resourceSpec))
143+
.isInstanceOf(NullPointerException.class);
144+
assertThatThrownBy(() -> transformation.setResources(resourceSpec, null))
145+
.isInstanceOf(NullPointerException.class);
146+
}
147+
137148
/** A test implementation of {@link Transformation}. */
138149
private static class TestTransformation<T> extends Transformation<T> {
139150

0 commit comments

Comments
 (0)