当前位置: 首页>>代码示例>>Java>>正文


Java ValueState类代码示例

本文整理汇总了Java中org.apache.flink.api.common.state.ValueState的典型用法代码示例。如果您正苦于以下问题:Java ValueState类的具体用法?Java ValueState怎么用?Java ValueState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ValueState类属于org.apache.flink.api.common.state包,在下文中一共展示了ValueState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testValueStateNullAsDefaultValue

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
/**
 * Verify that {@link ValueStateDescriptor} allows {@code null} as default.
 */
@Test
public void testValueStateNullAsDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, null);

	ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.value());

	state.update("Ciao");
	assertEquals("Ciao", state.value());

	state.clear();
	assertNull(state.value());

	backend.dispose();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:StateBackendTestBase.java

示例2: testValueStateDefaultValue

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
/**
 * Verify that an empty {@code ValueState} will yield the default value.
 */
@Test
public void testValueStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, "Hello");

	ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertEquals("Hello", state.value());

	state.update("Ciao");
	assertEquals("Ciao", state.value());

	state.clear();
	assertEquals("Hello", state.value());

	backend.dispose();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:StateBackendTestBase.java

示例3: testCopyDefaultValue

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Test
public void testCopyDefaultValue() throws Exception {
	final AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ValueStateDescriptor<IntValue> kvId = new ValueStateDescriptor<>("id", IntValue.class, new IntValue(-1));

	ValueState<IntValue> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	IntValue default1 = state.value();

	backend.setCurrentKey(2);
	IntValue default2 = state.value();

	assertNotNull(default1);
	assertNotNull(default2);
	assertEquals(default1, default2);
	assertFalse(default1 == default2);

	backend.dispose();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:StateBackendTestBase.java

示例4: getKeyValueState

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public <S extends Serializable> ValueState<S> getKeyValueState(String name,
	Class<S> stateType,
	S defaultState) {
	checkNotNull(stateType, "The state type class must not be null");

	TypeInformation<S> typeInfo;
	try {
		typeInfo = TypeExtractor.getForClass(stateType);
	}
	catch (Exception e) {
		throw new RuntimeException("Cannot analyze type '" + stateType.getName() +
			"' from the class alone, due to generic type parameters. " +
			"Please specify the TypeInformation directly.", e);
	}

	return getKeyValueState(name, typeInfo, defaultState);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:WindowOperator.java

示例5: flatMap

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
	out.collect(value);

	ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
	if (state == null) {
		throw new RuntimeException("Missing key value state for " + value);
	}

	assertEquals(value.f1, state.value());
	getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:StatefulJobSavepointFrom12MigrationITCase.java

示例6: processElement

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void processElement(StreamRecord<Tuple2<Long, Long>> element) throws Exception {
	ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
			element.getValue().f0,
			LongSerializer.INSTANCE,
			stateDescriptor);

	assertEquals(state.value(), element.getValue().f1);
	getRuntimeContext().getAccumulator(SUCCESSFUL_PROCESS_CHECK_ACCUMULATOR).add(1);

	output.collect(element);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:StatefulJobSavepointFrom12MigrationITCase.java

示例7: onEventTime

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void onEventTime(InternalTimer<Long, Long> timer) throws Exception {
	ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
			timer.getNamespace(),
			LongSerializer.INSTANCE,
			stateDescriptor);

	assertEquals(state.value(), timer.getNamespace());
	getRuntimeContext().getAccumulator(SUCCESSFUL_EVENT_TIME_CHECK_ACCUMULATOR).add(1);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:11,代码来源:StatefulJobSavepointFrom12MigrationITCase.java

示例8: onProcessingTime

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void onProcessingTime(InternalTimer<Long, Long> timer) throws Exception {
	ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
			timer.getNamespace(),
			LongSerializer.INSTANCE,
			stateDescriptor);

	assertEquals(state.value(), timer.getNamespace());
	getRuntimeContext().getAccumulator(SUCCESSFUL_PROCESSING_TIME_CHECK_ACCUMULATOR).add(1);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:11,代码来源:StatefulJobSavepointFrom12MigrationITCase.java

示例9: flatMap

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
	out.collect(value);

	ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
	if (state == null) {
		throw new RuntimeException("Missing key value state for " + value);
	}

	assertEquals(value.f1, state.value());
	assertEquals(LegacyCheckpointedFlatMap.checkpointedTuple, restoredState);
	getRuntimeContext().getAccumulator(SUCCESSFUL_CHECK_ACCUMULATOR).add(1);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:StatefulJobSavepointFrom11MigrationITCase.java

示例10: flatMap

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
	out.collect(value);

	ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
	if (state == null) {
		throw new RuntimeException("Missing key value state for " + value);
	}

	assertEquals(value.f1, state.value());
	assertEquals(LegacyCheckpointedFlatMap.CHECKPOINTED_TUPLE, restoredState);
	getRuntimeContext().getAccumulator(SUCCESSFUL_CHECK_ACCUMULATOR).add(1);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:StatefulUDFSavepointMigrationITCase.java

示例11: testDisposeDeletesAllDirectories

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Test
public void testDisposeDeletesAllDirectories() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
	Collection<File> allFilesInDbDir =
		FileUtils.listFilesAndDirs(new File(dbPath), new AcceptAllFilter(), new AcceptAllFilter());
	try {
		ValueStateDescriptor<String> kvId =
			new ValueStateDescriptor<>("id", String.class, null);

		kvId.initializeSerializerUnlessSet(new ExecutionConfig());

		ValueState<String> state =
			backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

		backend.setCurrentKey(1);
		state.update("Hello");

		// more than just the root directory
		assertTrue(allFilesInDbDir.size() > 1);
	} finally {
		IOUtils.closeQuietly(backend);
		backend.dispose();
	}
	allFilesInDbDir =
		FileUtils.listFilesAndDirs(new File(dbPath), new AcceptAllFilter(), new AcceptAllFilter());

	// just the root directory left
	assertEquals(1, allFilesInDbDir.size());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:30,代码来源:RocksDBStateBackendTest.java

示例12: open

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void open() throws Exception {
	super.open();

	// also get the state in open, this way we are sure that it was created before
	// we trigger the test checkpoint
	ValueState<String> state = getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE,
			new ValueStateDescriptor<>("count", StringSerializer.INSTANCE));

}
 
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:RocksDBAsyncSnapshotTest.java

示例13: processElement

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Override
public void processElement(StreamRecord<String> element) throws Exception {
	// we also don't care

	ValueState<String> state = getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE,
			new ValueStateDescriptor<>("count", StringSerializer.INSTANCE));

	state.update(element.getValue());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:RocksDBAsyncSnapshotTest.java

示例14: testKeyedCEPOperatorNFAUpdateTimes

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
@Test
public void testKeyedCEPOperatorNFAUpdateTimes() throws Exception {
	SelectCepOperator<Event, Integer, Map<String, List<Event>>> operator = CepOperatorTestUtilities.getKeyedCepOpearator(
		true,
		new SimpleNFAFactory());
	OneInputStreamOperatorTestHarness<Event, Map<String, List<Event>>> harness = CepOperatorTestUtilities.getCepTestHarness(operator);

	try {
		harness.open();

		final ValueState nfaOperatorState = (ValueState) Whitebox.<ValueState>getInternalState(operator, "nfaOperatorState");
		final ValueState nfaOperatorStateSpy = Mockito.spy(nfaOperatorState);
		Whitebox.setInternalState(operator, "nfaOperatorState", nfaOperatorStateSpy);

		Event startEvent = new Event(42, "c", 1.0);
		SubEvent middleEvent = new SubEvent(42, "a", 1.0, 10.0);
		Event endEvent = new Event(42, "b", 1.0);

		harness.processElement(new StreamRecord<>(startEvent, 1L));
		harness.processElement(new StreamRecord<>(new Event(42, "d", 1.0), 4L));
		harness.processElement(new StreamRecord<Event>(middleEvent, 4L));
		harness.processElement(new StreamRecord<>(endEvent, 4L));

		// verify the number of invocations NFA is updated
		Mockito.verify(nfaOperatorStateSpy, Mockito.times(2)).update(Mockito.any());

		// get and verify the output
		Queue<Object> result = harness.getOutput();

		assertEquals(1, result.size());

		verifyPattern(result.poll(), startEvent, middleEvent, endEvent);
	} finally {
		harness.close();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:37,代码来源:CEPOperatorTest.java

示例15: GenericReducingState

import org.apache.flink.api.common.state.ValueState; //导入依赖的package包/类
/**
 * Creates a new {@code ReducingState} that wraps the given {@link ValueState}. The
 * {@code ValueState} must have a default value of {@code null}.
 *
 * @param wrappedState The wrapped {@code ValueState}
 * @param reduceFunction The {@code ReduceFunction} to use for combining values.
 */
@SuppressWarnings("unchecked")
public GenericReducingState(ValueState<T> wrappedState, ReduceFunction<T> reduceFunction) {
	if (!(wrappedState instanceof KvState)) {
		throw new IllegalArgumentException("Wrapped state must be a KvState.");
	}
	this.wrappedState = (W) wrappedState;
	this.reduceFunction = reduceFunction;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:16,代码来源:GenericReducingState.java


注:本文中的org.apache.flink.api.common.state.ValueState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。