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-17331][runtime] Explicitly get the ByteBuf length of all class…
…es which is written to NettyMessage Currently, the length of some header fields in NettyMessage is hardcoded: InputChannelID, ExecutionAttemptID, e.t.c. So if we make some changes for such field, then we are not ware that it also needs to change the respective length for related netty messages component. This PR explicitly get the ByteBuf length of all classes which is written to NettyMessage to avoid such problems.
- Loading branch information
Showing
7 changed files
with
203 additions
and
6 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
45 changes: 45 additions & 0 deletions
45
...runtime/src/test/java/org/apache/flink/runtime/executiongraph/ExecutionAttemptIDTest.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:https://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.executiongraph; | ||
|
||
import org.apache.flink.runtime.io.network.netty.NettyBufferPool; | ||
|
||
import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** Tests for {@link ExecutionAttemptID}. */ | ||
public class ExecutionAttemptIDTest { | ||
private static final NettyBufferPool ALLOCATOR = new NettyBufferPool(1); | ||
|
||
@Test | ||
public void testByteBufWriteAndRead() { | ||
final ExecutionAttemptID executionAttemptID = new ExecutionAttemptID(); | ||
final int byteBufLen = ExecutionAttemptID.getByteBufLength(); | ||
final ByteBuf byteBuf = ALLOCATOR.directBuffer(byteBufLen, byteBufLen); | ||
executionAttemptID.writeTo(byteBuf); | ||
|
||
assertThat(byteBuf.writerIndex(), is(equalTo(ExecutionAttemptID.getByteBufLength()))); | ||
assertThat(ExecutionAttemptID.fromByteBuf(byteBuf), is(equalTo(executionAttemptID))); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../test/java/org/apache/flink/runtime/io/network/partition/consumer/InputChannelIDTest.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:https://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.io.network.partition.consumer; | ||
|
||
import org.apache.flink.runtime.io.network.netty.NettyBufferPool; | ||
|
||
import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** Tests for {@link InputChannelID}. */ | ||
public class InputChannelIDTest { | ||
private static final NettyBufferPool ALLOCATOR = new NettyBufferPool(1); | ||
|
||
@Test | ||
public void testByteBufWriteAndRead() { | ||
final InputChannelID inputChannelID = new InputChannelID(); | ||
final int byteBufLen = InputChannelID.getByteBufLength(); | ||
final ByteBuf byteBuf = ALLOCATOR.directBuffer(byteBufLen, byteBufLen); | ||
inputChannelID.writeTo(byteBuf); | ||
|
||
assertThat(byteBuf.writerIndex(), is(equalTo(InputChannelID.getByteBufLength()))); | ||
assertThat(InputChannelID.fromByteBuf(byteBuf), is(equalTo(inputChannelID))); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...me/src/test/java/org/apache/flink/runtime/jobgraph/IntermediateResultPartitionIDTest.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,50 @@ | ||
/* | ||
* 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:https://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.jobgraph; | ||
|
||
import org.apache.flink.runtime.io.network.netty.NettyBufferPool; | ||
|
||
import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** Tests for {@link IntermediateResultPartitionID}. */ | ||
public class IntermediateResultPartitionIDTest { | ||
private static final NettyBufferPool ALLOCATOR = new NettyBufferPool(1); | ||
|
||
@Test | ||
public void testByteBufWriteAndRead() { | ||
final IntermediateResultPartitionID intermediateResultPartitionID = | ||
new IntermediateResultPartitionID(); | ||
final int byteBufLen = IntermediateResultPartitionID.getByteBufLength(); | ||
final ByteBuf byteBuf = ALLOCATOR.directBuffer(byteBufLen, byteBufLen); | ||
intermediateResultPartitionID.writeTo(byteBuf); | ||
|
||
assertThat( | ||
byteBuf.writerIndex(), | ||
is(equalTo(IntermediateResultPartitionID.getByteBufLength()))); | ||
assertThat( | ||
IntermediateResultPartitionID.fromByteBuf(byteBuf), | ||
is(equalTo(intermediateResultPartitionID))); | ||
} | ||
} |