com.ververica.cdc.connectors.utils.TestSourceContext Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2023 Ververica Inc.
*
* Licensed 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 com.ververica.cdc.connectors.utils;
import org.apache.flink.streaming.api.functions.source.SourceFunction;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
import java.util.concurrent.LinkedBlockingQueue;
/** A testable {@link SourceFunction.SourceContext}. */
public class TestSourceContext implements SourceFunction.SourceContext {
private final Object checkpointLock = new Object();
private LinkedBlockingQueue> collectedOutputs = new LinkedBlockingQueue<>();
@Override
public void collect(T element) {
this.collectedOutputs.add(new StreamRecord<>(element));
}
@Override
public void collectWithTimestamp(T element, long timestamp) {
this.collectedOutputs.offer(new StreamRecord<>(element, timestamp));
}
@Override
public void emitWatermark(Watermark mark) {
throw new UnsupportedOperationException();
}
@Override
public void markAsTemporarilyIdle() {}
@Override
public Object getCheckpointLock() {
return checkpointLock;
}
@Override
public void close() {}
public StreamRecord removeLatestOutput() {
return collectedOutputs.poll();
}
public LinkedBlockingQueue> getCollectedOutputs() {
return collectedOutputs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy