Java Code Examples for org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups#UnregisteredTaskMetricGroup

The following examples show how to use org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups#UnregisteredTaskMetricGroup . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OneInputStreamTaskTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {
	final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator())
		.chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.finish();

	final TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	final StreamMockEnvironment env = new StreamMockEnvironment(
		testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
		@Override
		public TaskMetricGroup getMetricGroup() {
			return taskMetricGroup;
		}
	};

	final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

	testHarness.invoke(env);
	testHarness.waitForTaskRunning();

	final int numRecords = 5;

	for (int x = 0; x < numRecords; x++) {
		testHarness.processElement(new StreamRecord<>("hello"));
	}
	testHarness.waitForInputProcessing();

	assertEquals(numRecords, numRecordsInCounter.getCount());
	assertEquals(numRecords * 2 * 2 * 2, numRecordsOutCounter.getCount());

	testHarness.endInput();
	testHarness.waitForTaskCompletion();
}
 
Example 2
Source File: TwoInputStreamTaskTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {
	final TwoInputStreamTaskTestHarness<String, String, String> testHarness = new TwoInputStreamTaskTestHarness<>(TwoInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator())
		.chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.finish();

	final TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	final StreamMockEnvironment env = new StreamMockEnvironment(
		testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
		@Override
		public TaskMetricGroup getMetricGroup() {
			return taskMetricGroup;
		}
	};

	final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

	testHarness.invoke(env);
	testHarness.waitForTaskRunning();

	final int numRecords1 = 5;
	final int numRecords2 = 3;

	for (int x = 0; x < numRecords1; x++) {
		testHarness.processElement(new StreamRecord<>("hello"), 0, 0);
	}

	for (int x = 0; x < numRecords2; x++) {
		testHarness.processElement(new StreamRecord<>("hello"), 1, 0);
	}
	testHarness.waitForInputProcessing();

	assertEquals(numRecords1 + numRecords2, numRecordsInCounter.getCount());
	assertEquals((numRecords1 + numRecords2) * 2 * 2 * 2, numRecordsOutCounter.getCount());

	testHarness.endInput();
	testHarness.waitForTaskCompletion();
}
 
Example 3
Source File: OneInputStreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {
	final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator())
		.chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.finish();

	final TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	final StreamMockEnvironment env = new StreamMockEnvironment(
		testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
		@Override
		public TaskMetricGroup getMetricGroup() {
			return taskMetricGroup;
		}
	};

	final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

	testHarness.invoke(env);
	testHarness.waitForTaskRunning();

	final int numRecords = 5;

	for (int x = 0; x < numRecords; x++) {
		testHarness.processElement(new StreamRecord<>("hello"));
	}
	testHarness.waitForInputProcessing();

	assertEquals(numRecords, numRecordsInCounter.getCount());
	assertEquals(numRecords * 2 * 2 * 2, numRecordsOutCounter.getCount());

	testHarness.endInput();
	testHarness.waitForTaskCompletion();
}
 
Example 4
Source File: TwoInputStreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {
	final TwoInputStreamTaskTestHarness<String, String, String> testHarness = new TwoInputStreamTaskTestHarness<>(
		isInputSelectable ? TwoInputSelectableStreamTask::new : TwoInputStreamTask::new,
		BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator())
		.chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.finish();

	final TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	final StreamMockEnvironment env = new StreamMockEnvironment(
		testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
		@Override
		public TaskMetricGroup getMetricGroup() {
			return taskMetricGroup;
		}
	};

	final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

	testHarness.invoke(env);
	testHarness.waitForTaskRunning();

	final int numRecords1 = 5;
	final int numRecords2 = 3;

	for (int x = 0; x < numRecords1; x++) {
		testHarness.processElement(new StreamRecord<>("hello"), 0, 0);
	}

	for (int x = 0; x < numRecords2; x++) {
		testHarness.processElement(new StreamRecord<>("hello"), 1, 0);
	}
	testHarness.waitForInputProcessing();

	assertEquals(numRecords1 + numRecords2, numRecordsInCounter.getCount());
	assertEquals((numRecords1 + numRecords2) * 2 * 2 * 2, numRecordsOutCounter.getCount());

	testHarness.endInput();
	testHarness.waitForTaskCompletion();
}
 
Example 5
Source File: OneInputStreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {
	final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator())
		.chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.finish();

	final TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	final StreamMockEnvironment env = new StreamMockEnvironment(
		testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
		@Override
		public TaskMetricGroup getMetricGroup() {
			return taskMetricGroup;
		}
	};

	final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

	testHarness.invoke(env);
	testHarness.waitForTaskRunning();

	final int numRecords = 5;

	for (int x = 0; x < numRecords; x++) {
		testHarness.processElement(new StreamRecord<>("hello"));
	}
	testHarness.waitForInputProcessing();

	assertEquals(numRecords, numRecordsInCounter.getCount());
	assertEquals(numRecords * 2 * 2 * 2, numRecordsOutCounter.getCount());

	testHarness.endInput();
	testHarness.waitForTaskCompletion();
}
 
Example 6
Source File: TwoInputStreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {
	final TwoInputStreamTaskTestHarness<String, String, String> testHarness = new TwoInputStreamTaskTestHarness<>(
		TwoInputStreamTask::new,
		BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator())
		.chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
		.finish();

	final TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	final StreamMockEnvironment env = new StreamMockEnvironment(
		testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
		@Override
		public TaskMetricGroup getMetricGroup() {
			return taskMetricGroup;
		}
	};

	final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

	testHarness.invoke(env);
	testHarness.waitForTaskRunning();

	final int numRecords1 = 5;
	final int numRecords2 = 3;

	for (int x = 0; x < numRecords1; x++) {
		testHarness.processElement(new StreamRecord<>("hello"), 0, 0);
	}

	for (int x = 0; x < numRecords2; x++) {
		testHarness.processElement(new StreamRecord<>("hello"), 1, 0);
	}
	testHarness.waitForInputProcessing();

	assertEquals(numRecords1 + numRecords2, numRecordsInCounter.getCount());
	assertEquals((numRecords1 + numRecords2) * 2 * 2 * 2, numRecordsOutCounter.getCount());

	testHarness.endInput();
	testHarness.waitForTaskCompletion();
}
 
Example 7
Source File: MultipleInputStreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testOperatorMetricReuse() throws Exception {

	TaskMetricGroup taskMetricGroup = new UnregisteredMetricGroups.UnregisteredTaskMetricGroup() {
		@Override
		public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
			return new OperatorMetricGroup(NoOpMetricRegistry.INSTANCE, this, operatorID, name);
		}
	};

	try (StreamTaskMailboxTestHarness<String> testHarness =
		new MultipleInputStreamTaskTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO)
			.addInput(BasicTypeInfo.STRING_TYPE_INFO)
			.addInput(BasicTypeInfo.STRING_TYPE_INFO)
			.addInput(BasicTypeInfo.STRING_TYPE_INFO)
			.setupOperatorChain(new DuplicatingOperatorFactory())
			.chain(new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
			.chain(new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()))
			.finish()
			.setTaskMetricGroup(taskMetricGroup)
			.build()) {
		Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
		Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();

		int numRecords1 = 5;
		int numRecords2 = 3;
		int numRecords3 = 2;
		for (int x = 0; x < numRecords1; x++) {
			testHarness.processElement(new StreamRecord<>("hello"), 0, 0);
		}
		for (int x = 0; x < numRecords2; x++) {
			testHarness.processElement(new StreamRecord<>("hello"), 1, 0);
		}
		for (int x = 0; x < numRecords3; x++) {
			testHarness.processElement(new StreamRecord<>("hello"), 2, 0);
		}

		int totalRecords = numRecords1 + numRecords2 + numRecords3;
		assertEquals(totalRecords, numRecordsInCounter.getCount());
		assertEquals((totalRecords) * 2 * 2 * 2, numRecordsOutCounter.getCount());
		testHarness.waitForTaskCompletion();
	}
}