forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-25920] Refactor & Revise SinkWriterOperatorTestBase
The stateful SinkWriterOperatorTestBase test cases used EOI to manipulate the state which was never clean. In particular, it also stored the input elements in state until EOI arrived and emitted them all at once. For state restoration tests, we emitted records after EOI arrived. This commit changed the writer state completely to just capture the record count, which is much more realistic than storing actual payload. The tests now directly assert on the state instead of output. This commit also introduces an adaptor for serializing basic types in the writer state and replaces the hard-to-maintain SinkAndSuppliers with an InspectableSink in the sink writer tests that require an abstraction on top of the different Sink flavors. (cherry picked from commit 4217408)
- Loading branch information
Showing
18 changed files
with
403 additions
and
475 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
flink-core/src/main/java/org/apache/flink/core/io/SimpleVersionedSerializerAdapter.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,58 @@ | ||
/* | ||
* 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.core.io; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
import org.apache.flink.api.common.typeutils.TypeSerializer; | ||
import org.apache.flink.core.memory.DataInputDeserializer; | ||
import org.apache.flink.core.memory.DataOutputSerializer; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* Adapter for {@link TypeSerializer} to {@link SimpleVersionedSerializer}. The implementation is | ||
* naive and should only be used for non-critical paths and tests. | ||
*/ | ||
@Internal | ||
public class SimpleVersionedSerializerAdapter<T> | ||
implements SimpleVersionedSerializer<T>, Serializable { | ||
private final TypeSerializer<T> serializer; | ||
|
||
public SimpleVersionedSerializerAdapter(TypeSerializer<T> serializer) { | ||
this.serializer = serializer; | ||
} | ||
|
||
public int getVersion() { | ||
return serializer.snapshotConfiguration().getCurrentVersion(); | ||
} | ||
|
||
public byte[] serialize(T value) throws IOException { | ||
DataOutputSerializer dataOutputSerializer = new DataOutputSerializer(10); | ||
serializer.serialize(value, dataOutputSerializer); | ||
return dataOutputSerializer.getCopyOfBuffer(); | ||
} | ||
|
||
public T deserialize(int version, byte[] serialized) throws IOException { | ||
DataInputDeserializer dataInputDeserializer = new DataInputDeserializer(serialized); | ||
T value = serializer.deserialize(dataInputDeserializer); | ||
dataInputDeserializer.releaseArrays(); | ||
return value; | ||
} | ||
} |
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
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.