Java Code Examples for org.apache.flink.streaming.api.windowing.time.Time#milliseconds()

The following examples show how to use org.apache.flink.streaming.api.windowing.time.Time#milliseconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoundedOutOfOrdernessTimestampExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialFinalAndWatermarkUnderflow() {
	BoundedOutOfOrdernessTimestampExtractor<Long> extractor = new LongExtractor(Time.milliseconds(10L));
	assertEquals(Long.MIN_VALUE, extractor.getCurrentWatermark().getTimestamp());

	extractor.extractTimestamp(Long.MIN_VALUE, -1L);

	// the following two lines check for underflow.
	// We have a max latency of 5 millis.
	// We insert an element with ts of Long.MIN_VALUE + 2, which will now be the max ts,
	// then when getting the next watermark, we would have Long.MIN_VALUE + 2 - 5 which
	// would lead to underflow.

	extractor.extractTimestamp(Long.MIN_VALUE + 2, -1);
	assertEquals(Long.MIN_VALUE, extractor.getCurrentWatermark().getTimestamp());

	extractor.extractTimestamp(Long.MAX_VALUE, -1L);
	assertEquals(Long.MAX_VALUE - 10, extractor.getCurrentWatermark().getTimestamp());
}
 
Example 2
Source File: BoundedOutOfOrdernessTimestampExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialFinalAndWatermarkUnderflow() {
	BoundedOutOfOrdernessTimestampExtractor<Long> extractor = new LongExtractor(Time.milliseconds(10L));
	assertEquals(Long.MIN_VALUE, extractor.getCurrentWatermark().getTimestamp());

	extractor.extractTimestamp(Long.MIN_VALUE, -1L);

	// the following two lines check for underflow.
	// We have a max latency of 5 millis.
	// We insert an element with ts of Long.MIN_VALUE + 2, which will now be the max ts,
	// then when getting the next watermark, we would have Long.MIN_VALUE + 2 - 5 which
	// would lead to underflow.

	extractor.extractTimestamp(Long.MIN_VALUE + 2, -1);
	assertEquals(Long.MIN_VALUE, extractor.getCurrentWatermark().getTimestamp());

	extractor.extractTimestamp(Long.MAX_VALUE, -1L);
	assertEquals(Long.MAX_VALUE - 10, extractor.getCurrentWatermark().getTimestamp());
}
 
Example 3
Source File: BoundedOutOfOrdernessTimestampExtractorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialFinalAndWatermarkUnderflow() {
	BoundedOutOfOrdernessTimestampExtractor<Long> extractor = new LongExtractor(Time.milliseconds(10L));
	assertEquals(Long.MIN_VALUE, extractor.getCurrentWatermark().getTimestamp());

	extractor.extractTimestamp(Long.MIN_VALUE, -1L);

	// the following two lines check for underflow.
	// We have a max latency of 5 millis.
	// We insert an element with ts of Long.MIN_VALUE + 2, which will now be the max ts,
	// then when getting the next watermark, we would have Long.MIN_VALUE + 2 - 5 which
	// would lead to underflow.

	extractor.extractTimestamp(Long.MIN_VALUE + 2, -1);
	assertEquals(Long.MIN_VALUE, extractor.getCurrentWatermark().getTimestamp());

	extractor.extractTimestamp(Long.MAX_VALUE, -1L);
	assertEquals(Long.MAX_VALUE - 10, extractor.getCurrentWatermark().getTimestamp());
}
 
Example 4
Source File: JoinedStreamsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAllowedLateness() {
	Time lateness = Time.milliseconds(42L);

	JoinedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.join(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getAllowedLateness().toMilliseconds());
}
 
Example 5
Source File: JoinedStreamsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAllowedLateness() {
	Time lateness = Time.milliseconds(42L);

	JoinedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.join(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getAllowedLateness().toMilliseconds());
}
 
Example 6
Source File: DataStreamAllroundTestJobFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
static BoundedOutOfOrdernessTimestampExtractor<Event> createTimestampExtractor(ParameterTool pt) {
	return new BoundedOutOfOrdernessTimestampExtractor<Event>(
		Time.milliseconds(
			pt.getLong(
				SEQUENCE_GENERATOR_SRC_EVENT_TIME_MAX_OUT_OF_ORDERNESS.key(),
				SEQUENCE_GENERATOR_SRC_EVENT_TIME_MAX_OUT_OF_ORDERNESS.defaultValue()))) {

		private static final long serialVersionUID = -3154419724891779938L;

		@Override
		public long extractTimestamp(Event element) {
			return element.getEventTime();
		}
	};
}
 
Example 7
Source File: BoundedOutOfOrdernessTimestampExtractorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitializationAndRuntime() {
	Time maxAllowedLateness = Time.milliseconds(10L);
	BoundedOutOfOrdernessTimestampExtractor<Long> extractor =
		new LongExtractor(maxAllowedLateness);

	assertEquals(maxAllowedLateness.toMilliseconds(),
		extractor.getMaxOutOfOrdernessInMillis());

	runValidTests(extractor);
}
 
Example 8
Source File: CoGroupedStreamsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAllowedLateness() {
	Time lateness = Time.milliseconds(42L);

	CoGroupedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.coGroup(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getAllowedLateness().toMilliseconds());
}
 
Example 9
Source File: CoGroupedStreamsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelegateToCoGrouped() {
	Time lateness = Time.milliseconds(42L);

	CoGroupedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.coGroup(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	withLateness.apply(coGroupFunction, BasicTypeInfo.STRING_TYPE_INFO);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getWindowedStream().getAllowedLateness());
}
 
Example 10
Source File: DataStreamAllroundTestJobFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static BoundedOutOfOrdernessTimestampExtractor<Event> createTimestampExtractor(ParameterTool pt) {
	return new BoundedOutOfOrdernessTimestampExtractor<Event>(
		Time.milliseconds(
			pt.getLong(
				SEQUENCE_GENERATOR_SRC_EVENT_TIME_MAX_OUT_OF_ORDERNESS.key(),
				SEQUENCE_GENERATOR_SRC_EVENT_TIME_MAX_OUT_OF_ORDERNESS.defaultValue()))) {

		private static final long serialVersionUID = -3154419724891779938L;

		@Override
		public long extractTimestamp(Event element) {
			return element.getEventTime();
		}
	};
}
 
Example 11
Source File: JoinedStreamsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelegateToCoGrouped() {
	Time lateness = Time.milliseconds(42L);

	JoinedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.join(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	withLateness.apply(joinFunction, BasicTypeInfo.STRING_TYPE_INFO);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getCoGroupedWindowedStream().getAllowedLateness().toMilliseconds());
}
 
Example 12
Source File: DataStreamAllroundTestJobFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
static BoundedOutOfOrdernessTimestampExtractor<Event> createTimestampExtractor(ParameterTool pt) {
	return new BoundedOutOfOrdernessTimestampExtractor<Event>(
		Time.milliseconds(
			pt.getLong(
				SEQUENCE_GENERATOR_SRC_EVENT_TIME_MAX_OUT_OF_ORDERNESS.key(),
				SEQUENCE_GENERATOR_SRC_EVENT_TIME_MAX_OUT_OF_ORDERNESS.defaultValue()))) {

		private static final long serialVersionUID = -3154419724891779938L;

		@Override
		public long extractTimestamp(Event element) {
			return element.getEventTime();
		}
	};
}
 
Example 13
Source File: BoundedOutOfOrdernessTimestampExtractorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitializationAndRuntime() {
	Time maxAllowedLateness = Time.milliseconds(10L);
	BoundedOutOfOrdernessTimestampExtractor<Long> extractor =
		new LongExtractor(maxAllowedLateness);

	assertEquals(maxAllowedLateness.toMilliseconds(),
		extractor.getMaxOutOfOrdernessInMillis());

	runValidTests(extractor);
}
 
Example 14
Source File: CoGroupedStreamsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAllowedLateness() {
	Time lateness = Time.milliseconds(42L);

	CoGroupedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.coGroup(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getAllowedLateness().toMilliseconds());
}
 
Example 15
Source File: CoGroupedStreamsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelegateToCoGrouped() {
	Time lateness = Time.milliseconds(42L);

	CoGroupedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.coGroup(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	withLateness.apply(coGroupFunction, BasicTypeInfo.STRING_TYPE_INFO);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getWindowedStream().getAllowedLateness());
}
 
Example 16
Source File: JoinedStreamsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAllowedLateness() {
	Time lateness = Time.milliseconds(42L);

	JoinedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.join(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getAllowedLateness().toMilliseconds());
}
 
Example 17
Source File: JoinedStreamsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelegateToCoGrouped() {
	Time lateness = Time.milliseconds(42L);

	JoinedStreams.WithWindow<String, String, String, TimeWindow> withLateness = dataStream1
		.join(dataStream2)
		.where(keySelector)
		.equalTo(keySelector)
		.window(tsAssigner)
		.allowedLateness(lateness);

	withLateness.apply(joinFunction, BasicTypeInfo.STRING_TYPE_INFO);

	Assert.assertEquals(lateness.toMilliseconds(), withLateness.getCoGroupedWindowedStream().getAllowedLateness().toMilliseconds());
}
 
Example 18
Source File: Sort.java    From flink-learning with Apache License 2.0 4 votes vote down vote up
public TimestampsAndWatermarks() {
    super(Time.milliseconds(OUT_OF_ORDERNESS));
}
 
Example 19
Source File: Sort.java    From flink-training-exercises with Apache License 2.0 4 votes vote down vote up
public TimestampsAndWatermarks() {
	super(Time.milliseconds(OUT_OF_ORDERNESS / 2));
}
 
Example 20
Source File: Sort.java    From flink-training-exercises with Apache License 2.0 4 votes vote down vote up
public TimestampsAndWatermarks() {
	super(Time.milliseconds(OUT_OF_ORDERNESS));
}