Java Code Examples for org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider#getStream()

The following examples show how to use org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider#getStream() . 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: StateInitializationContextImplTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void getKeyedStateStreams() throws Exception {

	int readKeyGroupCount = 0;

	for (KeyGroupStatePartitionStreamProvider stateStreamProvider
			: initializationContext.getRawKeyedStateInputs()) {

		Assert.assertNotNull(stateStreamProvider);

		try (InputStream is = stateStreamProvider.getStream()) {
			DataInputView div = new DataInputViewStreamWrapper(is);
			int val = div.readInt();
			++readKeyGroupCount;
			Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
		}
	}

	Assert.assertEquals(writtenKeyGroups, readKeyGroupCount);
}
 
Example 2
Source File: StateInitializationContextImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void getKeyedStateStreams() throws Exception {

	int readKeyGroupCount = 0;

	for (KeyGroupStatePartitionStreamProvider stateStreamProvider
			: initializationContext.getRawKeyedStateInputs()) {

		Assert.assertNotNull(stateStreamProvider);

		try (InputStream is = stateStreamProvider.getStream()) {
			DataInputView div = new DataInputViewStreamWrapper(is);
			int val = div.readInt();
			++readKeyGroupCount;
			Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
		}
	}

	Assert.assertEquals(writtenKeyGroups, readKeyGroupCount);
}
 
Example 3
Source File: StateInitializationContextImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void getKeyedStateStreams() throws Exception {

	int readKeyGroupCount = 0;

	for (KeyGroupStatePartitionStreamProvider stateStreamProvider
			: initializationContext.getRawKeyedStateInputs()) {

		Assert.assertNotNull(stateStreamProvider);

		try (InputStream is = stateStreamProvider.getStream()) {
			DataInputView div = new DataInputViewStreamWrapper(is);
			int val = div.readInt();
			++readKeyGroupCount;
			Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
		}
	}

	Assert.assertEquals(writtenKeyGroups, readKeyGroupCount);
}
 
Example 4
Source File: StateInitializationContextImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void close() throws Exception {

	int count = 0;
	int stopCount = NUM_HANDLES / 2;
	boolean isClosed = false;

	try {
		for (KeyGroupStatePartitionStreamProvider stateStreamProvider
				: initializationContext.getRawKeyedStateInputs()) {
			Assert.assertNotNull(stateStreamProvider);

			if (count == stopCount) {
				closableRegistry.close();
				isClosed = true;
			}

			try (InputStream is = stateStreamProvider.getStream()) {
				DataInputView div = new DataInputViewStreamWrapper(is);
				try {
					int val = div.readInt();
					Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
					if (isClosed) {
						Assert.fail("Close was ignored: stream");
					}
					++count;
				} catch (IOException ioex) {
					if (!isClosed) {
						throw ioex;
					}
				}
			}
		}
		Assert.fail("Close was ignored: registry");
	} catch (IOException iex) {
		Assert.assertTrue(isClosed);
		Assert.assertEquals(stopCount, count);
	}

}
 
Example 5
Source File: StateInitializationContextImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void close() throws Exception {

	int count = 0;
	int stopCount = NUM_HANDLES / 2;
	boolean isClosed = false;

	try {
		for (KeyGroupStatePartitionStreamProvider stateStreamProvider
				: initializationContext.getRawKeyedStateInputs()) {
			Assert.assertNotNull(stateStreamProvider);

			if (count == stopCount) {
				closableRegistry.close();
				isClosed = true;
			}

			try (InputStream is = stateStreamProvider.getStream()) {
				DataInputView div = new DataInputViewStreamWrapper(is);
				try {
					int val = div.readInt();
					Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
					if (isClosed) {
						Assert.fail("Close was ignored: stream");
					}
					++count;
				} catch (IOException ioex) {
					if (!isClosed) {
						throw ioex;
					}
				}
			}
		}
		Assert.fail("Close was ignored: registry");
	} catch (IOException iex) {
		Assert.assertTrue(isClosed);
		Assert.assertEquals(stopCount, count);
	}

}
 
Example 6
Source File: StateInitializationContextImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void close() throws Exception {

	int count = 0;
	int stopCount = NUM_HANDLES / 2;
	boolean isClosed = false;

	try {
		for (KeyGroupStatePartitionStreamProvider stateStreamProvider
				: initializationContext.getRawKeyedStateInputs()) {
			Assert.assertNotNull(stateStreamProvider);

			if (count == stopCount) {
				closableRegistry.close();
				isClosed = true;
			}

			try (InputStream is = stateStreamProvider.getStream()) {
				DataInputView div = new DataInputViewStreamWrapper(is);
				try {
					int val = div.readInt();
					Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
					if (isClosed) {
						Assert.fail("Close was ignored: stream");
					}
					++count;
				} catch (IOException ioex) {
					if (!isClosed) {
						throw ioex;
					}
				}
			}
		}
		Assert.fail("Close was ignored: registry");
	} catch (IOException iex) {
		Assert.assertTrue(isClosed);
		Assert.assertEquals(stopCount, count);
	}

}