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


Java DummyEnvironment类代码示例

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


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

示例1: createStateInternals

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
@Override
protected StateInternals createStateInternals() {
  MemoryStateBackend backend = new MemoryStateBackend();
  try {
    AbstractKeyedStateBackend<ByteBuffer> keyedStateBackend = backend.createKeyedStateBackend(
        new DummyEnvironment("test", 1, 0),
        new JobID(),
        "test_op",
        new GenericTypeInfo<>(ByteBuffer.class).createSerializer(new ExecutionConfig()),
        1,
        new KeyGroupRange(0, 0),
        new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));

    keyedStateBackend.setCurrentKey(
        ByteBuffer.wrap(CoderUtils.encodeToByteArray(StringUtf8Coder.of(), "Hello")));

    return new FlinkStateInternals<>(keyedStateBackend, StringUtf8Coder.of());
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:FlinkStateInternalsTest.java

示例2: getKeyedStateBackend

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
private static KeyedStateBackend<ByteBuffer> getKeyedStateBackend(int numberOfKeyGroups,
                                                 KeyGroupRange keyGroupRange) {
  MemoryStateBackend backend = new MemoryStateBackend();
  try {
    AbstractKeyedStateBackend<ByteBuffer> keyedStateBackend = backend.createKeyedStateBackend(
        new DummyEnvironment("test", 1, 0),
        new JobID(),
        "test_op",
        new GenericTypeInfo<>(ByteBuffer.class).createSerializer(new ExecutionConfig()),
        numberOfKeyGroups,
        keyGroupRange,
        new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
    keyedStateBackend.setCurrentKey(ByteBuffer.wrap(
        CoderUtils.encodeToByteArray(StringUtf8Coder.of(), "1")));
    return keyedStateBackend;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:FlinkKeyGroupStateInternalsTest.java

示例3: validateSupportForAsyncSnapshots

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
private void validateSupportForAsyncSnapshots(AbstractStateBackend backend) throws IOException {

		AbstractKeyedStateBackend<Integer> keyedStateBackend = backend.createKeyedStateBackend(
			new DummyEnvironment("Test", 1, 0),
			new JobID(),
			"testOperator",
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			null
		);

		try {
			Assert.assertTrue(keyedStateBackend.supportsAsynchronousSnapshots());
		} finally {
			IOUtils.closeQuietly(keyedStateBackend);
			keyedStateBackend.dispose();
		}
	}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:HeapKeyedStateBackendAsyncByDefaultTest.java

示例4: createStateInternals

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
@Override
protected StateInternals createStateInternals() {
  MemoryStateBackend backend = new MemoryStateBackend();
  try {
    OperatorStateBackend operatorStateBackend =
        backend.createOperatorStateBackend(new DummyEnvironment("test", 1, 0), "");
    return new FlinkSplitStateInternals<>(operatorStateBackend);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:FlinkSplitStateInternalsTest.java

示例5: createStateInternals

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
@Override
protected StateInternals createStateInternals() {
  MemoryStateBackend backend = new MemoryStateBackend();
  try {
    OperatorStateBackend operatorStateBackend =
        backend.createOperatorStateBackend(new DummyEnvironment("test", 1, 0), "");
    return new FlinkBroadcastStateInternals<>(1, operatorStateBackend);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:FlinkBroadcastStateInternalsTest.java

示例6: createKeyedBackend

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
private static RocksDBKeyedStateBackend<String> createKeyedBackend(RocksDBStateBackend backend) throws Exception {
	RocksDBKeyedStateBackend<String> keyedBackend = (RocksDBKeyedStateBackend<String>) backend.createKeyedStateBackend(
			new DummyEnvironment("TestTask", 1, 0),
			new JobID(),
			"test-op",
			StringSerializer.INSTANCE,
			16,
			new KeyGroupRange(2, 3),
			mock(TaskKvStateRegistry.class));

	keyedBackend.restore(null);

	return keyedBackend;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:15,代码来源:RocksDBReducingStateTest.java

示例7: createMapPlainMockOp

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static AbstractStreamOperator<?> createMapPlainMockOp() throws Exception {

	AbstractStreamOperator<?> operatorMock = mock(AbstractStreamOperator.class);
	ExecutionConfig config = new ExecutionConfig();

	KeyedStateBackend keyedStateBackend = mock(KeyedStateBackend.class);

	DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, config);

	when(operatorMock.getExecutionConfig()).thenReturn(config);

	doAnswer(new Answer<MapState<Integer, String>>() {

		@Override
		public MapState<Integer, String> answer(InvocationOnMock invocationOnMock) throws Throwable {
			MapStateDescriptor<Integer, String> descr =
					(MapStateDescriptor<Integer, String>) invocationOnMock.getArguments()[2];

			AbstractKeyedStateBackend<Integer> backend = new MemoryStateBackend().createKeyedStateBackend(
					new DummyEnvironment("test_task", 1, 0),
					new JobID(),
					"test_op",
					IntSerializer.INSTANCE,
					1,
					new KeyGroupRange(0, 0),
					new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
			backend.setCurrentKey(0);
			return backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, descr);
		}
	}).when(keyedStateBackend).getPartitionedState(Matchers.any(), any(TypeSerializer.class), any(MapStateDescriptor.class));

	when(operatorMock.getKeyedStateStore()).thenReturn(keyedStateStore);
	return operatorMock;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:StreamingRuntimeContextTest.java

示例8: testStop

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
@Test
public void testStop() {
	final StoppableSourceStreamTask<Object, StoppableSource> sourceTask =
			new StoppableSourceStreamTask<>(new DummyEnvironment("test", 1, 0), null);

	sourceTask.headOperator = new StoppableStreamSource<>(new StoppableSource());

	sourceTask.stop();

	assertTrue(stopped);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:SourceStreamTaskStoppingTest.java

示例9: testStopBeforeInitialization

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
@Test
public void testStopBeforeInitialization() throws Exception {

	final StoppableSourceStreamTask<Object, StoppableFailingSource> sourceTask =
			new StoppableSourceStreamTask<>(new DummyEnvironment("test", 1, 0), null);
	sourceTask.stop();

	sourceTask.headOperator = new StoppableStreamSource<>(new StoppableFailingSource());
	sourceTask.run();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:11,代码来源:SourceStreamTaskStoppingTest.java

示例10: TriggerTestHarness

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
public TriggerTestHarness(
		Trigger<T, W> trigger,
		TypeSerializer<W> windowSerializer) throws Exception {
	this.trigger = trigger;
	this.windowSerializer = windowSerializer;

	// we only ever use one key, other tests make sure that windows work across different
	// keys
	DummyEnvironment dummyEnv = new DummyEnvironment("test", 1, 0);
	MemoryStateBackend backend = new MemoryStateBackend();

	@SuppressWarnings("unchecked")
	HeapKeyedStateBackend<Integer> stateBackend = (HeapKeyedStateBackend<Integer>) backend.createKeyedStateBackend(dummyEnv,
			new JobID(),
			"test_op",
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
	this.stateBackend = stateBackend;

	this.stateBackend.setCurrentKey(KEY);

	this.internalTimerService = new TestInternalTimerService<>(new KeyContext() {
		@Override
		public void setCurrentKey(Object key) {
			// ignore
		}

		@Override
		public Object getCurrentKey() {
			return KEY;
		}
	});
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:TriggerTestHarness.java

示例11: createKeyedBackend

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
private static RocksDBKeyedStateBackend<String> createKeyedBackend(RocksDBStateBackend backend) throws Exception {
	RocksDBKeyedStateBackend<String> keyedBackend = (RocksDBKeyedStateBackend<String>) backend.createKeyedStateBackend(
					new DummyEnvironment("TestTask", 1, 0),
					new JobID(),
					"test-op",
					StringSerializer.INSTANCE,
					16,
					new KeyGroupRange(2, 3),
					mock(TaskKvStateRegistry.class));

	keyedBackend.restore(null);

	return keyedBackend;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:15,代码来源:RocksDBAggregatingStateTest.java

示例12: testCleanupOfSnapshotsInFailureCase

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
/**
 * Test that the snapshot files are cleaned up in case of a failure during the snapshot
 * procedure.
 */
@Test
public void testCleanupOfSnapshotsInFailureCase() throws Exception {
	long checkpointId = 1L;
	long timestamp = 42L;

	Environment env = new DummyEnvironment("test task", 1, 0);

	CheckpointStreamFactory.CheckpointStateOutputStream outputStream = mock(CheckpointStreamFactory.CheckpointStateOutputStream.class);
	CheckpointStreamFactory checkpointStreamFactory = mock(CheckpointStreamFactory.class);
	AbstractStateBackend stateBackend = mock(AbstractStateBackend.class);

	final IOException testException = new IOException("Test exception");

	doReturn(checkpointStreamFactory).when(stateBackend).createStreamFactory(any(JobID.class), anyString());
	doThrow(testException).when(outputStream).write(anyInt());
	doReturn(outputStream).when(checkpointStreamFactory).createCheckpointStateOutputStream(eq(checkpointId), eq(timestamp));

	RocksDBStateBackend backend = new RocksDBStateBackend(stateBackend);

	backend.setDbStoragePath(temporaryFolder.newFolder().toURI().toString());

	AbstractKeyedStateBackend<Void> keyedStateBackend = backend.createKeyedStateBackend(
		env,
		new JobID(),
		"test operator",
		VoidSerializer.INSTANCE,
		1,
		new KeyGroupRange(0, 0),
		null);

	try {

		keyedStateBackend.restore(null);

		// register a state so that the state backend has to checkpoint something
		keyedStateBackend.getPartitionedState(
			"namespace",
			StringSerializer.INSTANCE,
			new ValueStateDescriptor<>("foobar", String.class));

		RunnableFuture<KeyedStateHandle> snapshotFuture = keyedStateBackend.snapshot(
			checkpointId, timestamp, checkpointStreamFactory, CheckpointOptions.forCheckpoint());

		try {
			FutureUtil.runIfNotDoneAndGet(snapshotFuture);
			fail("Expected an exception to be thrown here.");
		} catch (ExecutionException e) {
			Assert.assertEquals(testException, e.getCause());
		}

		verify(outputStream).close();
	} finally {
		IOUtils.closeQuietly(keyedStateBackend);
		keyedStateBackend.dispose();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:61,代码来源:RocksDBAsyncSnapshotTest.java

示例13: testQueryUnknownKey

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
/**
 * Tests the failure response with {@link UnknownKeyOrNamespace} as cause
 * on queries for non-existing keys.
 */
@Test
public void testQueryUnknownKey() throws Exception {
	KvStateRegistry registry = new KvStateRegistry();
	AtomicKvStateRequestStats 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);
	KeyedStateBackend<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<Integer> desc = new ValueStateDescriptor<>("any", IntSerializer.INSTANCE);
	desc.setQueryable("vanilla");

	backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc);

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

	long requestId = Integer.MAX_VALUE + 22982L;

	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);

	ByteBuf buf = (ByteBuf) readInboundBlocking(channel);
	buf.skipBytes(4); // skip frame length

	// Verify the response
	assertEquals(KvStateRequestType.REQUEST_FAILURE, KvStateRequestSerializer.deserializeHeader(buf));
	KvStateRequestFailure response = KvStateRequestSerializer.deserializeKvStateRequestFailure(buf);

	assertEquals(requestId, response.getRequestId());

	assertTrue("Did not respond with expected failure cause", response.getCause() instanceof UnknownKeyOrNamespace);

	assertEquals(1, stats.getNumRequests());
	assertEquals(1, stats.getNumFailed());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:68,代码来源:KvStateServerHandlerTest.java

示例14: testQueryExecutorShutDown

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的package包/类
/**
 * Tests the failure response on a rejected execution, because the query
 * executor has been closed.
 */
@Test
public void testQueryExecutorShutDown() throws Exception {
	KvStateRegistry registry = new KvStateRegistry();
	AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();

	ExecutorService closedExecutor = Executors.newSingleThreadExecutor();
	closedExecutor.shutdown();
	assertTrue(closedExecutor.isShutdown());

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

	int numKeyGroups = 1;
	AbstractStateBackend abstractBackend = new MemoryStateBackend();
	DummyEnvironment dummyEnv = new DummyEnvironment("test", 1, 0);
	dummyEnv.setKvStateRegistry(registry);
	KeyedStateBackend<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<Integer> desc = new ValueStateDescriptor<>("any", IntSerializer.INSTANCE);
	desc.setQueryable("vanilla");

	backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc);

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

	ByteBuf request = KvStateRequestSerializer.serializeKvStateRequest(
			channel.alloc(),
			282872,
			registryListener.kvStateId,
			new byte[0]);

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

	ByteBuf buf = (ByteBuf) readInboundBlocking(channel);
	buf.skipBytes(4); // skip frame length

	// Verify the response
	assertEquals(KvStateRequestType.REQUEST_FAILURE, KvStateRequestSerializer.deserializeHeader(buf));
	KvStateRequestFailure response = KvStateRequestSerializer.deserializeKvStateRequestFailure(buf);

	assertTrue(response.getCause().getMessage().contains("RejectedExecutionException"));

	assertEquals(1, stats.getNumRequests());
	assertEquals(1, stats.getNumFailed());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:62,代码来源:KvStateServerHandlerTest.java

示例15: testChunkedResponse

import org.apache.flink.runtime.operators.testutils.DummyEnvironment; //导入依赖的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


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