Java Code Examples for org.apache.flink.api.common.state.ListState#addAll()

The following examples show how to use org.apache.flink.api.common.state.ListState#addAll() . 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: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null}.
 */
@Test
public void testListStateAddAllNull() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);
		state.addAll(null);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 2
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null}.
 */
@Test
public void testListStateAddAllNull() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);
		state.addAll(null);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 3
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null}.
 */
@Test
public void testListStateAddAllNull() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);
		state.addAll(null);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 4
Source File: AsyncWaitOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void snapshotState(StateSnapshotContext context) throws Exception {
	super.snapshotState(context);

	ListState<StreamElement> partitionableState =
		getOperatorStateBackend().getListState(new ListStateDescriptor<>(STATE_NAME, inStreamElementSerializer));
	partitionableState.clear();

	try {
		partitionableState.addAll(queue.values());
	} catch (Exception e) {
		partitionableState.clear();

		throw new Exception("Could not add stream element queue entries to operator state " +
			"backend of operator " + getOperatorName() + '.', e);
	}
}
 
Example 5
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null} entries in the list of entries
 * to add.
 */
@Test
public void testListStateAddAllNullEntries() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);

		List<Long> adding = new ArrayList<>();
		adding.add(3L);
		adding.add(null);
		adding.add(5L);
		state.addAll(adding);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 6
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null} entries in the list of entries
 * to add.
 */
@Test
public void testListStateAddAllNullEntries() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);

		List<Long> adding = new ArrayList<>();
		adding.add(3L);
		adding.add(null);
		adding.add(5L);
		state.addAll(adding);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 7
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null} entries in the list of entries
 * to add.
 */
@Test
public void testListStateAddAllNullEntries() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);

		List<Long> adding = new ArrayList<>();
		adding.add(3L);
		adding.add(null);
		adding.add(5L);
		state.addAll(adding);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 8
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testListStateAPIs() throws Exception {

	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());
		state.add(17L);
		state.add(11L);
		assertThat(state.get(), containsInAnyOrder(17L, 11L));
		// update(emptyList) should remain the value null
		state.update(Collections.emptyList());
		assertNull(state.get());
		state.update(Arrays.asList(10L, 16L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertNull(state.get());
		assertNull(state.get());
		state.addAll(Collections.emptyList());
		assertNull(state.get());
		state.addAll(Arrays.asList(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));

		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.update(Arrays.asList(1L, 2L));
		assertThat(state.get(), containsInAnyOrder(1L, 2L));

		keyedBackend.setCurrentKey("def");
		assertThat(state.get(), containsInAnyOrder(10L, 16L));
		state.clear();
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		state.add(3L);
		state.add(2L);
		state.add(1L);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertThat(state.get(), containsInAnyOrder(1L, 2L, 3L, 2L, 1L));
		state.update(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(5L, 6L));
		state.clear();

		// make sure all lists / maps are cleared
		assertThat("State backend is not empty.", keyedBackend.numKeyValueStateEntries(), is(0));
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 9
Source File: BucketsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testMergeAtScaleInAndMaxCounterAtRecovery() throws Exception {
	final File outDir = TEMP_FOLDER.newFolder();
	final Path path = new Path(outDir.toURI());

	final RollingPolicy<String, String> onCheckpointRP =
			DefaultRollingPolicy
					.create()
					.withMaxPartSize(7L) // roll with 2 elements
					.build();

	final MockListState<byte[]> bucketStateContainerOne = new MockListState<>();
	final MockListState<byte[]> bucketStateContainerTwo = new MockListState<>();

	final MockListState<Long> partCounterContainerOne = new MockListState<>();
	final MockListState<Long> partCounterContainerTwo = new MockListState<>();

	final Buckets<String, String> bucketsOne = createBuckets(path, onCheckpointRP, 0);
	final Buckets<String, String> bucketsTwo = createBuckets(path, onCheckpointRP, 1);

	bucketsOne.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
	bucketsOne.snapshotState(0L, bucketStateContainerOne, partCounterContainerOne);

	Assert.assertEquals(1L, bucketsOne.getMaxPartCounter());

	// make sure we have one in-progress file here
	Assert.assertNotNull(bucketsOne.getActiveBuckets().get("test1").getInProgressPart());

	// add a couple of in-progress files so that the part counter increases.
	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));

	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));

	bucketsTwo.snapshotState(0L, bucketStateContainerTwo, partCounterContainerTwo);

	Assert.assertEquals(2L, bucketsTwo.getMaxPartCounter());

	// make sure we have one in-progress file here and a pending
	Assert.assertEquals(1L, bucketsTwo.getActiveBuckets().get("test1").getPendingPartsPerCheckpoint().size());
	Assert.assertNotNull(bucketsTwo.getActiveBuckets().get("test1").getInProgressPart());

	final ListState<byte[]> mergedBucketStateContainer = new MockListState<>();
	final ListState<Long> mergedPartCounterContainer = new MockListState<>();

	mergedBucketStateContainer.addAll(bucketStateContainerOne.getBackingList());
	mergedBucketStateContainer.addAll(bucketStateContainerTwo.getBackingList());

	mergedPartCounterContainer.addAll(partCounterContainerOne.getBackingList());
	mergedPartCounterContainer.addAll(partCounterContainerTwo.getBackingList());

	final Buckets<String, String> restoredBuckets =
			restoreBuckets(path, onCheckpointRP, 0, mergedBucketStateContainer, mergedPartCounterContainer);

	// we get the maximum of the previous tasks
	Assert.assertEquals(2L, restoredBuckets.getMaxPartCounter());

	final Map<String, Bucket<String, String>> activeBuckets = restoredBuckets.getActiveBuckets();
	Assert.assertEquals(1L, activeBuckets.size());
	Assert.assertTrue(activeBuckets.keySet().contains("test1"));

	final Bucket<String, String> bucket = activeBuckets.get("test1");
	Assert.assertEquals("test1", bucket.getBucketId());
	Assert.assertEquals(new Path(path, "test1"), bucket.getBucketPath());

	Assert.assertNotNull(bucket.getInProgressPart()); // the restored part file

	// this is due to the Bucket#merge(). The in progress file of one
	// of the previous tasks is put in the list of pending files.
	Assert.assertEquals(1L, bucket.getPendingPartsForCurrentCheckpoint().size());

	// we commit the pending for previous checkpoints
	Assert.assertTrue(bucket.getPendingPartsPerCheckpoint().isEmpty());
}
 
Example 10
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testListStateAPIs() throws Exception {

	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());
		state.add(17L);
		state.add(11L);
		assertThat(state.get(), containsInAnyOrder(17L, 11L));
		// update(emptyList) should remain the value null
		state.update(Collections.emptyList());
		assertNull(state.get());
		state.update(Arrays.asList(10L, 16L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertNull(state.get());
		assertNull(state.get());
		state.addAll(Collections.emptyList());
		assertNull(state.get());
		state.addAll(Arrays.asList(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));

		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.update(Arrays.asList(1L, 2L));
		assertThat(state.get(), containsInAnyOrder(1L, 2L));

		keyedBackend.setCurrentKey("def");
		assertThat(state.get(), containsInAnyOrder(10L, 16L));
		state.clear();
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		state.add(3L);
		state.add(2L);
		state.add(1L);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertThat(state.get(), containsInAnyOrder(1L, 2L, 3L, 2L, 1L));
		state.update(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(5L, 6L));
		state.clear();

		// make sure all lists / maps are cleared
		assertThat("State backend is not empty.", keyedBackend.numKeyValueStateEntries(), is(0));
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 11
Source File: BucketsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMergeAtScaleInAndMaxCounterAtRecovery() throws Exception {
	final File outDir = TEMP_FOLDER.newFolder();
	final Path path = new Path(outDir.toURI());

	final RollingPolicy<String, String> onCheckpointRP =
			DefaultRollingPolicy
					.create()
					.withMaxPartSize(7L) // roll with 2 elements
					.build();

	final MockListState<byte[]> bucketStateContainerOne = new MockListState<>();
	final MockListState<byte[]> bucketStateContainerTwo = new MockListState<>();

	final MockListState<Long> partCounterContainerOne = new MockListState<>();
	final MockListState<Long> partCounterContainerTwo = new MockListState<>();

	final Buckets<String, String> bucketsOne = createBuckets(path, onCheckpointRP, 0);
	final Buckets<String, String> bucketsTwo = createBuckets(path, onCheckpointRP, 1);

	bucketsOne.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
	bucketsOne.snapshotState(0L, bucketStateContainerOne, partCounterContainerOne);

	Assert.assertEquals(1L, bucketsOne.getMaxPartCounter());

	// make sure we have one in-progress file here
	Assert.assertNotNull(bucketsOne.getActiveBuckets().get("test1").getInProgressPart());

	// add a couple of in-progress files so that the part counter increases.
	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));

	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));

	bucketsTwo.snapshotState(0L, bucketStateContainerTwo, partCounterContainerTwo);

	Assert.assertEquals(2L, bucketsTwo.getMaxPartCounter());

	// make sure we have one in-progress file here and a pending
	Assert.assertEquals(1L, bucketsTwo.getActiveBuckets().get("test1").getPendingPartsPerCheckpoint().size());
	Assert.assertNotNull(bucketsTwo.getActiveBuckets().get("test1").getInProgressPart());

	final ListState<byte[]> mergedBucketStateContainer = new MockListState<>();
	final ListState<Long> mergedPartCounterContainer = new MockListState<>();

	mergedBucketStateContainer.addAll(bucketStateContainerOne.getBackingList());
	mergedBucketStateContainer.addAll(bucketStateContainerTwo.getBackingList());

	mergedPartCounterContainer.addAll(partCounterContainerOne.getBackingList());
	mergedPartCounterContainer.addAll(partCounterContainerTwo.getBackingList());

	final Buckets<String, String> restoredBuckets =
			restoreBuckets(path, onCheckpointRP, 0, mergedBucketStateContainer, mergedPartCounterContainer);

	// we get the maximum of the previous tasks
	Assert.assertEquals(2L, restoredBuckets.getMaxPartCounter());

	final Map<String, Bucket<String, String>> activeBuckets = restoredBuckets.getActiveBuckets();
	Assert.assertEquals(1L, activeBuckets.size());
	Assert.assertTrue(activeBuckets.keySet().contains("test1"));

	final Bucket<String, String> bucket = activeBuckets.get("test1");
	Assert.assertEquals("test1", bucket.getBucketId());
	Assert.assertEquals(new Path(path, "test1"), bucket.getBucketPath());

	Assert.assertNotNull(bucket.getInProgressPart()); // the restored part file

	// this is due to the Bucket#merge(). The in progress file of one
	// of the previous tasks is put in the list of pending files.
	Assert.assertEquals(1L, bucket.getPendingPartsForCurrentCheckpoint().size());

	// we commit the pending for previous checkpoints
	Assert.assertTrue(bucket.getPendingPartsPerCheckpoint().isEmpty());
}
 
Example 12
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testListStateAPIs() throws Exception {

	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());
		state.add(17L);
		state.add(11L);
		assertThat(state.get(), containsInAnyOrder(17L, 11L));
		// update(emptyList) should remain the value null
		state.update(Collections.emptyList());
		assertNull(state.get());
		state.update(Arrays.asList(10L, 16L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertNull(state.get());
		assertNull(state.get());
		state.addAll(Collections.emptyList());
		assertNull(state.get());
		state.addAll(Arrays.asList(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));

		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.update(Arrays.asList(1L, 2L));
		assertThat(state.get(), containsInAnyOrder(1L, 2L));

		keyedBackend.setCurrentKey("def");
		assertThat(state.get(), containsInAnyOrder(10L, 16L));
		state.clear();
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		state.add(3L);
		state.add(2L);
		state.add(1L);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertThat(state.get(), containsInAnyOrder(1L, 2L, 3L, 2L, 1L));
		state.update(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(5L, 6L));
		state.clear();

		// make sure all lists / maps are cleared
		assertThat("State backend is not empty.", keyedBackend.numKeyValueStateEntries(), is(0));
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 13
Source File: BucketsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMergeAtScaleInAndMaxCounterAtRecovery() throws Exception {
	final File outDir = TEMP_FOLDER.newFolder();
	final Path path = new Path(outDir.toURI());

	final RollingPolicy<String, String> onCheckpointRP =
			DefaultRollingPolicy
					.builder()
					.withMaxPartSize(7L) // roll with 2 elements
					.build();

	final MockListState<byte[]> bucketStateContainerOne = new MockListState<>();
	final MockListState<byte[]> bucketStateContainerTwo = new MockListState<>();

	final MockListState<Long> partCounterContainerOne = new MockListState<>();
	final MockListState<Long> partCounterContainerTwo = new MockListState<>();

	final Buckets<String, String> bucketsOne = createBuckets(path, onCheckpointRP, 0);
	final Buckets<String, String> bucketsTwo = createBuckets(path, onCheckpointRP, 1);

	bucketsOne.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
	bucketsOne.snapshotState(0L, bucketStateContainerOne, partCounterContainerOne);

	Assert.assertEquals(1L, bucketsOne.getMaxPartCounter());

	// make sure we have one in-progress file here
	Assert.assertNotNull(bucketsOne.getActiveBuckets().get("test1").getInProgressPart());

	// add a couple of in-progress files so that the part counter increases.
	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));

	bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));

	bucketsTwo.snapshotState(0L, bucketStateContainerTwo, partCounterContainerTwo);

	Assert.assertEquals(2L, bucketsTwo.getMaxPartCounter());

	// make sure we have one in-progress file here and a pending
	Assert.assertEquals(1L, bucketsTwo.getActiveBuckets().get("test1").getPendingFileRecoverablesPerCheckpoint().size());
	Assert.assertNotNull(bucketsTwo.getActiveBuckets().get("test1").getInProgressPart());

	final ListState<byte[]> mergedBucketStateContainer = new MockListState<>();
	final ListState<Long> mergedPartCounterContainer = new MockListState<>();

	mergedBucketStateContainer.addAll(bucketStateContainerOne.getBackingList());
	mergedBucketStateContainer.addAll(bucketStateContainerTwo.getBackingList());

	mergedPartCounterContainer.addAll(partCounterContainerOne.getBackingList());
	mergedPartCounterContainer.addAll(partCounterContainerTwo.getBackingList());

	final Buckets<String, String> restoredBuckets =
			restoreBuckets(path, onCheckpointRP, 0, mergedBucketStateContainer, mergedPartCounterContainer);

	// we get the maximum of the previous tasks
	Assert.assertEquals(2L, restoredBuckets.getMaxPartCounter());

	final Map<String, Bucket<String, String>> activeBuckets = restoredBuckets.getActiveBuckets();
	Assert.assertEquals(1L, activeBuckets.size());
	Assert.assertTrue(activeBuckets.keySet().contains("test1"));

	final Bucket<String, String> bucket = activeBuckets.get("test1");
	Assert.assertEquals("test1", bucket.getBucketId());
	Assert.assertEquals(new Path(path, "test1"), bucket.getBucketPath());

	Assert.assertNotNull(bucket.getInProgressPart()); // the restored part file

	// this is due to the Bucket#merge(). The in progress file of one
	// of the previous tasks is put in the list of pending files.
	Assert.assertEquals(1L, bucket.getPendingFileRecoverablesForCurrentCheckpoint().size());

	// we commit the pending for previous checkpoints
	Assert.assertTrue(bucket.getPendingFileRecoverablesPerCheckpoint().isEmpty());
}