本文整理汇总了Java中org.apache.flink.api.common.state.ValueState.clear方法的典型用法代码示例。如果您正苦于以下问题:Java ValueState.clear方法的具体用法?Java ValueState.clear怎么用?Java ValueState.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.common.state.ValueState
的用法示例。
在下文中一共展示了ValueState.clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
示例3: testValueStateNullUpdate
import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
/**
* This test verifies that passing {@code null} to {@link ValueState#update(Object)} acts
* the same as {@link ValueState#clear()}.
*
* @throws Exception
*/
@Test
@SuppressWarnings("unchecked")
public void testValueStateNullUpdate() throws Exception {
// precondition: LongSerializer must fail on null value. this way the test would fail
// later if null values where actually stored in the state instead of acting as clear()
try {
LongSerializer.INSTANCE.serialize(null,
new DataOutputViewStreamWrapper(new ByteArrayOutputStream()));
fail("Should fail with NullPointerException");
} catch (NullPointerException e) {
// alrighty
}
CheckpointStreamFactory streamFactory = createStreamFactory();
AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
ValueStateDescriptor<Long> kvId = new ValueStateDescriptor<>("id", LongSerializer.INSTANCE, 42L);
ValueState<Long> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
// some modifications to the state
backend.setCurrentKey(1);
// verify default value
assertEquals(42L, (long) state.value());
state.update(1L);
assertEquals(1L, (long) state.value());
backend.setCurrentKey(2);
assertEquals(42L, (long) state.value());
backend.setCurrentKey(1);
state.clear();
assertEquals(42L, (long) state.value());
state.update(17L);
assertEquals(17L, (long) state.value());
state.update(null);
assertEquals(42L, (long) state.value());
// draw a snapshot
KeyedStateHandle snapshot1 = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpoint()));
backend.dispose();
backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot1);
snapshot1.discardState();
backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
backend.dispose();
}
示例4: testNumStateEntries
import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testNumStateEntries() throws Exception {
AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class);
assertEquals(0, backend.numStateEntries());
ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
backend.setCurrentKey(0);
state.update("hello");
state.update("ciao");
assertEquals(1, backend.numStateEntries());
backend.setCurrentKey(42);
state.update("foo");
assertEquals(2, backend.numStateEntries());
backend.setCurrentKey(0);
state.clear();
assertEquals(1, backend.numStateEntries());
backend.setCurrentKey(42);
state.clear();
assertEquals(0, backend.numStateEntries());
backend.dispose();
}