forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-30301][tests] Use NoOp HeartbeatServices in TaskExecutorTest
To introduce the no-op implementation, HeartbeatServices interface is extracted. Additionally, '-1' constant is moved from various places to HeartbeatManagerOptions.
- Loading branch information
1 parent
f8105bb
commit b4fe4a4
Showing
23 changed files
with
276 additions
and
114 deletions.
There are no files selected for viewing
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
93 changes: 93 additions & 0 deletions
93
flink-runtime/src/main/java/org/apache/flink/runtime/heartbeat/HeartbeatServicesImpl.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,93 @@ | ||
/* | ||
* 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.runtime.heartbeat; | ||
|
||
import org.apache.flink.runtime.clusterframework.types.ResourceID; | ||
import org.apache.flink.util.Preconditions; | ||
import org.apache.flink.util.concurrent.ScheduledExecutor; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import static org.apache.flink.configuration.HeartbeatManagerOptions.FAILED_RPC_DETECTION_DISABLED; | ||
|
||
/** A default {@link HeartbeatServices} implementation. */ | ||
public final class HeartbeatServicesImpl implements HeartbeatServices { | ||
|
||
/** Heartbeat interval for the created services. */ | ||
private final long heartbeatInterval; | ||
|
||
/** Heartbeat timeout for the created services. */ | ||
private final long heartbeatTimeout; | ||
|
||
private final int failedRpcRequestsUntilUnreachable; | ||
|
||
public HeartbeatServicesImpl(long heartbeatInterval, long heartbeatTimeout) { | ||
this(heartbeatInterval, heartbeatTimeout, FAILED_RPC_DETECTION_DISABLED); | ||
} | ||
|
||
public HeartbeatServicesImpl( | ||
long heartbeatInterval, long heartbeatTimeout, int failedRpcRequestsUntilUnreachable) { | ||
Preconditions.checkArgument( | ||
0L < heartbeatInterval, "The heartbeat interval must be larger than 0."); | ||
Preconditions.checkArgument( | ||
heartbeatInterval <= heartbeatTimeout, | ||
"The heartbeat timeout should be larger or equal than the heartbeat interval."); | ||
Preconditions.checkArgument( | ||
failedRpcRequestsUntilUnreachable > 0 | ||
|| failedRpcRequestsUntilUnreachable == FAILED_RPC_DETECTION_DISABLED, | ||
"The number of failed heartbeat RPC requests has to be larger than 0 or -1 (deactivated)."); | ||
|
||
this.heartbeatInterval = heartbeatInterval; | ||
this.heartbeatTimeout = heartbeatTimeout; | ||
this.failedRpcRequestsUntilUnreachable = failedRpcRequestsUntilUnreachable; | ||
} | ||
|
||
@Override | ||
public <I, O> HeartbeatManager<I, O> createHeartbeatManager( | ||
ResourceID resourceId, | ||
HeartbeatListener<I, O> heartbeatListener, | ||
ScheduledExecutor mainThreadExecutor, | ||
Logger log) { | ||
|
||
return new HeartbeatManagerImpl<>( | ||
heartbeatTimeout, | ||
failedRpcRequestsUntilUnreachable, | ||
resourceId, | ||
heartbeatListener, | ||
mainThreadExecutor, | ||
log); | ||
} | ||
|
||
@Override | ||
public <I, O> HeartbeatManager<I, O> createHeartbeatManagerSender( | ||
ResourceID resourceId, | ||
HeartbeatListener<I, O> heartbeatListener, | ||
ScheduledExecutor mainThreadExecutor, | ||
Logger log) { | ||
|
||
return new HeartbeatManagerSenderImpl<>( | ||
heartbeatInterval, | ||
heartbeatTimeout, | ||
failedRpcRequestsUntilUnreachable, | ||
resourceId, | ||
heartbeatListener, | ||
mainThreadExecutor, | ||
log); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
flink-runtime/src/main/java/org/apache/flink/runtime/heartbeat/NoOpHeartbeatServices.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,52 @@ | ||
/* | ||
* 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.runtime.heartbeat; | ||
|
||
import org.apache.flink.runtime.clusterframework.types.ResourceID; | ||
import org.apache.flink.util.concurrent.ScheduledExecutor; | ||
|
||
import org.slf4j.Logger; | ||
|
||
/** {@link HeartbeatServices} implementation which does nothing. */ | ||
public class NoOpHeartbeatServices implements HeartbeatServices { | ||
private static final NoOpHeartbeatServices INSTANCE = new NoOpHeartbeatServices(); | ||
|
||
private NoOpHeartbeatServices() {} | ||
|
||
@Override | ||
public <I, O> HeartbeatManager<I, O> createHeartbeatManager( | ||
ResourceID resourceId, | ||
HeartbeatListener<I, O> heartbeatListener, | ||
ScheduledExecutor mainThreadExecutor, | ||
Logger log) { | ||
return NoOpHeartbeatManager.getInstance(); | ||
} | ||
|
||
@Override | ||
public <I, O> HeartbeatManager<I, O> createHeartbeatManagerSender( | ||
ResourceID resourceId, | ||
HeartbeatListener<I, O> heartbeatListener, | ||
ScheduledExecutor mainThreadExecutor, | ||
Logger log) { | ||
return NoOpHeartbeatManager.getInstance(); | ||
} | ||
|
||
public static NoOpHeartbeatServices getInstance() { | ||
return 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
Oops, something went wrong.