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


Java ValueState.update方法代码示例

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


在下文中一共展示了ValueState.update方法的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: 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

示例4: 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

示例5: testGetKeys

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
public void testGetKeys() throws Exception {
	final int elementsToTest = 1000;
	String fieldName = "get-keys-test";
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
	try {
		ValueState<Integer> keyedState = backend.getOrCreateKeyedState(
			VoidNamespaceSerializer.INSTANCE,
			new ValueStateDescriptor<>(fieldName, IntSerializer.INSTANCE));
		((InternalValueState<VoidNamespace, Integer>) keyedState).setCurrentNamespace(VoidNamespace.INSTANCE);

		for (int key = 0; key < elementsToTest; key++) {
			backend.setCurrentKey(key);
			keyedState.update(key * 2);
		}

		try (Stream<Integer> keysStream = backend.getKeys(fieldName, VoidNamespace.INSTANCE).sorted()) {
			PrimitiveIterator.OfInt actualIterator = keysStream.mapToInt(value -> value.intValue()).iterator();

			for (int expectedKey = 0; expectedKey < elementsToTest; expectedKey++) {
				assertTrue(actualIterator.hasNext());
				assertEquals(expectedKey, actualIterator.nextInt());
			}

			assertFalse(actualIterator.hasNext());
		}
	}
	finally {
		IOUtils.closeQuietly(backend);
		backend.dispose();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:33,代码来源:StateBackendTestBase.java

示例6: testRestoreWithWrongKeySerializer

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
public void testRestoreWithWrongKeySerializer() throws Exception {
	CheckpointStreamFactory streamFactory = createStreamFactory();

	// use an IntSerializer at first
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

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

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

	// write some state
	backend.setCurrentKey(1);
	state.update("1");
	backend.setCurrentKey(2);
	state.update("2");

	// draw a snapshot
	KeyedStateHandle snapshot1 = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpoint()));

	backend.dispose();

	// restore with the wrong key serializer
	try {
		restoreKeyedBackend(DoubleSerializer.INSTANCE, snapshot1);

		fail("should recognize wrong key serializer");
	} catch (StateMigrationException ignored) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:32,代码来源:StateBackendTestBase.java

示例7: onElement

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Override
public TriggerResult onElement(T element, long timestamp, W window, TriggerContext ctx) throws Exception {
	ValueState<T> lastElementState = ctx.getPartitionedState(stateDesc);
	if (lastElementState.value() == null) {
		lastElementState.update(element);
		return TriggerResult.CONTINUE;
	}
	if (deltaFunction.getDelta(lastElementState.value(), element) > this.threshold) {
		lastElementState.update(element);
		return TriggerResult.FIRE;
	}
	return TriggerResult.CONTINUE;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:DeltaTrigger.java

示例8: testSharedIncrementalStateDeRegistration

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的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();
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:65,代码来源:RocksDBStateBackendTest.java

示例9: testChunkedResponse

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
/**
 * Tests that large responses are chunked.
 */
@Test
public void testChunkedResponse() throws Exception {
	KvStateRegistry registry = new KvStateRegistry();
	KvStateRequestStats stats = new AtomicKvStateRequestStats();

	KvStateServerHandler handler = new KvStateServerHandler(registry, TEST_THREAD_POOL, stats);
	EmbeddedChannel channel = new EmbeddedChannel(getFrameDecoder(), handler);

	int numKeyGroups = 1;
	AbstractStateBackend abstractBackend = new MemoryStateBackend();
	DummyEnvironment dummyEnv = new DummyEnvironment("test", 1, 0);
	dummyEnv.setKvStateRegistry(registry);
	AbstractKeyedStateBackend<Integer> backend = abstractBackend.createKeyedStateBackend(
			dummyEnv,
			new JobID(),
			"test_op",
			IntSerializer.INSTANCE,
			numKeyGroups,
			new KeyGroupRange(0, 0),
			registry.createTaskRegistry(dummyEnv.getJobID(), dummyEnv.getJobVertexId()));

	final TestRegistryListener registryListener = new TestRegistryListener();
	registry.registerListener(registryListener);

	// Register state
	ValueStateDescriptor<byte[]> desc = new ValueStateDescriptor<>("any", BytePrimitiveArraySerializer.INSTANCE);
	desc.setQueryable("vanilla");

	ValueState<byte[]> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE,
			desc);

	// Update KvState
	byte[] bytes = new byte[2 * channel.config().getWriteBufferHighWaterMark()];

	byte current = 0;
	for (int i = 0; i < bytes.length; i++) {
		bytes[i] = current++;
	}

	int key = 99812822;
	backend.setCurrentKey(key);
	state.update(bytes);

	// Request
	byte[] serializedKeyAndNamespace = KvStateRequestSerializer.serializeKeyAndNamespace(
			key,
			IntSerializer.INSTANCE,
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE);

	long requestId = Integer.MAX_VALUE + 182828L;

	assertTrue(registryListener.registrationName.equals("vanilla"));

	ByteBuf request = KvStateRequestSerializer.serializeKvStateRequest(
			channel.alloc(),
			requestId,
			registryListener.kvStateId,
			serializedKeyAndNamespace);

	// Write the request and wait for the response
	channel.writeInbound(request);

	Object msg = readInboundBlocking(channel);
	assertTrue("Not ChunkedByteBuf", msg instanceof ChunkedByteBuf);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:72,代码来源:KvStateServerHandlerTest.java

示例10: testKryoRegisteringRestoreResilienceWithRegisteredType

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
/**
 * Verify state restore resilience when:
 *  - snapshot was taken without any Kryo registrations, specific serializers or default serializers for the state type
 *  - restored with the state type registered (no specific serializer)
 *
 * This test should not fail, because de- / serialization of the state should not be performed with Kryo's default
 * {@link com.esotericsoftware.kryo.serializers.FieldSerializer}.
 */
@Test
public void testKryoRegisteringRestoreResilienceWithRegisteredType() throws Exception {
	CheckpointStreamFactory streamFactory = createStreamFactory();
	Environment env = new DummyEnvironment("test", 1, 0);
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE, env);

	TypeInformation<TestPojo> pojoType = new GenericTypeInfo<>(TestPojo.class);

	// make sure that we are in fact using the KryoSerializer
	assertTrue(pojoType.createSerializer(env.getExecutionConfig()) instanceof KryoSerializer);

	ValueStateDescriptor<TestPojo> kvId = new ValueStateDescriptor<>("id", pojoType);

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

	// ============== create snapshot - no Kryo registration or specific / default serializers ==============

	// make some more modifications
	backend.setCurrentKey(1);
	state.update(new TestPojo("u1", 1));

	backend.setCurrentKey(2);
	state.update(new TestPojo("u2", 2));

	KeyedStateHandle snapshot = runSnapshot(backend.snapshot(
			682375462378L,
			2,
			streamFactory,
			CheckpointOptions.forCheckpoint()));

	backend.dispose();

	// ====================================== restore snapshot  ======================================

	env.getExecutionConfig().registerKryoType(TestPojo.class);

	backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot, env);

	snapshot.discardState();

	state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
	backend.setCurrentKey(1);
	assertEquals(state.value(), new TestPojo("u1", 1));

	backend.setCurrentKey(2);
	assertEquals(state.value(), new TestPojo("u2", 2));

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

示例11: testMultipleValueStates

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testMultipleValueStates() throws Exception {
	CheckpointStreamFactory streamFactory = createStreamFactory();

	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			new DummyEnvironment("test_op", 1, 0));

	ValueStateDescriptor<String> desc1 = new ValueStateDescriptor<>("a-string", StringSerializer.INSTANCE);
	ValueStateDescriptor<Integer> desc2 = new ValueStateDescriptor<>("an-integer", IntSerializer.INSTANCE);

	ValueState<String> state1 = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc1);
	ValueState<Integer> state2 = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc2);

	// some modifications to the state
	backend.setCurrentKey(1);
	assertNull(state1.value());
	assertNull(state2.value());
	state1.update("1");

	// state2 should still have nothing
	assertEquals("1", state1.value());
	assertNull(state2.value());
	state2.update(13);

	// both have some state now
	assertEquals("1", state1.value());
	assertEquals(13, (int) state2.value());

	// draw a snapshot
	KeyedStateHandle snapshot1 = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpoint()));

	backend.dispose();
	backend = restoreKeyedBackend(
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			Collections.singletonList(snapshot1),
			new DummyEnvironment("test_op", 1, 0));

	snapshot1.discardState();

	backend.setCurrentKey(1);

	state1 = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc1);
	state2 = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc2);

	// verify that they are still the same
	assertEquals("1", state1.value());
	assertEquals(13, (int) state2.value());

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

示例12: 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

示例13: testValueStateRestoreWithWrongSerializers

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testValueStateRestoreWithWrongSerializers() throws Exception {
	CheckpointStreamFactory streamFactory = createStreamFactory();
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

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

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

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

		// draw a snapshot
		KeyedStateHandle snapshot1 = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpoint()));

		backend.dispose();
		// restore the first snapshot and validate it
		backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot1);
		snapshot1.discardState();

		@SuppressWarnings("unchecked")
		TypeSerializer<String> fakeStringSerializer =
			(TypeSerializer<String>) (TypeSerializer<?>) FloatSerializer.INSTANCE;

		try {
			kvId = new ValueStateDescriptor<>("id", fakeStringSerializer);

			state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

			state.value();

			fail("should recognize wrong serializers");
		} catch (StateMigrationException ignored) {
			// expected
		}
	} finally {
		backend.dispose();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:44,代码来源:StateBackendTestBase.java

示例14: testKeyedStateRestoreFailsIfSerializerDeserializationFails

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的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"));
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:52,代码来源:MemoryStateBackendTest.java

示例15: testChunkedResponse

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
/**
 * Tests that large responses are chunked.
 */
@Test
public void testChunkedResponse() throws Exception {
	KvStateRegistry registry = new KvStateRegistry();
	KvStateRequestStats stats = new AtomicKvStateRequestStats();

	MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
			new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());

	KvStateServerHandler handler = new KvStateServerHandler(testServer, registry, serializer, stats);
	EmbeddedChannel channel = new EmbeddedChannel(getFrameDecoder(), handler);

	int numKeyGroups = 1;
	AbstractStateBackend abstractBackend = new MemoryStateBackend();
	DummyEnvironment dummyEnv = new DummyEnvironment("test", 1, 0);
	dummyEnv.setKvStateRegistry(registry);
	AbstractKeyedStateBackend<Integer> backend = abstractBackend.createKeyedStateBackend(
			dummyEnv,
			new JobID(),
			"test_op",
			IntSerializer.INSTANCE,
			numKeyGroups,
			new KeyGroupRange(0, 0),
			registry.createTaskRegistry(dummyEnv.getJobID(), dummyEnv.getJobVertexId()));

	final TestRegistryListener registryListener = new TestRegistryListener();
	registry.registerListener(registryListener);

	// Register state
	ValueStateDescriptor<byte[]> desc = new ValueStateDescriptor<>("any", BytePrimitiveArraySerializer.INSTANCE);
	desc.setQueryable("vanilla");

	ValueState<byte[]> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE,
			desc);

	// Update KvState
	byte[] bytes = new byte[2 * channel.config().getWriteBufferHighWaterMark()];

	byte current = 0;
	for (int i = 0; i < bytes.length; i++) {
		bytes[i] = current++;
	}

	int key = 99812822;
	backend.setCurrentKey(key);
	state.update(bytes);

	// Request
	byte[] serializedKeyAndNamespace = KvStateSerializer.serializeKeyAndNamespace(
			key,
			IntSerializer.INSTANCE,
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE);

	long requestId = Integer.MAX_VALUE + 182828L;

	assertTrue(registryListener.registrationName.equals("vanilla"));

	KvStateInternalRequest request = new KvStateInternalRequest(registryListener.kvStateId, serializedKeyAndNamespace);
	ByteBuf serRequest = MessageSerializer.serializeRequest(channel.alloc(), requestId, request);

	// Write the request and wait for the response
	channel.writeInbound(serRequest);

	Object msg = readInboundBlocking(channel);
	assertTrue("Not ChunkedByteBuf", msg instanceof ChunkedByteBuf);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:72,代码来源:KvStateServerHandlerTest.java


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