org.apache.flink.runtime.state.ttl.StateBackendTestContext Java Examples

The following examples show how to use org.apache.flink.runtime.state.ttl.StateBackendTestContext. 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: RocksDBTtlStateTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected StateBackendTestContext createStateBackendTestContext(TtlTimeProvider timeProvider) {
	return new StateBackendTestContext(timeProvider) {
		@Override
		protected StateBackend createStateBackend() {
			return RocksDBTtlStateTestBase.this.createStateBackend();
		}
	};
}
 
Example #2
Source File: RocksDBTtlStateTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected StateBackendTestContext createStateBackendTestContext(TtlTimeProvider timeProvider) {
	return new StateBackendTestContext(timeProvider) {
		@Override
		protected StateBackend createStateBackend() {
			return RocksDBTtlStateTestBase.this.createStateBackend();
		}
	};
}
 
Example #3
Source File: RocksDBTtlStateTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected StateBackendTestContext createStateBackendTestContext(TtlTimeProvider timeProvider) {
	return new StateBackendTestContext(timeProvider) {
		@Override
		protected StateBackend createStateBackend() {
			return RocksDBTtlStateTestBase.this.createStateBackend();
		}
	};
}
 
Example #4
Source File: RocksDBTtlStateTestBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("resource")
private void testCompactFilter(boolean takeSnapshot, boolean rescaleAfterRestore) throws Exception {
	int numberOfKeyGroupsAfterRestore = StateBackendTestContext.NUMBER_OF_KEY_GROUPS;
	if (rescaleAfterRestore) {
		numberOfKeyGroupsAfterRestore *= 2;
	}

	StateDescriptor<?, ?> stateDesc = initTest(getConfBuilder(TTL)
		.cleanupInBackground()
		.setStateVisibility(StateTtlConfig.StateVisibility.ReturnExpiredIfNotCleanedUp)
		.build());

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 0L);

	sbetc.setCurrentKey("k1");
	ctx().update(ctx().updateEmpty);
	checkUnexpiredOriginalAvailable();

	sbetc.setCurrentKey("k2");
	ctx().update(ctx().updateEmpty);
	checkUnexpiredOriginalAvailable();

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 50L);

	sbetc.setCurrentKey("k1");
	checkUnexpiredOriginalAvailable();
	assertEquals(UNEXPIRED_AVAIL, ctx().getUpdateEmpty, ctx().get());

	ctx().update(ctx().updateUnexpired);
	checkUnexpiredOriginalAvailable();

	sbetc.setCurrentKey("k2");
	checkUnexpiredOriginalAvailable();
	assertEquals(UNEXPIRED_AVAIL, ctx().getUpdateEmpty, ctx().get());

	ctx().update(ctx().updateUnexpired);
	checkUnexpiredOriginalAvailable();

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	// compaction which should not touch unexpired data
	// and merge list element with different expiration time
	setTimeAndCompact(stateDesc, 80L);
	// expire oldest data
	setTimeAndCompact(stateDesc, 120L);

	sbetc.setCurrentKey("k1");
	checkUnexpiredOriginalAvailable();
	assertEquals(UPDATED_UNEXPIRED_AVAIL, ctx().getUnexpired, ctx().get());

	sbetc.setCurrentKey("k2");
	checkUnexpiredOriginalAvailable();
	assertEquals(UPDATED_UNEXPIRED_AVAIL, ctx().getUnexpired, ctx().get());

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 170L);
	sbetc.setCurrentKey("k1");
	assertEquals("Expired original state should be unavailable", ctx().emptyValue, ctx().getOriginal());
	assertEquals(EXPIRED_UNAVAIL, ctx().emptyValue, ctx().get());

	sbetc.setCurrentKey("k2");
	assertEquals("Expired original state should be unavailable", ctx().emptyValue, ctx().getOriginal());
	assertEquals("Expired state should be unavailable", ctx().emptyValue, ctx().get());
}
 
Example #5
Source File: RocksDBTtlStateTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("resource")
private void testCompactFilter(boolean takeSnapshot, boolean rescaleAfterRestore) throws Exception {
	int numberOfKeyGroupsAfterRestore = StateBackendTestContext.NUMBER_OF_KEY_GROUPS;
	if (rescaleAfterRestore) {
		numberOfKeyGroupsAfterRestore *= 2;
	}

	StateDescriptor<?, ?> stateDesc = initTest(getConfBuilder(TTL)
		.cleanupInBackground()
		.setStateVisibility(StateTtlConfig.StateVisibility.ReturnExpiredIfNotCleanedUp)
		.build());

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 0L);

	sbetc.setCurrentKey("k1");
	ctx().update(ctx().updateEmpty);
	checkUnexpiredOriginalAvailable();

	sbetc.setCurrentKey("k2");
	ctx().update(ctx().updateEmpty);
	checkUnexpiredOriginalAvailable();

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 50L);

	sbetc.setCurrentKey("k1");
	checkUnexpiredOriginalAvailable();
	assertEquals(UNEXPIRED_AVAIL, ctx().getUpdateEmpty, ctx().get());

	ctx().update(ctx().updateUnexpired);
	checkUnexpiredOriginalAvailable();

	sbetc.setCurrentKey("k2");
	checkUnexpiredOriginalAvailable();
	assertEquals(UNEXPIRED_AVAIL, ctx().getUpdateEmpty, ctx().get());

	ctx().update(ctx().updateUnexpired);
	checkUnexpiredOriginalAvailable();

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	// compaction which should not touch unexpired data
	// and merge list element with different expiration time
	setTimeAndCompact(stateDesc, 80L);
	// expire oldest data
	setTimeAndCompact(stateDesc, 120L);

	sbetc.setCurrentKey("k1");
	checkUnexpiredOriginalAvailable();
	assertEquals(UPDATED_UNEXPIRED_AVAIL, ctx().getUnexpired, ctx().get());

	sbetc.setCurrentKey("k2");
	checkUnexpiredOriginalAvailable();
	assertEquals(UPDATED_UNEXPIRED_AVAIL, ctx().getUnexpired, ctx().get());

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 170L);
	sbetc.setCurrentKey("k1");
	assertEquals("Expired original state should be unavailable", ctx().emptyValue, ctx().getOriginal());
	assertEquals(EXPIRED_UNAVAIL, ctx().emptyValue, ctx().get());

	sbetc.setCurrentKey("k2");
	assertEquals("Expired original state should be unavailable", ctx().emptyValue, ctx().getOriginal());
	assertEquals("Expired state should be unavailable", ctx().emptyValue, ctx().get());
}
 
Example #6
Source File: RocksDBTtlStateTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("resource")
private void testCompactFilter(boolean takeSnapshot, boolean rescaleAfterRestore) throws Exception {
	int numberOfKeyGroupsAfterRestore = StateBackendTestContext.NUMBER_OF_KEY_GROUPS;
	if (rescaleAfterRestore) {
		numberOfKeyGroupsAfterRestore *= 2;
	}

	StateDescriptor<?, ?> stateDesc = initTest(getConfBuilder(TTL)
		.setStateVisibility(StateTtlConfig.StateVisibility.ReturnExpiredIfNotCleanedUp)
		.build());

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 0L);

	sbetc.setCurrentKey("k1");
	ctx().update(ctx().updateEmpty);
	checkUnexpiredOriginalAvailable();

	sbetc.setCurrentKey("k2");
	ctx().update(ctx().updateEmpty);
	checkUnexpiredOriginalAvailable();

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 50L);

	sbetc.setCurrentKey("k1");
	checkUnexpiredOriginalAvailable();
	assertEquals(UNEXPIRED_AVAIL, ctx().getUpdateEmpty, ctx().get());

	ctx().update(ctx().updateUnexpired);
	checkUnexpiredOriginalAvailable();

	sbetc.setCurrentKey("k2");
	checkUnexpiredOriginalAvailable();
	assertEquals(UNEXPIRED_AVAIL, ctx().getUpdateEmpty, ctx().get());

	ctx().update(ctx().updateUnexpired);
	checkUnexpiredOriginalAvailable();

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	// compaction which should not touch unexpired data
	// and merge list element with different expiration time
	setTimeAndCompact(stateDesc, 80L);
	// expire oldest data
	setTimeAndCompact(stateDesc, 120L);

	sbetc.setCurrentKey("k1");
	checkUnexpiredOriginalAvailable();
	assertEquals(UPDATED_UNEXPIRED_AVAIL, ctx().getUnexpired, ctx().get());

	sbetc.setCurrentKey("k2");
	checkUnexpiredOriginalAvailable();
	assertEquals(UPDATED_UNEXPIRED_AVAIL, ctx().getUnexpired, ctx().get());

	if (takeSnapshot) {
		takeAndRestoreSnapshot(numberOfKeyGroupsAfterRestore);
	}

	setTimeAndCompact(stateDesc, 170L);
	sbetc.setCurrentKey("k1");
	assertTrue("Expired original state should be unavailable", ctx().isOriginalEmptyValue());
	assertEquals(EXPIRED_UNAVAIL, ctx().emptyValue, ctx().get());

	sbetc.setCurrentKey("k2");
	assertTrue("Expired original state should be unavailable", ctx().isOriginalEmptyValue());
	assertEquals("Expired state should be unavailable", ctx().emptyValue, ctx().get());
}