本文整理汇总了Java中org.apache.flink.api.common.state.ValueStateDescriptor.initializeSerializerUnlessSet方法的典型用法代码示例。如果您正苦于以下问题:Java ValueStateDescriptor.initializeSerializerUnlessSet方法的具体用法?Java ValueStateDescriptor.initializeSerializerUnlessSet怎么用?Java ValueStateDescriptor.initializeSerializerUnlessSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.common.state.ValueStateDescriptor
的用法示例。
在下文中一共展示了ValueStateDescriptor.initializeSerializerUnlessSet方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asQueryableState
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入方法依赖的package包/类
/**
* Publishes the keyed stream as a queryable ValueState instance.
*
* @param queryableStateName Name under which to the publish the queryable state instance
* @param stateDescriptor State descriptor to create state instance from
* @return Queryable state instance
*/
@PublicEvolving
public QueryableStateStream<KEY, T> asQueryableState(
String queryableStateName,
ValueStateDescriptor<T> stateDescriptor) {
transform("Queryable state: " + queryableStateName,
getType(),
new QueryableValueStateOperator<>(queryableStateName, stateDescriptor));
stateDescriptor.initializeSerializerUnlessSet(getExecutionConfig());
return new QueryableStateStream<>(
queryableStateName,
stateDescriptor,
getKeyType().createSerializer(getExecutionConfig()));
}
示例2: testDisposeDeletesAllDirectories
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入方法依赖的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());
}
示例3: getState
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入方法依赖的package包/类
@Override
public <T> ValueState<T> getState(ValueStateDescriptor<T> stateProperties) {
requireNonNull(stateProperties, "The state properties must not be null");
try {
stateProperties.initializeSerializerUnlessSet(executionConfig);
return getPartitionedState(stateProperties);
} catch (Exception e) {
throw new RuntimeException("Error while getting state", e);
}
}
示例4: testSharedIncrementalStateDeRegistration
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入方法依赖的package包/类
@Test
public void testSharedIncrementalStateDeRegistration() throws Exception {
if (enableIncrementalCheckpointing) {
AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
try {
ValueStateDescriptor<String> kvId =
new ValueStateDescriptor<>("id", String.class, null);
kvId.initializeSerializerUnlessSet(new ExecutionConfig());
ValueState<String> state =
backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
Queue<IncrementalKeyedStateHandle> previousStateHandles = new LinkedList<>();
SharedStateRegistry sharedStateRegistry = spy(new SharedStateRegistry());
for (int checkpointId = 0; checkpointId < 3; ++checkpointId) {
reset(sharedStateRegistry);
backend.setCurrentKey(checkpointId);
state.update("Hello-" + checkpointId);
RunnableFuture<KeyedStateHandle> snapshot = backend.snapshot(
checkpointId,
checkpointId,
createStreamFactory(),
CheckpointOptions.forCheckpoint());
snapshot.run();
IncrementalKeyedStateHandle stateHandle = (IncrementalKeyedStateHandle) snapshot.get();
Map<StateHandleID, StreamStateHandle> sharedState =
new HashMap<>(stateHandle.getSharedState());
stateHandle.registerSharedStates(sharedStateRegistry);
for (Map.Entry<StateHandleID, StreamStateHandle> e : sharedState.entrySet()) {
verify(sharedStateRegistry).registerReference(
stateHandle.createSharedStateRegistryKeyFromFileName(e.getKey()),
e.getValue());
}
previousStateHandles.add(stateHandle);
backend.notifyCheckpointComplete(checkpointId);
//-----------------------------------------------------------------
if (previousStateHandles.size() > 1) {
checkRemove(previousStateHandles.remove(), sharedStateRegistry);
}
}
while (!previousStateHandles.isEmpty()) {
reset(sharedStateRegistry);
checkRemove(previousStateHandles.remove(), sharedStateRegistry);
}
} finally {
IOUtils.closeQuietly(backend);
backend.dispose();
}
}
}
示例5: testKeyedStateRestoreFailsIfSerializerDeserializationFails
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入方法依赖的package包/类
/**
* Verifies that memory-backed keyed state backend fails with appropriate error and message if
* previous serializer can not be restored.
*/
@Test
public void testKeyedStateRestoreFailsIfSerializerDeserializationFails() throws Exception {
CheckpointStreamFactory streamFactory = createStreamFactory();
KeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, null);
kvId.initializeSerializerUnlessSet(new ExecutionConfig());
HeapKeyedStateBackend<Integer> heapBackend = (HeapKeyedStateBackend<Integer>) backend;
assertEquals(0, heapBackend.numStateEntries());
ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
// write some state
backend.setCurrentKey(0);
state.update("hello");
state.update("ciao");
KeyedStateHandle snapshot = runSnapshot(((HeapKeyedStateBackend<Integer>) backend).snapshot(
682375462378L,
2,
streamFactory,
CheckpointOptions.forCheckpoint()));
backend.dispose();
// ========== restore snapshot ==========
Environment env = mock(Environment.class);
when(env.getExecutionConfig()).thenReturn(new ExecutionConfig());
when(env.getUserClassLoader()).thenReturn(OperatorStateBackendTest.class.getClassLoader());
// mock failure when deserializing serializer
TypeSerializerSerializationUtil.TypeSerializerSerializationProxy<?> mockProxy =
mock(TypeSerializerSerializationUtil.TypeSerializerSerializationProxy.class);
doThrow(new IOException()).when(mockProxy).read(any(DataInputViewStreamWrapper.class));
PowerMockito.whenNew(TypeSerializerSerializationUtil.TypeSerializerSerializationProxy.class).withAnyArguments().thenReturn(mockProxy);
try {
restoreKeyedBackend(IntSerializer.INSTANCE, snapshot, env);
fail("The keyed state restore should have failed if the previous state serializer could not be loaded.");
} catch (IOException expected) {
Assert.assertTrue(expected.getMessage().contains("Unable to restore keyed state"));
}
}
示例6: getState
import org.apache.flink.api.common.state.ValueStateDescriptor; //导入方法依赖的package包/类
@Override
public <T> ValueState<T> getState(ValueStateDescriptor<T> stateProperties) {
KeyedStateStore keyedStateStore = checkPreconditionsAndGetKeyedStateStore(stateProperties);
stateProperties.initializeSerializerUnlessSet(getExecutionConfig());
return keyedStateStore.getState(stateProperties);
}