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


Java ValueState.clear方法代码示例

本文整理汇总了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();
}
 
开发者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: 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();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:60,代码来源:StateBackendTestBase.java

示例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();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:35,代码来源:StateBackendTestBase.java


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